@pelcro/react-pelcro-js 4.0.0-alpha.108 → 4.0.0-alpha.109
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/dist/index.cjs.js +64 -18
- package/dist/index.esm.js +64 -18
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -3783,7 +3783,8 @@ var labels$X = {
|
|
|
3783
3783
|
summary: "Order summary",
|
|
3784
3784
|
total: "Total",
|
|
3785
3785
|
subtotal: "Subtotal",
|
|
3786
|
-
shippingRate: "Shipping Rate"
|
|
3786
|
+
shippingRate: "Shipping Rate",
|
|
3787
|
+
tax: "Tax"
|
|
3787
3788
|
};
|
|
3788
3789
|
var shop_en = {
|
|
3789
3790
|
buttons: buttons$h,
|
|
@@ -9552,7 +9553,7 @@ const trackSubscriptionOnGA = () => {
|
|
|
9552
9553
|
couponCode
|
|
9553
9554
|
} = usePelcro.getStore();
|
|
9554
9555
|
|
|
9555
|
-
/*
|
|
9556
|
+
/*
|
|
9556
9557
|
getting the latest subscription id from invoices instead of subscriptions
|
|
9557
9558
|
to handle gifted subs which are not added to subs list
|
|
9558
9559
|
*/
|
|
@@ -9763,6 +9764,10 @@ const refreshUser = () => {
|
|
|
9763
9764
|
}
|
|
9764
9765
|
});
|
|
9765
9766
|
};
|
|
9767
|
+
const isStagingEnvironment = () => {
|
|
9768
|
+
var _window$Pelcro$enviro2;
|
|
9769
|
+
return (_window$Pelcro$enviro2 = window.Pelcro.environment) === null || _window$Pelcro$enviro2 === void 0 ? void 0 : _window$Pelcro$enviro2.domain.includes("staging");
|
|
9770
|
+
};
|
|
9766
9771
|
|
|
9767
9772
|
const resources = {
|
|
9768
9773
|
en: {
|
|
@@ -38727,28 +38732,56 @@ const OrderCreateSummary = ({
|
|
|
38727
38732
|
} = useTranslation("shop");
|
|
38728
38733
|
const [items, setItems] = React.useState([]);
|
|
38729
38734
|
const [paymentInfo, setPaymentInfo] = React.useState({});
|
|
38735
|
+
const {
|
|
38736
|
+
selectedAddressId
|
|
38737
|
+
} = usePelcro();
|
|
38738
|
+
async function fetchOrderSummary(orderSummaryPaylod) {
|
|
38739
|
+
try {
|
|
38740
|
+
const domain = isStagingEnvironment() ? "https://staging.pelcro.com" : "https://www.pelcro.com";
|
|
38741
|
+
const url = `${domain}/api/v1/sdk/ecommerce/order-summary`;
|
|
38742
|
+
const response = await fetch(url, {
|
|
38743
|
+
method: "POST",
|
|
38744
|
+
headers: {
|
|
38745
|
+
"Content-Type": "application/json",
|
|
38746
|
+
Authorization: `Bearer ${window.Pelcro.user.read().auth_token}`
|
|
38747
|
+
},
|
|
38748
|
+
body: JSON.stringify(orderSummaryPaylod)
|
|
38749
|
+
});
|
|
38750
|
+
if (response.ok) {
|
|
38751
|
+
var _data$data;
|
|
38752
|
+
const data = await response.json();
|
|
38753
|
+
console.log("data", data);
|
|
38754
|
+
setPaymentInfo({
|
|
38755
|
+
total: data === null || data === void 0 ? void 0 : data.data.total,
|
|
38756
|
+
shippingRate: data === null || data === void 0 ? void 0 : data.data.shipping_rate,
|
|
38757
|
+
subtotal: data === null || data === void 0 ? void 0 : data.data.subtotal,
|
|
38758
|
+
taxes: data === null || data === void 0 ? void 0 : (_data$data = data.data) === null || _data$data === void 0 ? void 0 : _data$data.tax_rate
|
|
38759
|
+
});
|
|
38760
|
+
}
|
|
38761
|
+
} catch (error) {
|
|
38762
|
+
console.error(error);
|
|
38763
|
+
}
|
|
38764
|
+
}
|
|
38730
38765
|
React.useEffect(() => {
|
|
38766
|
+
var _window$Pelcro$site$r;
|
|
38731
38767
|
if (!(order !== null && order !== void 0 && order.length) || paymentInfo !== null && paymentInfo !== void 0 && paymentInfo.total) {
|
|
38732
38768
|
return;
|
|
38733
38769
|
}
|
|
38734
|
-
|
|
38770
|
+
const orderSummaryPaylod = {
|
|
38735
38771
|
items: order.map(item => {
|
|
38736
38772
|
return {
|
|
38737
38773
|
sku_id: item.id,
|
|
38738
38774
|
quantity: item.quantity
|
|
38739
38775
|
};
|
|
38740
38776
|
})
|
|
38741
|
-
}
|
|
38742
|
-
|
|
38743
|
-
|
|
38744
|
-
|
|
38745
|
-
|
|
38746
|
-
|
|
38747
|
-
|
|
38748
|
-
|
|
38749
|
-
});
|
|
38750
|
-
});
|
|
38751
|
-
}, [order, paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.total]);
|
|
38777
|
+
};
|
|
38778
|
+
if ((_window$Pelcro$site$r = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r !== void 0 && _window$Pelcro$site$r.taxes_enabled) {
|
|
38779
|
+
orderSummaryPaylod.address_id = selectedAddressId;
|
|
38780
|
+
}
|
|
38781
|
+
orderSummaryPaylod.site_id = window.Pelcro.siteid;
|
|
38782
|
+
console.log("orderSummaryPaylod", orderSummaryPaylod);
|
|
38783
|
+
fetchOrderSummary(orderSummaryPaylod);
|
|
38784
|
+
}, [order, paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.total, selectedAddressId]);
|
|
38752
38785
|
React.useEffect(() => {
|
|
38753
38786
|
const isQuickPurchase = !Array.isArray(order);
|
|
38754
38787
|
if (isQuickPurchase) {
|
|
@@ -38766,9 +38799,16 @@ const OrderCreateSummary = ({
|
|
|
38766
38799
|
var _order$2;
|
|
38767
38800
|
return getFormattedPriceByLocal((paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.shippingRate) || 0, order === null || order === void 0 ? void 0 : (_order$2 = order[0]) === null || _order$2 === void 0 ? void 0 : _order$2.currency, getPageOrDefaultLanguage());
|
|
38768
38801
|
}, [paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.shippingRate, order]);
|
|
38769
|
-
const
|
|
38802
|
+
const taxRate = React.useMemo(() => {
|
|
38770
38803
|
var _order$3;
|
|
38771
|
-
|
|
38804
|
+
if (!(paymentInfo !== null && paymentInfo !== void 0 && paymentInfo.taxes)) {
|
|
38805
|
+
return "0";
|
|
38806
|
+
}
|
|
38807
|
+
return getFormattedPriceByLocal((paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.taxes) || 0, order === null || order === void 0 ? void 0 : (_order$3 = order[0]) === null || _order$3 === void 0 ? void 0 : _order$3.currency, getPageOrDefaultLanguage());
|
|
38808
|
+
}, [paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.taxes, order]);
|
|
38809
|
+
const total = React.useMemo(() => {
|
|
38810
|
+
var _order$4;
|
|
38811
|
+
return getFormattedPriceByLocal((paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.total) || 0, order === null || order === void 0 ? void 0 : (_order$4 = order[0]) === null || _order$4 === void 0 ? void 0 : _order$4.currency, getPageOrDefaultLanguage());
|
|
38772
38812
|
}, [paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.total, order]);
|
|
38773
38813
|
return /*#__PURE__*/React__default['default'].createElement("div", {
|
|
38774
38814
|
className: "plc-px-8 md:plc-px-0"
|
|
@@ -38818,7 +38858,13 @@ const OrderCreateSummary = ({
|
|
|
38818
38858
|
className: "plc-text-base"
|
|
38819
38859
|
}, t("labels.shippingRate")), /*#__PURE__*/React__default['default'].createElement("dd", {
|
|
38820
38860
|
className: "plc-text-base"
|
|
38821
|
-
}, shippingRate)), /*#__PURE__*/React__default['default'].createElement("div", {
|
|
38861
|
+
}, shippingRate)), taxRate !== "0" && /*#__PURE__*/React__default['default'].createElement("div", {
|
|
38862
|
+
className: "plc-flex plc-justify-between plc-text-gray-900"
|
|
38863
|
+
}, /*#__PURE__*/React__default['default'].createElement("dt", {
|
|
38864
|
+
className: "plc-text-base"
|
|
38865
|
+
}, t("labels.tax")), /*#__PURE__*/React__default['default'].createElement("dd", {
|
|
38866
|
+
className: "plc-text-base"
|
|
38867
|
+
}, taxRate)), /*#__PURE__*/React__default['default'].createElement("div", {
|
|
38822
38868
|
className: "plc-flex plc-justify-between plc-border-t plc-border-gray-200 plc-pt-6 plc-text-gray-900"
|
|
38823
38869
|
}, /*#__PURE__*/React__default['default'].createElement("dt", {
|
|
38824
38870
|
className: "plc-text-base"
|
|
@@ -40101,7 +40147,7 @@ BillingAddressSelectModal.viewId = "billing-address-select";
|
|
|
40101
40147
|
const moveDefaultPaymentMethodToStart = paymentMethods => {
|
|
40102
40148
|
const defaultPaymentMethod = getDefaultPaymentMethod(paymentMethods);
|
|
40103
40149
|
const paymentMethodsWithoutDefault = paymentMethods.filter(paymentMethod => paymentMethod.id !== defaultPaymentMethod.id);
|
|
40104
|
-
if (defaultPaymentMethod.status !== "chargeable") {
|
|
40150
|
+
if ((defaultPaymentMethod === null || defaultPaymentMethod === void 0 ? void 0 : defaultPaymentMethod.status) !== "chargeable") {
|
|
40105
40151
|
return paymentMethodsWithoutDefault;
|
|
40106
40152
|
}
|
|
40107
40153
|
return [defaultPaymentMethod, ...paymentMethodsWithoutDefault];
|
package/dist/index.esm.js
CHANGED
|
@@ -3753,7 +3753,8 @@ var labels$X = {
|
|
|
3753
3753
|
summary: "Order summary",
|
|
3754
3754
|
total: "Total",
|
|
3755
3755
|
subtotal: "Subtotal",
|
|
3756
|
-
shippingRate: "Shipping Rate"
|
|
3756
|
+
shippingRate: "Shipping Rate",
|
|
3757
|
+
tax: "Tax"
|
|
3757
3758
|
};
|
|
3758
3759
|
var shop_en = {
|
|
3759
3760
|
buttons: buttons$h,
|
|
@@ -9522,7 +9523,7 @@ const trackSubscriptionOnGA = () => {
|
|
|
9522
9523
|
couponCode
|
|
9523
9524
|
} = usePelcro.getStore();
|
|
9524
9525
|
|
|
9525
|
-
/*
|
|
9526
|
+
/*
|
|
9526
9527
|
getting the latest subscription id from invoices instead of subscriptions
|
|
9527
9528
|
to handle gifted subs which are not added to subs list
|
|
9528
9529
|
*/
|
|
@@ -9733,6 +9734,10 @@ const refreshUser = () => {
|
|
|
9733
9734
|
}
|
|
9734
9735
|
});
|
|
9735
9736
|
};
|
|
9737
|
+
const isStagingEnvironment = () => {
|
|
9738
|
+
var _window$Pelcro$enviro2;
|
|
9739
|
+
return (_window$Pelcro$enviro2 = window.Pelcro.environment) === null || _window$Pelcro$enviro2 === void 0 ? void 0 : _window$Pelcro$enviro2.domain.includes("staging");
|
|
9740
|
+
};
|
|
9736
9741
|
|
|
9737
9742
|
const resources = {
|
|
9738
9743
|
en: {
|
|
@@ -38697,28 +38702,56 @@ const OrderCreateSummary = ({
|
|
|
38697
38702
|
} = useTranslation("shop");
|
|
38698
38703
|
const [items, setItems] = useState([]);
|
|
38699
38704
|
const [paymentInfo, setPaymentInfo] = useState({});
|
|
38705
|
+
const {
|
|
38706
|
+
selectedAddressId
|
|
38707
|
+
} = usePelcro();
|
|
38708
|
+
async function fetchOrderSummary(orderSummaryPaylod) {
|
|
38709
|
+
try {
|
|
38710
|
+
const domain = isStagingEnvironment() ? "https://staging.pelcro.com" : "https://www.pelcro.com";
|
|
38711
|
+
const url = `${domain}/api/v1/sdk/ecommerce/order-summary`;
|
|
38712
|
+
const response = await fetch(url, {
|
|
38713
|
+
method: "POST",
|
|
38714
|
+
headers: {
|
|
38715
|
+
"Content-Type": "application/json",
|
|
38716
|
+
Authorization: `Bearer ${window.Pelcro.user.read().auth_token}`
|
|
38717
|
+
},
|
|
38718
|
+
body: JSON.stringify(orderSummaryPaylod)
|
|
38719
|
+
});
|
|
38720
|
+
if (response.ok) {
|
|
38721
|
+
var _data$data;
|
|
38722
|
+
const data = await response.json();
|
|
38723
|
+
console.log("data", data);
|
|
38724
|
+
setPaymentInfo({
|
|
38725
|
+
total: data === null || data === void 0 ? void 0 : data.data.total,
|
|
38726
|
+
shippingRate: data === null || data === void 0 ? void 0 : data.data.shipping_rate,
|
|
38727
|
+
subtotal: data === null || data === void 0 ? void 0 : data.data.subtotal,
|
|
38728
|
+
taxes: data === null || data === void 0 ? void 0 : (_data$data = data.data) === null || _data$data === void 0 ? void 0 : _data$data.tax_rate
|
|
38729
|
+
});
|
|
38730
|
+
}
|
|
38731
|
+
} catch (error) {
|
|
38732
|
+
console.error(error);
|
|
38733
|
+
}
|
|
38734
|
+
}
|
|
38700
38735
|
useEffect(() => {
|
|
38736
|
+
var _window$Pelcro$site$r;
|
|
38701
38737
|
if (!(order !== null && order !== void 0 && order.length) || paymentInfo !== null && paymentInfo !== void 0 && paymentInfo.total) {
|
|
38702
38738
|
return;
|
|
38703
38739
|
}
|
|
38704
|
-
|
|
38740
|
+
const orderSummaryPaylod = {
|
|
38705
38741
|
items: order.map(item => {
|
|
38706
38742
|
return {
|
|
38707
38743
|
sku_id: item.id,
|
|
38708
38744
|
quantity: item.quantity
|
|
38709
38745
|
};
|
|
38710
38746
|
})
|
|
38711
|
-
}
|
|
38712
|
-
|
|
38713
|
-
|
|
38714
|
-
|
|
38715
|
-
|
|
38716
|
-
|
|
38717
|
-
|
|
38718
|
-
|
|
38719
|
-
});
|
|
38720
|
-
});
|
|
38721
|
-
}, [order, paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.total]);
|
|
38747
|
+
};
|
|
38748
|
+
if ((_window$Pelcro$site$r = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r !== void 0 && _window$Pelcro$site$r.taxes_enabled) {
|
|
38749
|
+
orderSummaryPaylod.address_id = selectedAddressId;
|
|
38750
|
+
}
|
|
38751
|
+
orderSummaryPaylod.site_id = window.Pelcro.siteid;
|
|
38752
|
+
console.log("orderSummaryPaylod", orderSummaryPaylod);
|
|
38753
|
+
fetchOrderSummary(orderSummaryPaylod);
|
|
38754
|
+
}, [order, paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.total, selectedAddressId]);
|
|
38722
38755
|
useEffect(() => {
|
|
38723
38756
|
const isQuickPurchase = !Array.isArray(order);
|
|
38724
38757
|
if (isQuickPurchase) {
|
|
@@ -38736,9 +38769,16 @@ const OrderCreateSummary = ({
|
|
|
38736
38769
|
var _order$2;
|
|
38737
38770
|
return getFormattedPriceByLocal((paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.shippingRate) || 0, order === null || order === void 0 ? void 0 : (_order$2 = order[0]) === null || _order$2 === void 0 ? void 0 : _order$2.currency, getPageOrDefaultLanguage());
|
|
38738
38771
|
}, [paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.shippingRate, order]);
|
|
38739
|
-
const
|
|
38772
|
+
const taxRate = useMemo(() => {
|
|
38740
38773
|
var _order$3;
|
|
38741
|
-
|
|
38774
|
+
if (!(paymentInfo !== null && paymentInfo !== void 0 && paymentInfo.taxes)) {
|
|
38775
|
+
return "0";
|
|
38776
|
+
}
|
|
38777
|
+
return getFormattedPriceByLocal((paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.taxes) || 0, order === null || order === void 0 ? void 0 : (_order$3 = order[0]) === null || _order$3 === void 0 ? void 0 : _order$3.currency, getPageOrDefaultLanguage());
|
|
38778
|
+
}, [paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.taxes, order]);
|
|
38779
|
+
const total = useMemo(() => {
|
|
38780
|
+
var _order$4;
|
|
38781
|
+
return getFormattedPriceByLocal((paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.total) || 0, order === null || order === void 0 ? void 0 : (_order$4 = order[0]) === null || _order$4 === void 0 ? void 0 : _order$4.currency, getPageOrDefaultLanguage());
|
|
38742
38782
|
}, [paymentInfo === null || paymentInfo === void 0 ? void 0 : paymentInfo.total, order]);
|
|
38743
38783
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
38744
38784
|
className: "plc-px-8 md:plc-px-0"
|
|
@@ -38788,7 +38828,13 @@ const OrderCreateSummary = ({
|
|
|
38788
38828
|
className: "plc-text-base"
|
|
38789
38829
|
}, t("labels.shippingRate")), /*#__PURE__*/React__default.createElement("dd", {
|
|
38790
38830
|
className: "plc-text-base"
|
|
38791
|
-
}, shippingRate)), /*#__PURE__*/React__default.createElement("div", {
|
|
38831
|
+
}, shippingRate)), taxRate !== "0" && /*#__PURE__*/React__default.createElement("div", {
|
|
38832
|
+
className: "plc-flex plc-justify-between plc-text-gray-900"
|
|
38833
|
+
}, /*#__PURE__*/React__default.createElement("dt", {
|
|
38834
|
+
className: "plc-text-base"
|
|
38835
|
+
}, t("labels.tax")), /*#__PURE__*/React__default.createElement("dd", {
|
|
38836
|
+
className: "plc-text-base"
|
|
38837
|
+
}, taxRate)), /*#__PURE__*/React__default.createElement("div", {
|
|
38792
38838
|
className: "plc-flex plc-justify-between plc-border-t plc-border-gray-200 plc-pt-6 plc-text-gray-900"
|
|
38793
38839
|
}, /*#__PURE__*/React__default.createElement("dt", {
|
|
38794
38840
|
className: "plc-text-base"
|
|
@@ -40071,7 +40117,7 @@ BillingAddressSelectModal.viewId = "billing-address-select";
|
|
|
40071
40117
|
const moveDefaultPaymentMethodToStart = paymentMethods => {
|
|
40072
40118
|
const defaultPaymentMethod = getDefaultPaymentMethod(paymentMethods);
|
|
40073
40119
|
const paymentMethodsWithoutDefault = paymentMethods.filter(paymentMethod => paymentMethod.id !== defaultPaymentMethod.id);
|
|
40074
|
-
if (defaultPaymentMethod.status !== "chargeable") {
|
|
40120
|
+
if ((defaultPaymentMethod === null || defaultPaymentMethod === void 0 ? void 0 : defaultPaymentMethod.status) !== "chargeable") {
|
|
40075
40121
|
return paymentMethodsWithoutDefault;
|
|
40076
40122
|
}
|
|
40077
40123
|
return [defaultPaymentMethod, ...paymentMethodsWithoutDefault];
|