@managesome/eposmatic-toolkit 0.2.296 → 0.2.297
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,13 @@ 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
|
+
};
|
|
978
985
|
for (let i = 0; i < offers.length; i++) {
|
|
979
986
|
const offer = offers[i];
|
|
980
987
|
const stats = {
|
|
@@ -1181,15 +1188,23 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1181
1188
|
continue;
|
|
1182
1189
|
}
|
|
1183
1190
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1184
|
-
const
|
|
1191
|
+
const maxClaimsPerOrder = offer.pathway_to_unlock_type_orders?.max_claims == null
|
|
1192
|
+
? Infinity
|
|
1193
|
+
: Math.max(1, offer.pathway_to_unlock_type_orders.max_claims);
|
|
1194
|
+
const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, offer.pathway_to_unlock_type_orders?.total_amount);
|
|
1195
|
+
const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder);
|
|
1196
|
+
const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
|
|
1197
|
+
offerToCheck: offer,
|
|
1198
|
+
pathwayUnlockableClaims: totalUnlockableClaims,
|
|
1199
|
+
});
|
|
1200
|
+
const isClaimable = redeemedTimes < maxRedeemableClaims;
|
|
1185
1201
|
stats.redeemed_times = redeemedTimes;
|
|
1186
|
-
stats.applicable_quantity =
|
|
1187
|
-
|
|
1188
|
-
|
|
1202
|
+
stats.applicable_quantity = maxRedeemableClaims;
|
|
1203
|
+
stats.claimable = isClaimable;
|
|
1204
|
+
if (!isClaimable) {
|
|
1189
1205
|
stats.message = 'This offer is redeemed ✅';
|
|
1190
1206
|
}
|
|
1191
1207
|
else {
|
|
1192
|
-
stats.claimable = true;
|
|
1193
1208
|
stats.message = `🎉 You have unlocked this offer 🎉`;
|
|
1194
1209
|
totalClaimableOffers += 1;
|
|
1195
1210
|
}
|
|
@@ -1435,11 +1450,15 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1435
1450
|
continue;
|
|
1436
1451
|
}
|
|
1437
1452
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1438
|
-
const
|
|
1453
|
+
const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
|
|
1454
|
+
offerToCheck: offer,
|
|
1455
|
+
pathwayUnlockableClaims: totalUnlockableClaims,
|
|
1456
|
+
});
|
|
1457
|
+
const isClaimable = redeemedTimes < maxRedeemableClaims;
|
|
1439
1458
|
stats.redeemed_times = redeemedTimes;
|
|
1440
|
-
stats.applicable_quantity =
|
|
1441
|
-
stats.claimable =
|
|
1442
|
-
if (
|
|
1459
|
+
stats.applicable_quantity = maxRedeemableClaims;
|
|
1460
|
+
stats.claimable = isClaimable;
|
|
1461
|
+
if (!isClaimable) {
|
|
1443
1462
|
stats.message = 'This offer is redeemed ✅';
|
|
1444
1463
|
}
|
|
1445
1464
|
else {
|
|
@@ -1687,11 +1706,15 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1687
1706
|
continue;
|
|
1688
1707
|
}
|
|
1689
1708
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1690
|
-
const
|
|
1709
|
+
const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
|
|
1710
|
+
offerToCheck: offer,
|
|
1711
|
+
pathwayUnlockableClaims: totalUnlockableClaims,
|
|
1712
|
+
});
|
|
1713
|
+
const isClaimable = redeemedTimes < maxRedeemableClaims;
|
|
1691
1714
|
stats.redeemed_times = redeemedTimes;
|
|
1692
|
-
stats.applicable_quantity =
|
|
1693
|
-
stats.claimable =
|
|
1694
|
-
if (
|
|
1715
|
+
stats.applicable_quantity = maxRedeemableClaims;
|
|
1716
|
+
stats.claimable = isClaimable;
|
|
1717
|
+
if (!isClaimable) {
|
|
1695
1718
|
stats.message = 'This offer is redeemed ✅';
|
|
1696
1719
|
}
|
|
1697
1720
|
else {
|
|
@@ -1948,11 +1971,21 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1948
1971
|
continue;
|
|
1949
1972
|
}
|
|
1950
1973
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
1951
|
-
const
|
|
1974
|
+
const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
|
|
1975
|
+
const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, total_amount);
|
|
1976
|
+
const voucherInventoryClaimCap = matchedVoucher != null && !matchedVoucher.is_public
|
|
1977
|
+
? Math.max(0, spendableVoucherCount + redeemedTimesForOffer)
|
|
1978
|
+
: Infinity;
|
|
1979
|
+
const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap);
|
|
1980
|
+
const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
|
|
1981
|
+
offerToCheck: offer,
|
|
1982
|
+
pathwayUnlockableClaims: totalUnlockableClaims,
|
|
1983
|
+
});
|
|
1984
|
+
const isClaimable = redeemedTimes < maxRedeemableClaims;
|
|
1952
1985
|
stats.redeemed_times = redeemedTimes;
|
|
1953
|
-
stats.applicable_quantity =
|
|
1954
|
-
stats.claimable =
|
|
1955
|
-
if (
|
|
1986
|
+
stats.applicable_quantity = maxRedeemableClaims;
|
|
1987
|
+
stats.claimable = isClaimable;
|
|
1988
|
+
if (!isClaimable) {
|
|
1956
1989
|
stats.message = 'This offer is redeemed ✅';
|
|
1957
1990
|
}
|
|
1958
1991
|
else {
|