@betterstore/react 0.3.80 → 0.3.81
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/index.cjs.js +38 -3
- package/dist/index.mjs +38 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -35750,42 +35750,57 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35750
35750
|
};
|
|
35751
35751
|
function generatePaymentSecret() {
|
|
35752
35752
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35753
|
+
console.log("[Payment Debug] Generating new payment secret");
|
|
35753
35754
|
const { paymentSecret, publicKey, checkoutSession } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
|
|
35754
35755
|
setPaymentSecret(paymentSecret);
|
|
35755
35756
|
setPublicKey(publicKey);
|
|
35756
35757
|
setCheckout(checkoutSession);
|
|
35758
|
+
console.log("[Payment Debug] New payment secret generated");
|
|
35757
35759
|
});
|
|
35758
35760
|
}
|
|
35759
35761
|
React.useEffect(() => {
|
|
35760
35762
|
if (step === "payment" &&
|
|
35761
35763
|
!paymentSecret &&
|
|
35762
35764
|
!paymentSecretPromiseRef.current) {
|
|
35765
|
+
console.log("[Payment Debug] Initial payment secret generation triggered by useEffect");
|
|
35763
35766
|
paymentSecretPromiseRef.current = generatePaymentSecret().finally(() => {
|
|
35764
35767
|
paymentSecretPromiseRef.current = null;
|
|
35765
35768
|
});
|
|
35766
35769
|
}
|
|
35767
35770
|
}, [paymentSecret, step]);
|
|
35768
35771
|
const applyDiscountCode = (code) => __awaiter(this, void 0, void 0, function* () {
|
|
35772
|
+
console.log("[Payment Debug] Applying discount code:", code);
|
|
35769
35773
|
const newCheckout = yield storeClient.applyDiscountCode(clientSecret, checkoutId, code);
|
|
35770
35774
|
setCheckout(newCheckout);
|
|
35771
35775
|
if (step === "payment") {
|
|
35772
35776
|
const newTotal = calculateTotalWithDiscounts(newCheckout);
|
|
35773
35777
|
const currentTotal = calculateTotalWithDiscounts(checkout);
|
|
35778
|
+
console.log("[Payment Debug] Discount applied - New total:", newTotal, "Current total:", currentTotal);
|
|
35774
35779
|
if (newTotal !== currentTotal) {
|
|
35780
|
+
console.log("[Payment Debug] Total changed, regenerating payment secret");
|
|
35775
35781
|
yield generatePaymentSecret();
|
|
35776
35782
|
setPaymentComponentKey((prev) => prev + 1);
|
|
35777
35783
|
}
|
|
35784
|
+
else {
|
|
35785
|
+
console.log("[Payment Debug] Total unchanged, skipping payment secret regeneration");
|
|
35786
|
+
}
|
|
35778
35787
|
}
|
|
35779
35788
|
});
|
|
35780
35789
|
const revalidateDiscounts = () => __awaiter(this, void 0, void 0, function* () {
|
|
35790
|
+
console.log("[Payment Debug] Revalidating discounts");
|
|
35781
35791
|
if (step === "payment") {
|
|
35782
35792
|
const newCheckout = yield storeClient.revalidateDiscounts(clientSecret, checkoutId);
|
|
35783
35793
|
const newTotal = calculateTotalWithDiscounts(newCheckout);
|
|
35784
35794
|
const currentTotal = calculateTotalWithDiscounts(checkout);
|
|
35795
|
+
console.log("[Payment Debug] Discounts revalidated - New total:", newTotal, "Current total:", currentTotal);
|
|
35785
35796
|
if (newTotal !== currentTotal) {
|
|
35797
|
+
console.log("[Payment Debug] Total changed, regenerating payment secret");
|
|
35786
35798
|
yield generatePaymentSecret();
|
|
35787
35799
|
setPaymentComponentKey((prev) => prev + 1);
|
|
35788
35800
|
}
|
|
35801
|
+
else {
|
|
35802
|
+
console.log("[Payment Debug] Total unchanged, skipping payment secret regeneration");
|
|
35803
|
+
}
|
|
35789
35804
|
setCheckout(newCheckout);
|
|
35790
35805
|
}
|
|
35791
35806
|
else {
|
|
@@ -35794,15 +35809,21 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35794
35809
|
}
|
|
35795
35810
|
});
|
|
35796
35811
|
const removeDiscount = (id) => __awaiter(this, void 0, void 0, function* () {
|
|
35812
|
+
console.log("[Payment Debug] Removing discount:", id);
|
|
35797
35813
|
const newCheckout = yield storeClient.removeDiscount(clientSecret, checkoutId, id);
|
|
35798
35814
|
setCheckout(newCheckout);
|
|
35799
35815
|
if (step === "payment") {
|
|
35800
35816
|
const newTotal = calculateTotalWithDiscounts(newCheckout);
|
|
35801
35817
|
const currentTotal = calculateTotalWithDiscounts(checkout);
|
|
35818
|
+
console.log("[Payment Debug] Discount removed - New total:", newTotal, "Current total:", currentTotal);
|
|
35802
35819
|
if (newTotal !== currentTotal) {
|
|
35820
|
+
console.log("[Payment Debug] Total changed, regenerating payment secret");
|
|
35803
35821
|
yield generatePaymentSecret();
|
|
35804
35822
|
setPaymentComponentKey((prev) => prev + 1);
|
|
35805
35823
|
}
|
|
35824
|
+
else {
|
|
35825
|
+
console.log("[Payment Debug] Total unchanged, skipping payment secret regeneration");
|
|
35826
|
+
}
|
|
35806
35827
|
}
|
|
35807
35828
|
});
|
|
35808
35829
|
const calculateTotalWithDiscounts = (checkout) => {
|
|
@@ -35819,17 +35840,31 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35819
35840
|
const isShippingFree = subtotal > shippingPrice &&
|
|
35820
35841
|
checkout.appliedDiscounts.some((discount) => discount.discount.type === "FREE_SHIPPING");
|
|
35821
35842
|
const filteredDiscounts = checkout.appliedDiscounts.filter((discount) => discount.discount.type !== "FREE_SHIPPING");
|
|
35822
|
-
|
|
35843
|
+
const finalTotal = total -
|
|
35823
35844
|
filteredDiscounts.reduce((acc, { amount }) => acc + amount, 0) -
|
|
35824
|
-
(isShippingFree ? shippingPrice : 0)
|
|
35845
|
+
(isShippingFree ? shippingPrice : 0);
|
|
35846
|
+
console.log("[Payment Debug] Total calculation:", {
|
|
35847
|
+
subtotal,
|
|
35848
|
+
shippingPrice,
|
|
35849
|
+
tax: checkout.tax,
|
|
35850
|
+
isShippingFree,
|
|
35851
|
+
discountAmount: filteredDiscounts.reduce((acc, { amount }) => acc + amount, 0),
|
|
35852
|
+
finalTotal,
|
|
35853
|
+
});
|
|
35854
|
+
return finalTotal;
|
|
35825
35855
|
};
|
|
35826
35856
|
React.useEffect(() => {
|
|
35857
|
+
console.log("[Payment Debug] Setting up discount revalidation interval");
|
|
35827
35858
|
const interval = setTimeout(() => {
|
|
35828
35859
|
if (step !== "payment") {
|
|
35860
|
+
console.log("[Payment Debug] Interval triggered revalidation");
|
|
35829
35861
|
revalidateDiscounts();
|
|
35830
35862
|
}
|
|
35831
35863
|
}, 1000 * 5);
|
|
35832
|
-
return () =>
|
|
35864
|
+
return () => {
|
|
35865
|
+
console.log("[Payment Debug] Clearing revalidation interval");
|
|
35866
|
+
clearInterval(interval);
|
|
35867
|
+
};
|
|
35833
35868
|
}, []);
|
|
35834
35869
|
return (React.createElement(IframeWrapper, { iframeRef: iframeRef },
|
|
35835
35870
|
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 " },
|
package/dist/index.mjs
CHANGED
|
@@ -35730,42 +35730,57 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35730
35730
|
};
|
|
35731
35731
|
function generatePaymentSecret() {
|
|
35732
35732
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35733
|
+
console.log("[Payment Debug] Generating new payment secret");
|
|
35733
35734
|
const { paymentSecret, publicKey, checkoutSession } = yield storeClient.generateCheckoutPaymentSecret(clientSecret, checkoutId);
|
|
35734
35735
|
setPaymentSecret(paymentSecret);
|
|
35735
35736
|
setPublicKey(publicKey);
|
|
35736
35737
|
setCheckout(checkoutSession);
|
|
35738
|
+
console.log("[Payment Debug] New payment secret generated");
|
|
35737
35739
|
});
|
|
35738
35740
|
}
|
|
35739
35741
|
useEffect(() => {
|
|
35740
35742
|
if (step === "payment" &&
|
|
35741
35743
|
!paymentSecret &&
|
|
35742
35744
|
!paymentSecretPromiseRef.current) {
|
|
35745
|
+
console.log("[Payment Debug] Initial payment secret generation triggered by useEffect");
|
|
35743
35746
|
paymentSecretPromiseRef.current = generatePaymentSecret().finally(() => {
|
|
35744
35747
|
paymentSecretPromiseRef.current = null;
|
|
35745
35748
|
});
|
|
35746
35749
|
}
|
|
35747
35750
|
}, [paymentSecret, step]);
|
|
35748
35751
|
const applyDiscountCode = (code) => __awaiter(this, void 0, void 0, function* () {
|
|
35752
|
+
console.log("[Payment Debug] Applying discount code:", code);
|
|
35749
35753
|
const newCheckout = yield storeClient.applyDiscountCode(clientSecret, checkoutId, code);
|
|
35750
35754
|
setCheckout(newCheckout);
|
|
35751
35755
|
if (step === "payment") {
|
|
35752
35756
|
const newTotal = calculateTotalWithDiscounts(newCheckout);
|
|
35753
35757
|
const currentTotal = calculateTotalWithDiscounts(checkout);
|
|
35758
|
+
console.log("[Payment Debug] Discount applied - New total:", newTotal, "Current total:", currentTotal);
|
|
35754
35759
|
if (newTotal !== currentTotal) {
|
|
35760
|
+
console.log("[Payment Debug] Total changed, regenerating payment secret");
|
|
35755
35761
|
yield generatePaymentSecret();
|
|
35756
35762
|
setPaymentComponentKey((prev) => prev + 1);
|
|
35757
35763
|
}
|
|
35764
|
+
else {
|
|
35765
|
+
console.log("[Payment Debug] Total unchanged, skipping payment secret regeneration");
|
|
35766
|
+
}
|
|
35758
35767
|
}
|
|
35759
35768
|
});
|
|
35760
35769
|
const revalidateDiscounts = () => __awaiter(this, void 0, void 0, function* () {
|
|
35770
|
+
console.log("[Payment Debug] Revalidating discounts");
|
|
35761
35771
|
if (step === "payment") {
|
|
35762
35772
|
const newCheckout = yield storeClient.revalidateDiscounts(clientSecret, checkoutId);
|
|
35763
35773
|
const newTotal = calculateTotalWithDiscounts(newCheckout);
|
|
35764
35774
|
const currentTotal = calculateTotalWithDiscounts(checkout);
|
|
35775
|
+
console.log("[Payment Debug] Discounts revalidated - New total:", newTotal, "Current total:", currentTotal);
|
|
35765
35776
|
if (newTotal !== currentTotal) {
|
|
35777
|
+
console.log("[Payment Debug] Total changed, regenerating payment secret");
|
|
35766
35778
|
yield generatePaymentSecret();
|
|
35767
35779
|
setPaymentComponentKey((prev) => prev + 1);
|
|
35768
35780
|
}
|
|
35781
|
+
else {
|
|
35782
|
+
console.log("[Payment Debug] Total unchanged, skipping payment secret regeneration");
|
|
35783
|
+
}
|
|
35769
35784
|
setCheckout(newCheckout);
|
|
35770
35785
|
}
|
|
35771
35786
|
else {
|
|
@@ -35774,15 +35789,21 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35774
35789
|
}
|
|
35775
35790
|
});
|
|
35776
35791
|
const removeDiscount = (id) => __awaiter(this, void 0, void 0, function* () {
|
|
35792
|
+
console.log("[Payment Debug] Removing discount:", id);
|
|
35777
35793
|
const newCheckout = yield storeClient.removeDiscount(clientSecret, checkoutId, id);
|
|
35778
35794
|
setCheckout(newCheckout);
|
|
35779
35795
|
if (step === "payment") {
|
|
35780
35796
|
const newTotal = calculateTotalWithDiscounts(newCheckout);
|
|
35781
35797
|
const currentTotal = calculateTotalWithDiscounts(checkout);
|
|
35798
|
+
console.log("[Payment Debug] Discount removed - New total:", newTotal, "Current total:", currentTotal);
|
|
35782
35799
|
if (newTotal !== currentTotal) {
|
|
35800
|
+
console.log("[Payment Debug] Total changed, regenerating payment secret");
|
|
35783
35801
|
yield generatePaymentSecret();
|
|
35784
35802
|
setPaymentComponentKey((prev) => prev + 1);
|
|
35785
35803
|
}
|
|
35804
|
+
else {
|
|
35805
|
+
console.log("[Payment Debug] Total unchanged, skipping payment secret regeneration");
|
|
35806
|
+
}
|
|
35786
35807
|
}
|
|
35787
35808
|
});
|
|
35788
35809
|
const calculateTotalWithDiscounts = (checkout) => {
|
|
@@ -35799,17 +35820,31 @@ function CheckoutEmbedComponent({ checkoutId, config }) {
|
|
|
35799
35820
|
const isShippingFree = subtotal > shippingPrice &&
|
|
35800
35821
|
checkout.appliedDiscounts.some((discount) => discount.discount.type === "FREE_SHIPPING");
|
|
35801
35822
|
const filteredDiscounts = checkout.appliedDiscounts.filter((discount) => discount.discount.type !== "FREE_SHIPPING");
|
|
35802
|
-
|
|
35823
|
+
const finalTotal = total -
|
|
35803
35824
|
filteredDiscounts.reduce((acc, { amount }) => acc + amount, 0) -
|
|
35804
|
-
(isShippingFree ? shippingPrice : 0)
|
|
35825
|
+
(isShippingFree ? shippingPrice : 0);
|
|
35826
|
+
console.log("[Payment Debug] Total calculation:", {
|
|
35827
|
+
subtotal,
|
|
35828
|
+
shippingPrice,
|
|
35829
|
+
tax: checkout.tax,
|
|
35830
|
+
isShippingFree,
|
|
35831
|
+
discountAmount: filteredDiscounts.reduce((acc, { amount }) => acc + amount, 0),
|
|
35832
|
+
finalTotal,
|
|
35833
|
+
});
|
|
35834
|
+
return finalTotal;
|
|
35805
35835
|
};
|
|
35806
35836
|
useEffect(() => {
|
|
35837
|
+
console.log("[Payment Debug] Setting up discount revalidation interval");
|
|
35807
35838
|
const interval = setTimeout(() => {
|
|
35808
35839
|
if (step !== "payment") {
|
|
35840
|
+
console.log("[Payment Debug] Interval triggered revalidation");
|
|
35809
35841
|
revalidateDiscounts();
|
|
35810
35842
|
}
|
|
35811
35843
|
}, 1000 * 5);
|
|
35812
|
-
return () =>
|
|
35844
|
+
return () => {
|
|
35845
|
+
console.log("[Payment Debug] Clearing revalidation interval");
|
|
35846
|
+
clearInterval(interval);
|
|
35847
|
+
};
|
|
35813
35848
|
}, []);
|
|
35814
35849
|
return (React__default.createElement(IframeWrapper, { iframeRef: iframeRef },
|
|
35815
35850
|
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 " },
|