@managesome/eposmatic-toolkit 0.2.309 → 0.2.310
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.
|
@@ -76,7 +76,7 @@ interface IGetOffersWithStats {
|
|
|
76
76
|
customer: Partial<ICustomer> | null;
|
|
77
77
|
vouchers: IVoucher[] | undefined;
|
|
78
78
|
giftCards: IGiftCard[] | undefined;
|
|
79
|
-
customerOfferRedemptionCounts: Record<string, number> | undefined;
|
|
79
|
+
customerOfferRedemptionCounts: Record<string, number> | null | undefined;
|
|
80
80
|
redeemed_offers: IOrder['redeemed_offers'] | null | undefined;
|
|
81
81
|
platform: PLATFORMS_ENUM | undefined;
|
|
82
82
|
currency_symbol: ITenant['currency_symbol'] | undefined;
|
|
@@ -949,13 +949,19 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
949
949
|
};
|
|
950
950
|
const isOfferUsesPerCustomerExhausted = (offerToCheck) => {
|
|
951
951
|
const maxUsesPerCustomer = getOfferMaxUsesPerCustomer(offerToCheck);
|
|
952
|
-
|
|
952
|
+
if (maxUsesPerCustomer == null)
|
|
953
|
+
return false;
|
|
954
|
+
if (customerOfferRedemptionCounts == null)
|
|
955
|
+
return true;
|
|
956
|
+
return (customerOfferRedemptionCounts[offerToCheck._id] ?? 0) >= maxUsesPerCustomer;
|
|
953
957
|
};
|
|
954
958
|
const getRemainingOfferUsesForCustomer = (offerToCheck) => {
|
|
955
959
|
const maxUsesPerCustomer = getOfferMaxUsesPerCustomer(offerToCheck);
|
|
956
960
|
if (maxUsesPerCustomer == null)
|
|
957
961
|
return Infinity;
|
|
958
|
-
|
|
962
|
+
if (customerOfferRedemptionCounts == null)
|
|
963
|
+
return 0;
|
|
964
|
+
const redeemedByCustomer = customerOfferRedemptionCounts[offerToCheck._id] ?? 0;
|
|
959
965
|
return Math.max(0, maxUsesPerCustomer - redeemedByCustomer);
|
|
960
966
|
};
|
|
961
967
|
const getOrderValueClaimTimes = (orderValue, minAmount) => {
|
|
@@ -1849,7 +1855,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1849
1855
|
const spendableVoucherCount = normalizedMatchedVoucherCode == null ? 0 : (spendableVoucherCodesByCode[normalizedMatchedVoucherCode] ?? 0);
|
|
1850
1856
|
const customerVoucherUsageCount = matchedVoucher == null ? 0 : (customerOfferRedemptionCounts?.[matchedVoucher._id] ?? 0);
|
|
1851
1857
|
const voucherUsesPerCustomerExhausted = matchedVoucher?.max_uses_per_customer != null &&
|
|
1852
|
-
customerVoucherUsageCount >= matchedVoucher.max_uses_per_customer;
|
|
1858
|
+
(customerOfferRedemptionCounts == null || customerVoucherUsageCount >= matchedVoucher.max_uses_per_customer);
|
|
1853
1859
|
const hasVoucherAccess = matchedVoucher != null && (matchedVoucher.is_public || spendableVoucherCount > 0 || redeemedTimesForOffer > 0);
|
|
1854
1860
|
const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount || 1);
|
|
1855
1861
|
if (!hasMatchingVoucher) {
|
|
@@ -2109,6 +2115,47 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2109
2115
|
});
|
|
2110
2116
|
}
|
|
2111
2117
|
}
|
|
2118
|
+
// When customerOfferRedemptionCounts is null, invalidate claimability for offers whose
|
|
2119
|
+
// reward vouchers/gift-cards have max_uses_per_customer set, since we cannot verify the limit.
|
|
2120
|
+
if (customerOfferRedemptionCounts == null) {
|
|
2121
|
+
for (let i = 0; i < offersWithStats.length; i++) {
|
|
2122
|
+
const { offer, stats } = offersWithStats[i];
|
|
2123
|
+
if (!stats.claimable)
|
|
2124
|
+
continue;
|
|
2125
|
+
if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER && offer.reward_voucher != null) {
|
|
2126
|
+
const vIds = Object.keys(offer.reward_voucher.voucher_ids);
|
|
2127
|
+
for (let vIdx = 0; vIdx < vIds.length; vIdx++) {
|
|
2128
|
+
const rewardVoucher = vouchersById.get(vIds[vIdx]);
|
|
2129
|
+
if (rewardVoucher != null && rewardVoucher.max_uses_per_customer != null) {
|
|
2130
|
+
stats.claimable = false;
|
|
2131
|
+
stats.applicable_quantity = 0;
|
|
2132
|
+
unlockedOffersApplicableTimes[offer._id] = 0;
|
|
2133
|
+
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
2134
|
+
totalClaimableOffers = totalClaimableOffers.filter((id) => id !== offer._id);
|
|
2135
|
+
stats.action_hint = getActionHint(offer, stats.claimable);
|
|
2136
|
+
break;
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS &&
|
|
2141
|
+
offer.reward_gift_cards != null &&
|
|
2142
|
+
stats.claimable) {
|
|
2143
|
+
const gcIds = Object.keys(offer.reward_gift_cards.gift_card_ids);
|
|
2144
|
+
for (let gcIdx = 0; gcIdx < gcIds.length; gcIdx++) {
|
|
2145
|
+
const giftCard = giftCardsById.get(gcIds[gcIdx]);
|
|
2146
|
+
if (giftCard != null && giftCard.max_uses_per_customer != null) {
|
|
2147
|
+
stats.claimable = false;
|
|
2148
|
+
stats.applicable_quantity = 0;
|
|
2149
|
+
unlockedOffersApplicableTimes[offer._id] = 0;
|
|
2150
|
+
stats.message = '⛔️ You have reached your personal limit for this reward ⛔️';
|
|
2151
|
+
totalClaimableOffers = totalClaimableOffers.filter((id) => id !== offer._id);
|
|
2152
|
+
stats.action_hint = getActionHint(offer, stats.claimable);
|
|
2153
|
+
break;
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2112
2159
|
return {
|
|
2113
2160
|
offersWithStats,
|
|
2114
2161
|
totalClaimableOffers,
|