@betterstore/react 0.3.14 → 0.3.16

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @betterstore/sdk
2
2
 
3
+ ## 0.3.16
4
+
5
+ ### Patch Changes
6
+
7
+ - bug fix
8
+
9
+ ## 0.3.15
10
+
11
+ ### Patch Changes
12
+
13
+ - bug fixes
14
+
3
15
  ## 0.3.14
4
16
 
5
17
  ### Patch Changes
@@ -17,6 +17,10 @@ interface CheckoutFormProps {
17
17
  setShippingCost: (cost: number) => void;
18
18
  exchangeRate: number;
19
19
  setCheckout: (checkout: any) => void;
20
+ setPaymentSecret: (paymentSecret: string) => void;
21
+ setPublicKey: (publicKey: string) => void;
22
+ paymentSecret: string | null;
23
+ publicKey: string | null;
20
24
  }
21
- export default function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, setCheckout, }: CheckoutFormProps): React.JSX.Element;
25
+ export default function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, setCheckout, setPaymentSecret, setPublicKey, paymentSecret, publicKey, }: CheckoutFormProps): React.JSX.Element;
22
26
  export {};
package/dist/index.cjs.js CHANGED
@@ -35241,7 +35241,13 @@ var PaymentElement$1 = React.memo(PaymentElement);
35241
35241
 
35242
35242
  function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack, contactEmail, shippingAddress, shippingName, shippingPrice, checkoutAppearance, fonts, locale, publicKey, }) {
35243
35243
  const [isSubmitting, setIsSubmitting] = React.useState(false);
35244
+ const [key, setKey] = React.useState(0);
35244
35245
  const { t } = useTranslation();
35246
+ React.useEffect(() => {
35247
+ if (paymentSecret) {
35248
+ setKey((prev) => prev + 1);
35249
+ }
35250
+ }, [paymentSecret]);
35245
35251
  return (React.createElement("div", { className: "space-y-6" },
35246
35252
  React.createElement("div", null,
35247
35253
  React.createElement("h2", { className: "mb-2" }, t("CheckoutEmbed.Payment.title")),
@@ -35268,7 +35274,7 @@ function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack,
35268
35274
  " \u00B7 ",
35269
35275
  shippingPrice)),
35270
35276
  React.createElement(Button, { variant: "link", size: "link", onClick: onBack }, t("CheckoutEmbed.Shipping.change")))),
