@nextblock-cms/ecom 0.12.12 → 0.12.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +1 -1
- package/index.d.ts +2 -0
- package/index.es.js +108 -106
- package/lib/components/Checkout.cjs.js +1 -1
- package/lib/components/Checkout.es.js +32 -33
- package/lib/components/CustomerProfileForm.cjs.js +1 -1
- package/lib/components/CustomerProfileForm.es.js +185 -238
- package/lib/components/FreemiusLicensePanel.cjs.js +1 -0
- package/lib/components/FreemiusLicensePanel.d.ts +6 -0
- package/lib/components/FreemiusLicensePanel.es.js +66 -0
- package/lib/components/InvoiceViewerShell.cjs.js +2 -2
- package/lib/components/InvoiceViewerShell.d.ts +3 -1
- package/lib/components/InvoiceViewerShell.es.js +13 -11
- package/lib/customer-orders.cjs.js +1 -1
- package/lib/customer-orders.d.ts +2 -0
- package/lib/customer-orders.es.js +30 -27
- package/lib/freemius-license-types.d.ts +19 -0
- package/lib/freemius-license.cjs.js +1 -0
- package/lib/freemius-license.d.ts +20 -0
- package/lib/freemius-license.es.js +41 -0
- package/lib/freemius-order-sync.cjs.js +1 -1
- package/lib/freemius-order-sync.es.js +62 -52
- package/lib/pages/cms/orders/types.d.ts +0 -1
- package/lib/pages/cms/products/actions.cjs.js +1 -1
- package/lib/pages/cms/products/actions.es.js +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +104 -62
- package/lib/product-actions.cjs.js +3 -3
- package/lib/product-actions.d.ts +2 -1
- package/lib/product-actions.es.js +45 -44
- package/lib/server-actions/customer-actions.cjs.js +1 -1
- package/lib/server-actions/customer-actions.d.ts +0 -1
- package/lib/server-actions/customer-actions.es.js +12 -13
- package/package.json +4 -4
- package/server.cjs.js +1 -1
- package/server.d.ts +1 -0
- package/server.es.js +77 -75
package/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("./lib/components/CartDrawer.cjs.js"),P=require("./lib/components/Cart.cjs.js"),g=require("./lib/components/Checkout.cjs.js"),y=require("./lib/components/CartIcon.cjs.js"),v=require("./lib/components/CouponForm.cjs.js"),S=require("./lib/components/CurrencySwitcher.cjs.js"),T=require("./lib/components/AddToCartButton.cjs.js"),b=require("./lib/components/ProductCard.cjs.js"),p=require("./lib/components/ProductGrid.cjs.js"),I=require("./lib/components/ProductGallery.cjs.js"),D=require("./lib/components/FeaturedProduct.cjs.js"),_=require("./lib/components/CustomerProfileForm.cjs.js"),R=require("./lib/components/SubscriptionSelector.cjs.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("./lib/components/CartDrawer.cjs.js"),P=require("./lib/components/Cart.cjs.js"),g=require("./lib/components/Checkout.cjs.js"),y=require("./lib/components/CartIcon.cjs.js"),v=require("./lib/components/CouponForm.cjs.js"),S=require("./lib/components/CurrencySwitcher.cjs.js"),T=require("./lib/components/AddToCartButton.cjs.js"),b=require("./lib/components/ProductCard.cjs.js"),p=require("./lib/components/ProductGrid.cjs.js"),I=require("./lib/components/ProductGallery.cjs.js"),D=require("./lib/components/FeaturedProduct.cjs.js"),_=require("./lib/components/CustomerProfileForm.cjs.js"),R=require("./lib/components/SubscriptionSelector.cjs.js"),F=require("./lib/components/InvoiceDocument.cjs.js"),q=require("./lib/components/InvoiceViewerShell.cjs.js"),A=require("./lib/components/FreemiusLicensePanel.cjs.js"),E=require("./lib/components/AccountNavigationMenu.cjs.js"),L=require("./lib/components/SimpleTiptapRenderer.cjs.js"),O=require("./lib/pages/cms/products/components/ProductForm.cjs.js"),f=require("./lib/pages/cms/products/components/ProductCategorySelector.cjs.js"),u=require("./lib/cart-store.cjs.js"),s=require("./lib/coupons.cjs.js"),l=require("./lib/CurrencyProvider.cjs.js"),e=require("./lib/currency.cjs.js"),z=require("./lib/currency-store.cjs.js"),d=require("./lib/use-cart.cjs.js"),a=require("./lib/customer.cjs.js"),i=require("./lib/types.cjs.js"),n=require("./lib/trials.cjs.js"),t=require("./lib/order-tax-details.cjs.js"),o=require("./lib/invoice.cjs.js"),c=require("./lib/invoice-ui.cjs.js"),V=require("./lib/product-schema.cjs.js"),m=require("./lib/product-context.cjs.js"),h=require("./lib/components/ProductDetailsLayout.cjs.js"),r=require("./lib/variation-utils.cjs.js");exports.CartDrawer=C.CartDrawer;exports.Cart=P.Cart;exports.Checkout=g.Checkout;exports.CartIcon=y.CartIcon;exports.CouponForm=v.CouponForm;exports.CurrencySwitcher=S.CurrencySwitcher;exports.AddToCartButton=T.AddToCartButton;exports.ProductCard=b.ProductCard;exports.ProductGrid=p.ProductGrid;exports.ProductGallery=I.ProductGallery;exports.FeaturedProduct=D.FeaturedProduct;exports.CustomerProfileForm=_.CustomerProfileForm;exports.SubscriptionSelector=R.SubscriptionSelector;exports.InvoiceDocument=F.InvoiceDocument;exports.InvoiceViewerShell=q.InvoiceViewerShell;exports.FreemiusLicensePanel=A.FreemiusLicensePanel;exports.AccountNavigationMenu=E.AccountNavigationMenu;exports.SimpleTiptapRenderer=L.SimpleTiptapRenderer;exports.ProductForm=O.ProductForm;exports.ProductCategorySelector=f.ProductCategorySelector;exports.getCartItemActivePrice=u.getCartItemActivePrice;exports.useCartStore=u.useCartStore;exports.useCartSubtotal=u.useCartSubtotal;exports.useCartTotalItems=u.useCartTotalItems;exports.emptyProviderDiscounts=s.emptyProviderDiscounts;exports.getCartLineCouponKey=s.getCartLineCouponKey;exports.normalizeCouponCode=s.normalizeCouponCode;exports.CurrencyProvider=l.CurrencyProvider;exports.useCurrency=l.useCurrency;exports.CURRENCY_ROUNDING_MODES=e.CURRENCY_ROUNDING_MODES;exports.applyCurrencyRounding=e.applyCurrencyRounding;exports.convertMinorUnitAmount=e.convertMinorUnitAmount;exports.describeCurrencyRoundingRule=e.describeCurrencyRoundingRule;exports.getCurrencyLookup=e.getCurrencyLookup;exports.getDefaultCurrency=e.getDefaultCurrency;exports.getExchangeRateForCurrency=e.getExchangeRateForCurrency;exports.inferCurrencyCodeFromLocale=e.inferCurrencyCodeFromLocale;exports.isSaleWindowActive=e.isSaleWindowActive;exports.isScheduledPriceDue=e.isScheduledPriceDue;exports.normalizeCurrencyRecord=e.normalizeCurrencyRecord;exports.normalizeCurrencyRoundingMode=e.normalizeCurrencyRoundingMode;exports.normalizePriceMap=e.normalizePriceMap;exports.normalizeSalePriceMap=e.normalizeSalePriceMap;exports.resolveEffectivePriceForCurrency=e.resolveEffectivePriceForCurrency;exports.resolvePriceForCurrency=e.resolvePriceForCurrency;exports.resolvePriceRangeForCurrency=e.resolvePriceRangeForCurrency;exports.sortCurrencies=e.sortCurrencies;exports.useCurrencyPreferenceStore=z.useCurrencyPreferenceStore;exports.useCart=d.useCart;exports.useIsCartHydrated=d.useIsCartHydrated;exports.addressesMatch=a.addressesMatch;exports.emptyCustomerAddress=a.emptyCustomerAddress;exports.isCustomerAddressComplete=a.isCustomerAddressComplete;exports.normalizeCustomerAddress=a.normalizeCustomerAddress;exports.normalizeOrderCustomerDetails=a.normalizeOrderCustomerDetails;exports.DEFAULT_ENABLED_PAYMENT_PROVIDERS=i.DEFAULT_ENABLED_PAYMENT_PROVIDERS;exports.derivePaymentProviderFromProductType=i.derivePaymentProviderFromProductType;exports.getProductPaymentProvider=i.getProductPaymentProvider;exports.isDigitalItem=i.isDigitalItem;exports.isDigitalProduct=i.isDigitalProduct;exports.normalizeEnabledPaymentProviders=i.normalizeEnabledPaymentProviders;exports.getTrialCheckoutMode=n.getTrialCheckoutMode;exports.getTrialLabel=n.getTrialLabel;exports.getTrialPaymentRequirementLabel=n.getTrialPaymentRequirementLabel;exports.getTrialPeriodDays=n.getTrialPeriodDays;exports.getTrialSummary=n.getTrialSummary;exports.aggregateOrderTaxLines=t.aggregateOrderTaxLines;exports.buildOrderTaxDetailsFromCalculation=t.buildOrderTaxDetailsFromCalculation;exports.buildOrderTaxDetailsFromStripeSession=t.buildOrderTaxDetailsFromStripeSession;exports.getOrderTaxRateJurisdiction=t.getOrderTaxRateJurisdiction;exports.getOrderTaxRateLabel=t.getOrderTaxRateLabel;exports.getOrderTaxRatePercentage=t.getOrderTaxRatePercentage;exports.normalizeOrderTaxDetails=t.normalizeOrderTaxDetails;exports.DEFAULT_INVOICE_SETTINGS=o.DEFAULT_INVOICE_SETTINGS;exports.INVOICE_SETTINGS_KEY=o.INVOICE_SETTINGS_KEY;exports.formatInvoiceCurrency=o.formatInvoiceCurrency;exports.formatInvoiceDate=o.formatInvoiceDate;exports.getInvoiceAddressLines=o.getInvoiceAddressLines;exports.normalizeInvoiceSettings=o.normalizeInvoiceSettings;exports.serializeInvoiceSettings=o.serializeInvoiceSettings;exports.buildInvoiceDocumentLabels=c.buildInvoiceDocumentLabels;exports.getInvoiceLocale=c.getInvoiceLocale;exports.localizeInvoicePresentationData=c.localizeInvoicePresentationData;exports.translateOrFallback=c.translateOrFallback;exports.translateOrderStatus=c.translateOrderStatus;exports.productSchema=V.productSchema;exports.ProductProvider=m.ProductProvider;exports.useProduct=m.useProduct;exports.ProductDetailsLayout=h.ProductDetailsLayout;exports.buildCombinationKey=r.buildCombinationKey;exports.buildVariantLabel=r.buildVariantLabel;exports.chooseInitialVariantSelections=r.chooseInitialVariantSelections;exports.extractSelectedTermsByAttribute=r.extractSelectedTermsByAttribute;exports.findMatchingVariant=r.findMatchingVariant;exports.generateVariantDrafts=r.generateVariantDrafts;exports.getAvailableTermIdsForAttribute=r.getAvailableTermIdsForAttribute;exports.getVariantEffectivePriceRange=r.getVariantEffectivePriceRange;exports.mapRawVariantRelations=r.mapRawVariantRelations;exports.normalizeSelectionsToAvailableVariants=r.normalizeSelectionsToAvailableVariants;exports.resolveAttributeName=r.resolveAttributeName;exports.resolveTermValue=r.resolveTermValue;exports.resolveTranslatedText=r.resolveTranslatedText;
|
package/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export * from './lib/components/CustomerProfileForm';
|
|
|
13
13
|
export * from './lib/components/SubscriptionSelector';
|
|
14
14
|
export * from './lib/components/InvoiceDocument';
|
|
15
15
|
export * from './lib/components/InvoiceViewerShell';
|
|
16
|
+
export * from './lib/components/FreemiusLicensePanel';
|
|
17
|
+
export type { FreemiusOrderLicense } from './lib/freemius-license-types';
|
|
16
18
|
export * from './lib/components/AccountNavigationMenu';
|
|
17
19
|
export * from './lib/components/SimpleTiptapRenderer';
|
|
18
20
|
export { ProductForm } from './lib/pages/cms/products/components/ProductForm';
|
package/index.es.js
CHANGED
|
@@ -13,126 +13,128 @@ import { CustomerProfileForm as D } from "./lib/components/CustomerProfileForm.e
|
|
|
13
13
|
import { SubscriptionSelector as R } from "./lib/components/SubscriptionSelector.es.js";
|
|
14
14
|
import { InvoiceDocument as E } from "./lib/components/InvoiceDocument.es.js";
|
|
15
15
|
import { InvoiceViewerShell as L } from "./lib/components/InvoiceViewerShell.es.js";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
16
|
+
import { FreemiusLicensePanel as z } from "./lib/components/FreemiusLicensePanel.es.js";
|
|
17
|
+
import { AccountNavigationMenu as N } from "./lib/components/AccountNavigationMenu.es.js";
|
|
18
|
+
import { SimpleTiptapRenderer as M } from "./lib/components/SimpleTiptapRenderer.es.js";
|
|
19
|
+
import { ProductForm as w } from "./lib/pages/cms/products/components/ProductForm.es.js";
|
|
20
|
+
import { ProductCategorySelector as U } from "./lib/pages/cms/products/components/ProductCategorySelector.es.js";
|
|
21
|
+
import { getCartItemActivePrice as B, useCartStore as K, useCartSubtotal as Y, useCartTotalItems as q } from "./lib/cart-store.es.js";
|
|
22
|
+
import { emptyProviderDiscounts as J, getCartLineCouponKey as W, normalizeCouponCode as j } from "./lib/coupons.es.js";
|
|
23
|
+
import { CurrencyProvider as X, useCurrency as Z } from "./lib/CurrencyProvider.es.js";
|
|
24
|
+
import { CURRENCY_ROUNDING_MODES as ee, applyCurrencyRounding as re, convertMinorUnitAmount as oe, describeCurrencyRoundingRule as te, getCurrencyLookup as ae, getDefaultCurrency as ie, getExchangeRateForCurrency as ne, inferCurrencyCodeFromLocale as ce, isSaleWindowActive as me, isScheduledPriceDue as ue, normalizeCurrencyRecord as le, normalizeCurrencyRoundingMode as se, normalizePriceMap as de, normalizeSalePriceMap as pe, resolveEffectivePriceForCurrency as Ce, resolvePriceForCurrency as fe, resolvePriceRangeForCurrency as xe, sortCurrencies as Pe } from "./lib/currency.es.js";
|
|
25
|
+
import { useCurrencyPreferenceStore as ye } from "./lib/currency-store.es.js";
|
|
26
|
+
import { useCart as Te, useIsCartHydrated as Se } from "./lib/use-cart.es.js";
|
|
27
|
+
import { addressesMatch as De, emptyCustomerAddress as be, isCustomerAddressComplete as Re, normalizeCustomerAddress as Ae, normalizeOrderCustomerDetails as Ee } from "./lib/customer.es.js";
|
|
28
|
+
import { DEFAULT_ENABLED_PAYMENT_PROVIDERS as Le, derivePaymentProviderFromProductType as Oe, getProductPaymentProvider as ze, isDigitalItem as Ve, isDigitalProduct as Ne, normalizeEnabledPaymentProviders as he } from "./lib/types.es.js";
|
|
29
|
+
import { getTrialCheckoutMode as _e, getTrialLabel as we, getTrialPaymentRequirementLabel as Ge, getTrialPeriodDays as Ue, getTrialSummary as ke } from "./lib/trials.es.js";
|
|
30
|
+
import { aggregateOrderTaxLines as Ke, buildOrderTaxDetailsFromCalculation as Ye, buildOrderTaxDetailsFromStripeSession as qe, getOrderTaxRateJurisdiction as He, getOrderTaxRateLabel as Je, getOrderTaxRatePercentage as We, normalizeOrderTaxDetails as je } from "./lib/order-tax-details.es.js";
|
|
31
|
+
import { DEFAULT_INVOICE_SETTINGS as Xe, INVOICE_SETTINGS_KEY as Ze, formatInvoiceCurrency as $e, formatInvoiceDate as er, getInvoiceAddressLines as rr, normalizeInvoiceSettings as or, serializeInvoiceSettings as tr } from "./lib/invoice.es.js";
|
|
32
|
+
import { buildInvoiceDocumentLabels as ir, getInvoiceLocale as nr, localizeInvoicePresentationData as cr, translateOrFallback as mr, translateOrderStatus as ur } from "./lib/invoice-ui.es.js";
|
|
33
|
+
import { productSchema as sr } from "./lib/product-schema.es.js";
|
|
34
|
+
import { ProductProvider as pr, useProduct as Cr } from "./lib/product-context.es.js";
|
|
35
|
+
import { ProductDetailsLayout as xr } from "./lib/components/ProductDetailsLayout.es.js";
|
|
36
|
+
import { buildCombinationKey as gr, buildVariantLabel as yr, chooseInitialVariantSelections as vr, extractSelectedTermsByAttribute as Tr, findMatchingVariant as Sr, generateVariantDrafts as Ir, getAvailableTermIdsForAttribute as Dr, getVariantEffectivePriceRange as br, mapRawVariantRelations as Rr, normalizeSelectionsToAvailableVariants as Ar, resolveAttributeName as Er, resolveTermValue as Fr, resolveTranslatedText as Lr } from "./lib/variation-utils.es.js";
|
|
36
37
|
export {
|
|
37
|
-
|
|
38
|
+
N as AccountNavigationMenu,
|
|
38
39
|
C as AddToCartButton,
|
|
39
|
-
|
|
40
|
+
ee as CURRENCY_ROUNDING_MODES,
|
|
40
41
|
a as Cart,
|
|
41
42
|
o as CartDrawer,
|
|
42
43
|
m as CartIcon,
|
|
43
44
|
n as Checkout,
|
|
44
45
|
l as CouponForm,
|
|
45
|
-
|
|
46
|
+
X as CurrencyProvider,
|
|
46
47
|
d as CurrencySwitcher,
|
|
47
48
|
D as CustomerProfileForm,
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
Le as DEFAULT_ENABLED_PAYMENT_PROVIDERS,
|
|
50
|
+
Xe as DEFAULT_INVOICE_SETTINGS,
|
|
50
51
|
S as FeaturedProduct,
|
|
51
|
-
|
|
52
|
+
z as FreemiusLicensePanel,
|
|
53
|
+
Ze as INVOICE_SETTINGS_KEY,
|
|
52
54
|
E as InvoiceDocument,
|
|
53
55
|
L as InvoiceViewerShell,
|
|
54
56
|
x as ProductCard,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
U as ProductCategorySelector,
|
|
58
|
+
xr as ProductDetailsLayout,
|
|
59
|
+
w as ProductForm,
|
|
58
60
|
v as ProductGallery,
|
|
59
61
|
g as ProductGrid,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
pr as ProductProvider,
|
|
63
|
+
M as SimpleTiptapRenderer,
|
|
62
64
|
R as SubscriptionSelector,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
65
|
+
De as addressesMatch,
|
|
66
|
+
Ke as aggregateOrderTaxLines,
|
|
67
|
+
re as applyCurrencyRounding,
|
|
68
|
+
gr as buildCombinationKey,
|
|
69
|
+
ir as buildInvoiceDocumentLabels,
|
|
70
|
+
Ye as buildOrderTaxDetailsFromCalculation,
|
|
71
|
+
qe as buildOrderTaxDetailsFromStripeSession,
|
|
72
|
+
yr as buildVariantLabel,
|
|
73
|
+
vr as chooseInitialVariantSelections,
|
|
74
|
+
oe as convertMinorUnitAmount,
|
|
75
|
+
Oe as derivePaymentProviderFromProductType,
|
|
76
|
+
te as describeCurrencyRoundingRule,
|
|
77
|
+
be as emptyCustomerAddress,
|
|
78
|
+
J as emptyProviderDiscounts,
|
|
79
|
+
Tr as extractSelectedTermsByAttribute,
|
|
80
|
+
Sr as findMatchingVariant,
|
|
81
|
+
$e as formatInvoiceCurrency,
|
|
82
|
+
er as formatInvoiceDate,
|
|
83
|
+
Ir as generateVariantDrafts,
|
|
84
|
+
Dr as getAvailableTermIdsForAttribute,
|
|
85
|
+
B as getCartItemActivePrice,
|
|
86
|
+
W as getCartLineCouponKey,
|
|
87
|
+
ae as getCurrencyLookup,
|
|
88
|
+
ie as getDefaultCurrency,
|
|
89
|
+
ne as getExchangeRateForCurrency,
|
|
90
|
+
rr as getInvoiceAddressLines,
|
|
91
|
+
nr as getInvoiceLocale,
|
|
92
|
+
He as getOrderTaxRateJurisdiction,
|
|
93
|
+
Je as getOrderTaxRateLabel,
|
|
94
|
+
We as getOrderTaxRatePercentage,
|
|
95
|
+
ze as getProductPaymentProvider,
|
|
96
|
+
_e as getTrialCheckoutMode,
|
|
97
|
+
we as getTrialLabel,
|
|
98
|
+
Ge as getTrialPaymentRequirementLabel,
|
|
99
|
+
Ue as getTrialPeriodDays,
|
|
100
|
+
ke as getTrialSummary,
|
|
101
|
+
br as getVariantEffectivePriceRange,
|
|
102
|
+
ce as inferCurrencyCodeFromLocale,
|
|
103
|
+
Re as isCustomerAddressComplete,
|
|
104
|
+
Ve as isDigitalItem,
|
|
105
|
+
Ne as isDigitalProduct,
|
|
106
|
+
me as isSaleWindowActive,
|
|
107
|
+
ue as isScheduledPriceDue,
|
|
108
|
+
cr as localizeInvoicePresentationData,
|
|
109
|
+
Rr as mapRawVariantRelations,
|
|
110
|
+
j as normalizeCouponCode,
|
|
111
|
+
le as normalizeCurrencyRecord,
|
|
112
|
+
se as normalizeCurrencyRoundingMode,
|
|
113
|
+
Ae as normalizeCustomerAddress,
|
|
114
|
+
he as normalizeEnabledPaymentProviders,
|
|
115
|
+
or as normalizeInvoiceSettings,
|
|
116
|
+
Ee as normalizeOrderCustomerDetails,
|
|
117
|
+
je as normalizeOrderTaxDetails,
|
|
118
|
+
de as normalizePriceMap,
|
|
119
|
+
pe as normalizeSalePriceMap,
|
|
120
|
+
Ar as normalizeSelectionsToAvailableVariants,
|
|
121
|
+
sr as productSchema,
|
|
122
|
+
Er as resolveAttributeName,
|
|
123
|
+
Ce as resolveEffectivePriceForCurrency,
|
|
124
|
+
fe as resolvePriceForCurrency,
|
|
125
|
+
xe as resolvePriceRangeForCurrency,
|
|
126
|
+
Fr as resolveTermValue,
|
|
127
|
+
Lr as resolveTranslatedText,
|
|
128
|
+
tr as serializeInvoiceSettings,
|
|
129
|
+
Pe as sortCurrencies,
|
|
130
|
+
mr as translateOrFallback,
|
|
131
|
+
ur as translateOrderStatus,
|
|
132
|
+
Te as useCart,
|
|
133
|
+
K as useCartStore,
|
|
134
|
+
Y as useCartSubtotal,
|
|
135
|
+
q as useCartTotalItems,
|
|
136
|
+
Z as useCurrency,
|
|
137
|
+
ye as useCurrencyPreferenceStore,
|
|
138
|
+
Se as useIsCartHydrated,
|
|
139
|
+
Cr as useProduct
|
|
138
140
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),qe=require("@nextblock-cms/ui/badge"),he=require("@nextblock-cms/ui/button"),x=require("@nextblock-cms/ui/card"),Ve=require("@nextblock-cms/ui/checkbox"),F=require("@nextblock-cms/ui/input"),N=require("@nextblock-cms/ui/label"),We=require("@nextblock-cms/ui/separator"),xe=require("@nextblock-cms/ui/radio-group"),Ze=require("@freemius/checkout"),_e=require("../cart-store.cjs.js"),es=require("../use-cart.cjs.js"),o=require("react"),P=require("lucide-react"),f=require("@nextblock-cms/utils"),$e=require("../countries.cjs.js"),ss=require("../server-actions/shipping-actions.cjs.js"),ts=require("../server-actions/tax-actions.cjs.js"),ge=require("../types.cjs.js"),X=require("../states.cjs.js"),B=require("../customer.cjs.js"),rs=require("../CurrencyProvider.cjs.js"),Te=require("../trials.cjs.js"),cs=require("./CouponForm.cjs.js"),ns=process.env.NEXT_PUBLIC_IS_SANDBOX==="true",ne="nextblock-checkout-draft-v1";function ie(t,j){return{...B.emptyCustomerAddress(),company_name:t?.company_name||"",recipient_name:t?.recipient_name||j||"",line1:t?.line1||"",line2:t?.line2||"",city:t?.city||"",state:t?.state||"",postal_code:t?.postal_code||"",country_code:$e.normalizeCountryCode(t?.country_code)||"CA"}}function is(t){const j=B.normalizeCustomerAddress(t);return!(!j?.country_code||!j.postal_code||X.countryUsesStructuredStates(j.country_code)&&!j.state)}function fe(t,j,I){return t.reduce((n,g)=>{const{price:h,sale_price:q}=_e.getCartItemActivePrice(g,{currencyCode:j,currencies:I});return n+(q??h)*g.quantity},0)}function Fe({idPrefix:t,title:j,description:I,value:n,onChange:g}){const{t:h}=f.useTranslations(),q=h("company_name")==="company_name"?"Company name":h("company_name"),$=h("select_an_option")==="select_an_option"?"Select an option":h("select_an_option"),Y=h("state_province")==="state_province"?"State / Province":h("state_province"),K=X.getStatesForCountry(n.country_code),H=X.countryUsesStructuredStates(n.country_code);return e.jsxs(x.Card,{children:[e.jsxs(x.CardHeader,{children:[e.jsxs(x.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(P.MapPin,{className:"w-5 h-5"}),j]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:I})]}),e.jsxs(x.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-company`,children:q}),e.jsx(F.Input,{id:`${t}-company`,value:n.company_name,onChange:a=>g({...n,company_name:a.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-name`,children:h("full_name")}),e.jsx(F.Input,{id:`${t}-name`,value:n.recipient_name,onChange:a=>g({...n,recipient_name:a.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-country`,children:h("country")}),e.jsx("select",{id:`${t}-country`,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:n.country_code,onChange:a=>{const U=a.target.value,le=X.getStatesForCountry(U);g({...n,country_code:U,state:le.some(V=>V.code===n.state)?n.state:""})},children:$e.countries.map(a=>e.jsx("option",{value:a.code,children:a.name},a.code))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-line1`,children:h("address_line_1")}),e.jsx(F.Input,{id:`${t}-line1`,value:n.line1,onChange:a=>g({...n,line1:a.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-line2`,children:h("address_line_2")}),e.jsx(F.Input,{id:`${t}-line2`,value:n.line2,onChange:a=>g({...n,line2:a.target.value})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-city`,children:h("city")}),e.jsx(F.Input,{id:`${t}-city`,value:n.city,onChange:a=>g({...n,city:a.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-state`,children:h("state_province")}),H?e.jsxs("select",{id:`${t}-state`,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:n.state,onChange:a=>g({...n,state:a.target.value}),children:[e.jsx("option",{value:"",children:`${$}: ${Y}`}),K.map(a=>e.jsx("option",{value:a.code,children:a.name},a.code))]}):e.jsx(F.Input,{id:`${t}-state`,value:n.state,onChange:a=>g({...n,state:a.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-postal`,children:h("postal_zip_code")}),e.jsx(F.Input,{id:`${t}-postal`,value:n.postal_code,onChange:a=>g({...n,postal_code:a.target.value})})]})]})]})]})}function Ie({title:t,description:j,badgeLabel:I,children:n}){return e.jsxs(x.Card,{children:[e.jsx(x.CardHeader,{children:e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx(x.CardTitle,{children:t}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:j})]}),I?e.jsx(qe.Badge,{variant:"secondary",children:I}):null]})}),e.jsx(x.CardContent,{className:"space-y-4",children:n})]})}const ls=({initialCustomer:t})=>{const[j,I]=o.useState({}),[n,g]=o.useState(null),[h,q]=o.useState({}),[$,Y]=o.useState(t?.email||""),[K,H]=o.useState(""),[a,U]=o.useState(t?.phone||""),[le,V]=o.useState(!1),[Le,je]=o.useState(null),[ye,W]=o.useState(!1),[Me,Z]=o.useState(!1),[G,ee]=o.useState([]),[y,z]=o.useState(null),[k,se]=o.useState(null),[L,Ee]=o.useState(null),[A,be]=o.useState(()=>ie(t?.billingAddress,t?.fullName)),[O,Ne]=o.useState(()=>ie(t?.shippingAddress??t?.billingAddress,t?.fullName)),[E,ve]=o.useState(!t?.shippingAddress||B.addressesMatch(t?.billingAddress,t?.shippingAddress)),J=es.useCart(s=>s),{t:c,lang:ae}=f.useTranslations(),{activeCurrencyCode:l,currencies:M}=rs.useCurrency(),b=J?.items??[],v=o.useMemo(()=>b.filter(s=>!ge.isDigitalItem(s)),[b]),C=o.useMemo(()=>b.filter(s=>ge.isDigitalItem(s)),[b]),D=t?.isAuthenticated??!1,r=(s,i,m)=>{const u=c(s,m);if(u!==s)return u;if(!m)return i;let _=i;return Object.entries(m).forEach(([p,d])=>{_=_.replace(new RegExp(`\\{${p}\\}`,"g"),String(d))}),_},S=v.length>0,De=o.useMemo(()=>fe(b,l,M),[l,M,b]),oe=o.useMemo(()=>fe(v,l,M),[l,M,v]),de=o.useMemo(()=>fe(C,l,M),[l,M,C]),ue=L?.providerDiscounts.stripe??0,me=L?.providerDiscounts.freemius??0,te=Math.max(0,oe-ue),Re=Math.max(0,de-me),w=o.useMemo(()=>E?A:O,[A,O,E]),R=o.useMemo(()=>S?w:A,[A,S,w]),re=!S||is(w),ce=o.useMemo(()=>G.find(s=>s.id===y),[G,y]),Ce=o.useMemo(()=>te+(ce?.amount??0)+(k&&!k.isPendingExternalCalculation?k.amount:0),[te,ce,k]),Be=Ce+Re;if(o.useEffect(()=>{if(!(D||typeof window>"u"))try{const s=window.localStorage.getItem(ne);if(!s)return;const i=JSON.parse(s);i.email&&Y(i.email),i.phone&&U(i.phone),i.billingAddress&&be(ie(i.billingAddress)),i.shippingAddress&&Ne(ie(i.shippingAddress)),typeof i.useBillingForShipping=="boolean"&&ve(i.useBillingForShipping),(typeof i.selectedMethodId=="string"||i.selectedMethodId===null)&&z(i.selectedMethodId)}catch(s){console.error("[Checkout] Failed to restore checkout draft:",s)}},[D]),o.useEffect(()=>{if(!(typeof window>"u")){if(D){window.localStorage.removeItem(ne);return}window.localStorage.setItem(ne,JSON.stringify({email:$,phone:a,billingAddress:A,shippingAddress:O,useBillingForShipping:E,selectedMethodId:y}))}},[A,$,D,a,y,O,E]),o.useEffect(()=>{if(!S){ee([]),z(null),W(!1);return}if(!re){ee([]),z(null),W(!1);return}let s=!1;const m=setTimeout(async()=>{if(!w.country_code)return;W(!0);const u=await ss.getShippingEstimates(te,{country:w.country_code,state:w.state,postal_code:w.postal_code},ae,l);s||(u.success&&u.methods?(ee(u.methods),u.methods.length>0&&(!y||!u.methods.find(_=>_.id===y))&&z(u.methods[0].id)):(ee([]),z(null)),W(!1))},400);return()=>{s=!0,clearTimeout(m)}},[l,S,re,ae,y,w.country_code,w.postal_code,w.state,te]),o.useEffect(()=>{const i=setTimeout(async()=>{if(!S||!R.country_code){Z(!1),se(null);return}if(X.countryUsesStructuredStates(R.country_code)&&!R.state){Z(!1),se(null);return}Z(!0);const m=await ts.getTaxEstimate(v,{country_code:R.country_code,state:R.state},l,L?.code??null,b);m.success&&m.tax?se(m.tax):se(null),Z(!1)},300);return()=>clearTimeout(i)},[l,S,v,R.country_code,R.state,L?.code,b]),!J)return null;const Se=()=>{V(!1),je(null)},ke=le?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:Se,children:e.jsxs("div",{className:"relative bg-background border rounded-xl shadow-2xl p-8 max-w-md mx-4",onClick:s=>s.stopPropagation(),children:[e.jsx("button",{onClick:Se,className:"absolute top-4 right-4 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(P.X,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-full bg-amber-100 dark:bg-amber-900/20",children:e.jsx(P.FlaskConical,{className:"h-6 w-6 text-amber-600 dark:text-amber-400"})}),e.jsx("h2",{className:"text-xl font-semibold",children:c("ecommerce.checkout_successful")})]}),e.jsx("p",{className:"text-muted-foreground mb-2",children:c("ecommerce.sandbox_notice")}),e.jsx("p",{className:"text-muted-foreground mb-2",children:Le==="stripe"?r("ecommerce.sandbox_checkout_stripe_description","This simulated step represents the Stripe checkout for physical products."):r("ecommerce.sandbox_checkout_freemius_description","This simulated step represents the Freemius checkout for digital products.")}),e.jsx("p",{className:"text-muted-foreground mb-6",children:c("ecommerce.license_notice")}),e.jsx("a",{href:"https://nextblock.ca",target:"_blank",rel:"noopener noreferrer",className:"block w-full text-center py-3 px-4 rounded-lg bg-primary text-primary-foreground font-semibold hover:opacity-90 transition-opacity",children:c("ecommerce.purchase_at")})]})}):null,ze=s=>{if(!D&&(!$||!/^\S+@\S+\.\S+$/.test($)))return H(c("ecommerce.invalid_email")),null;const i=B.normalizeCustomerAddress(A);if(!B.isCustomerAddressComplete(i))return alert(c("checkout_complete_billing_address")),null;const m=S?B.normalizeCustomerAddress(E?A:O):null;if(s==="stripe"){if(!B.isCustomerAddressComplete(m))return alert(c("checkout_complete_shipping_address")),null;if(!y)return alert(r("ecommerce.shipping_method_required","Please select a shipping method before continuing.")),null}return H(""),{normalizedBillingAddress:i,normalizedShippingAddress:m}},we=async(s,i,m)=>{q(_=>({..._,[s]:""}));const u=ze(s);if(u){if(ns){const _=new Set(i.map(d=>d.id)),p=b.filter(d=>!_.has(d.id));J.setItems(p),p.length===0&&J.removeCoupon(),je(s),V(!0),typeof window<"u"&&p.length===0&&window.localStorage.removeItem(ne);return}g(m);try{const _=await fetch("/api/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:i,customerEmail:D?void 0:$,customerPhone:a||null,billingAddress:u.normalizedBillingAddress,shippingAddress:s==="stripe"?u.normalizedShippingAddress:null,shippingMethodId:s==="stripe"?y:null,locale:ae,currencyCode:l,couponCode:L?.code??J.appliedCoupon?.code??null,couponContextItems:b})}),p=await _.json();if(!_.ok){const d=p?.errorKey&&typeof p.errorKey=="string"?r(p.errorKey,p?.error||r("ecommerce.generic_error","Something went wrong."),p.errorParams):p?.error||c("ecommerce.generic_error");q(Q=>({...Q,[s]:d})),g(null);return}if(p.customProps&&p.customProps.provider==="freemius"){const d=p.customProps;let Q=null;const Je=()=>{window.location.href=`/checkout/success?session_id=${d.order_id}`},Pe=T=>(Q||(Q=fetch("/api/checkout/freemius/sync",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({orderId:d.order_id,checkoutResponse:T})}).then(async Ae=>{if(!Ae.ok){const Ye=await Ae.json().catch(()=>null);console.error("Freemius checkout sync failed:",Ye)}})),Q),Qe={product_id:d.plugin_id,public_key:d.public_key,sandbox:d.sandbox},Xe={name:c("ecommerce.checkout_overlay_title"),plan_id:d.plan_id,...d.billing_cycle?{billing_cycle:d.billing_cycle}:{},...d.trial?{trial:d.trial}:{},...d.coupon?{coupon:d.coupon}:{},user_email:d.user_email,user_firstname:d.user_firstname,user_lastname:d.user_lastname,sandbox:d.sandbox,purchaseCompleted:function(T){Pe(T)},success:function(T){(async()=>{try{await Pe(T)}finally{Je()}})()}};try{new Ze.Checkout(Qe).open(Xe),g(null)}catch(T){alert(c("ecommerce.checkout_popup_blocked")+" "+(T.message||String(T))),p.url&&(window.location.href=p.url),g(null)}}else p.url?window.location.href=p.url:(q(d=>({...d,[s]:c("ecommerce.checkout_failed")+(p.error||r("ecommerce.unknown_error","Unknown error"))})),g(null))}catch(_){console.error(_),q(p=>({...p,[s]:c("ecommerce.generic_error")})),g(null)}}};if(b.length===0)return e.jsxs(e.Fragment,{children:[ke,e.jsxs("div",{className:"container mx-auto flex min-h-[50vh] flex-col items-center justify-center p-8 text-center",children:[e.jsx("h1",{className:"mb-4 text-2xl font-bold",children:c("ecommerce.cart_empty")}),e.jsx("p",{className:"mb-8 text-muted-foreground",children:c("ecommerce.cart_empty_description")}),e.jsx(he.Button,{asChild:!0,children:e.jsx("a",{href:"/shop",children:c("ecommerce.go_to_shop")})})]})]});const pe=S?re?ye?r("ecommerce.calculating_shipping","Calculating shipping..."):y?null:G.length>0?c("ecommerce.select_rate"):c("ecommerce.no_rates_for_region"):r("ecommerce.waiting_on_address_info","Complete your shipping address to view available shipping options."):null,Oe=n!==null||pe!==null,Ke=v.length===1?r("ecommerce.item_count_one","{count} item",{count:v.length}):r("ecommerce.item_count_other","{count} items",{count:v.length}),He=C.length===1?r("ecommerce.license_count_one","{count} license",{count:C.length}):r("ecommerce.license_count_other","{count} licenses",{count:C.length}),Ue=s=>ge.isDigitalItem(s)?r("ecommerce.digital_label","Digital"):r("ecommerce.physical_label","Physical"),Ge=s=>s==="monthly"?r("ecommerce.checkout_billing_cycle_monthly","Monthly subscription"):s==="annual"?r("ecommerce.checkout_billing_cycle_annual","Annual subscription"):s==="lifetime"?r("ecommerce.checkout_billing_cycle_lifetime","Lifetime subscription"):null;return e.jsxs("div",{className:"container mx-auto px-4 py-12 md:px-6",children:[ke,e.jsxs("div",{className:"mx-auto max-w-6xl",children:[e.jsx("h1",{className:"mb-8 text-3xl font-bold",children:c("ecommerce.checkout")}),e.jsxs("div",{className:"grid gap-8 lg:grid-cols-12 lg:items-start",children:[e.jsxs("div",{className:"lg:col-span-8 space-y-6",children:[e.jsxs(x.Card,{children:[e.jsx(x.CardHeader,{children:e.jsxs(x.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(P.CreditCard,{className:"w-5 h-5"}),c("ecommerce.contact_information")]})}),e.jsxs(x.CardContent,{className:"space-y-4",children:[D?e.jsx("div",{className:"rounded-xl border bg-muted/20 p-4 text-sm text-muted-foreground",children:c("checkout_prefill_notice",{email:t?.email||""})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs(N.Label,{htmlFor:"checkout-email",children:[c("ecommerce.email_address")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(F.Input,{id:"checkout-email",type:"email",placeholder:c("ecommerce.email_placeholder"),value:$,onChange:s=>{Y(s.target.value),K&&H("")},required:!0}),K?e.jsx("p",{className:"text-xs text-destructive mt-1",children:K}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:"checkout-phone",children:c("phone_number")}),e.jsx(F.Input,{id:"checkout-phone",placeholder:c("optional"),value:a,onChange:s=>U(s.target.value)})]})]})]}),e.jsx(Fe,{idPrefix:"billing",title:c("billing_address"),description:c("checkout_billing_address_help"),value:A,onChange:be}),S?e.jsxs("div",{className:"flex items-center space-x-3 rounded-xl border bg-muted/20 p-4",children:[e.jsx(Ve.Checkbox,{id:"use-billing-for-shipping",checked:E,onCheckedChange:s=>ve(!!s)}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(N.Label,{htmlFor:"use-billing-for-shipping",className:"cursor-pointer",children:c("use_billing_for_shipping")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c("checkout_use_billing_for_shipping_help")})]})]}):null,S&&!E?e.jsx(Fe,{idPrefix:"shipping",title:c("shipping_address"),description:c("checkout_shipping_address_help"),value:O,onChange:Ne}):null,S?e.jsxs(x.Card,{children:[e.jsx(x.CardHeader,{children:e.jsxs(x.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(P.ChevronRight,{className:"w-5 h-5 text-primary"}),c("ecommerce.shipping_method")]})}),e.jsx(x.CardContent,{children:ye?e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(P.Loader2,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):G.length>0?e.jsx("div",{className:"space-y-3",children:G.map(s=>e.jsxs("div",{onClick:()=>z(s.id),className:`flex items-center justify-between p-4 rounded-lg border-2 cursor-pointer transition-all ${y===s.id?"border-primary bg-primary/5":"border-neutral-100 hover:border-neutral-200"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-4 h-4 rounded-full border flex items-center justify-center ${y===s.id?"border-primary":"border-neutral-300"}`,children:y===s.id?e.jsx("div",{className:"w-2 h-2 rounded-full bg-primary"}):null}),e.jsx("span",{className:"font-medium",children:s.name})]}),e.jsx("span",{className:"font-bold",children:f.formatPrice(s.amount,l)})]},s.id))}):e.jsx("div",{className:"py-4 text-center text-muted-foreground bg-muted/30 rounded-lg italic",children:re?c("ecommerce.no_rates_for_region"):r("ecommerce.waiting_on_address_info","Complete your shipping address to view available shipping options.")})})]}):null]}),e.jsxs("div",{className:"lg:col-span-4 space-y-6",children:[e.jsxs(x.Card,{className:"top-6",children:[e.jsx(x.CardHeader,{children:e.jsx(x.CardTitle,{children:c("ecommerce.order_summary")})}),e.jsxs(x.CardContent,{className:"space-y-4",children:[e.jsx("div",{className:"space-y-3 max-h-[260px] overflow-y-auto pr-2",children:b.map(s=>{const i=_e.getCartItemActivePrice(s,{currencyCode:l,currencies:M}),m=Te.getTrialSummary(s);return e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex gap-3",children:[s.image_url?e.jsx("div",{className:"h-10 w-10 shrink-0 overflow-hidden rounded border bg-neutral-100",children:e.jsx("img",{src:s.image_url,alt:s.title,className:"h-full w-full object-cover"})}):null,e.jsxs("div",{className:"grid gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-xs line-clamp-1",children:s.title}),e.jsx(qe.Badge,{variant:"outline",className:"text-[9px] uppercase",children:Ue(s)})]}),s.variant_label?e.jsx("span",{className:"text-[10px] text-muted-foreground line-clamp-1",children:s.variant_label}):null,e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[c("ecommerce.qty"),": ",s.quantity]}),m?e.jsxs("span",{className:"text-[10px] font-medium text-emerald-700",children:[m.label," - ",m.paymentRequirementLabel]}):null]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-0.5 shrink-0",children:[e.jsx("span",{className:"font-medium text-xs",children:f.formatPrice((i.sale_price??i.price)*s.quantity,l)}),i.sale_price?e.jsx("span",{className:"text-[9px] text-muted-foreground line-through",children:f.formatPrice(i.price*s.quantity,l)}):null]})]},`${s.id}-${s.variant_id||"base"}`)})}),e.jsx(We.Separator,{}),e.jsx(cs.CouponForm,{items:b,currencyCode:l,onQuoteChange:Ee}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:c("ecommerce.subtotal")}),e.jsx("span",{children:f.formatPrice(De,l)})]}),v.length>0?e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:r("ecommerce.physical_products","Physical products")}),e.jsx("span",{children:f.formatPrice(oe,l)})]}):null,C.length>0?e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:r("ecommerce.digital_products","Digital products")}),e.jsx("span",{children:f.formatPrice(de,l)})]}):null,L?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsxs("span",{children:[r("ecommerce.discount","Discount")," (",L.code,")"]}),e.jsxs("span",{children:["-",f.formatPrice(L.discountTotal,l)]})]}):null,(v.length>0||C.length>0)&&e.jsxs("div",{className:"flex justify-between font-bold text-lg pt-2 border-t mt-2",children:[e.jsx("span",{children:r("ecommerce.estimated_total","Estimated total")}),e.jsx("span",{className:"text-primary",children:f.formatPrice(Be,l)})]})]})]})]}),v.length>0?e.jsxs(Ie,{title:r("ecommerce.stripe_checkout_title","Stripe Checkout"),description:r("ecommerce.stripe_checkout_description","Pay for physical products in one Stripe checkout session."),badgeLabel:Ke,children:[e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:r("ecommerce.physical_subtotal","Physical subtotal")}),e.jsx("span",{children:f.formatPrice(oe,l)})]}),ue>0?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsx("span",{children:r("ecommerce.discount","Discount")}),e.jsxs("span",{children:["-",f.formatPrice(ue,l)]})]}):null,e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:c("ecommerce.shipping")}),e.jsx("span",{children:ce?f.formatPrice(ce.amount,l):"-"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:r("ecommerce.tax","Tax")}),e.jsx("span",{children:Me?"...":k?.isPendingExternalCalculation?r("ecommerce.tax_calculated_on_stripe","Calculated on Stripe"):k?f.formatPrice(k.amount,l):"-"})]}),k&&k.lines.length>0?e.jsx("div",{className:"rounded-lg bg-muted/20 px-3 py-2 text-xs text-muted-foreground",children:k.lines.map(s=>e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsxs("span",{children:[s.name," (",s.rate.toFixed(4),"%)"]}),e.jsx("span",{children:f.formatPrice(s.amount,l)})]},s.id||`${s.name}-${s.rate}`))}):null,e.jsxs("div",{className:"flex justify-between font-semibold pt-2 border-t",children:[e.jsx("span",{children:r("ecommerce.total_on_stripe","Total on Stripe")}),e.jsx("span",{children:f.formatPrice(Ce,l)})]})]}),e.jsxs(he.Button,{className:"w-full",size:"lg",onClick:()=>we("stripe",v,"stripe"),disabled:Oe,children:[n==="stripe"?e.jsx(P.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(P.Package,{className:"mr-2 h-4 w-4"}),n==="stripe"?c("ecommerce.processing"):r("ecommerce.checkout_physical_products","Checkout Physical Products")]}),pe&&n===null?e.jsx("p",{className:"text-[11px] text-muted-foreground",children:pe}):null,h.stripe?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:h.stripe}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:k?.isPendingExternalCalculation?r("checkout_stripe_tax_finalized_notice","Tax will be finalized by Stripe Tax on the payment step."):r("ecommerce.shipping_taxes_collected_on_stripe","Shipping and taxes are only collected during the Stripe step for physical products.")})]}):null,C.length>0?e.jsxs(Ie,{title:r("ecommerce.freemius_checkout_title","Freemius Checkout"),description:r("ecommerce.freemius_checkout_description","Digital products use the Freemius checkout flow."),badgeLabel:He,children:[e.jsx("div",{className:"space-y-3",children:C.map(s=>{const i=_e.getCartItemActivePrice(s,{currencyCode:l,currencies:M}),m=Te.getTrialSummary(s),u=`freemius:${s.id}`,_=m?j[u]||"paid":void 0;return e.jsxs("div",{className:"rounded-lg border p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.title}),s.billing_cycle?e.jsx("p",{className:"text-xs text-muted-foreground capitalize",children:Ge(s.billing_cycle)}):null,m?e.jsxs("p",{className:"text-xs font-medium text-emerald-700",children:[m.label," - ",m.paymentRequirementLabel]}):null]}),e.jsx("span",{className:"font-medium",children:f.formatPrice(i.sale_price??i.price,l)})]}),m&&!s.trial_requires_payment_method&&e.jsxs("div",{className:"bg-muted/30 p-3 rounded-md border text-sm mt-2 mb-3",children:[e.jsx("p",{className:"font-medium mb-3",children:r("ecommerce.freemius_trial_preference_title","How would you like to start your trial?")}),e.jsxs(xe.RadioGroup,{value:j[u]||"paid",onValueChange:p=>I(d=>({...d,[u]:p})),className:"gap-3",children:[e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(xe.RadioGroupItem,{value:"paid",id:`${u}-paid`,className:"mt-1"}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(N.Label,{htmlFor:`${u}-paid`,className:"font-medium leading-none cursor-pointer",children:r("ecommerce.freemius_trial_with_card","Enter Payment Details Now (Still get full trial length free)")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("ecommerce.freemius_trial_with_card_help","You will not be billed until the trial ends. Cancel anytime.")})]})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(xe.RadioGroupItem,{value:"free",id:`${u}-free`,className:"mt-1"}),e.jsx("div",{className:"grid gap-1.5",children:e.jsx(N.Label,{htmlFor:`${u}-free`,className:"font-medium leading-none cursor-pointer",children:r("ecommerce.freemius_trial_no_card","Start Free Trial (No card required)")})})]})]})]}),e.jsxs(he.Button,{className:"w-full h-auto min-h-[2.75rem] py-2",variant:C.length>1?"outline":"default",onClick:()=>we("freemius",[{...s,..._?{trial_preference:_}:{}}],u),disabled:n!==null,children:[n===u?e.jsx(P.Loader2,{className:"mr-2 h-4 w-4 shrink-0 animate-spin"}):e.jsx(P.Download,{className:"mr-2 h-4 w-4 shrink-0"}),e.jsx("span",{className:"whitespace-normal text-left",children:n===u?c("ecommerce.processing"):C.length>1?r("ecommerce.checkout_product","Checkout {title}",{title:s.title}):r("ecommerce.checkout_digital_product","Checkout Digital Product")})]})]},u)})}),e.jsxs("div",{className:"flex justify-between text-sm font-semibold border-t pt-3",children:[e.jsx("span",{children:r("ecommerce.digital_subtotal","Digital subtotal")}),e.jsx("span",{children:f.formatPrice(de,l)})]}),me>0?e.jsxs("div",{className:"flex justify-between text-sm font-semibold text-emerald-600",children:[e.jsx("span",{children:r("ecommerce.discount","Discount")}),e.jsxs("span",{children:["-",f.formatPrice(me,l)]})]}):null,h.freemius?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:h.freemius}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:C.length>1?r("ecommerce.freemius_multi_checkout_notice","Freemius licenses are completed one at a time, so each digital product gets its own checkout action."):r("ecommerce.freemius_tax_notice","Taxes and compliance for digital products are handled inside the Freemius checkout.")})]}):null]})]})]})]})};exports.Checkout=ls;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),qe=require("@nextblock-cms/ui/badge"),he=require("@nextblock-cms/ui/button"),x=require("@nextblock-cms/ui/card"),Ve=require("@nextblock-cms/ui/checkbox"),F=require("@nextblock-cms/ui/input"),N=require("@nextblock-cms/ui/label"),We=require("@nextblock-cms/ui/separator"),xe=require("@nextblock-cms/ui/radio-group"),Ze=require("@freemius/checkout"),_e=require("../cart-store.cjs.js"),es=require("../use-cart.cjs.js"),o=require("react"),P=require("lucide-react"),f=require("@nextblock-cms/utils"),$e=require("../countries.cjs.js"),ss=require("../server-actions/shipping-actions.cjs.js"),ts=require("../server-actions/tax-actions.cjs.js"),ge=require("../types.cjs.js"),X=require("../states.cjs.js"),B=require("../customer.cjs.js"),rs=require("../CurrencyProvider.cjs.js"),Te=require("../trials.cjs.js"),cs=require("./CouponForm.cjs.js"),ns=process.env.NEXT_PUBLIC_IS_SANDBOX==="true",ne="nextblock-checkout-draft-v1";function ie(t,j){return{...B.emptyCustomerAddress(),company_name:t?.company_name||"",recipient_name:t?.recipient_name||j||"",line1:t?.line1||"",line2:t?.line2||"",city:t?.city||"",state:t?.state||"",postal_code:t?.postal_code||"",country_code:$e.normalizeCountryCode(t?.country_code)||"CA"}}function is(t){const j=B.normalizeCustomerAddress(t);return!(!j?.country_code||!j.postal_code||X.countryUsesStructuredStates(j.country_code)&&!j.state)}function fe(t,j,I){return t.reduce((n,g)=>{const{price:h,sale_price:q}=_e.getCartItemActivePrice(g,{currencyCode:j,currencies:I});return n+(q??h)*g.quantity},0)}function Fe({idPrefix:t,title:j,description:I,value:n,onChange:g}){const{t:h}=f.useTranslations(),q=h("company_name")==="company_name"?"Company name":h("company_name"),$=h("select_an_option")==="select_an_option"?"Select an option":h("select_an_option"),Y=h("state_province")==="state_province"?"State / Province":h("state_province"),K=X.getStatesForCountry(n.country_code),H=X.countryUsesStructuredStates(n.country_code);return e.jsxs(x.Card,{children:[e.jsxs(x.CardHeader,{children:[e.jsxs(x.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(P.MapPin,{className:"w-5 h-5"}),j]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:I})]}),e.jsxs(x.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-company`,children:q}),e.jsx(F.Input,{id:`${t}-company`,value:n.company_name,onChange:a=>g({...n,company_name:a.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-name`,children:h("full_name")}),e.jsx(F.Input,{id:`${t}-name`,value:n.recipient_name,onChange:a=>g({...n,recipient_name:a.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-country`,children:h("country")}),e.jsx("select",{id:`${t}-country`,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:n.country_code,onChange:a=>{const U=a.target.value,le=X.getStatesForCountry(U);g({...n,country_code:U,state:le.some(V=>V.code===n.state)?n.state:""})},children:$e.countries.map(a=>e.jsx("option",{value:a.code,children:a.name},a.code))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-line1`,children:h("address_line_1")}),e.jsx(F.Input,{id:`${t}-line1`,value:n.line1,onChange:a=>g({...n,line1:a.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-line2`,children:h("address_line_2")}),e.jsx(F.Input,{id:`${t}-line2`,value:n.line2,onChange:a=>g({...n,line2:a.target.value})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-city`,children:h("city")}),e.jsx(F.Input,{id:`${t}-city`,value:n.city,onChange:a=>g({...n,city:a.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-state`,children:h("state_province")}),H?e.jsxs("select",{id:`${t}-state`,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:n.state,onChange:a=>g({...n,state:a.target.value}),children:[e.jsx("option",{value:"",children:`${$}: ${Y}`}),K.map(a=>e.jsx("option",{value:a.code,children:a.name},a.code))]}):e.jsx(F.Input,{id:`${t}-state`,value:n.state,onChange:a=>g({...n,state:a.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-postal`,children:h("postal_zip_code")}),e.jsx(F.Input,{id:`${t}-postal`,value:n.postal_code,onChange:a=>g({...n,postal_code:a.target.value})})]})]})]})]})}function Ie({title:t,description:j,badgeLabel:I,children:n}){return e.jsxs(x.Card,{children:[e.jsx(x.CardHeader,{children:e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx(x.CardTitle,{children:t}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:j})]}),I?e.jsx(qe.Badge,{variant:"secondary",children:I}):null]})}),e.jsx(x.CardContent,{className:"space-y-4",children:n})]})}const ls=({initialCustomer:t})=>{const[j,I]=o.useState({}),[n,g]=o.useState(null),[h,q]=o.useState({}),[$,Y]=o.useState(t?.email||""),[K,H]=o.useState(""),[a,U]=o.useState(t?.phone||""),[le,V]=o.useState(!1),[Le,je]=o.useState(null),[ye,W]=o.useState(!1),[Me,Z]=o.useState(!1),[G,ee]=o.useState([]),[y,z]=o.useState(null),[S,se]=o.useState(null),[L,Ee]=o.useState(null),[A,be]=o.useState(()=>ie(t?.billingAddress,t?.fullName)),[O,Ne]=o.useState(()=>ie(t?.shippingAddress??t?.billingAddress,t?.fullName)),[E,ve]=o.useState(!t?.shippingAddress||B.addressesMatch(t?.billingAddress,t?.shippingAddress)),J=es.useCart(s=>s),{t:c,lang:ae}=f.useTranslations(),{activeCurrencyCode:l,currencies:M}=rs.useCurrency(),b=J?.items??[],v=o.useMemo(()=>b.filter(s=>!ge.isDigitalItem(s)),[b]),k=o.useMemo(()=>b.filter(s=>ge.isDigitalItem(s)),[b]),D=t?.isAuthenticated??!1,r=(s,i,m)=>{const u=c(s,m);if(u!==s)return u;if(!m)return i;let _=i;return Object.entries(m).forEach(([p,d])=>{_=_.replace(new RegExp(`\\{${p}\\}`,"g"),String(d))}),_},C=v.length>0,De=o.useMemo(()=>fe(b,l,M),[l,M,b]),oe=o.useMemo(()=>fe(v,l,M),[l,M,v]),de=o.useMemo(()=>fe(k,l,M),[l,M,k]),ue=L?.providerDiscounts.stripe??0,me=L?.providerDiscounts.freemius??0,te=Math.max(0,oe-ue),Re=Math.max(0,de-me),w=o.useMemo(()=>E?A:O,[A,O,E]),R=o.useMemo(()=>C?w:A,[A,C,w]),re=!C||is(w),ce=o.useMemo(()=>G.find(s=>s.id===y),[G,y]),Ce=o.useMemo(()=>te+(ce?.amount??0)+(S&&!S.isPendingExternalCalculation?S.amount:0),[te,ce,S]),Be=Ce+Re;if(o.useEffect(()=>{if(!(D||typeof window>"u"))try{const s=window.localStorage.getItem(ne);if(!s)return;const i=JSON.parse(s);i.email&&Y(i.email),i.phone&&U(i.phone),i.billingAddress&&be(ie(i.billingAddress)),i.shippingAddress&&Ne(ie(i.shippingAddress)),typeof i.useBillingForShipping=="boolean"&&ve(i.useBillingForShipping),(typeof i.selectedMethodId=="string"||i.selectedMethodId===null)&&z(i.selectedMethodId)}catch(s){console.error("[Checkout] Failed to restore checkout draft:",s)}},[D]),o.useEffect(()=>{if(!(typeof window>"u")){if(D){window.localStorage.removeItem(ne);return}window.localStorage.setItem(ne,JSON.stringify({email:$,phone:a,billingAddress:A,shippingAddress:O,useBillingForShipping:E,selectedMethodId:y}))}},[A,$,D,a,y,O,E]),o.useEffect(()=>{if(!C){ee([]),z(null),W(!1);return}if(!re){ee([]),z(null),W(!1);return}let s=!1;const m=setTimeout(async()=>{if(!w.country_code)return;W(!0);const u=await ss.getShippingEstimates(te,{country:w.country_code,state:w.state,postal_code:w.postal_code},ae,l);s||(u.success&&u.methods?(ee(u.methods),u.methods.length>0&&(!y||!u.methods.find(_=>_.id===y))&&z(u.methods[0].id)):(ee([]),z(null)),W(!1))},400);return()=>{s=!0,clearTimeout(m)}},[l,C,re,ae,y,w.country_code,w.postal_code,w.state,te]),o.useEffect(()=>{const i=setTimeout(async()=>{if(!C||!R.country_code){Z(!1),se(null);return}if(X.countryUsesStructuredStates(R.country_code)&&!R.state){Z(!1),se(null);return}Z(!0);const m=await ts.getTaxEstimate(v,{country_code:R.country_code,state:R.state},l,L?.code??null,b);m.success&&m.tax?se(m.tax):se(null),Z(!1)},300);return()=>clearTimeout(i)},[l,C,v,R.country_code,R.state,L?.code,b]),!J)return null;const Se=()=>{V(!1),je(null)},ke=le?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:Se,children:e.jsxs("div",{className:"relative bg-background border rounded-xl shadow-2xl p-8 max-w-md mx-4",onClick:s=>s.stopPropagation(),children:[e.jsx("button",{onClick:Se,className:"absolute top-4 right-4 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(P.X,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-full bg-amber-100 dark:bg-amber-900/20",children:e.jsx(P.FlaskConical,{className:"h-6 w-6 text-amber-600 dark:text-amber-400"})}),e.jsx("h2",{className:"text-xl font-semibold",children:c("ecommerce.checkout_successful")})]}),e.jsx("p",{className:"text-muted-foreground mb-2",children:c("ecommerce.sandbox_notice")}),e.jsx("p",{className:"text-muted-foreground mb-2",children:Le==="stripe"?r("ecommerce.sandbox_checkout_stripe_description","This simulated step represents the Stripe checkout for physical products."):r("ecommerce.sandbox_checkout_freemius_description","This simulated step represents the Freemius checkout for digital products.")}),e.jsx("p",{className:"text-muted-foreground mb-6",children:c("ecommerce.license_notice")}),e.jsx("a",{href:"https://nextblock.ca",target:"_blank",rel:"noopener noreferrer",className:"block w-full text-center py-3 px-4 rounded-lg bg-primary text-primary-foreground font-semibold hover:opacity-90 transition-opacity",children:c("ecommerce.purchase_at")})]})}):null,ze=s=>{if(!D&&(!$||!/^\S+@\S+\.\S+$/.test($)))return H(c("ecommerce.invalid_email")),null;const i=B.normalizeCustomerAddress(A);if(!B.isCustomerAddressComplete(i))return alert(c("checkout_complete_billing_address")),null;const m=C?B.normalizeCustomerAddress(E?A:O):null;if(s==="stripe"){if(!B.isCustomerAddressComplete(m))return alert(c("checkout_complete_shipping_address")),null;if(!y)return alert(r("ecommerce.shipping_method_required","Please select a shipping method before continuing.")),null}return H(""),{normalizedBillingAddress:i,normalizedShippingAddress:m}},we=async(s,i,m)=>{q(_=>({..._,[s]:""}));const u=ze(s);if(u){if(ns){const _=new Set(i.map(d=>d.id)),p=b.filter(d=>!_.has(d.id));J.setItems(p),p.length===0&&J.removeCoupon(),je(s),V(!0),typeof window<"u"&&p.length===0&&window.localStorage.removeItem(ne);return}g(m);try{const _=await fetch("/api/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:i,customerEmail:D?void 0:$,customerPhone:a||null,billingAddress:u.normalizedBillingAddress,shippingAddress:s==="stripe"?u.normalizedShippingAddress:null,shippingMethodId:s==="stripe"?y:null,locale:ae,currencyCode:l,couponCode:L?.code??J.appliedCoupon?.code??null,couponContextItems:b})}),p=await _.json();if(!_.ok){const d=p?.errorKey&&typeof p.errorKey=="string"?r(p.errorKey,p?.error||r("ecommerce.generic_error","Something went wrong."),p.errorParams):p?.error||c("ecommerce.generic_error");q(Q=>({...Q,[s]:d})),g(null);return}if(p.customProps&&p.customProps.provider==="freemius"){const d=p.customProps;let Q=null;const Je=()=>{window.location.href=`/checkout/success?session_id=${d.order_id}`},Pe=T=>(Q||(Q=fetch("/api/checkout/freemius/sync",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({orderId:d.order_id,checkoutResponse:T})}).then(async Ae=>{if(!Ae.ok){const Ye=await Ae.json().catch(()=>null);console.error("Freemius checkout sync failed:",Ye)}})),Q),Qe={product_id:d.plugin_id,public_key:d.public_key,sandbox:d.sandbox},Xe={name:c("ecommerce.checkout_overlay_title"),plan_id:d.plan_id,...d.billing_cycle?{billing_cycle:d.billing_cycle}:{},...d.trial?{trial:d.trial}:{},...d.coupon?{coupon:d.coupon}:{},user_email:d.user_email,user_firstname:d.user_firstname,user_lastname:d.user_lastname,sandbox:d.sandbox,purchaseCompleted:function(T){Pe(T)},success:function(T){(async()=>{try{await Pe(T)}finally{Je()}})()}};try{new Ze.Checkout(Qe).open(Xe),g(null)}catch(T){alert(c("ecommerce.checkout_popup_blocked")+" "+(T.message||String(T))),p.url&&(window.location.href=p.url),g(null)}}else p.url?window.location.href=p.url:(q(d=>({...d,[s]:c("ecommerce.checkout_failed")+(p.error||r("ecommerce.unknown_error","Unknown error"))})),g(null))}catch(_){console.error(_),q(p=>({...p,[s]:c("ecommerce.generic_error")})),g(null)}}};if(b.length===0)return e.jsxs(e.Fragment,{children:[ke,e.jsxs("div",{className:"container mx-auto flex min-h-[50vh] flex-col items-center justify-center p-8 text-center",children:[e.jsx("h1",{className:"mb-4 text-2xl font-bold",children:c("ecommerce.cart_empty")}),e.jsx("p",{className:"mb-8 text-muted-foreground",children:c("ecommerce.cart_empty_description")}),e.jsx(he.Button,{asChild:!0,children:e.jsx("a",{href:"/shop",children:c("ecommerce.go_to_shop")})})]})]});const pe=C?re?ye?r("ecommerce.calculating_shipping","Calculating shipping..."):y?null:G.length>0?c("ecommerce.select_rate"):c("ecommerce.no_rates_for_region"):r("ecommerce.waiting_on_address_info","Complete your shipping address to view available shipping options."):null,Oe=n!==null||pe!==null,Ke=v.length===1?r("ecommerce.item_count_one","{count} item",{count:v.length}):r("ecommerce.item_count_other","{count} items",{count:v.length}),He=k.length===1?r("ecommerce.license_count_one","{count} license",{count:k.length}):r("ecommerce.license_count_other","{count} licenses",{count:k.length}),Ue=s=>ge.isDigitalItem(s)?r("ecommerce.digital_label","Digital"):r("ecommerce.physical_label","Physical"),Ge=s=>s==="monthly"?r("ecommerce.checkout_billing_cycle_monthly","Monthly subscription"):s==="annual"?r("ecommerce.checkout_billing_cycle_annual","Annual subscription"):s==="lifetime"?r("ecommerce.checkout_billing_cycle_lifetime","Lifetime subscription"):null;return e.jsxs("div",{className:"container mx-auto px-4 py-12 md:px-6",children:[ke,e.jsxs("div",{className:"mx-auto max-w-6xl",children:[e.jsx("h1",{className:"mb-8 text-3xl font-bold",children:c("ecommerce.checkout")}),e.jsxs("div",{className:"grid gap-8 lg:grid-cols-12 lg:items-start",children:[e.jsxs("div",{className:"lg:col-span-8 space-y-6",children:[e.jsxs(x.Card,{children:[e.jsx(x.CardHeader,{children:e.jsxs(x.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(P.CreditCard,{className:"w-5 h-5"}),c("ecommerce.contact_information")]})}),e.jsxs(x.CardContent,{className:"space-y-4",children:[D?e.jsx("div",{className:"rounded-xl border bg-muted/20 p-4 text-sm text-muted-foreground",children:c("checkout_prefill_notice",{email:t?.email||""})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs(N.Label,{htmlFor:"checkout-email",children:[c("ecommerce.email_address")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(F.Input,{id:"checkout-email",type:"email",placeholder:c("ecommerce.email_placeholder"),value:$,onChange:s=>{Y(s.target.value),K&&H("")},required:!0}),K?e.jsx("p",{className:"text-xs text-destructive mt-1",children:K}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:"checkout-phone",children:c("phone_number")}),e.jsx(F.Input,{id:"checkout-phone",placeholder:c("optional"),value:a,onChange:s=>U(s.target.value)})]})]})]}),e.jsx(Fe,{idPrefix:"billing",title:c("billing_address"),description:c("checkout_billing_address_help"),value:A,onChange:be}),C?e.jsxs("div",{className:"flex items-center space-x-3 rounded-xl border bg-muted/20 p-4",children:[e.jsx(Ve.Checkbox,{id:"use-billing-for-shipping",checked:E,onCheckedChange:s=>ve(!!s)}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(N.Label,{htmlFor:"use-billing-for-shipping",className:"cursor-pointer",children:c("use_billing_for_shipping")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c("checkout_use_billing_for_shipping_help")})]})]}):null,C&&!E?e.jsx(Fe,{idPrefix:"shipping",title:c("shipping_address"),description:c("checkout_shipping_address_help"),value:O,onChange:Ne}):null,C?e.jsxs(x.Card,{children:[e.jsx(x.CardHeader,{children:e.jsxs(x.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(P.ChevronRight,{className:"w-5 h-5 text-primary"}),c("ecommerce.shipping_method")]})}),e.jsx(x.CardContent,{children:ye?e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(P.Loader2,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):G.length>0?e.jsx("div",{className:"space-y-3",children:G.map(s=>e.jsxs("div",{onClick:()=>z(s.id),className:`flex items-center justify-between p-4 rounded-lg border-2 cursor-pointer transition-all ${y===s.id?"border-primary bg-primary/5":"border-neutral-100 hover:border-neutral-200"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-4 h-4 rounded-full border flex items-center justify-center ${y===s.id?"border-primary":"border-neutral-300"}`,children:y===s.id?e.jsx("div",{className:"w-2 h-2 rounded-full bg-primary"}):null}),e.jsx("span",{className:"font-medium",children:s.name})]}),e.jsx("span",{className:"font-bold",children:f.formatPrice(s.amount,l)})]},s.id))}):e.jsx("div",{className:"py-4 text-center text-muted-foreground bg-muted/30 rounded-lg italic",children:re?c("ecommerce.no_rates_for_region"):r("ecommerce.waiting_on_address_info","Complete your shipping address to view available shipping options.")})})]}):null]}),e.jsxs("div",{className:"lg:col-span-4 space-y-6",children:[e.jsxs(x.Card,{className:"top-6",children:[e.jsx(x.CardHeader,{children:e.jsx(x.CardTitle,{children:c("ecommerce.order_summary")})}),e.jsxs(x.CardContent,{className:"space-y-4",children:[e.jsx("div",{className:"space-y-3 max-h-[260px] overflow-y-auto pr-2",children:b.map(s=>{const i=_e.getCartItemActivePrice(s,{currencyCode:l,currencies:M}),m=Te.getTrialSummary(s);return e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex gap-3",children:[s.image_url?e.jsx("div",{className:"h-10 w-10 shrink-0 overflow-hidden rounded border bg-neutral-100",children:e.jsx("img",{src:s.image_url,alt:s.title,className:"h-full w-full object-cover"})}):null,e.jsxs("div",{className:"grid gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-xs line-clamp-1",children:s.title}),e.jsx(qe.Badge,{variant:"outline",className:"text-[9px] uppercase",children:Ue(s)})]}),s.variant_label?e.jsx("span",{className:"text-[10px] text-muted-foreground line-clamp-1",children:s.variant_label}):null,e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[c("ecommerce.qty"),": ",s.quantity]}),m?e.jsxs("span",{className:"text-[10px] font-medium text-emerald-700",children:[m.label," - ",m.paymentRequirementLabel]}):null]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-0.5 shrink-0",children:[e.jsx("span",{className:"font-medium text-xs",children:f.formatPrice((i.sale_price??i.price)*s.quantity,l)}),i.sale_price?e.jsx("span",{className:"text-[9px] text-muted-foreground line-through",children:f.formatPrice(i.price*s.quantity,l)}):null]})]},`${s.id}-${s.variant_id||"base"}`)})}),e.jsx(We.Separator,{}),e.jsx(cs.CouponForm,{items:b,currencyCode:l,onQuoteChange:Ee}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:c("ecommerce.subtotal")}),e.jsx("span",{children:f.formatPrice(De,l)})]}),v.length>0?e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:r("ecommerce.physical_products","Physical products")}),e.jsx("span",{children:f.formatPrice(oe,l)})]}):null,k.length>0?e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:r("ecommerce.digital_products","Digital products")}),e.jsx("span",{children:f.formatPrice(de,l)})]}):null,L?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsxs("span",{children:[r("ecommerce.discount","Discount")," (",L.code,")"]}),e.jsxs("span",{children:["-",f.formatPrice(L.discountTotal,l)]})]}):null,(v.length>0||k.length>0)&&e.jsxs("div",{className:"flex justify-between font-bold text-lg pt-2 border-t mt-2",children:[e.jsx("span",{children:r("ecommerce.estimated_total","Estimated total")}),e.jsx("span",{className:"text-primary",children:f.formatPrice(Be,l)})]})]})]})]}),v.length>0?e.jsxs(Ie,{title:r("ecommerce.stripe_checkout_title","Stripe Checkout"),description:r("ecommerce.stripe_checkout_description","Pay for physical products in one Stripe checkout session."),badgeLabel:Ke,children:[e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:r("ecommerce.physical_subtotal","Physical subtotal")}),e.jsx("span",{children:f.formatPrice(oe,l)})]}),ue>0?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsx("span",{children:r("ecommerce.discount","Discount")}),e.jsxs("span",{children:["-",f.formatPrice(ue,l)]})]}):null,e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:c("ecommerce.shipping")}),e.jsx("span",{children:ce?f.formatPrice(ce.amount,l):"-"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:r("ecommerce.tax","Tax")}),e.jsx("span",{children:Me?"...":S?.isPendingExternalCalculation?r("ecommerce.tax_calculated_on_stripe","Calculated on Stripe"):S?f.formatPrice(S.amount,l):"-"})]}),S&&S.lines.length>0?e.jsx("div",{className:"rounded-lg bg-muted/20 px-3 py-2 text-xs text-muted-foreground",children:S.lines.map(s=>e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsxs("span",{children:[s.name," (",s.rate.toFixed(4),"%)"]}),e.jsx("span",{children:f.formatPrice(s.amount,l)})]},s.id||`${s.name}-${s.rate}`))}):null,e.jsxs("div",{className:"flex justify-between font-semibold pt-2 border-t",children:[e.jsx("span",{children:r("ecommerce.total_on_stripe","Total on Stripe")}),e.jsx("span",{children:f.formatPrice(Ce,l)})]})]}),e.jsxs(he.Button,{className:"w-full",size:"lg",onClick:()=>we("stripe",v,"stripe"),disabled:Oe,children:[n==="stripe"?e.jsx(P.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(P.Package,{className:"mr-2 h-4 w-4"}),n==="stripe"?c("ecommerce.processing"):r("ecommerce.checkout_physical_products","Checkout Physical Products")]}),pe&&n===null?e.jsx("p",{className:"text-[11px] text-muted-foreground",children:pe}):null,h.stripe?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:h.stripe}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:S?.isPendingExternalCalculation?r("checkout_stripe_tax_finalized_notice","Tax will be finalized by Stripe Tax on the payment step."):r("ecommerce.shipping_taxes_collected_on_stripe","Shipping and taxes are only collected during the Stripe step for physical products.")})]}):null,k.length>0?e.jsxs(Ie,{title:r("ecommerce.freemius_checkout_title","Freemius Checkout"),description:r("ecommerce.freemius_checkout_description","Digital products use the Freemius checkout flow."),badgeLabel:He,children:[e.jsx("div",{className:"space-y-3",children:k.map(s=>{const i=_e.getCartItemActivePrice(s,{currencyCode:l,currencies:M}),m=Te.getTrialSummary(s),u=`freemius:${s.id}`,_=m?j[u]||"paid":void 0;return e.jsxs("div",{className:"rounded-lg border p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.title}),s.billing_cycle?e.jsx("p",{className:"text-xs text-muted-foreground capitalize",children:Ge(s.billing_cycle)}):null,m?e.jsxs("p",{className:"text-xs font-medium text-emerald-700",children:[m.label," - ",m.paymentRequirementLabel]}):null]}),e.jsx("span",{className:"font-medium",children:f.formatPrice(i.sale_price??i.price,l)})]}),m&&!s.trial_requires_payment_method&&e.jsxs("div",{className:"bg-muted/30 p-3 rounded-md border text-sm mt-2 mb-3",children:[e.jsx("p",{className:"font-medium mb-3",children:r("ecommerce.freemius_trial_preference_title","How would you like to start your trial?")}),e.jsxs(xe.RadioGroup,{value:j[u]||"paid",onValueChange:p=>I(d=>({...d,[u]:p})),className:"gap-3",children:[e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(xe.RadioGroupItem,{value:"paid",id:`${u}-paid`,className:"mt-1"}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(N.Label,{htmlFor:`${u}-paid`,className:"font-medium leading-none cursor-pointer",children:r("ecommerce.freemius_trial_with_card","Enter Payment Details Now (Still get full trial length free)")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("ecommerce.freemius_trial_with_card_help","You will not be billed until the trial ends. Cancel anytime.")})]})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(xe.RadioGroupItem,{value:"free",id:`${u}-free`,className:"mt-1"}),e.jsx("div",{className:"grid gap-1.5",children:e.jsx(N.Label,{htmlFor:`${u}-free`,className:"font-medium leading-none cursor-pointer",children:r("ecommerce.freemius_trial_no_card","Start Free Trial (No card required)")})})]})]})]}),e.jsxs(he.Button,{className:"w-full h-auto min-h-[2.75rem] py-2",onClick:()=>we("freemius",[{...s,..._?{trial_preference:_}:{}}],u),disabled:n!==null,children:[n===u?e.jsx(P.Loader2,{className:"mr-2 h-4 w-4 shrink-0 animate-spin"}):e.jsx(P.Download,{className:"mr-2 h-4 w-4 shrink-0"}),e.jsx("span",{className:"whitespace-normal text-left",children:n===u?c("ecommerce.processing"):k.length>1?r("ecommerce.checkout_product","Checkout {title}",{title:s.title}):r("ecommerce.checkout_digital_product","Checkout Digital Product")})]})]},u)})}),e.jsxs("div",{className:"flex justify-between text-sm font-semibold border-t pt-3",children:[e.jsx("span",{children:r("ecommerce.digital_subtotal","Digital subtotal")}),e.jsx("span",{children:f.formatPrice(de,l)})]}),me>0?e.jsxs("div",{className:"flex justify-between text-sm font-semibold text-emerald-600",children:[e.jsx("span",{children:r("ecommerce.discount","Discount")}),e.jsxs("span",{children:["-",f.formatPrice(me,l)]})]}):null,h.freemius?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:h.freemius}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:k.length>1?r("ecommerce.freemius_multi_checkout_notice","Freemius licenses are completed one at a time, so each digital product gets its own checkout action."):r("ecommerce.freemius_tax_notice","Taxes and compliance for digital products are handled inside the Freemius checkout.")})]}):null]})]})]})]})};exports.Checkout=ls;
|