{invoiceAllowed() && (
-
}
- disableStartIcon={true}
- tabIndex={-1}
- tooltipContent="This will enable the product for the customer immediately, and redirect you to Stripe to finalize the invoice"
- isLoading={invoiceLoading}
- disabled={invoiceLoading || checkoutLoading}
- onClick={() => handleAttachClicked(true)}
- >
- Invoice Customer
-
+
+ //
}
+ // disableStartIcon={true}
+ // tabIndex={-1}
+ // tooltipContent="This will enable the product for the customer immediately, and redirect you to Stripe to finalize the invoice"
+ // isLoading={invoiceLoading}
+ // disabled={invoiceLoading || checkoutLoading}
+ // onClick={() => handleAttachClicked(true)}
+ // >
+ // Invoice Customer
+ //
)}
}
isLoading={checkoutLoading}
disabled={invoiceLoading || checkoutLoading}
- onClick={() => handleAttachClicked(false)}
+ onClick={() =>
+ handleAttachClicked({
+ useInvoice: false,
+ setLoading: setCheckoutLoading,
+ })
+ }
>
{getButtonText()}
diff --git a/vite/src/views/customers/customer/product/components/InvoiceCustomerButton.tsx b/vite/src/views/customers/customer/product/components/InvoiceCustomerButton.tsx
new file mode 100644
index 000000000..8eb952b83
--- /dev/null
+++ b/vite/src/views/customers/customer/product/components/InvoiceCustomerButton.tsx
@@ -0,0 +1,103 @@
+import FieldLabel from "@/components/general/modal-components/FieldLabel";
+import { Button } from "@/components/ui/button";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
+import { AttachBranch, AttachFunction } from "@autumn/shared";
+import { ArrowUpRightFromSquare } from "lucide-react";
+import { useState } from "react";
+
+export const InvoiceCustomerButton = ({
+ handleAttachClicked,
+ preview,
+}: {
+ handleAttachClicked: any;
+ preview?: any;
+}) => {
+ const [immediateLoading, setImmediateLoading] = useState(false);
+ const [afterPaymentLoading, setAfterPaymentLoading] = useState(false);
+ const buttonsDisabled = immediateLoading || afterPaymentLoading;
+
+ const allowedBranches = [
+ AttachBranch.New,
+ AttachBranch.MainIsTrial,
+ AttachBranch.MainIsFree,
+ AttachBranch.OneOff,
+ AttachBranch.AddOn,
+ ];
+
+ // const immediateDisabled = !allowedBranches.includes(preview?.branch);
+
+ console.log("Preview:", preview);
+
+ return (
+
+
+ }
+ disableStartIcon={true}
+ tabIndex={-1}
+ tooltipContent="This will enable the product for the customer immediately, and redirect you to Stripe to finalize the invoice"
+ >
+ Invoice Customer
+
+
+
+
+
+
Enable Product Immediately
+
+ This will enable the product for the customer immediately, and
+ redirect you to Stripe to finalize the invoice
+
+
+
+
+ {preview?.func == AttachFunction.CreateCheckout && (
+
+
+
Enable Product After Payment
+
+ This will generate an invoice link for the customer, and enable
+ the product after they pay the invoice
+
+
+
+
+ )}
+
+
+ );
+};
diff --git a/vite/src/views/customers/customer/product/components/attachProductUtils.ts b/vite/src/views/customers/customer/product/components/attachProductUtils.ts
index 0f98b5a57..767d1ed9a 100644
--- a/vite/src/views/customers/customer/product/components/attachProductUtils.ts
+++ b/vite/src/views/customers/customer/product/components/attachProductUtils.ts
@@ -13,6 +13,7 @@ export const getAttachBody = ({
entityId,
optionsInput,
useInvoice,
+ enableProductImmediately = true,
successUrl,
version,
}: {
@@ -22,6 +23,7 @@ export const getAttachBody = ({
entityId: string;
optionsInput?: FeatureOptions[];
useInvoice?: boolean;
+ enableProductImmediately?: boolean;
successUrl?: string;
version?: number;
}) => {
@@ -47,7 +49,14 @@ export const getAttachBody = ({
...customData,
free_trial: isCustom ? product.free_trial || undefined : undefined,
- invoice_only: useInvoice,
+ invoice: useInvoice,
+ enable_product_immediately: useInvoice
+ ? enableProductImmediately
+ : undefined,
+
+ force_checkout:
+ useInvoice && enableProductImmediately === false ? true : undefined,
+
success_url: successUrl,
version: version ? Number(version) : undefined,
};
diff --git a/vite/src/views/main-sidebar/org-dropdown/hooks/useMemberships.tsx b/vite/src/views/main-sidebar/org-dropdown/hooks/useMemberships.tsx
index b3fec796e..12bc96b90 100644
--- a/vite/src/views/main-sidebar/org-dropdown/hooks/useMemberships.tsx
+++ b/vite/src/views/main-sidebar/org-dropdown/hooks/useMemberships.tsx
@@ -11,31 +11,31 @@ export const useMemberships = () => {
url: "/organization/members",
});
- const { data: session } = useSession();
- const { data: orgs } = useListOrganizations();
+ // const { data: session } = useSession();
+ // const { data: orgs } = useListOrganizations();
- const handleRemovedFromOrg = async () => {
- const inOrg = orgs?.find(
- (org: any) => org.id === session?.session?.activeOrganizationId,
- );
+ // const handleRemovedFromOrg = async () => {
+ // const inOrg = orgs?.find(
+ // (org: any) => org.id === session?.session?.activeOrganizationId,
+ // );
- if (!inOrg) {
- if (orgs && orgs.length > 0) {
- await authClient.organization.setActive({
- organizationId: orgs[0].id,
- });
- } else {
- const { data, error } = await authClient.revokeSessions();
- console.log("Revoked sessions", data, error);
- }
- window.location.reload();
- }
- };
+ // if (!inOrg) {
+ // if (orgs && orgs.length > 0) {
+ // await authClient.organization.setActive({
+ // organizationId: orgs[0].id,
+ // });
+ // } else {
+ // const { data, error } = await authClient.revokeSessions();
+ // console.log("Revoked sessions", data, error);
+ // }
+ // window.location.reload();
+ // }
+ // };
- useEffect(() => {
- if (!orgs) return;
- handleRemovedFromOrg();
- }, [orgs]);
+ // useEffect(() => {
+ // if (!orgs) return;
+ // handleRemovedFromOrg();
+ // }, [orgs]);
return {
memberships: data?.memberships || [],