@pelcro/react-pelcro-js 3.2.0-beta.14 → 3.2.0-beta.15
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 +20 -6
- package/dist/index.esm.js +20 -6
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -6438,6 +6438,19 @@ if (process.env.NODE_ENV === "development") {
|
|
|
6438
6438
|
c$1("Pelcro Store", usePelcro);
|
|
6439
6439
|
}
|
|
6440
6440
|
|
|
6441
|
+
/**
|
|
6442
|
+
* List of zero-decimal currencies.
|
|
6443
|
+
* @see https://stripe.com/docs/currencies#zero-decimal
|
|
6444
|
+
*
|
|
6445
|
+
*/
|
|
6446
|
+
|
|
6447
|
+
const ZERO_DECIMAL_CURRENCIES = ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'];
|
|
6448
|
+
/**
|
|
6449
|
+
* @param {string}
|
|
6450
|
+
* @return {boolean}
|
|
6451
|
+
*/
|
|
6452
|
+
|
|
6453
|
+
const isCurrencyZeroDecimal = currency => ZERO_DECIMAL_CURRENCIES.includes(currency);
|
|
6441
6454
|
const sortCountries = countries => {
|
|
6442
6455
|
const sortable = [];
|
|
6443
6456
|
delete countries.CA;
|
|
@@ -6524,7 +6537,7 @@ const getFormattedPriceByLocal = (amount, currency = "USD", locale = "en") => {
|
|
|
6524
6537
|
style: "currency",
|
|
6525
6538
|
currency
|
|
6526
6539
|
});
|
|
6527
|
-
return formatter.format(amount / 100);
|
|
6540
|
+
return isCurrencyZeroDecimal(currency) ? formatter.format(amount) : formatter.format(amount / 100);
|
|
6528
6541
|
};
|
|
6529
6542
|
/** check wether or not the user have any addresses
|
|
6530
6543
|
* @return {boolean} true if the user have at least one address, false otherwise
|
|
@@ -6541,7 +6554,7 @@ const calcAndFormatItemsTotal = (items, currency) => {
|
|
|
6541
6554
|
let totalWithoutDividingBy100 = 0;
|
|
6542
6555
|
|
|
6543
6556
|
for (const item of items) {
|
|
6544
|
-
totalWithoutDividingBy100 += parseFloat(item.price ? (item.price * item.quantity).toFixed(2) : item.amount.toFixed(2));
|
|
6557
|
+
totalWithoutDividingBy100 += parseFloat(item.price ? isCurrencyZeroDecimal(currency) ? item.price * item.quantity : (item.price * item.quantity).toFixed(2) : isCurrencyZeroDecimal(currency) ? item.amount : item.amount.toFixed(2));
|
|
6545
6558
|
}
|
|
6546
6559
|
|
|
6547
6560
|
return getFormattedPriceByLocal(totalWithoutDividingBy100, currency, getPageOrDefaultLanguage());
|
|
@@ -6621,7 +6634,7 @@ const disableScroll = () => {
|
|
|
6621
6634
|
}
|
|
6622
6635
|
};
|
|
6623
6636
|
const trackSubscriptionOnGA = () => {
|
|
6624
|
-
var
|
|
6637
|
+
var _window$Pelcro$user$r5, _window$Pelcro$user$r6, _ReactGA$set, _ReactGA$plugin, _ReactGA$plugin$execu, _ReactGA$plugin2, _ReactGA$plugin2$exec, _ReactGA$plugin3, _ReactGA$plugin3$exec, _ReactGA$event;
|
|
6625
6638
|
|
|
6626
6639
|
const {
|
|
6627
6640
|
product,
|
|
@@ -6642,13 +6655,14 @@ const trackSubscriptionOnGA = () => {
|
|
|
6642
6655
|
return;
|
|
6643
6656
|
}
|
|
6644
6657
|
|
|
6658
|
+
const currencyCode = (_window$Pelcro$user$r5 = (_window$Pelcro$user$r6 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r6 === void 0 ? void 0 : _window$Pelcro$user$r6.currency) !== null && _window$Pelcro$user$r5 !== void 0 ? _window$Pelcro$user$r5 : plan.currency;
|
|
6645
6659
|
ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$set = ReactGA.set) === null || _ReactGA$set === void 0 ? void 0 : _ReactGA$set.call(ReactGA, {
|
|
6646
|
-
currencyCode:
|
|
6660
|
+
currencyCode: currencyCode
|
|
6647
6661
|
});
|
|
6648
6662
|
ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin = ReactGA.plugin) === null || _ReactGA$plugin === void 0 ? void 0 : (_ReactGA$plugin$execu = _ReactGA$plugin.execute) === null || _ReactGA$plugin$execu === void 0 ? void 0 : _ReactGA$plugin$execu.call(_ReactGA$plugin, "ecommerce", "addTransaction", {
|
|
6649
6663
|
id: lastSubscriptionId,
|
|
6650
6664
|
affiliation: "Pelcro",
|
|
6651
|
-
revenue: plan !== null && plan !== void 0 && plan.amount ? plan.amount / 100 : 0,
|
|
6665
|
+
revenue: plan !== null && plan !== void 0 && plan.amount ? isCurrencyZeroDecimal(currencyCode) ? plan.amount : plan.amount / 100 : 0,
|
|
6652
6666
|
coupon: couponCode
|
|
6653
6667
|
});
|
|
6654
6668
|
ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin2 = ReactGA.plugin) === null || _ReactGA$plugin2 === void 0 ? void 0 : (_ReactGA$plugin2$exec = _ReactGA$plugin2.execute) === null || _ReactGA$plugin2$exec === void 0 ? void 0 : _ReactGA$plugin2$exec.call(_ReactGA$plugin2, "ecommerce", "addItem", {
|
|
@@ -6656,7 +6670,7 @@ const trackSubscriptionOnGA = () => {
|
|
|
6656
6670
|
name: product.name,
|
|
6657
6671
|
category: product.description,
|
|
6658
6672
|
variant: plan.nickname,
|
|
6659
|
-
price: plan !== null && plan !== void 0 && plan.amount ? plan.amount / 100 : 0,
|
|
6673
|
+
price: plan !== null && plan !== void 0 && plan.amount ? isCurrencyZeroDecimal(currencyCode) ? plan.amount : plan.amount / 100 : 0,
|
|
6660
6674
|
quantity: 1
|
|
6661
6675
|
});
|
|
6662
6676
|
ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin3 = ReactGA.plugin) === null || _ReactGA$plugin3 === void 0 ? void 0 : (_ReactGA$plugin3$exec = _ReactGA$plugin3.execute) === null || _ReactGA$plugin3$exec === void 0 ? void 0 : _ReactGA$plugin3$exec.call(_ReactGA$plugin3, "ecommerce", "send");
|
package/dist/index.esm.js
CHANGED
|
@@ -6408,6 +6408,19 @@ if (process.env.NODE_ENV === "development") {
|
|
|
6408
6408
|
c$1("Pelcro Store", usePelcro);
|
|
6409
6409
|
}
|
|
6410
6410
|
|
|
6411
|
+
/**
|
|
6412
|
+
* List of zero-decimal currencies.
|
|
6413
|
+
* @see https://stripe.com/docs/currencies#zero-decimal
|
|
6414
|
+
*
|
|
6415
|
+
*/
|
|
6416
|
+
|
|
6417
|
+
const ZERO_DECIMAL_CURRENCIES = ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'];
|
|
6418
|
+
/**
|
|
6419
|
+
* @param {string}
|
|
6420
|
+
* @return {boolean}
|
|
6421
|
+
*/
|
|
6422
|
+
|
|
6423
|
+
const isCurrencyZeroDecimal = currency => ZERO_DECIMAL_CURRENCIES.includes(currency);
|
|
6411
6424
|
const sortCountries = countries => {
|
|
6412
6425
|
const sortable = [];
|
|
6413
6426
|
delete countries.CA;
|
|
@@ -6494,7 +6507,7 @@ const getFormattedPriceByLocal = (amount, currency = "USD", locale = "en") => {
|
|
|
6494
6507
|
style: "currency",
|
|
6495
6508
|
currency
|
|
6496
6509
|
});
|
|
6497
|
-
return formatter.format(amount / 100);
|
|
6510
|
+
return isCurrencyZeroDecimal(currency) ? formatter.format(amount) : formatter.format(amount / 100);
|
|
6498
6511
|
};
|
|
6499
6512
|
/** check wether or not the user have any addresses
|
|
6500
6513
|
* @return {boolean} true if the user have at least one address, false otherwise
|
|
@@ -6511,7 +6524,7 @@ const calcAndFormatItemsTotal = (items, currency) => {
|
|
|
6511
6524
|
let totalWithoutDividingBy100 = 0;
|
|
6512
6525
|
|
|
6513
6526
|
for (const item of items) {
|
|
6514
|
-
totalWithoutDividingBy100 += parseFloat(item.price ? (item.price * item.quantity).toFixed(2) : item.amount.toFixed(2));
|
|
6527
|
+
totalWithoutDividingBy100 += parseFloat(item.price ? isCurrencyZeroDecimal(currency) ? item.price * item.quantity : (item.price * item.quantity).toFixed(2) : isCurrencyZeroDecimal(currency) ? item.amount : item.amount.toFixed(2));
|
|
6515
6528
|
}
|
|
6516
6529
|
|
|
6517
6530
|
return getFormattedPriceByLocal(totalWithoutDividingBy100, currency, getPageOrDefaultLanguage());
|
|
@@ -6591,7 +6604,7 @@ const disableScroll = () => {
|
|
|
6591
6604
|
}
|
|
6592
6605
|
};
|
|
6593
6606
|
const trackSubscriptionOnGA = () => {
|
|
6594
|
-
var
|
|
6607
|
+
var _window$Pelcro$user$r5, _window$Pelcro$user$r6, _ReactGA$set, _ReactGA$plugin, _ReactGA$plugin$execu, _ReactGA$plugin2, _ReactGA$plugin2$exec, _ReactGA$plugin3, _ReactGA$plugin3$exec, _ReactGA$event;
|
|
6595
6608
|
|
|
6596
6609
|
const {
|
|
6597
6610
|
product,
|
|
@@ -6612,13 +6625,14 @@ const trackSubscriptionOnGA = () => {
|
|
|
6612
6625
|
return;
|
|
6613
6626
|
}
|
|
6614
6627
|
|
|
6628
|
+
const currencyCode = (_window$Pelcro$user$r5 = (_window$Pelcro$user$r6 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r6 === void 0 ? void 0 : _window$Pelcro$user$r6.currency) !== null && _window$Pelcro$user$r5 !== void 0 ? _window$Pelcro$user$r5 : plan.currency;
|
|
6615
6629
|
ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$set = ReactGA.set) === null || _ReactGA$set === void 0 ? void 0 : _ReactGA$set.call(ReactGA, {
|
|
6616
|
-
currencyCode:
|
|
6630
|
+
currencyCode: currencyCode
|
|
6617
6631
|
});
|
|
6618
6632
|
ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin = ReactGA.plugin) === null || _ReactGA$plugin === void 0 ? void 0 : (_ReactGA$plugin$execu = _ReactGA$plugin.execute) === null || _ReactGA$plugin$execu === void 0 ? void 0 : _ReactGA$plugin$execu.call(_ReactGA$plugin, "ecommerce", "addTransaction", {
|
|
6619
6633
|
id: lastSubscriptionId,
|
|
6620
6634
|
affiliation: "Pelcro",
|
|
6621
|
-
revenue: plan !== null && plan !== void 0 && plan.amount ? plan.amount / 100 : 0,
|
|
6635
|
+
revenue: plan !== null && plan !== void 0 && plan.amount ? isCurrencyZeroDecimal(currencyCode) ? plan.amount : plan.amount / 100 : 0,
|
|
6622
6636
|
coupon: couponCode
|
|
6623
6637
|
});
|
|
6624
6638
|
ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin2 = ReactGA.plugin) === null || _ReactGA$plugin2 === void 0 ? void 0 : (_ReactGA$plugin2$exec = _ReactGA$plugin2.execute) === null || _ReactGA$plugin2$exec === void 0 ? void 0 : _ReactGA$plugin2$exec.call(_ReactGA$plugin2, "ecommerce", "addItem", {
|
|
@@ -6626,7 +6640,7 @@ const trackSubscriptionOnGA = () => {
|
|
|
6626
6640
|
name: product.name,
|
|
6627
6641
|
category: product.description,
|
|
6628
6642
|
variant: plan.nickname,
|
|
6629
|
-
price: plan !== null && plan !== void 0 && plan.amount ? plan.amount / 100 : 0,
|
|
6643
|
+
price: plan !== null && plan !== void 0 && plan.amount ? isCurrencyZeroDecimal(currencyCode) ? plan.amount : plan.amount / 100 : 0,
|
|
6630
6644
|
quantity: 1
|
|
6631
6645
|
});
|
|
6632
6646
|
ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin3 = ReactGA.plugin) === null || _ReactGA$plugin3 === void 0 ? void 0 : (_ReactGA$plugin3$exec = _ReactGA$plugin3.execute) === null || _ReactGA$plugin3$exec === void 0 ? void 0 : _ReactGA$plugin3$exec.call(_ReactGA$plugin3, "ecommerce", "send");
|