@betterstore/react 0.2.33 → 0.2.34
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 +6 -0
- package/dist/components/checkout-embed/checkout-form.d.ts +4 -2
- package/dist/components/checkout-embed/steps/payment/form.d.ts +3 -2
- package/dist/components/payment-element/index.d.ts +3 -2
- package/dist/index.cjs.js +13 -7
- package/dist/index.mjs +13 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CheckoutSession, createStoreClient } from "@betterstore/sdk";
|
|
2
|
-
import { StripeElementsOptions } from "@stripe/stripe-js";
|
|
2
|
+
import { StripeElementLocale, StripeElementsOptions } from "@stripe/stripe-js";
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { AppearanceConfig } from "./appearance";
|
|
5
5
|
interface CheckoutFormProps {
|
|
@@ -13,6 +13,8 @@ interface CheckoutFormProps {
|
|
|
13
13
|
currency: string;
|
|
14
14
|
checkoutAppearance?: AppearanceConfig;
|
|
15
15
|
fonts?: StripeElementsOptions["fonts"];
|
|
16
|
+
locale?: StripeElementLocale;
|
|
17
|
+
setShippingCost: (cost: number) => void;
|
|
16
18
|
}
|
|
17
|
-
export default function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, }: CheckoutFormProps): React.JSX.Element;
|
|
19
|
+
export default function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, }: CheckoutFormProps): React.JSX.Element;
|
|
18
20
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StripeElementsOptions } from "@stripe/stripe-js";
|
|
1
|
+
import { StripeElementLocale, StripeElementsOptions } from "@stripe/stripe-js";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { AppearanceConfig } from "../../appearance";
|
|
4
4
|
interface PaymentFormProps {
|
|
@@ -13,6 +13,7 @@ interface PaymentFormProps {
|
|
|
13
13
|
shippingPrice: string;
|
|
14
14
|
checkoutAppearance?: AppearanceConfig;
|
|
15
15
|
fonts?: StripeElementsOptions["fonts"];
|
|
16
|
+
locale?: StripeElementLocale;
|
|
16
17
|
}
|
|
17
|
-
export default function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack, contactEmail, shippingAddress, shippingProvider, shippingPrice, checkoutAppearance, fonts, }: PaymentFormProps): React.JSX.Element;
|
|
18
|
+
export default function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack, contactEmail, shippingAddress, shippingProvider, shippingPrice, checkoutAppearance, fonts, locale, }: PaymentFormProps): React.JSX.Element;
|
|
18
19
|
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Appearance, StripeElementsOptions } from "@stripe/stripe-js";
|
|
1
|
+
import { Appearance, StripeElementLocale, StripeElementsOptions } from "@stripe/stripe-js";
|
|
2
2
|
import React from "react";
|
|
3
|
-
declare function PaymentElement({ paymentSecret, checkoutAppearance, fonts, onSuccess, onError, children, }: {
|
|
3
|
+
declare function PaymentElement({ paymentSecret, checkoutAppearance, locale, fonts, onSuccess, onError, children, }: {
|
|
4
4
|
paymentSecret: string;
|
|
5
5
|
checkoutAppearance?: Appearance;
|
|
6
|
+
locale?: StripeElementLocale;
|
|
6
7
|
fonts?: StripeElementsOptions["fonts"];
|
|
7
8
|
onSuccess?: () => void;
|
|
8
9
|
onError?: () => void;
|
package/dist/index.cjs.js
CHANGED
|
@@ -34176,9 +34176,9 @@ var CheckoutForm$2 = React.memo(CheckoutForm$1);
|
|
|
34176
34176
|
|
|
34177
34177
|
const publicStripeKey = "pk_test_51OjSZ2JoDmiuDQz4Vub296KIgTCy4y8NJos59h93bq3sLe3veuXnV9XVmvvWDFlt3aEWHY4pOuIXyahEjjKZwezn00qo4U5fQS";
|
|
34178
34178
|
const stripePromise = loadStripe(publicStripeKey);
|
|
34179
|
-
function PaymentElement({ paymentSecret, checkoutAppearance, fonts, onSuccess, onError, children, }) {
|
|
34179
|
+
function PaymentElement({ paymentSecret, checkoutAppearance, locale, fonts, onSuccess, onError, children, }) {
|
|
34180
34180
|
const options = {
|
|
34181
|
-
locale: "en",
|
|
34181
|
+
locale: locale !== null && locale !== void 0 ? locale : "en",
|
|
34182
34182
|
appearance: checkoutAppearance,
|
|
34183
34183
|
clientSecret: paymentSecret,
|
|
34184
34184
|
fonts: fonts,
|
|
@@ -34188,7 +34188,7 @@ function PaymentElement({ paymentSecret, checkoutAppearance, fonts, onSuccess, o
|
|
|
34188
34188
|
}
|
|
34189
34189
|
var PaymentElement$1 = React.memo(PaymentElement);
|
|
34190
34190
|
|
|
34191
|
-
function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack, contactEmail, shippingAddress, shippingProvider, shippingPrice, checkoutAppearance, fonts, }) {
|
|
34191
|
+
function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack, contactEmail, shippingAddress, shippingProvider, shippingPrice, checkoutAppearance, fonts, locale, }) {
|
|
34192
34192
|
const { t } = useTranslation();
|
|
34193
34193
|
return (React.createElement("div", { className: "space-y-6" },
|
|
34194
34194
|
React.createElement("div", null,
|
|
@@ -34216,7 +34216,7 @@ function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack,
|
|
|
34216
34216
|
" \u00B7 ",
|
|
34217
34217
|
shippingPrice)),
|
|
34218
34218
|
React.createElement(Button, { variant: "link", size: "link", onClick: onBack }, t("CheckoutEmbed.Shipping.change")))),
|
|
34219
|
-
React.createElement("div", { className: "mt-8" }, paymentSecret && (React.createElement(PaymentElement$1, { fonts: fonts, checkoutAppearance: convertCheckoutAppearanceToStripeAppearance(checkoutAppearance, fonts), paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError },
|
|
34219
|
+
React.createElement("div", { className: "mt-8" }, paymentSecret && (React.createElement(PaymentElement$1, { fonts: fonts, checkoutAppearance: convertCheckoutAppearanceToStripeAppearance(checkoutAppearance, fonts), locale: locale, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError },
|
|
34220
34220
|
React.createElement("div", { className: "flex justify-between items-center pt-8" },
|
|
34221
34221
|
React.createElement(Button, { type: "button", variant: "ghost", onClick: onBack },
|
|
34222
34222
|
React.createElement(ChevronLeft, null),
|
|
@@ -34313,7 +34313,7 @@ const motionSettings = {
|
|
|
34313
34313
|
exit: { opacity: 0 },
|
|
34314
34314
|
transition: { duration: 0.2 },
|
|
34315
34315
|
};
|
|
34316
|
-
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, }) {
|
|
34316
|
+
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, }) {
|
|
34317
34317
|
const { formData, setFormData, step, setStep } = useFormStore(checkoutId)();
|
|
34318
34318
|
const [paymentSecret, setPaymentSecret] = React.useState(null);
|
|
34319
34319
|
const [shippingRates, setShippingRates] = React.useState([]);
|
|
@@ -34409,6 +34409,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34409
34409
|
});
|
|
34410
34410
|
const paymentSecret = yield storeClient.generateCheckoutsPaymentSecret(clientSecret, checkoutId);
|
|
34411
34411
|
setPaymentSecret(paymentSecret);
|
|
34412
|
+
setShippingCost(data.amount * 100);
|
|
34412
34413
|
setStep("payment");
|
|
34413
34414
|
});
|
|
34414
34415
|
// Navigate back to previous step
|
|
@@ -34440,7 +34441,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34440
34441
|
step === "shipping" && formData.customer && (React.createElement(motion.div, Object.assign({ key: "shipping" }, motionSettings, { className: "absolute w-full" }),
|
|
34441
34442
|
React.createElement(ShippingMethodForm, { shippingRates: shippingRates, initialData: formData.shipping, onSubmit: handleShippingSubmit, onBack: handleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address) }))),
|
|
34442
34443
|
step === "payment" && formData.customer && formData.shipping && (React.createElement(motion.div, Object.assign({ key: "payment" }, motionSettings, { className: "absolute w-full" }),
|
|
34443
|
-
React.createElement(PaymentForm, { fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingProvider: formData.shipping.provider, shippingPrice: formData.shipping.amount.toString() + " " + currency }))))));
|
|
34444
|
+
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), shippingProvider: formData.shipping.provider, shippingPrice: formData.shipping.amount.toString() + " " + currency }))))));
|
|
34444
34445
|
}
|
|
34445
34446
|
|
|
34446
34447
|
function CheckoutFormLoading() {
|
|
@@ -34580,9 +34581,14 @@ function CheckoutEmbed({ checkoutId, config }) {
|
|
|
34580
34581
|
if (!checkout && !loading) {
|
|
34581
34582
|
throw new Error("Checkout not found");
|
|
34582
34583
|
}
|
|
34584
|
+
const setShippingCost = (cost) => {
|
|
34585
|
+
if (!checkout)
|
|
34586
|
+
return;
|
|
34587
|
+
setCheckout(Object.assign(Object.assign({}, checkout), { shipping: cost }));
|
|
34588
|
+
};
|
|
34583
34589
|
return (React.createElement("div", { className: "checkout-embed mx-auto max-w-[1200px] min-h-screen overflow-x-hidden py-8 md:py-12 grid md:grid-cols-7 " },
|
|
34584
34590
|
React.createElement(Appearance, { appearance: appearance }),
|
|
34585
|
-
React.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React.createElement(CheckoutFormLoading, null)) : (React.createElement(CheckoutForm, { 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 }))),
|
|
34591
|
+
React.createElement("div", { className: "md:col-span-4 px-4 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 }))),
|
|
34586
34592
|
React.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React.createElement(CheckoutSummaryLoading, null)) : (React.createElement(CheckoutSummary, { currency: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _b !== void 0 ? _b : "", lineItems: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _c !== void 0 ? _c : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, cancelUrl: cancelUrl, exchangeRate: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _d !== void 0 ? _d : 1 })))));
|
|
34587
34593
|
}
|
|
34588
34594
|
var index = React.memo(CheckoutEmbed);
|
package/dist/index.mjs
CHANGED
|
@@ -34153,9 +34153,9 @@ var CheckoutForm$2 = memo$1(CheckoutForm$1);
|
|
|
34153
34153
|
|
|
34154
34154
|
const publicStripeKey = "pk_test_51OjSZ2JoDmiuDQz4Vub296KIgTCy4y8NJos59h93bq3sLe3veuXnV9XVmvvWDFlt3aEWHY4pOuIXyahEjjKZwezn00qo4U5fQS";
|
|
34155
34155
|
const stripePromise = loadStripe(publicStripeKey);
|
|
34156
|
-
function PaymentElement({ paymentSecret, checkoutAppearance, fonts, onSuccess, onError, children, }) {
|
|
34156
|
+
function PaymentElement({ paymentSecret, checkoutAppearance, locale, fonts, onSuccess, onError, children, }) {
|
|
34157
34157
|
const options = {
|
|
34158
|
-
locale: "en",
|
|
34158
|
+
locale: locale !== null && locale !== void 0 ? locale : "en",
|
|
34159
34159
|
appearance: checkoutAppearance,
|
|
34160
34160
|
clientSecret: paymentSecret,
|
|
34161
34161
|
fonts: fonts,
|
|
@@ -34165,7 +34165,7 @@ function PaymentElement({ paymentSecret, checkoutAppearance, fonts, onSuccess, o
|
|
|
34165
34165
|
}
|
|
34166
34166
|
var PaymentElement$1 = memo$1(PaymentElement);
|
|
34167
34167
|
|
|
34168
|
-
function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack, contactEmail, shippingAddress, shippingProvider, shippingPrice, checkoutAppearance, fonts, }) {
|
|
34168
|
+
function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack, contactEmail, shippingAddress, shippingProvider, shippingPrice, checkoutAppearance, fonts, locale, }) {
|
|
34169
34169
|
const { t } = useTranslation();
|
|
34170
34170
|
return (React__default.createElement("div", { className: "space-y-6" },
|
|
34171
34171
|
React__default.createElement("div", null,
|
|
@@ -34193,7 +34193,7 @@ function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack,
|
|
|
34193
34193
|
" \u00B7 ",
|
|
34194
34194
|
shippingPrice)),
|
|
34195
34195
|
React__default.createElement(Button, { variant: "link", size: "link", onClick: onBack }, t("CheckoutEmbed.Shipping.change")))),
|
|
34196
|
-
React__default.createElement("div", { className: "mt-8" }, paymentSecret && (React__default.createElement(PaymentElement$1, { fonts: fonts, checkoutAppearance: convertCheckoutAppearanceToStripeAppearance(checkoutAppearance, fonts), paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError },
|
|
34196
|
+
React__default.createElement("div", { className: "mt-8" }, paymentSecret && (React__default.createElement(PaymentElement$1, { fonts: fonts, checkoutAppearance: convertCheckoutAppearanceToStripeAppearance(checkoutAppearance, fonts), locale: locale, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError },
|
|
34197
34197
|
React__default.createElement("div", { className: "flex justify-between items-center pt-8" },
|
|
34198
34198
|
React__default.createElement(Button, { type: "button", variant: "ghost", onClick: onBack },
|
|
34199
34199
|
React__default.createElement(ChevronLeft, null),
|
|
@@ -34290,7 +34290,7 @@ const motionSettings = {
|
|
|
34290
34290
|
exit: { opacity: 0 },
|
|
34291
34291
|
transition: { duration: 0.2 },
|
|
34292
34292
|
};
|
|
34293
|
-
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, }) {
|
|
34293
|
+
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, }) {
|
|
34294
34294
|
const { formData, setFormData, step, setStep } = useFormStore(checkoutId)();
|
|
34295
34295
|
const [paymentSecret, setPaymentSecret] = useState(null);
|
|
34296
34296
|
const [shippingRates, setShippingRates] = useState([]);
|
|
@@ -34386,6 +34386,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34386
34386
|
});
|
|
34387
34387
|
const paymentSecret = yield storeClient.generateCheckoutsPaymentSecret(clientSecret, checkoutId);
|
|
34388
34388
|
setPaymentSecret(paymentSecret);
|
|
34389
|
+
setShippingCost(data.amount * 100);
|
|
34389
34390
|
setStep("payment");
|
|
34390
34391
|
});
|
|
34391
34392
|
// Navigate back to previous step
|
|
@@ -34417,7 +34418,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34417
34418
|
step === "shipping" && formData.customer && (React__default.createElement(motion.div, Object.assign({ key: "shipping" }, motionSettings, { className: "absolute w-full" }),
|
|
34418
34419
|
React__default.createElement(ShippingMethodForm, { shippingRates: shippingRates, initialData: formData.shipping, onSubmit: handleShippingSubmit, onBack: handleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address) }))),
|
|
34419
34420
|
step === "payment" && formData.customer && formData.shipping && (React__default.createElement(motion.div, Object.assign({ key: "payment" }, motionSettings, { className: "absolute w-full" }),
|
|
34420
|
-
React__default.createElement(PaymentForm, { fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingProvider: formData.shipping.provider, shippingPrice: formData.shipping.amount.toString() + " " + currency }))))));
|
|
34421
|
+
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), shippingProvider: formData.shipping.provider, shippingPrice: formData.shipping.amount.toString() + " " + currency }))))));
|
|
34421
34422
|
}
|
|
34422
34423
|
|
|
34423
34424
|
function CheckoutFormLoading() {
|
|
@@ -34557,9 +34558,14 @@ function CheckoutEmbed({ checkoutId, config }) {
|
|
|
34557
34558
|
if (!checkout && !loading) {
|
|
34558
34559
|
throw new Error("Checkout not found");
|
|
34559
34560
|
}
|
|
34561
|
+
const setShippingCost = (cost) => {
|
|
34562
|
+
if (!checkout)
|
|
34563
|
+
return;
|
|
34564
|
+
setCheckout(Object.assign(Object.assign({}, checkout), { shipping: cost }));
|
|
34565
|
+
};
|
|
34560
34566
|
return (React__default.createElement("div", { className: "checkout-embed mx-auto max-w-[1200px] min-h-screen overflow-x-hidden py-8 md:py-12 grid md:grid-cols-7 " },
|
|
34561
34567
|
React__default.createElement(Appearance, { appearance: appearance }),
|
|
34562
|
-
React__default.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React__default.createElement(CheckoutFormLoading, null)) : (React__default.createElement(CheckoutForm, { 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 }))),
|
|
34568
|
+
React__default.createElement("div", { className: "md:col-span-4 px-4 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 }))),
|
|
34563
34569
|
React__default.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React__default.createElement(CheckoutSummaryLoading, null)) : (React__default.createElement(CheckoutSummary, { currency: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _b !== void 0 ? _b : "", lineItems: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _c !== void 0 ? _c : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, cancelUrl: cancelUrl, exchangeRate: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _d !== void 0 ? _d : 1 })))));
|
|
34564
34570
|
}
|
|
34565
34571
|
var index = memo$1(CheckoutEmbed);
|