@betterstore/react 0.3.76 → 0.3.78
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/CHANGELOG.md +12 -0
- package/dist/components/checkout-embed/checkout-form.d.ts +1 -4
- package/dist/components/checkout-embed/steps/summary/discount-code.d.ts +1 -2
- package/dist/components/checkout-embed/steps/summary/index.d.ts +1 -2
- package/dist/index.cjs.js +33 -42
- package/dist/index.mjs +33 -42
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -16,11 +16,8 @@ interface CheckoutFormProps {
|
|
|
16
16
|
locale?: StripeElementLocale;
|
|
17
17
|
setShippingCost: (cost: number) => void;
|
|
18
18
|
exchangeRate: number;
|
|
19
|
-
setCheckout: (checkout: any) => void;
|
|
20
|
-
setPaymentSecret: (paymentSecret: string) => void;
|
|
21
|
-
setPublicKey: (publicKey: string) => void;
|
|
22
19
|
paymentSecret: string | null;
|
|
23
20
|
publicKey: string | null;
|
|
24
21
|
}
|
|
25
|
-
export default function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate,
|
|
22
|
+
export default function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, paymentSecret, publicKey, }: CheckoutFormProps): React.JSX.Element;
|
|
26
23
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
export default function DiscountCode({ applyDiscountCode,
|
|
2
|
+
export default function DiscountCode({ applyDiscountCode, }: {
|
|
3
3
|
applyDiscountCode: (code: string) => Promise<void>;
|
|
4
|
-
revalidateDiscounts: () => Promise<void>;
|
|
5
4
|
}): React.JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CheckoutSession, LineItem } from "@betterstore/sdk";
|
|
2
2
|
import React from "react";
|
|
3
|
-
export default function CheckoutSummary({ appliedDiscounts, lineItems, shipping, tax, currency, onCancel, exchangeRate, applyDiscountCode,
|
|
3
|
+
export default function CheckoutSummary({ appliedDiscounts, lineItems, shipping, tax, currency, onCancel, exchangeRate, applyDiscountCode, removeDiscount, }: {
|
|
4
4
|
appliedDiscounts: CheckoutSession["appliedDiscounts"];
|
|
5
5
|
lineItems: LineItem[];
|
|
6
6
|
shipping?: number | null;
|
|
@@ -9,6 +9,5 @@ export default function CheckoutSummary({ appliedDiscounts, lineItems, shipping,
|
|
|
9
9
|
exchangeRate: number;
|
|
10
10
|
onCancel: () => void;
|
|
11
11
|
applyDiscountCode: (code: string) => Promise<void>;
|
|
12
|
-
revalidateDiscounts: () => Promise<void>;
|
|
13
12
|
removeDiscount: (id: string) => Promise<void>;
|
|
14
13
|
}): React.JSX.Element;
|
package/dist/index.cjs.js
CHANGED
|
@@ -35293,10 +35293,9 @@ const resetFormStore = (formData) => {
|
|
|
35293
35293
|
localStorage.setItem("checkout", JSON.stringify(Object.assign(Object.assign({}, currentState), { state: Object.assign(Object.assign({}, currentState.state), { step: "customer", formData: { customer: formData.customer } }) })));
|
|
35294
35294
|
};
|
|
35295
35295
|
|
|
35296
|
-
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate,
|
|
35296
|
+
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, paymentSecret, publicKey, }) {
|
|
35297
35297
|
const { formData, setFormData, step, setStep, checkoutId: storedCheckoutId, setCheckoutId, } = useFormStore();
|
|
35298
35298
|
const [shippingRates, setShippingRates] = React.useState([]);
|
|
35299
|
-
const paymentSecretPromiseRef = React.useRef(null);
|
|
35300
35299
|
const validateStep = React.useCallback(() => {
|
|
35301
35300
|
if (step === "customer")
|
|
35302
35301
|
return;
|
|
@@ -35450,28 +35449,6 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
35450
35449
|
const handleDoubleBack = () => {
|
|
35451
35450
|
setStep("customer");
|
|
35452
35451
|
};
|
|
35453
|
-
React.useEffect(() => {
|
|
35454
|
-
const generatePaymentSecret = () => __awaiter(this, void 0, void 0, function* () {
|
|
35455
|
-
try {
|
|
35456
|
-
const { paymentSecret, publicKey, checkoutSession: newCheckout, } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
|
|
35457
|
-
setPaymentSecret(paymentSecret);
|
|
35458
|
-
setPublicKey(publicKey);
|
|
35459
|
-
setCheckout(newCheckout);
|
|
35460
|
-
}
|
|
35461
|
-
catch (error) {
|
|
35462
|
-
console.error("Failed to generate payment secret:", error);
|
|
35463
|
-
onError();
|
|
35464
|
-
}
|
|
35465
|
-
finally {
|
|
35466
|
-
paymentSecretPromiseRef.current = null;
|
|
35467
|
-
}
|
|
35468
|
-
});
|
|
35469
|
-
if (step === "payment" &&
|
|
35470
|
-
!paymentSecret &&
|
|
35471
|
-
!paymentSecretPromiseRef.current) {
|
|
35472
|
-
paymentSecretPromiseRef.current = generatePaymentSecret();
|
|
35473
|
-
}
|
|
35474
|
-
}, [step, checkoutId, clientSecret, paymentSecret, onError]);
|
|
35475
35452
|
const renderStep = () => {
|
|
35476
35453
|
if (step === "payment" && formData.customer && formData.shipping) {
|
|
35477
35454
|
return (React.createElement(PaymentForm, { locale: locale, fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingName: formData.shipping.name, shippingPrice: storeHelpers.formatPrice(formData.shipping.price, currency, exchangeRate), publicKey: publicKey }));
|
|
@@ -35503,7 +35480,7 @@ function InputGroupLoading({ className }) {
|
|
|
35503
35480
|
React.createElement(Skeleton, { className: "w-full h-10" })));
|
|
35504
35481
|
}
|
|
35505
35482
|
|
|
35506
|
-
function DiscountCode({ applyDiscountCode,
|
|
35483
|
+
function DiscountCode({ applyDiscountCode, }) {
|
|
35507
35484
|
const { t } = useTranslation();
|
|
35508
35485
|
const [discountCode, setDiscountCode] = React.useState("");
|
|
35509
35486
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
@@ -35514,7 +35491,6 @@ function DiscountCode({ applyDiscountCode, revalidateDiscounts, }) {
|
|
|
35514
35491
|
setIsLoading(true);
|
|
35515
35492
|
try {
|
|
35516
35493
|
yield applyDiscountCode(discountCode);
|
|
35517
|
-
// await revalidateDiscounts();
|
|
35518
35494
|
setDiscountCode("");
|
|
35519
35495
|
toast.success(t("CheckoutEmbed.Summary.discountCodeSuccess"));
|
|
35520
35496
|
}
|
|
@@ -35537,7 +35513,7 @@ function DiscountCode({ applyDiscountCode, revalidateDiscounts, }) {
|
|
|
35537
35513
|
error && React.createElement("p", { className: "text-red-500 mt-2 text-sm" }, error)));
|
|
35538
35514
|
}
|
|
35539
35515
|
|
|
35540
|
-
function CheckoutSummary({ appliedDiscounts, lineItems, shipping, tax, currency, onCancel, exchangeRate, applyDiscountCode,
|
|
35516
|
+
function CheckoutSummary({ appliedDiscounts, lineItems, shipping, tax, currency, onCancel, exchangeRate, applyDiscountCode, removeDiscount, }) {
|
|
35541
35517
|
var _a, _b;
|
|
35542
35518
|
const { formData } = useFormStore();
|
|
35543
35519
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
@@ -35610,7 +35586,7 @@ function CheckoutSummary({ appliedDiscounts, lineItems, shipping, tax, currency,
|
|
|
35610
35586
|
"hidden md:grid": !isOpen,
|
|
35611
35587
|
grid: isOpen,
|
|
35612
35588
|
}) },
|
|
35613
|
-
React.createElement(DiscountCode, { applyDiscountCode: applyDiscountCode
|
|
35589
|
+
React.createElement(DiscountCode, { applyDiscountCode: applyDiscountCode })))),
|
|
35614
35590
|
React.createElement("hr", { className: clsx("order-5 md:order-none", {
|
|
35615
35591
|
"hidden md:block": !isOpen,
|
|
35616
35592
|
block: isOpen,
|
|
@@ -35726,6 +35702,7 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35726
35702
|
const iframeRef = React.useRef(null);
|
|
35727
35703
|
React.useMemo(() => createI18nInstance(locale), []);
|
|
35728
35704
|
const { formData, step } = useFormStore();
|
|
35705
|
+
const paymentSecretPromiseRef = React.useRef(null);
|
|
35729
35706
|
const [paymentSecret, setPaymentSecret] = React.useState(null);
|
|
35730
35707
|
const [publicKey, setPublicKey] = React.useState(null);
|
|
35731
35708
|
const [checkout, setCheckout] = React.useState(null);
|
|
@@ -35776,16 +35753,33 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35776
35753
|
return;
|
|
35777
35754
|
setCheckout(Object.assign(Object.assign({}, checkout), { shipping: cost }));
|
|
35778
35755
|
};
|
|
35756
|
+
function generatePaymentSecret() {
|
|
35757
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35758
|
+
const { paymentSecret, publicKey, checkoutSession } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
|
|
35759
|
+
setPaymentSecret(paymentSecret);
|
|
35760
|
+
setPublicKey(publicKey);
|
|
35761
|
+
setCheckout(checkoutSession);
|
|
35762
|
+
});
|
|
35763
|
+
}
|
|
35764
|
+
React.useEffect(() => {
|
|
35765
|
+
if (step === "payment" &&
|
|
35766
|
+
!paymentSecret &&
|
|
35767
|
+
!paymentSecretPromiseRef.current) {
|
|
35768
|
+
paymentSecretPromiseRef.current = generatePaymentSecret().finally(() => {
|
|
35769
|
+
paymentSecretPromiseRef.current = null;
|
|
35770
|
+
});
|
|
35771
|
+
}
|
|
35772
|
+
}, [paymentSecret, step]);
|
|
35779
35773
|
const applyDiscountCode = (code) => __awaiter(this, void 0, void 0, function* () {
|
|
35780
35774
|
const newCheckout = yield storeClient.applyDiscountCode(clientSecret, checkoutId, code);
|
|
35781
35775
|
setCheckout(newCheckout);
|
|
35776
|
+
if (step === "payment") {
|
|
35777
|
+
yield generatePaymentSecret();
|
|
35778
|
+
}
|
|
35782
35779
|
});
|
|
35783
35780
|
const revalidateDiscounts = () => __awaiter(this, void 0, void 0, function* () {
|
|
35784
35781
|
if (step === "payment") {
|
|
35785
|
-
|
|
35786
|
-
setPaymentSecret(paymentSecret);
|
|
35787
|
-
setPublicKey(publicKey);
|
|
35788
|
-
setCheckout(checkoutSession);
|
|
35782
|
+
yield generatePaymentSecret();
|
|
35789
35783
|
}
|
|
35790
35784
|
else {
|
|
35791
35785
|
const newCheckout = yield storeClient.revalidateDiscounts(clientSecret, checkoutId);
|
|
@@ -35794,29 +35788,26 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35794
35788
|
});
|
|
35795
35789
|
const removeDiscount = (id) => __awaiter(this, void 0, void 0, function* () {
|
|
35796
35790
|
const newCheckout = yield storeClient.removeDiscount(clientSecret, checkoutId, id);
|
|
35791
|
+
setCheckout(newCheckout);
|
|
35797
35792
|
if (step === "payment") {
|
|
35798
|
-
|
|
35799
|
-
setPaymentSecret(paymentSecret);
|
|
35800
|
-
setPublicKey(publicKey);
|
|
35801
|
-
setCheckout(checkoutSession);
|
|
35802
|
-
}
|
|
35803
|
-
else {
|
|
35804
|
-
setCheckout(newCheckout);
|
|
35793
|
+
yield generatePaymentSecret();
|
|
35805
35794
|
}
|
|
35806
35795
|
});
|
|
35807
35796
|
React.useEffect(() => {
|
|
35808
35797
|
const interval = setTimeout(() => {
|
|
35809
|
-
|
|
35798
|
+
if (step !== "payment") {
|
|
35799
|
+
revalidateDiscounts();
|
|
35800
|
+
}
|
|
35810
35801
|
}, 1000 * 5);
|
|
35811
35802
|
return () => clearInterval(interval);
|
|
35812
35803
|
}, []);
|
|
35813
35804
|
return (React.createElement(IframeWrapper, { iframeRef: iframeRef },
|
|
35814
35805
|
React.createElement("div", { className: "checkout-embed h-max gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
|
|
35815
35806
|
React.createElement(Appearance, { appearance: appearance, fonts: config.fonts, iframeRef: iframeRef }),
|
|
35816
|
-
React.createElement("div", { className: "md:col-span-4 px-4 h-max md:px-8" }, loading ? (React.createElement(CheckoutFormLoading, null)) : (React.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1,
|
|
35807
|
+
React.createElement("div", { className: "md:col-span-4 px-4 h-max md:px-8" }, loading ? (React.createElement(CheckoutFormLoading, null)) : (React.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1, publicKey: publicKey, paymentSecret: paymentSecret }))),
|
|
35817
35808
|
React.createElement("div", { className: "md:col-span-3 px-4 md:px-8 h-max order-first md:order-last" },
|
|
35818
35809
|
React.createElement(Toaster, null),
|
|
35819
|
-
loading ? (React.createElement(CheckoutSummaryLoading, null)) : (React.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, onCancel: onCancel, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1, applyDiscountCode: applyDiscountCode, appliedDiscounts: (_f = checkout === null || checkout === void 0 ? void 0 : checkout.appliedDiscounts) !== null && _f !== void 0 ? _f : [],
|
|
35810
|
+
loading ? (React.createElement(CheckoutSummaryLoading, null)) : (React.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, onCancel: onCancel, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1, applyDiscountCode: applyDiscountCode, appliedDiscounts: (_f = checkout === null || checkout === void 0 ? void 0 : checkout.appliedDiscounts) !== null && _f !== void 0 ? _f : [], removeDiscount: removeDiscount }))))));
|
|
35820
35811
|
}
|
|
35821
35812
|
const CheckoutEmbed = React.memo(CheckoutEmbedComponent);
|
|
35822
35813
|
|
package/dist/index.mjs
CHANGED
|
@@ -35273,10 +35273,9 @@ const resetFormStore = (formData) => {
|
|
|
35273
35273
|
localStorage.setItem("checkout", JSON.stringify(Object.assign(Object.assign({}, currentState), { state: Object.assign(Object.assign({}, currentState.state), { step: "customer", formData: { customer: formData.customer } }) })));
|
|
35274
35274
|
};
|
|
35275
35275
|
|
|
35276
|
-
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate,
|
|
35276
|
+
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, paymentSecret, publicKey, }) {
|
|
35277
35277
|
const { formData, setFormData, step, setStep, checkoutId: storedCheckoutId, setCheckoutId, } = useFormStore();
|
|
35278
35278
|
const [shippingRates, setShippingRates] = useState([]);
|
|
35279
|
-
const paymentSecretPromiseRef = useRef(null);
|
|
35280
35279
|
const validateStep = useCallback(() => {
|
|
35281
35280
|
if (step === "customer")
|
|
35282
35281
|
return;
|
|
@@ -35430,28 +35429,6 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
35430
35429
|
const handleDoubleBack = () => {
|
|
35431
35430
|
setStep("customer");
|
|
35432
35431
|
};
|
|
35433
|
-
useEffect(() => {
|
|
35434
|
-
const generatePaymentSecret = () => __awaiter(this, void 0, void 0, function* () {
|
|
35435
|
-
try {
|
|
35436
|
-
const { paymentSecret, publicKey, checkoutSession: newCheckout, } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
|
|
35437
|
-
setPaymentSecret(paymentSecret);
|
|
35438
|
-
setPublicKey(publicKey);
|
|
35439
|
-
setCheckout(newCheckout);
|
|
35440
|
-
}
|
|
35441
|
-
catch (error) {
|
|
35442
|
-
console.error("Failed to generate payment secret:", error);
|
|
35443
|
-
onError();
|
|
35444
|
-
}
|
|
35445
|
-
finally {
|
|
35446
|
-
paymentSecretPromiseRef.current = null;
|
|
35447
|
-
}
|
|
35448
|
-
});
|
|
35449
|
-
if (step === "payment" &&
|
|
35450
|
-
!paymentSecret &&
|
|
35451
|
-
!paymentSecretPromiseRef.current) {
|
|
35452
|
-
paymentSecretPromiseRef.current = generatePaymentSecret();
|
|
35453
|
-
}
|
|
35454
|
-
}, [step, checkoutId, clientSecret, paymentSecret, onError]);
|
|
35455
35432
|
const renderStep = () => {
|
|
35456
35433
|
if (step === "payment" && formData.customer && formData.shipping) {
|
|
35457
35434
|
return (React__default.createElement(PaymentForm, { locale: locale, fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingName: formData.shipping.name, shippingPrice: storeHelpers.formatPrice(formData.shipping.price, currency, exchangeRate), publicKey: publicKey }));
|
|
@@ -35483,7 +35460,7 @@ function InputGroupLoading({ className }) {
|
|
|
35483
35460
|
React__default.createElement(Skeleton, { className: "w-full h-10" })));
|
|
35484
35461
|
}
|
|
35485
35462
|
|
|
35486
|
-
function DiscountCode({ applyDiscountCode,
|
|
35463
|
+
function DiscountCode({ applyDiscountCode, }) {
|
|
35487
35464
|
const { t } = useTranslation();
|
|
35488
35465
|
const [discountCode, setDiscountCode] = useState("");
|
|
35489
35466
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -35494,7 +35471,6 @@ function DiscountCode({ applyDiscountCode, revalidateDiscounts, }) {
|
|
|
35494
35471
|
setIsLoading(true);
|
|
35495
35472
|
try {
|
|
35496
35473
|
yield applyDiscountCode(discountCode);
|
|
35497
|
-
// await revalidateDiscounts();
|
|
35498
35474
|
setDiscountCode("");
|
|
35499
35475
|
toast.success(t("CheckoutEmbed.Summary.discountCodeSuccess"));
|
|
35500
35476
|
}
|
|
@@ -35517,7 +35493,7 @@ function DiscountCode({ applyDiscountCode, revalidateDiscounts, }) {
|
|
|
35517
35493
|
error && React__default.createElement("p", { className: "text-red-500 mt-2 text-sm" }, error)));
|
|
35518
35494
|
}
|
|
35519
35495
|
|
|
35520
|
-
function CheckoutSummary({ appliedDiscounts, lineItems, shipping, tax, currency, onCancel, exchangeRate, applyDiscountCode,
|
|
35496
|
+
function CheckoutSummary({ appliedDiscounts, lineItems, shipping, tax, currency, onCancel, exchangeRate, applyDiscountCode, removeDiscount, }) {
|
|
35521
35497
|
var _a, _b;
|
|
35522
35498
|
const { formData } = useFormStore();
|
|
35523
35499
|
const [isOpen, setIsOpen] = useState(false);
|
|
@@ -35590,7 +35566,7 @@ function CheckoutSummary({ appliedDiscounts, lineItems, shipping, tax, currency,
|
|
|
35590
35566
|
"hidden md:grid": !isOpen,
|
|
35591
35567
|
grid: isOpen,
|
|
35592
35568
|
}) },
|
|
35593
|
-
React__default.createElement(DiscountCode, { applyDiscountCode: applyDiscountCode
|
|
35569
|
+
React__default.createElement(DiscountCode, { applyDiscountCode: applyDiscountCode })))),
|
|
35594
35570
|
React__default.createElement("hr", { className: clsx("order-5 md:order-none", {
|
|
35595
35571
|
"hidden md:block": !isOpen,
|
|
35596
35572
|
block: isOpen,
|
|
@@ -35706,6 +35682,7 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35706
35682
|
const iframeRef = React__default.useRef(null);
|
|
35707
35683
|
React__default.useMemo(() => createI18nInstance(locale), []);
|
|
35708
35684
|
const { formData, step } = useFormStore();
|
|
35685
|
+
const paymentSecretPromiseRef = useRef(null);
|
|
35709
35686
|
const [paymentSecret, setPaymentSecret] = useState(null);
|
|
35710
35687
|
const [publicKey, setPublicKey] = useState(null);
|
|
35711
35688
|
const [checkout, setCheckout] = useState(null);
|
|
@@ -35756,16 +35733,33 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35756
35733
|
return;
|
|
35757
35734
|
setCheckout(Object.assign(Object.assign({}, checkout), { shipping: cost }));
|
|
35758
35735
|
};
|
|
35736
|
+
function generatePaymentSecret() {
|
|
35737
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35738
|
+
const { paymentSecret, publicKey, checkoutSession } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
|
|
35739
|
+
setPaymentSecret(paymentSecret);
|
|
35740
|
+
setPublicKey(publicKey);
|
|
35741
|
+
setCheckout(checkoutSession);
|
|
35742
|
+
});
|
|
35743
|
+
}
|
|
35744
|
+
useEffect(() => {
|
|
35745
|
+
if (step === "payment" &&
|
|
35746
|
+
!paymentSecret &&
|
|
35747
|
+
!paymentSecretPromiseRef.current) {
|
|
35748
|
+
paymentSecretPromiseRef.current = generatePaymentSecret().finally(() => {
|
|
35749
|
+
paymentSecretPromiseRef.current = null;
|
|
35750
|
+
});
|
|
35751
|
+
}
|
|
35752
|
+
}, [paymentSecret, step]);
|
|
35759
35753
|
const applyDiscountCode = (code) => __awaiter(this, void 0, void 0, function* () {
|
|
35760
35754
|
const newCheckout = yield storeClient.applyDiscountCode(clientSecret, checkoutId, code);
|
|
35761
35755
|
setCheckout(newCheckout);
|
|
35756
|
+
if (step === "payment") {
|
|
35757
|
+
yield generatePaymentSecret();
|
|
35758
|
+
}
|
|
35762
35759
|
});
|
|
35763
35760
|
const revalidateDiscounts = () => __awaiter(this, void 0, void 0, function* () {
|
|
35764
35761
|
if (step === "payment") {
|
|
35765
|
-
|
|
35766
|
-
setPaymentSecret(paymentSecret);
|
|
35767
|
-
setPublicKey(publicKey);
|
|
35768
|
-
setCheckout(checkoutSession);
|
|
35762
|
+
yield generatePaymentSecret();
|
|
35769
35763
|
}
|
|
35770
35764
|
else {
|
|
35771
35765
|
const newCheckout = yield storeClient.revalidateDiscounts(clientSecret, checkoutId);
|
|
@@ -35774,29 +35768,26 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35774
35768
|
});
|
|
35775
35769
|
const removeDiscount = (id) => __awaiter(this, void 0, void 0, function* () {
|
|
35776
35770
|
const newCheckout = yield storeClient.removeDiscount(clientSecret, checkoutId, id);
|
|
35771
|
+
setCheckout(newCheckout);
|
|
35777
35772
|
if (step === "payment") {
|
|
35778
|
-
|
|
35779
|
-
setPaymentSecret(paymentSecret);
|
|
35780
|
-
setPublicKey(publicKey);
|
|
35781
|
-
setCheckout(checkoutSession);
|
|
35782
|
-
}
|
|
35783
|
-
else {
|
|
35784
|
-
setCheckout(newCheckout);
|
|
35773
|
+
yield generatePaymentSecret();
|
|
35785
35774
|
}
|
|
35786
35775
|
});
|
|
35787
35776
|
useEffect(() => {
|
|
35788
35777
|
const interval = setTimeout(() => {
|
|
35789
|
-
|
|
35778
|
+
if (step !== "payment") {
|
|
35779
|
+
revalidateDiscounts();
|
|
35780
|
+
}
|
|
35790
35781
|
}, 1000 * 5);
|
|
35791
35782
|
return () => clearInterval(interval);
|
|
35792
35783
|
}, []);
|
|
35793
35784
|
return (React__default.createElement(IframeWrapper, { iframeRef: iframeRef },
|
|
35794
35785
|
React__default.createElement("div", { className: "checkout-embed h-max gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
|
|
35795
35786
|
React__default.createElement(Appearance, { appearance: appearance, fonts: config.fonts, iframeRef: iframeRef }),
|
|
35796
|
-
React__default.createElement("div", { className: "md:col-span-4 px-4 h-max md:px-8" }, loading ? (React__default.createElement(CheckoutFormLoading, null)) : (React__default.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1,
|
|
35787
|
+
React__default.createElement("div", { className: "md:col-span-4 px-4 h-max md:px-8" }, loading ? (React__default.createElement(CheckoutFormLoading, null)) : (React__default.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1, publicKey: publicKey, paymentSecret: paymentSecret }))),
|
|
35797
35788
|
React__default.createElement("div", { className: "md:col-span-3 px-4 md:px-8 h-max order-first md:order-last" },
|
|
35798
35789
|
React__default.createElement(Toaster, null),
|
|
35799
|
-
loading ? (React__default.createElement(CheckoutSummaryLoading, null)) : (React__default.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, onCancel: onCancel, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1, applyDiscountCode: applyDiscountCode, appliedDiscounts: (_f = checkout === null || checkout === void 0 ? void 0 : checkout.appliedDiscounts) !== null && _f !== void 0 ? _f : [],
|
|
35790
|
+
loading ? (React__default.createElement(CheckoutSummaryLoading, null)) : (React__default.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, onCancel: onCancel, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1, applyDiscountCode: applyDiscountCode, appliedDiscounts: (_f = checkout === null || checkout === void 0 ? void 0 : checkout.appliedDiscounts) !== null && _f !== void 0 ? _f : [], removeDiscount: removeDiscount }))))));
|
|
35800
35791
|
}
|
|
35801
35792
|
const CheckoutEmbed = memo(CheckoutEmbedComponent);
|
|
35802
35793
|
|