@managesome/eposmatic-toolkit 0.2.296 → 0.2.298
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.
|
@@ -975,6 +975,22 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
975
975
|
}
|
|
976
976
|
return Math.min(normalizedUnlockableClaims, getRemainingOfferUsesForCustomer(offerToCheck));
|
|
977
977
|
};
|
|
978
|
+
const getPathwayMaxRedeemableClaims = ({ offerToCheck, pathwayUnlockableClaims, }) => {
|
|
979
|
+
const normalizedUnlockableClaims = Math.max(0, pathwayUnlockableClaims);
|
|
980
|
+
if (normalizedUnlockableClaims === 0) {
|
|
981
|
+
return 0;
|
|
982
|
+
}
|
|
983
|
+
return Math.min(normalizedUnlockableClaims, getRemainingOfferUsesForCustomer(offerToCheck));
|
|
984
|
+
};
|
|
985
|
+
const isDiscountSlotOccupiedForOffer = (offerToCheck) => {
|
|
986
|
+
if (order_discount_details == null) {
|
|
987
|
+
return false;
|
|
988
|
+
}
|
|
989
|
+
if (offerToCheck.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER) {
|
|
990
|
+
return Boolean(order_discount_details.voucher_discount_id);
|
|
991
|
+
}
|
|
992
|
+
return Boolean(order_discount_details.loyalty_discount_id);
|
|
993
|
+
};
|
|
978
994
|
for (let i = 0; i < offers.length; i++) {
|
|
979
995
|
const offer = offers[i];
|
|
980
996
|
const stats = {
|
|
@@ -1062,15 +1078,19 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1062
1078
|
}
|
|
1063
1079
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1064
1080
|
const isRedeemed = redeemedTimes > 0;
|
|
1065
|
-
|
|
1081
|
+
const discountSlotOccupied = isDiscountSlotOccupiedForOffer(offer);
|
|
1082
|
+
stats.claimable = !isRedeemed && !discountSlotOccupied;
|
|
1066
1083
|
stats.applicable_quantity = 1;
|
|
1067
1084
|
stats.redeemed_times = redeemedTimes;
|
|
1068
|
-
if (
|
|
1069
|
-
|
|
1070
|
-
|
|
1085
|
+
if (isRedeemed) {
|
|
1086
|
+
stats.message = 'This offer is redeemed ✅';
|
|
1087
|
+
}
|
|
1088
|
+
else if (discountSlotOccupied) {
|
|
1089
|
+
stats.message = 'You already have an offer applied to your order.';
|
|
1071
1090
|
}
|
|
1072
1091
|
else {
|
|
1073
|
-
|
|
1092
|
+
totalClaimableOffers += 1;
|
|
1093
|
+
stats.message = `🎉 You have unlocked this offer 🎉`;
|
|
1074
1094
|
}
|
|
1075
1095
|
unlockedOffersApplicableTimes[offer._id] = stats.applicable_quantity;
|
|
1076
1096
|
}
|
|
@@ -1181,15 +1201,23 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1181
1201
|
continue;
|
|
1182
1202
|
}
|
|
1183
1203
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1184
|
-
const
|
|
1204
|
+
const maxClaimsPerOrder = offer.pathway_to_unlock_type_orders?.max_claims == null
|
|
1205
|
+
? Infinity
|
|
1206
|
+
: Math.max(1, offer.pathway_to_unlock_type_orders.max_claims);
|
|
1207
|
+
const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, offer.pathway_to_unlock_type_orders?.total_amount);
|
|
1208
|
+
const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder);
|
|
1209
|
+
const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
|
|
1210
|
+
offerToCheck: offer,
|
|
1211
|
+
pathwayUnlockableClaims: totalUnlockableClaims,
|
|
1212
|
+
});
|
|
1213
|
+
const isClaimable = redeemedTimes < maxRedeemableClaims;
|
|
1185
1214
|
stats.redeemed_times = redeemedTimes;
|
|
1186
|
-
stats.applicable_quantity =
|
|
1187
|
-
|
|
1188
|
-
|
|
1215
|
+
stats.applicable_quantity = maxRedeemableClaims;
|
|
1216
|
+
stats.claimable = isClaimable;
|
|
1217
|
+
if (!isClaimable) {
|
|
1189
1218
|
stats.message = 'This offer is redeemed ✅';
|
|
1190
1219
|
}
|
|
1191
1220
|
else {
|
|
1192
|
-
stats.claimable = true;
|
|
1193
1221
|
stats.message = `🎉 You have unlocked this offer 🎉`;
|
|
1194
1222
|
totalClaimableOffers += 1;
|
|
1195
1223
|
}
|
|
@@ -1328,12 +1356,16 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1328
1356
|
}
|
|
1329
1357
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1330
1358
|
const isRedeemed = redeemedTimes > 0;
|
|
1359
|
+
const discountSlotOccupied = isDiscountSlotOccupiedForOffer(offer);
|
|
1331
1360
|
stats.redeemed_times = redeemedTimes;
|
|
1332
1361
|
stats.applicable_quantity = 1;
|
|
1333
|
-
stats.claimable = !isRedeemed;
|
|
1362
|
+
stats.claimable = !isRedeemed && !discountSlotOccupied;
|
|
1334
1363
|
if (isRedeemed) {
|
|
1335
1364
|
stats.message = 'This offer is redeemed ✅';
|
|
1336
1365
|
}
|
|
1366
|
+
else if (discountSlotOccupied) {
|
|
1367
|
+
stats.message = 'You already have an offer applied to your order.';
|
|
1368
|
+
}
|
|
1337
1369
|
else {
|
|
1338
1370
|
totalClaimableOffers += 1;
|
|
1339
1371
|
stats.message = `🎉 You have unlocked this offer 🎉`;
|
|
@@ -1435,11 +1467,15 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1435
1467
|
continue;
|
|
1436
1468
|
}
|
|
1437
1469
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1438
|
-
const
|
|
1470
|
+
const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
|
|
1471
|
+
offerToCheck: offer,
|
|
1472
|
+
pathwayUnlockableClaims: totalUnlockableClaims,
|
|
1473
|
+
});
|
|
1474
|
+
const isClaimable = redeemedTimes < maxRedeemableClaims;
|
|
1439
1475
|
stats.redeemed_times = redeemedTimes;
|
|
1440
|
-
stats.applicable_quantity =
|
|
1441
|
-
stats.claimable =
|
|
1442
|
-
if (
|
|
1476
|
+
stats.applicable_quantity = maxRedeemableClaims;
|
|
1477
|
+
stats.claimable = isClaimable;
|
|
1478
|
+
if (!isClaimable) {
|
|
1443
1479
|
stats.message = 'This offer is redeemed ✅';
|
|
1444
1480
|
}
|
|
1445
1481
|
else {
|
|
@@ -1579,12 +1615,16 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1579
1615
|
}
|
|
1580
1616
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1581
1617
|
const isRedeemed = redeemedTimes > 0;
|
|
1618
|
+
const discountSlotOccupied = isDiscountSlotOccupiedForOffer(offer);
|
|
1582
1619
|
stats.redeemed_times = redeemedTimes;
|
|
1583
1620
|
stats.applicable_quantity = 1;
|
|
1584
|
-
stats.claimable = !isRedeemed;
|
|
1621
|
+
stats.claimable = !isRedeemed && !discountSlotOccupied;
|
|
1585
1622
|
if (isRedeemed) {
|
|
1586
1623
|
stats.message = 'This offer is redeemed ✅';
|
|
1587
1624
|
}
|
|
1625
|
+
else if (discountSlotOccupied) {
|
|
1626
|
+
stats.message = 'You already have an offer applied to your order.';
|
|
1627
|
+
}
|
|
1588
1628
|
else {
|
|
1589
1629
|
totalClaimableOffers += 1;
|
|
1590
1630
|
stats.message = `🎉 You have unlocked this offer 🎉`;
|
|
@@ -1687,11 +1727,15 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1687
1727
|
continue;
|
|
1688
1728
|
}
|
|
1689
1729
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1690
|
-
const
|
|
1730
|
+
const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
|
|
1731
|
+
offerToCheck: offer,
|
|
1732
|
+
pathwayUnlockableClaims: totalUnlockableClaims,
|
|
1733
|
+
});
|
|
1734
|
+
const isClaimable = redeemedTimes < maxRedeemableClaims;
|
|
1691
1735
|
stats.redeemed_times = redeemedTimes;
|
|
1692
|
-
stats.applicable_quantity =
|
|
1693
|
-
stats.claimable =
|
|
1694
|
-
if (
|
|
1736
|
+
stats.applicable_quantity = maxRedeemableClaims;
|
|
1737
|
+
stats.claimable = isClaimable;
|
|
1738
|
+
if (!isClaimable) {
|
|
1695
1739
|
stats.message = 'This offer is redeemed ✅';
|
|
1696
1740
|
}
|
|
1697
1741
|
else {
|
|
@@ -1833,12 +1877,16 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1833
1877
|
}
|
|
1834
1878
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1835
1879
|
const isRedeemed = redeemedTimes > 0;
|
|
1880
|
+
const discountSlotOccupied = isDiscountSlotOccupiedForOffer(offer);
|
|
1836
1881
|
stats.redeemed_times = redeemedTimes;
|
|
1837
1882
|
stats.applicable_quantity = 1;
|
|
1838
|
-
stats.claimable = !isRedeemed;
|
|
1883
|
+
stats.claimable = !isRedeemed && !discountSlotOccupied;
|
|
1839
1884
|
if (isRedeemed) {
|
|
1840
1885
|
stats.message = 'This offer is redeemed ✅';
|
|
1841
1886
|
}
|
|
1887
|
+
else if (discountSlotOccupied) {
|
|
1888
|
+
stats.message = 'You already have an offer applied to your order.';
|
|
1889
|
+
}
|
|
1842
1890
|
else {
|
|
1843
1891
|
totalClaimableOffers += 1;
|
|
1844
1892
|
stats.message = `🎉 You have unlocked this offer 🎉`;
|
|
@@ -1948,11 +1996,21 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1948
1996
|
continue;
|
|
1949
1997
|
}
|
|
1950
1998
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1951
|
-
const
|
|
1999
|
+
const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
|
|
2000
|
+
const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, total_amount);
|
|
2001
|
+
const voucherInventoryClaimCap = matchedVoucher != null && !matchedVoucher.is_public
|
|
2002
|
+
? Math.max(0, spendableVoucherCount + redeemedTimesForOffer)
|
|
2003
|
+
: Infinity;
|
|
2004
|
+
const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap);
|
|
2005
|
+
const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
|
|
2006
|
+
offerToCheck: offer,
|
|
2007
|
+
pathwayUnlockableClaims: totalUnlockableClaims,
|
|
2008
|
+
});
|
|
2009
|
+
const isClaimable = redeemedTimes < maxRedeemableClaims;
|
|
1952
2010
|
stats.redeemed_times = redeemedTimes;
|
|
1953
|
-
stats.applicable_quantity =
|
|
1954
|
-
stats.claimable =
|
|
1955
|
-
if (
|
|
2011
|
+
stats.applicable_quantity = maxRedeemableClaims;
|
|
2012
|
+
stats.claimable = isClaimable;
|
|
2013
|
+
if (!isClaimable) {
|
|
1956
2014
|
stats.message = 'This offer is redeemed ✅';
|
|
1957
2015
|
}
|
|
1958
2016
|
else {
|