35271
- 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, setSubmitting: setIsSubmitting, publicKey: publicKey },
35277
+ React.createElement("div", { className: "mt-8" }, paymentSecret && (React.createElement(PaymentElement$1, { key: key, fonts: fonts, checkoutAppearance: convertCheckoutAppearanceToStripeAppearance(checkoutAppearance, fonts), locale: locale, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, setSubmitting: setIsSubmitting, publicKey: publicKey },
35272
35278
  React.createElement("div", { className: "flex justify-between items-center pt-8" },
35273
35279
  React.createElement(Button, { type: "button", variant: "ghost", onClick: onBack },
35274
35280
  React.createElement(ChevronLeft, null),
@@ -35451,10 +35457,8 @@ const motionSettings = {
35451
35457
  exit: { opacity: 0 },
35452
35458
  transition: { duration: 0.2 },
35453
35459
  };
35454
- function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, setCheckout, }) {
35460
+ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, setCheckout, setPaymentSecret, setPublicKey, paymentSecret, publicKey, }) {
35455
35461
  const { formData, setFormData, step, setStep, checkoutId: storedCheckoutId, setCheckoutId, } = useFormStore();
35456
- const [paymentSecret, setPaymentSecret] = React.useState(null);
35457
- const [publicKey, setPublicKey] = React.useState(null);
35458
35462
  const [shippingRates, setShippingRates] = React.useState([]);
35459
35463
  const validateStep = React.useCallback(() => {
35460
35464
  if (step === "customer")
@@ -35609,9 +35613,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
35609
35613
  };
35610
35614
  React.useEffect(() => {
35611
35615
  const asyncFunc = () => __awaiter(this, void 0, void 0, function* () {
35612
- const _a = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId), { paymentSecret, publicKey, checkoutSession: newCheckout } = _a, rest = __rest(_a, ["paymentSecret", "publicKey", "checkoutSession"]);
35613
- console.log("newCheckout", newCheckout);
35614
- console.log("rest", rest);
35616
+ const { paymentSecret, publicKey, checkoutSession: newCheckout, } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
35615
35617
  setPaymentSecret(paymentSecret);
35616
35618
  setPublicKey(publicKey);
35617
35619
  setCheckout(newCheckout);
@@ -35854,7 +35856,9 @@ function CheckoutEmbed({ checkoutId, config }) {
35854
35856
  const { cancelUrl, successUrl, appearance, locale, clientSecret, clientProxy, } = config;
35855
35857
  const storeClient = React.useMemo(() => sdk.createStoreClient({ proxy: clientProxy }), [clientProxy]);
35856
35858
  React.useMemo(() => createI18nInstance(locale), []);
35857
- const { formData, setFormData, setStep } = useFormStore();
35859
+ const { formData, step } = useFormStore();
35860
+ const [paymentSecret, setPaymentSecret] = React.useState(null);
35861
+ const [publicKey, setPublicKey] = React.useState(null);
35858
35862
  const [checkout, setCheckout] = React.useState(null);
35859
35863
  const [loading, setLoading] = React.useState(true);
35860
35864
  React.useEffect(() => {
@@ -35908,12 +35912,28 @@ function CheckoutEmbed({ checkoutId, config }) {
35908
35912
  setCheckout(newCheckout);
35909
35913
  });
35910
35914
  const revalidateDiscounts = () => __awaiter(this, void 0, void 0, function* () {
35911
- const newCheckout = yield storeClient.revalidateDiscounts(clientSecret, checkoutId);
35912
- setCheckout(newCheckout);
35915
+ if (step === "payment") {
35916
+ const { paymentSecret, publicKey, checkoutSession } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
35917
+ setPaymentSecret(paymentSecret);
35918
+ setPublicKey(publicKey);
35919
+ setCheckout(checkoutSession);
35920
+ }
35921
+ else {
35922
+ const newCheckout = yield storeClient.revalidateDiscounts(clientSecret, checkoutId);
35923
+ setCheckout(newCheckout);
35924
+ }
35913
35925
  });
35914
35926
  const removeDiscount = (id) => __awaiter(this, void 0, void 0, function* () {
35915
35927
  const newCheckout = yield storeClient.removeDiscount(clientSecret, checkoutId, id);
35916
- setCheckout(newCheckout);
35928
+ if (step === "payment") {
35929
+ const { paymentSecret, publicKey, checkoutSession } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
35930
+ setPaymentSecret(paymentSecret);
35931
+ setPublicKey(publicKey);
35932
+ setCheckout(checkoutSession);
35933
+ }
35934
+ else {
35935
+ setCheckout(newCheckout);
35936
+ }
35917
35937
  });
35918
35938
  React.useEffect(() => {
35919
35939
  const interval = setTimeout(() => {
@@ -35923,7 +35943,7 @@ function CheckoutEmbed({ checkoutId, config }) {
35923
35943
  }, []);
35924
35944
  return (React.createElement("div", { className: "checkout-embed scrollbar-hidden mx-auto max-w-[1200px] min-h-screen overflow-x-hidden gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
35925
35945
  React.createElement(Appearance, { appearance: appearance }),
35926
- 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, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1, setCheckout: setCheckout }))),
35946
+ 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, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1, setCheckout: setCheckout, setPublicKey: setPublicKey, publicKey: publicKey, setPaymentSecret: setPaymentSecret, paymentSecret: paymentSecret }))),
35927
35947
  React.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" },
35928
35948
  React.createElement(Toaster, null),
35929
35949
  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 : [], revalidateDiscounts: revalidateDiscounts, removeDiscount: removeDiscount })))));
package/dist/index.mjs CHANGED
@@ -35218,7 +35218,13 @@ var PaymentElement$1 = memo$1(PaymentElement);
35218
35218
 
35219
35219
  function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack, contactEmail, shippingAddress, shippingName, shippingPrice, checkoutAppearance, fonts, locale, publicKey, }) {
35220
35220
  const [isSubmitting, setIsSubmitting] = useState(false);
35221
+ const [key, setKey] = useState(0);
35221
35222
  const { t } = useTranslation();
35223
+ useEffect(() => {
35224
+ if (paymentSecret) {
35225
+ setKey((prev) => prev + 1);
35226
+ }
35227
+ }, [paymentSecret]);
35222
35228
  return (React__default.createElement("div", { className: "space-y-6" },
35223
35229
  React__default.createElement("div", null,
35224
35230
  React__default.createElement("h2", { className: "mb-2" }, t("CheckoutEmbed.Payment.title")),
@@ -35245,7 +35251,7 @@ function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack,
35245
35251
  " \u00B7 ",
35246
35252
  shippingPrice)),
35247
35253
  React__default.createElement(Button, { variant: "link", size: "link", onClick: onBack }, t("CheckoutEmbed.Shipping.change")))),
35248
- 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, setSubmitting: setIsSubmitting, publicKey: publicKey },
35254
+ React__default.createElement("div", { className: "mt-8" }, paymentSecret && (React__default.createElement(PaymentElement$1, { key: key, fonts: fonts, checkoutAppearance: convertCheckoutAppearanceToStripeAppearance(checkoutAppearance, fonts), locale: locale, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, setSubmitting: setIsSubmitting, publicKey: publicKey },
35249
35255
  React__default.createElement("div", { className: "flex justify-between items-center pt-8" },
35250
35256
  React__default.createElement(Button, { type: "button", variant: "ghost", onClick: onBack },
35251
35257
  React__default.createElement(ChevronLeft, null),
@@ -35428,10 +35434,8 @@ const motionSettings = {
35428
35434
  exit: { opacity: 0 },
35429
35435
  transition: { duration: 0.2 },
35430
35436
  };
35431
- function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, setCheckout, }) {
35437
+ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, setCheckout, setPaymentSecret, setPublicKey, paymentSecret, publicKey, }) {
35432
35438
  const { formData, setFormData, step, setStep, checkoutId: storedCheckoutId, setCheckoutId, } = useFormStore();
35433
- const [paymentSecret, setPaymentSecret] = useState(null);
35434
- const [publicKey, setPublicKey] = useState(null);
35435
35439
  const [shippingRates, setShippingRates] = useState([]);
35436
35440
  const validateStep = useCallback(() => {
35437
35441
  if (step === "customer")
@@ -35586,9 +35590,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
35586
35590
  };
35587
35591
  useEffect(() => {
35588
35592
  const asyncFunc = () => __awaiter(this, void 0, void 0, function* () {
35589
- const _a = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId), { paymentSecret, publicKey, checkoutSession: newCheckout } = _a, rest = __rest(_a, ["paymentSecret", "publicKey", "checkoutSession"]);
35590
- console.log("newCheckout", newCheckout);
35591
- console.log("rest", rest);
35593
+ const { paymentSecret, publicKey, checkoutSession: newCheckout, } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
35592
35594
  setPaymentSecret(paymentSecret);
35593
35595
  setPublicKey(publicKey);
35594
35596
  setCheckout(newCheckout);
@@ -35831,7 +35833,9 @@ function CheckoutEmbed({ checkoutId, config }) {
35831
35833
  const { cancelUrl, successUrl, appearance, locale, clientSecret, clientProxy, } = config;
35832
35834
  const storeClient = React__default.useMemo(() => createStoreClient({ proxy: clientProxy }), [clientProxy]);
35833
35835
  React__default.useMemo(() => createI18nInstance(locale), []);
35834
- const { formData, setFormData, setStep } = useFormStore();
35836
+ const { formData, step } = useFormStore();
35837
+ const [paymentSecret, setPaymentSecret] = useState(null);
35838
+ const [publicKey, setPublicKey] = useState(null);
35835
35839
  const [checkout, setCheckout] = useState(null);
35836
35840
  const [loading, setLoading] = useState(true);
35837
35841
  useEffect(() => {
@@ -35885,12 +35889,28 @@ function CheckoutEmbed({ checkoutId, config }) {
35885
35889
  setCheckout(newCheckout);
35886
35890
  });
35887
35891
  const revalidateDiscounts = () => __awaiter(this, void 0, void 0, function* () {
35888
- const newCheckout = yield storeClient.revalidateDiscounts(clientSecret, checkoutId);
35889
- setCheckout(newCheckout);
35892
+ if (step === "payment") {
35893
+ const { paymentSecret, publicKey, checkoutSession } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
35894
+ setPaymentSecret(paymentSecret);
35895
+ setPublicKey(publicKey);
35896
+ setCheckout(checkoutSession);
35897
+ }
35898
+ else {
35899
+ const newCheckout = yield storeClient.revalidateDiscounts(clientSecret, checkoutId);
35900
+ setCheckout(newCheckout);
35901
+ }
35890
35902
  });
35891
35903
  const removeDiscount = (id) => __awaiter(this, void 0, void 0, function* () {
35892
35904
  const newCheckout = yield storeClient.removeDiscount(clientSecret, checkoutId, id);
35893
- setCheckout(newCheckout);
35905
+ if (step === "payment") {
35906
+ const { paymentSecret, publicKey, checkoutSession } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
35907
+ setPaymentSecret(paymentSecret);
35908
+ setPublicKey(publicKey);
35909
+ setCheckout(checkoutSession);
35910
+ }
35911
+ else {
35912
+ setCheckout(newCheckout);
35913
+ }
35894
35914
  });
35895
35915
  useEffect(() => {
35896
35916
  const interval = setTimeout(() => {
@@ -35900,7 +35920,7 @@ function CheckoutEmbed({ checkoutId, config }) {
35900
35920
  }, []);
35901
35921
  return (React__default.createElement("div", { className: "checkout-embed scrollbar-hidden mx-auto max-w-[1200px] min-h-screen overflow-x-hidden gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
35902
35922
  React__default.createElement(Appearance, { appearance: appearance }),
35903
- 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, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1, setCheckout: setCheckout }))),
35923
+ 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, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1, setCheckout: setCheckout, setPublicKey: setPublicKey, publicKey: publicKey, setPaymentSecret: setPaymentSecret, paymentSecret: paymentSecret }))),
35904
35924
  React__default.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" },
35905
35925
  React__default.createElement(Toaster, null),
35906
35926
  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 : [], revalidateDiscounts: revalidateDiscounts, removeDiscount: removeDiscount })))));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterstore/react",
3
- "version": "0.3.14",
3
+ "version": "0.3.16",
4
4
  "description": "E-commerce for Developers",
5
5
  "private": false,
6
6
  "publishConfig": {