@managesome/eposmatic-toolkit 0.2.315 → 0.2.317
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.
|
@@ -69,7 +69,7 @@ export declare const SUBSCRIPTION_STATUS_COLOR: {
|
|
|
69
69
|
};
|
|
70
70
|
export declare const SPECIALS_CATEGORY_ID = "680437e050ad8ba788150b32";
|
|
71
71
|
export declare const SPECIALS_CATEGORY_NAME = "Specials";
|
|
72
|
-
export declare const
|
|
73
|
-
export declare const
|
|
74
|
-
export declare const
|
|
72
|
+
export declare const WALLET_CASHBACK_LOYALTY_DISCOUNT_ID = "wallet_cashback_redemption";
|
|
73
|
+
export declare const WALLET_CASHBACK_LOYALTY_DISCOUNT_NAME = "Wallet Cashback";
|
|
74
|
+
export declare const WALLET_CASHBACK_LOYALTY_REFERENCE = "WALLET_CASHBACK";
|
|
75
75
|
export {};
|
package/lib/constants/COMMON.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.WALLET_CASHBACK_LOYALTY_REFERENCE = exports.WALLET_CASHBACK_LOYALTY_DISCOUNT_NAME = exports.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID = exports.SPECIALS_CATEGORY_NAME = exports.SPECIALS_CATEGORY_ID = exports.SUBSCRIPTION_STATUS_COLOR = exports.AUTO_DELIVERY_CHARGES_PLATFORMS = exports.TAX_INVOICE_PROVIDER_CHARGES_MAP = exports.PAYMENT_CHARGES_MAP = exports.NOTIFICATION_CHARGES_MAP = exports.WHATSAPP_CHARGES_MAP = exports.SMS_CHARGES_MAP = exports.SMS_UNIT_LENGTH = exports.PROVIDER_OPERATIONAL_COUNTRIES = exports.ALL_PLAFORMS_OBJ = exports.LOW_VALUE_CURRENCY_COUNTRIES = void 0;
|
|
4
4
|
const ENUMS_1 = require("./ENUMS");
|
|
5
5
|
/**
|
|
6
6
|
* Countries with low-value currencies that should have:
|
|
@@ -342,6 +342,6 @@ exports.SUBSCRIPTION_STATUS_COLOR = {
|
|
|
342
342
|
};
|
|
343
343
|
exports.SPECIALS_CATEGORY_ID = '680437e050ad8ba788150b32';
|
|
344
344
|
exports.SPECIALS_CATEGORY_NAME = 'Specials';
|
|
345
|
-
exports.
|
|
346
|
-
exports.
|
|
347
|
-
exports.
|
|
345
|
+
exports.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID = 'wallet_cashback_redemption';
|
|
346
|
+
exports.WALLET_CASHBACK_LOYALTY_DISCOUNT_NAME = 'Wallet Cashback';
|
|
347
|
+
exports.WALLET_CASHBACK_LOYALTY_REFERENCE = 'WALLET_CASHBACK';
|
|
@@ -229,34 +229,78 @@ function getDiscountDetails(item_discount_details, itemTotalWithTaxAmount) {
|
|
|
229
229
|
...item_discount_details,
|
|
230
230
|
total_discount: 0,
|
|
231
231
|
};
|
|
232
|
+
let remainingPositiveDiscountableAmount = (0, utils_1.parseNum)(Math.max(0, itemTotalWithTaxAmount));
|
|
233
|
+
const consumePositiveDiscountAmount = (discountAmount) => {
|
|
234
|
+
if (discountAmount <= 0)
|
|
235
|
+
return;
|
|
236
|
+
remainingPositiveDiscountableAmount = (0, utils_1.parseNum)(Math.max(0, remainingPositiveDiscountableAmount - discountAmount));
|
|
237
|
+
};
|
|
238
|
+
const clearSpecialDiscountSlot = () => {
|
|
239
|
+
discount_details.special_discount_id = undefined;
|
|
240
|
+
discount_details.special_discount_name = undefined;
|
|
241
|
+
discount_details.special_discount = undefined;
|
|
242
|
+
discount_details.is_special_discount_percentage = false;
|
|
243
|
+
discount_details.special_discount_reason = undefined;
|
|
244
|
+
discount_details.special_reference_number = undefined;
|
|
245
|
+
};
|
|
246
|
+
const clearLoyaltyDiscountSlot = () => {
|
|
247
|
+
discount_details.loyalty_discount_id = undefined;
|
|
248
|
+
discount_details.loyalty_discount_name = undefined;
|
|
249
|
+
discount_details.loyalty_discount = undefined;
|
|
250
|
+
discount_details.is_loyalty_discount_percentage = false;
|
|
251
|
+
discount_details.loyalty_discount_reason = undefined;
|
|
252
|
+
discount_details.loyalty_reference_number = undefined;
|
|
253
|
+
};
|
|
254
|
+
const clearVoucherDiscountSlot = () => {
|
|
255
|
+
discount_details.voucher_discount_id = undefined;
|
|
256
|
+
discount_details.voucher_discount_name = undefined;
|
|
257
|
+
discount_details.voucher_discount = undefined;
|
|
258
|
+
discount_details.is_voucher_discount_percentage = false;
|
|
259
|
+
discount_details.voucher_discount_reason = undefined;
|
|
260
|
+
discount_details.voucher_reference_number = undefined;
|
|
261
|
+
};
|
|
232
262
|
if (special_discount_id && special_discount) {
|
|
233
|
-
|
|
234
|
-
|
|
263
|
+
const specialDiscountAmount = is_special_discount_percentage
|
|
264
|
+
? (0, utils_1.getPercentageAmount)(itemTotalWithTaxAmount, special_discount)
|
|
265
|
+
: special_discount;
|
|
266
|
+
if (specialDiscountAmount > remainingPositiveDiscountableAmount) {
|
|
267
|
+
clearSpecialDiscountSlot();
|
|
235
268
|
}
|
|
236
269
|
else {
|
|
237
|
-
discount_details.total_discount +=
|
|
270
|
+
discount_details.total_discount += specialDiscountAmount;
|
|
271
|
+
consumePositiveDiscountAmount(specialDiscountAmount);
|
|
238
272
|
}
|
|
273
|
+
// NOTE: we only keep the slot if it can be fully applied.
|
|
274
|
+
// Partial application is avoided so stale/invalid discounts are removed explicitly.
|
|
239
275
|
}
|
|
240
276
|
else {
|
|
241
277
|
delete discount_details.special_discount_reason;
|
|
242
278
|
}
|
|
243
279
|
if (loyalty_discount_id && loyalty_discount) {
|
|
244
|
-
|
|
245
|
-
|
|
280
|
+
const loyaltyDiscountAmount = is_loyalty_discount_percentage
|
|
281
|
+
? (0, utils_1.getPercentageAmount)(itemTotalWithTaxAmount, loyalty_discount)
|
|
282
|
+
: loyalty_discount;
|
|
283
|
+
if (loyaltyDiscountAmount > remainingPositiveDiscountableAmount) {
|
|
284
|
+
clearLoyaltyDiscountSlot();
|
|
246
285
|
}
|
|
247
286
|
else {
|
|
248
|
-
discount_details.total_discount +=
|
|
287
|
+
discount_details.total_discount += loyaltyDiscountAmount;
|
|
288
|
+
consumePositiveDiscountAmount(loyaltyDiscountAmount);
|
|
249
289
|
}
|
|
250
290
|
}
|
|
251
291
|
else {
|
|
252
292
|
delete discount_details.loyalty_discount_reason;
|
|
253
293
|
}
|
|
254
294
|
if (voucher_discount_id && voucher_discount) {
|
|
255
|
-
|
|
256
|
-
|
|
295
|
+
const voucherDiscountAmount = is_voucher_discount_percentage
|
|
296
|
+
? (0, utils_1.getPercentageAmount)(itemTotalWithTaxAmount, voucher_discount)
|
|
297
|
+
: voucher_discount;
|
|
298
|
+
if (voucherDiscountAmount > remainingPositiveDiscountableAmount) {
|
|
299
|
+
clearVoucherDiscountSlot();
|
|
257
300
|
}
|
|
258
301
|
else {
|
|
259
|
-
discount_details.total_discount +=
|
|
302
|
+
discount_details.total_discount += voucherDiscountAmount;
|
|
303
|
+
consumePositiveDiscountAmount(voucherDiscountAmount);
|
|
260
304
|
}
|
|
261
305
|
}
|
|
262
306
|
else {
|
|
@@ -388,121 +432,43 @@ function getNormalizedRedeemedOffersMap(redeemedOffers) {
|
|
|
388
432
|
}
|
|
389
433
|
return Object.keys(normalizedRedeemedOffers).length > 0 ? normalizedRedeemedOffers : null;
|
|
390
434
|
}
|
|
391
|
-
function
|
|
392
|
-
|
|
393
|
-
return true;
|
|
394
|
-
}
|
|
395
|
-
const normalizedRedeemedOffers = getNormalizedRedeemedOffersMap(redeemedOffers);
|
|
396
|
-
const rawOfferIds = Object.keys(redeemedOffers);
|
|
397
|
-
const normalizedOfferIds = Object.keys(normalizedRedeemedOffers ?? {});
|
|
398
|
-
if (rawOfferIds.length !== normalizedOfferIds.length) {
|
|
399
|
-
return false;
|
|
400
|
-
}
|
|
401
|
-
for (let i = 0; i < rawOfferIds.length; i++) {
|
|
402
|
-
const rawOfferId = rawOfferIds[i];
|
|
403
|
-
const normalizedOfferId = getNormalizedOfferId(rawOfferId);
|
|
404
|
-
const safeCount = toPositiveInteger(redeemedOffers[rawOfferId], 0);
|
|
405
|
-
if (normalizedOfferId == null || rawOfferId !== normalizedOfferId || safeCount <= 0) {
|
|
406
|
-
return false;
|
|
407
|
-
}
|
|
408
|
-
if ((normalizedRedeemedOffers?.[normalizedOfferId] ?? 0) !== safeCount) {
|
|
409
|
-
return false;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
return true;
|
|
413
|
-
}
|
|
414
|
-
function areRedeemedOffersEqual(currentRedeemedOffers, nextRedeemedOffers) {
|
|
415
|
-
const normalizedCurrentRedeemedOffers = getNormalizedRedeemedOffersMap(currentRedeemedOffers);
|
|
416
|
-
const normalizedNextRedeemedOffers = getNormalizedRedeemedOffersMap(nextRedeemedOffers);
|
|
417
|
-
if (normalizedCurrentRedeemedOffers == null || normalizedNextRedeemedOffers == null) {
|
|
418
|
-
return normalizedCurrentRedeemedOffers == null && normalizedNextRedeemedOffers == null;
|
|
419
|
-
}
|
|
420
|
-
const currentOfferIds = Object.keys(normalizedCurrentRedeemedOffers);
|
|
421
|
-
const nextOfferIds = Object.keys(normalizedNextRedeemedOffers);
|
|
422
|
-
if (currentOfferIds.length !== nextOfferIds.length) {
|
|
423
|
-
return false;
|
|
424
|
-
}
|
|
425
|
-
for (let i = 0; i < currentOfferIds.length; i++) {
|
|
426
|
-
const offerId = currentOfferIds[i];
|
|
427
|
-
if (normalizedCurrentRedeemedOffers[offerId] !== normalizedNextRedeemedOffers[offerId]) {
|
|
428
|
-
return false;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
return true;
|
|
435
|
+
function getRedeemedOffersMap(existingRedeemedOffers) {
|
|
436
|
+
return getNormalizedRedeemedOffersMap(existingRedeemedOffers);
|
|
432
437
|
}
|
|
433
|
-
function
|
|
434
|
-
|
|
435
|
-
|
|
438
|
+
function decrementRedeemedOfferUsageCount(redeemedOffers, offerId) {
|
|
439
|
+
const normalizedOfferId = getNormalizedOfferId(offerId);
|
|
440
|
+
if (normalizedOfferId == null || redeemedOffers == null) {
|
|
441
|
+
return redeemedOffers;
|
|
436
442
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
return null;
|
|
441
|
-
}
|
|
442
|
-
function getTotalSelectedOfferItemsAgainstOffer(categories, offerId) {
|
|
443
|
-
let totalSelectedOfferItems = 0;
|
|
444
|
-
for (let i = 0; i < categories.length; i++) {
|
|
445
|
-
const category = categories[i];
|
|
446
|
-
for (let j = 0; j < category.items.length; j++) {
|
|
447
|
-
const item = category.items[j];
|
|
448
|
-
const discountDetails = item.item_discount_details;
|
|
449
|
-
if (discountDetails == null)
|
|
450
|
-
continue;
|
|
451
|
-
const loyaltyDiscountId = getNormalizedOfferId(discountDetails.loyalty_discount_id);
|
|
452
|
-
const voucherDiscountId = getNormalizedOfferId(discountDetails.voucher_discount_id);
|
|
453
|
-
if (loyaltyDiscountId !== offerId && voucherDiscountId !== offerId)
|
|
454
|
-
continue;
|
|
455
|
-
totalSelectedOfferItems += toPositiveInteger(item.quantity, 0);
|
|
456
|
-
}
|
|
443
|
+
const previousCount = toPositiveInteger(redeemedOffers[normalizedOfferId], 0);
|
|
444
|
+
if (previousCount <= 0) {
|
|
445
|
+
return redeemedOffers;
|
|
457
446
|
}
|
|
458
|
-
return totalSelectedOfferItems;
|
|
459
|
-
}
|
|
460
|
-
function getReconciledRedeemedOffersMap({ existingRedeemedOffers, categories, offers, removedOfferIds, unlockedOffersApplicableTimes, }) {
|
|
461
447
|
const nextRedeemedOffers = {
|
|
462
|
-
...
|
|
448
|
+
...redeemedOffers,
|
|
463
449
|
};
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
const normalizedOfferId = getNormalizedOfferId(removedIds[i]);
|
|
467
|
-
if (normalizedOfferId == null)
|
|
468
|
-
continue;
|
|
450
|
+
const nextCount = previousCount - 1;
|
|
451
|
+
if (nextCount <= 0) {
|
|
469
452
|
delete nextRedeemedOffers[normalizedOfferId];
|
|
470
453
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
const normalizedOfferId = getNormalizedOfferId(offer._id);
|
|
474
|
-
if (normalizedOfferId == null)
|
|
475
|
-
continue;
|
|
476
|
-
const applicableQuantity = getItemRewardApplicableQuantity(offer);
|
|
477
|
-
if (applicableQuantity != null) {
|
|
478
|
-
const selectedItemsCount = getTotalSelectedOfferItemsAgainstOffer(categories, normalizedOfferId);
|
|
479
|
-
// Percentage strategy: any partial usage of an item reward counts as a redeemed slot.
|
|
480
|
-
const redeemedTimes = selectedItemsCount > 0 ? Math.ceil(selectedItemsCount / applicableQuantity) : 0;
|
|
481
|
-
if (redeemedTimes > 0) {
|
|
482
|
-
nextRedeemedOffers[normalizedOfferId] = redeemedTimes;
|
|
483
|
-
}
|
|
484
|
-
else {
|
|
485
|
-
delete nextRedeemedOffers[normalizedOfferId];
|
|
486
|
-
}
|
|
487
|
-
continue;
|
|
488
|
-
}
|
|
489
|
-
const existingRedeemedTimes = toPositiveInteger(nextRedeemedOffers[normalizedOfferId], 0);
|
|
490
|
-
if (existingRedeemedTimes <= 0) {
|
|
491
|
-
delete nextRedeemedOffers[normalizedOfferId];
|
|
492
|
-
continue;
|
|
493
|
-
}
|
|
494
|
-
const maxApplicableTimes = toPositiveInteger(unlockedOffersApplicableTimes?.[offer._id], 0);
|
|
495
|
-
if (maxApplicableTimes <= 0) {
|
|
496
|
-
// Preserve non-item claims as positive claimed-times when unlock state is temporarily unavailable.
|
|
497
|
-
nextRedeemedOffers[normalizedOfferId] = existingRedeemedTimes;
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
nextRedeemedOffers[normalizedOfferId] = Math.min(existingRedeemedTimes, maxApplicableTimes);
|
|
454
|
+
else {
|
|
455
|
+
nextRedeemedOffers[normalizedOfferId] = nextCount;
|
|
501
456
|
}
|
|
502
|
-
return
|
|
457
|
+
return getRedeemedOffersMap(nextRedeemedOffers);
|
|
503
458
|
}
|
|
504
|
-
function
|
|
505
|
-
|
|
459
|
+
function getSyncedRedeemedOffersAfterOrderDiscountOverflowCleanup({ redeemedOffers, previousOrderDiscountDetails, nextOrderDiscountDetails, }) {
|
|
460
|
+
let nextRedeemedOffers = redeemedOffers;
|
|
461
|
+
const previousLoyaltyDiscountId = getNormalizedOfferId(previousOrderDiscountDetails?.loyalty_discount_id);
|
|
462
|
+
const nextLoyaltyDiscountId = getNormalizedOfferId(nextOrderDiscountDetails?.loyalty_discount_id);
|
|
463
|
+
if (previousLoyaltyDiscountId != null && previousLoyaltyDiscountId !== nextLoyaltyDiscountId) {
|
|
464
|
+
nextRedeemedOffers = decrementRedeemedOfferUsageCount(nextRedeemedOffers, previousLoyaltyDiscountId);
|
|
465
|
+
}
|
|
466
|
+
const previousVoucherDiscountId = getNormalizedOfferId(previousOrderDiscountDetails?.voucher_discount_id);
|
|
467
|
+
const nextVoucherDiscountId = getNormalizedOfferId(nextOrderDiscountDetails?.voucher_discount_id);
|
|
468
|
+
if (previousVoucherDiscountId != null && previousVoucherDiscountId !== nextVoucherDiscountId) {
|
|
469
|
+
nextRedeemedOffers = decrementRedeemedOfferUsageCount(nextRedeemedOffers, previousVoucherDiscountId);
|
|
470
|
+
}
|
|
471
|
+
return getRedeemedOffersMap(nextRedeemedOffers);
|
|
506
472
|
}
|
|
507
473
|
function getWalletRedemptionsMap(walletRedemptions) {
|
|
508
474
|
if (walletRedemptions == null)
|
|
@@ -528,16 +494,88 @@ function getWalletRedemptionsMap(walletRedemptions) {
|
|
|
528
494
|
}
|
|
529
495
|
return Object.keys(normalized).length > 0 ? normalized : null;
|
|
530
496
|
}
|
|
531
|
-
function
|
|
532
|
-
|
|
497
|
+
function getSyncedWalletRedemptionsAfterOrderDiscountOverflowCleanup({ walletRedemptions, previousOrderDiscountDetails, nextOrderDiscountDetails, }) {
|
|
498
|
+
if (walletRedemptions == null) {
|
|
499
|
+
return walletRedemptions;
|
|
500
|
+
}
|
|
501
|
+
const previousLoyaltyDiscountId = getNormalizedOfferId(previousOrderDiscountDetails?.loyalty_discount_id);
|
|
502
|
+
const nextLoyaltyDiscountId = getNormalizedOfferId(nextOrderDiscountDetails?.loyalty_discount_id);
|
|
503
|
+
if (previousLoyaltyDiscountId == null || previousLoyaltyDiscountId === nextLoyaltyDiscountId) {
|
|
504
|
+
return walletRedemptions;
|
|
505
|
+
}
|
|
506
|
+
const walletGiftCardDiscountId = getNormalizedOfferId(walletRedemptions?.gift_cards?.gift_card_id);
|
|
507
|
+
const shouldClearWalletCashback = previousLoyaltyDiscountId === constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID &&
|
|
508
|
+
Number(walletRedemptions.cashback_amount ?? 0) > 0;
|
|
509
|
+
const shouldClearGiftCardRedemption = walletGiftCardDiscountId != null && walletGiftCardDiscountId === previousLoyaltyDiscountId;
|
|
510
|
+
if (!shouldClearWalletCashback && !shouldClearGiftCardRedemption) {
|
|
511
|
+
return walletRedemptions;
|
|
512
|
+
}
|
|
513
|
+
return getWalletRedemptionsMap({
|
|
514
|
+
...walletRedemptions,
|
|
515
|
+
...(shouldClearWalletCashback ? { cashback_amount: undefined } : {}),
|
|
516
|
+
...(shouldClearGiftCardRedemption ? { gift_cards: undefined } : {}),
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
function clearSpecialDiscountFields(orderDiscountDetails) {
|
|
520
|
+
return {
|
|
521
|
+
...orderDiscountDetails,
|
|
522
|
+
special_discount_id: undefined,
|
|
523
|
+
special_discount_name: undefined,
|
|
524
|
+
special_discount: undefined,
|
|
525
|
+
is_special_discount_percentage: false,
|
|
526
|
+
special_discount_reason: undefined,
|
|
527
|
+
special_reference_number: undefined,
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function getSyncedOrderDiscountDetailsWithoutRewardSpecialDiscount({ orderDiscountDetails, redeemedOffers, walletRedemptions, }) {
|
|
531
|
+
if (orderDiscountDetails == null) {
|
|
532
|
+
return orderDiscountDetails;
|
|
533
|
+
}
|
|
534
|
+
const normalizedSpecialDiscountId = getNormalizedOfferId(orderDiscountDetails.special_discount_id);
|
|
535
|
+
if (normalizedSpecialDiscountId == null) {
|
|
536
|
+
return orderDiscountDetails;
|
|
537
|
+
}
|
|
538
|
+
const hasRedeemedOfferForSpecialDiscount = redeemedOffers?.[normalizedSpecialDiscountId] != null;
|
|
539
|
+
const normalizedGiftCardId = getNormalizedOfferId(walletRedemptions?.gift_cards?.gift_card_id);
|
|
540
|
+
const isGiftCardRewardDiscount = normalizedGiftCardId != null && normalizedGiftCardId === normalizedSpecialDiscountId;
|
|
541
|
+
const isWalletCashbackRewardDiscount = normalizedSpecialDiscountId === constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID;
|
|
542
|
+
const isRewardLinkedSpecialDiscount = hasRedeemedOfferForSpecialDiscount || isGiftCardRewardDiscount || isWalletCashbackRewardDiscount;
|
|
543
|
+
if (!isRewardLinkedSpecialDiscount) {
|
|
544
|
+
return orderDiscountDetails;
|
|
545
|
+
}
|
|
546
|
+
const hasExistingRewardSlot = orderDiscountDetails.loyalty_discount_id != null || orderDiscountDetails.voucher_discount_id != null;
|
|
547
|
+
if (hasExistingRewardSlot) {
|
|
548
|
+
return clearSpecialDiscountFields(orderDiscountDetails);
|
|
549
|
+
}
|
|
550
|
+
return {
|
|
551
|
+
...clearSpecialDiscountFields(orderDiscountDetails),
|
|
552
|
+
loyalty_discount_id: normalizedSpecialDiscountId,
|
|
553
|
+
loyalty_discount_name: orderDiscountDetails.loyalty_discount_name ?? orderDiscountDetails.special_discount_name,
|
|
554
|
+
loyalty_discount: orderDiscountDetails.loyalty_discount ?? orderDiscountDetails.special_discount,
|
|
555
|
+
is_loyalty_discount_percentage: orderDiscountDetails.loyalty_discount_id != null || orderDiscountDetails.loyalty_discount != null
|
|
556
|
+
? orderDiscountDetails.is_loyalty_discount_percentage
|
|
557
|
+
: orderDiscountDetails.is_special_discount_percentage,
|
|
558
|
+
loyalty_discount_reason: orderDiscountDetails.loyalty_discount_reason ?? orderDiscountDetails.special_discount_reason,
|
|
559
|
+
loyalty_reference_number: orderDiscountDetails.loyalty_reference_number ?? orderDiscountDetails.special_reference_number,
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
function getSyncedItemDiscountDetailsWithoutRewardSpecialDiscount({ itemDiscountDetails, redeemedOffers, walletRedemptions, }) {
|
|
563
|
+
return getSyncedOrderDiscountDetailsWithoutRewardSpecialDiscount({
|
|
564
|
+
orderDiscountDetails: itemDiscountDetails,
|
|
565
|
+
redeemedOffers,
|
|
566
|
+
walletRedemptions,
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
function isWalletCashbackLoyaltyDiscount(orderDiscountDetails) {
|
|
570
|
+
return orderDiscountDetails?.loyalty_discount_id === constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID;
|
|
533
571
|
}
|
|
534
572
|
function getWalletCashbackAmountFromOrderData({ orderDiscountDetails, walletRedemptions, }) {
|
|
535
|
-
if (!
|
|
573
|
+
if (!isWalletCashbackLoyaltyDiscount(orderDiscountDetails)) {
|
|
536
574
|
return 0;
|
|
537
575
|
}
|
|
538
|
-
const
|
|
539
|
-
if (Number.isFinite(
|
|
540
|
-
return
|
|
576
|
+
const loyaltyDiscountAmount = Number(orderDiscountDetails?.loyalty_discount ?? 0);
|
|
577
|
+
if (Number.isFinite(loyaltyDiscountAmount) && loyaltyDiscountAmount > 0) {
|
|
578
|
+
return loyaltyDiscountAmount;
|
|
541
579
|
}
|
|
542
580
|
const walletRedemptionAmount = Number(walletRedemptions?.cashback_amount ?? 0);
|
|
543
581
|
return Number.isFinite(walletRedemptionAmount) && walletRedemptionAmount > 0 ? walletRedemptionAmount : 0;
|
|
@@ -549,19 +587,19 @@ function getSyncedWalletCashbackOrderDiscountDetails({ orderDiscountDetails, wal
|
|
|
549
587
|
if (walletCashbackAmount <= 0) {
|
|
550
588
|
return {
|
|
551
589
|
...orderDiscountDetails,
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
590
|
+
loyalty_discount_id: undefined,
|
|
591
|
+
loyalty_discount_name: undefined,
|
|
592
|
+
loyalty_discount: undefined,
|
|
593
|
+
is_loyalty_discount_percentage: false,
|
|
594
|
+
loyalty_reference_number: undefined,
|
|
557
595
|
total_discount: 0,
|
|
558
596
|
};
|
|
559
597
|
}
|
|
560
598
|
return {
|
|
561
599
|
...orderDiscountDetails,
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
600
|
+
loyalty_discount_id: constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID,
|
|
601
|
+
loyalty_discount: (0, utils_1.parseNum)(walletCashbackAmount),
|
|
602
|
+
is_loyalty_discount_percentage: false,
|
|
565
603
|
};
|
|
566
604
|
}
|
|
567
605
|
function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calculateItemMetadata) {
|
|
@@ -570,6 +608,8 @@ function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calcu
|
|
|
570
608
|
let subtotal = 0;
|
|
571
609
|
let totalItemsDiscount = 0;
|
|
572
610
|
const categories = [];
|
|
611
|
+
let syncedRedeemedOffers = getRedeemedOffersMap(data.redeemed_offers);
|
|
612
|
+
let syncedWalletRedemptions = getWalletRedemptionsMap(data.wallet_redemptions);
|
|
573
613
|
const length = data.categories?.length ?? 0;
|
|
574
614
|
for (let c = 0; c < length; c++) {
|
|
575
615
|
const category = data.categories[c];
|
|
@@ -577,7 +617,15 @@ function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calcu
|
|
|
577
617
|
const itemsLength = category.items.length;
|
|
578
618
|
for (let i = 0; i < itemsLength; i++) {
|
|
579
619
|
const item = category.items[i];
|
|
580
|
-
const
|
|
620
|
+
const syncedItemDiscountDetails = getSyncedItemDiscountDetailsWithoutRewardSpecialDiscount({
|
|
621
|
+
itemDiscountDetails: item.item_discount_details,
|
|
622
|
+
redeemedOffers: syncedRedeemedOffers,
|
|
623
|
+
walletRedemptions: syncedWalletRedemptions,
|
|
624
|
+
});
|
|
625
|
+
const { itemSubtotal, item_discount_details } = calculateItemTotalWithTax({
|
|
626
|
+
...item,
|
|
627
|
+
item_discount_details: syncedItemDiscountDetails ?? null,
|
|
628
|
+
});
|
|
581
629
|
const newItem = {
|
|
582
630
|
...item,
|
|
583
631
|
is_ready: item.is_ready || isCompleted,
|
|
@@ -602,11 +650,14 @@ function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calcu
|
|
|
602
650
|
});
|
|
603
651
|
}
|
|
604
652
|
let syncedOrderDiscountDetails = data.order_discount_details;
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
653
|
+
syncedOrderDiscountDetails = getSyncedOrderDiscountDetailsWithoutRewardSpecialDiscount({
|
|
654
|
+
orderDiscountDetails: syncedOrderDiscountDetails,
|
|
655
|
+
redeemedOffers: syncedRedeemedOffers,
|
|
656
|
+
walletRedemptions: syncedWalletRedemptions,
|
|
657
|
+
});
|
|
658
|
+
const hasWalletCashbackLoyaltyDiscount = isWalletCashbackLoyaltyDiscount(syncedOrderDiscountDetails);
|
|
608
659
|
const hasWalletCashbackMetadata = Number(syncedWalletRedemptions?.cashback_amount ?? 0) > 0;
|
|
609
|
-
if (
|
|
660
|
+
if (hasWalletCashbackLoyaltyDiscount) {
|
|
610
661
|
const requestedWalletCashbackAmount = getWalletCashbackAmountFromOrderData({
|
|
611
662
|
orderDiscountDetails: syncedOrderDiscountDetails,
|
|
612
663
|
walletRedemptions: syncedWalletRedemptions,
|
|
@@ -629,26 +680,13 @@ function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calcu
|
|
|
629
680
|
cashback_amount: undefined,
|
|
630
681
|
});
|
|
631
682
|
}
|
|
632
|
-
const hasNonWalletSpecialDiscount = syncedOrderDiscountDetails?.special_discount_id != null &&
|
|
633
|
-
syncedOrderDiscountDetails.special_discount_id !== constants_1.WALLET_CASHBACK_SPECIAL_DISCOUNT_ID;
|
|
634
683
|
const walletGiftCardRedeemedTimes = Number(syncedWalletRedemptions?.gift_cards?.value_redeemed ?? 0);
|
|
635
684
|
const hasWalletGiftCardMetadata = syncedWalletRedemptions?.gift_cards?.gift_card_id != null &&
|
|
636
685
|
syncedWalletRedemptions.gift_cards.gift_card_id.trim().length > 0 &&
|
|
637
686
|
Number.isFinite(walletGiftCardRedeemedTimes) &&
|
|
638
687
|
walletGiftCardRedeemedTimes > 0;
|
|
639
|
-
// Empty carts must not retain
|
|
688
|
+
// Empty carts must not retain offer-redemption state or gift-card wallet claims.
|
|
640
689
|
if (subtotal <= 0) {
|
|
641
|
-
if (hasNonWalletSpecialDiscount && syncedOrderDiscountDetails != null) {
|
|
642
|
-
syncedOrderDiscountDetails = {
|
|
643
|
-
...syncedOrderDiscountDetails,
|
|
644
|
-
special_discount_id: undefined,
|
|
645
|
-
special_discount_name: undefined,
|
|
646
|
-
special_discount: undefined,
|
|
647
|
-
is_special_discount_percentage: false,
|
|
648
|
-
special_reference_number: undefined,
|
|
649
|
-
total_discount: 0,
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
690
|
if (syncedRedeemedOffers != null) {
|
|
653
691
|
syncedRedeemedOffers = null;
|
|
654
692
|
}
|
|
@@ -660,7 +698,18 @@ function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calcu
|
|
|
660
698
|
}
|
|
661
699
|
}
|
|
662
700
|
const applyGSTOnOriginalPrice = data.exclude_discount_from_gst;
|
|
663
|
-
const
|
|
701
|
+
const previousOrderDiscountDetails = syncedOrderDiscountDetails;
|
|
702
|
+
const order_discount_details = getDiscountDetails(previousOrderDiscountDetails, subtotal);
|
|
703
|
+
syncedRedeemedOffers = getSyncedRedeemedOffersAfterOrderDiscountOverflowCleanup({
|
|
704
|
+
redeemedOffers: syncedRedeemedOffers,
|
|
705
|
+
previousOrderDiscountDetails,
|
|
706
|
+
nextOrderDiscountDetails: order_discount_details,
|
|
707
|
+
});
|
|
708
|
+
syncedWalletRedemptions = getSyncedWalletRedemptionsAfterOrderDiscountOverflowCleanup({
|
|
709
|
+
walletRedemptions: syncedWalletRedemptions,
|
|
710
|
+
previousOrderDiscountDetails,
|
|
711
|
+
nextOrderDiscountDetails: order_discount_details,
|
|
712
|
+
});
|
|
664
713
|
// This can be both negative or positive
|
|
665
714
|
const orderDiscount = order_discount_details?.total_discount ?? 0;
|
|
666
715
|
// However total order discount can never be negative
|
|
@@ -25,16 +25,16 @@ function getOrderSubtotalFromCategories(categories) {
|
|
|
25
25
|
}
|
|
26
26
|
return subtotal;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
return orderDiscountDetails?.
|
|
28
|
+
function isWalletCashbackLoyaltyDiscount(orderDiscountDetails) {
|
|
29
|
+
return orderDiscountDetails?.loyalty_discount_id === constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID;
|
|
30
30
|
}
|
|
31
31
|
function getWalletCashbackAmountFromOrderData({ orderDiscountDetails, walletRedemptions, }) {
|
|
32
|
-
if (!
|
|
32
|
+
if (!isWalletCashbackLoyaltyDiscount(orderDiscountDetails)) {
|
|
33
33
|
return 0;
|
|
34
34
|
}
|
|
35
|
-
const
|
|
36
|
-
if (Number.isFinite(
|
|
37
|
-
return (0, common_1.parseNum)(
|
|
35
|
+
const loyaltyDiscountAmount = Number(orderDiscountDetails?.loyalty_discount ?? 0);
|
|
36
|
+
if (Number.isFinite(loyaltyDiscountAmount) && loyaltyDiscountAmount > 0) {
|
|
37
|
+
return (0, common_1.parseNum)(loyaltyDiscountAmount);
|
|
38
38
|
}
|
|
39
39
|
const walletCashbackAmount = Number(walletRedemptions?.cashback_amount ?? 0);
|
|
40
40
|
if (Number.isFinite(walletCashbackAmount) && walletCashbackAmount > 0) {
|
|
@@ -49,19 +49,21 @@ function getSyncedWalletCashbackOrderDiscountDetails({ orderDiscountDetails, wal
|
|
|
49
49
|
if (walletCashbackAmount <= 0) {
|
|
50
50
|
return {
|
|
51
51
|
...orderDiscountDetails,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
loyalty_discount_id: undefined,
|
|
53
|
+
loyalty_discount_name: undefined,
|
|
54
|
+
loyalty_discount: undefined,
|
|
55
|
+
is_loyalty_discount_percentage: false,
|
|
56
|
+
loyalty_reference_number: undefined,
|
|
57
57
|
total_discount: 0,
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
return {
|
|
61
61
|
...orderDiscountDetails,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
loyalty_discount_id: constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID,
|
|
63
|
+
loyalty_discount_name: constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_NAME,
|
|
64
|
+
loyalty_discount: (0, common_1.parseNum)(walletCashbackAmount),
|
|
65
|
+
is_loyalty_discount_percentage: false,
|
|
66
|
+
loyalty_reference_number: constants_1.WALLET_CASHBACK_LOYALTY_REFERENCE,
|
|
65
67
|
};
|
|
66
68
|
}
|
|
67
69
|
// ================================><================================= //
|
|
@@ -137,6 +139,7 @@ function buildOfferDiscountUpdate({ offer, orderDiscountDetails, categories, })
|
|
|
137
139
|
loyalty_discount_name: offer.name,
|
|
138
140
|
loyalty_discount: discount_value,
|
|
139
141
|
is_loyalty_discount_percentage: is_discount_percentage,
|
|
142
|
+
loyalty_reference_number: undefined,
|
|
140
143
|
}
|
|
141
144
|
: {
|
|
142
145
|
voucher_discount_id: offer._id,
|
|
@@ -225,12 +228,12 @@ function buildOfferRewardUpdate({ offer, orderDiscountDetails, }) {
|
|
|
225
228
|
function buildGiftCardDiscountUpdate({ giftCard, orderDiscountDetails, categories, }) {
|
|
226
229
|
const rewardType = giftCard.reward_type;
|
|
227
230
|
if (rewardType === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT) {
|
|
228
|
-
// Already-applied guard for
|
|
229
|
-
if (orderDiscountDetails != null && orderDiscountDetails.
|
|
231
|
+
// Already-applied guard for loyalty-slot-based rewards.
|
|
232
|
+
if (orderDiscountDetails != null && orderDiscountDetails.loyalty_discount_id) {
|
|
230
233
|
return {
|
|
231
234
|
success: false,
|
|
232
235
|
discountDetails: null,
|
|
233
|
-
errorMessage: 'You already have a
|
|
236
|
+
errorMessage: 'You already have a loyalty reward discount applied.',
|
|
234
237
|
};
|
|
235
238
|
}
|
|
236
239
|
const reward = giftCard.reward_discount;
|
|
@@ -269,11 +272,11 @@ function buildGiftCardDiscountUpdate({ giftCard, orderDiscountDetails, categorie
|
|
|
269
272
|
: discount_value;
|
|
270
273
|
const discountDetails = {
|
|
271
274
|
...orderDiscountDetails,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
275
|
+
loyalty_discount_id: giftCard._id,
|
|
276
|
+
loyalty_discount_name: giftCard.name,
|
|
277
|
+
loyalty_discount: resolvedDiscount,
|
|
278
|
+
is_loyalty_discount_percentage: shouldNormalizeToStatic ? false : is_discount_percentage,
|
|
279
|
+
loyalty_reference_number: giftCard.code.trim().toUpperCase(),
|
|
277
280
|
total_discount: 0,
|
|
278
281
|
};
|
|
279
282
|
return { success: true, discountDetails, errorMessage: null };
|
|
@@ -523,27 +526,30 @@ offers) {
|
|
|
523
526
|
hasChanges = true;
|
|
524
527
|
}
|
|
525
528
|
const previousWalletCashbackAmount = (0, common_1.parseNum)(Number(wallet_redemptions?.cashback_amount ?? 0));
|
|
526
|
-
const
|
|
527
|
-
if (
|
|
529
|
+
const hasWalletCashbackLoyaltyDiscount = isWalletCashbackLoyaltyDiscount(order_discount_details);
|
|
530
|
+
if (hasWalletCashbackLoyaltyDiscount) {
|
|
528
531
|
const requestedWalletCashbackAmount = getWalletCashbackAmountFromOrderData({
|
|
529
532
|
orderDiscountDetails: order_discount_details,
|
|
530
533
|
walletRedemptions: wallet_redemptions,
|
|
531
534
|
});
|
|
532
535
|
const maxApplicableWalletCashback = (0, common_1.parseNum)(Math.max(0, orderLevelDiscountBaseAmount));
|
|
533
536
|
const syncedWalletCashbackAmount = (0, common_1.parseNum)(Math.min(requestedWalletCashbackAmount, maxApplicableWalletCashback));
|
|
534
|
-
const
|
|
535
|
-
const
|
|
536
|
-
const
|
|
537
|
+
const prevLoyaltyDiscountId = order_discount_details?.loyalty_discount_id;
|
|
538
|
+
const prevLoyaltyDiscountAmount = (0, common_1.parseNum)(Number(order_discount_details?.loyalty_discount ?? 0));
|
|
539
|
+
const prevIsLoyaltyDiscountPercentage = order_discount_details?.is_loyalty_discount_percentage === true;
|
|
540
|
+
const prevLoyaltyReferenceNumber = order_discount_details?.loyalty_reference_number;
|
|
537
541
|
const nextOrderDiscountDetails = getSyncedWalletCashbackOrderDiscountDetails({
|
|
538
542
|
orderDiscountDetails: order_discount_details,
|
|
539
543
|
walletCashbackAmount: syncedWalletCashbackAmount,
|
|
540
544
|
});
|
|
541
|
-
const
|
|
542
|
-
const
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
545
|
+
const nextLoyaltyDiscountId = nextOrderDiscountDetails?.loyalty_discount_id;
|
|
546
|
+
const nextLoyaltyDiscountAmount = (0, common_1.parseNum)(Number(nextOrderDiscountDetails?.loyalty_discount ?? 0));
|
|
547
|
+
const nextIsLoyaltyDiscountPercentage = nextOrderDiscountDetails?.is_loyalty_discount_percentage === true;
|
|
548
|
+
const nextLoyaltyReferenceNumber = nextOrderDiscountDetails?.loyalty_reference_number;
|
|
549
|
+
if (prevLoyaltyDiscountId !== nextLoyaltyDiscountId ||
|
|
550
|
+
prevLoyaltyDiscountAmount !== nextLoyaltyDiscountAmount ||
|
|
551
|
+
prevIsLoyaltyDiscountPercentage !== nextIsLoyaltyDiscountPercentage ||
|
|
552
|
+
prevLoyaltyReferenceNumber !== nextLoyaltyReferenceNumber) {
|
|
547
553
|
hasChanges = true;
|
|
548
554
|
}
|
|
549
555
|
order_discount_details = nextOrderDiscountDetails;
|
|
@@ -564,23 +570,34 @@ offers) {
|
|
|
564
570
|
});
|
|
565
571
|
hasChanges = true;
|
|
566
572
|
}
|
|
567
|
-
const
|
|
568
|
-
|
|
573
|
+
const hasOrderLevelLoyaltyDiscount = order_discount_details?.loyalty_discount_id != null;
|
|
574
|
+
const hasOrderLevelVoucherDiscount = order_discount_details?.voucher_discount_id != null;
|
|
569
575
|
const walletGiftCardRedeemedTimes = Number(wallet_redemptions?.gift_cards?.value_redeemed ?? 0);
|
|
570
576
|
const hasWalletGiftCardMetadata = wallet_redemptions?.gift_cards?.gift_card_id != null &&
|
|
571
577
|
wallet_redemptions.gift_cards.gift_card_id.trim().length > 0 &&
|
|
572
578
|
Number.isFinite(walletGiftCardRedeemedTimes) &&
|
|
573
579
|
walletGiftCardRedeemedTimes > 0;
|
|
574
|
-
// Empty carts must not retain
|
|
580
|
+
// Empty carts must not retain reward-driven loyalty/voucher discounts or gift-card wallet claims.
|
|
575
581
|
if (orderLevelDiscountBaseAmount <= 0) {
|
|
576
|
-
if (
|
|
582
|
+
if (hasOrderLevelLoyaltyDiscount && order_discount_details != null) {
|
|
577
583
|
order_discount_details = {
|
|
578
584
|
...order_discount_details,
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
585
|
+
loyalty_discount_id: undefined,
|
|
586
|
+
loyalty_discount_name: undefined,
|
|
587
|
+
loyalty_discount: undefined,
|
|
588
|
+
is_loyalty_discount_percentage: false,
|
|
589
|
+
loyalty_reference_number: undefined,
|
|
590
|
+
total_discount: 0,
|
|
591
|
+
};
|
|
592
|
+
hasChanges = true;
|
|
593
|
+
}
|
|
594
|
+
if (hasOrderLevelVoucherDiscount && order_discount_details != null) {
|
|
595
|
+
order_discount_details = {
|
|
596
|
+
...order_discount_details,
|
|
597
|
+
voucher_discount_id: undefined,
|
|
598
|
+
voucher_discount_name: undefined,
|
|
599
|
+
voucher_discount: undefined,
|
|
600
|
+
is_voucher_discount_percentage: false,
|
|
584
601
|
total_discount: 0,
|
|
585
602
|
};
|
|
586
603
|
hasChanges = true;
|
|
@@ -622,6 +639,7 @@ offers) {
|
|
|
622
639
|
loyalty_discount_name: undefined,
|
|
623
640
|
loyalty_discount: undefined,
|
|
624
641
|
is_loyalty_discount_percentage: false,
|
|
642
|
+
loyalty_reference_number: undefined,
|
|
625
643
|
};
|
|
626
644
|
}
|
|
627
645
|
else {
|
|
@@ -639,63 +657,72 @@ offers) {
|
|
|
639
657
|
// we check if either the loyalty_discount_id or voucher_discount_id
|
|
640
658
|
const loyaltyDiscountId = order_discount_details.loyalty_discount_id;
|
|
641
659
|
if (loyaltyDiscountId != null) {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
if (!hasRedeemedEntryForLoyalty) {
|
|
645
|
-
clearOrderLevelDiscount('loyalty');
|
|
646
|
-
}
|
|
647
|
-
else if (unlockedOffersMap[loyaltyDiscountId] == null || unlockedOffersMap[loyaltyDiscountId] <= 0) {
|
|
648
|
-
clearOrderLevelDiscount('loyalty');
|
|
660
|
+
if (loyaltyDiscountId === constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID) {
|
|
661
|
+
// Wallet cashback is synced separately above and does not participate in offer unlock accounting.
|
|
649
662
|
}
|
|
650
663
|
else {
|
|
651
|
-
// Find the offer to check for excluded_refs
|
|
652
664
|
const loyaltyOffer = offers.find((o) => o._id === loyaltyDiscountId);
|
|
653
|
-
if (loyaltyOffer
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
if (
|
|
665
|
+
if (loyaltyOffer == null) {
|
|
666
|
+
// Preserve non-offer loyalty discounts (for example gift-card discounts).
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
const normalizedLoyaltyDiscountId = getNormalizedOfferId(loyaltyDiscountId);
|
|
670
|
+
const hasRedeemedEntryForLoyalty = normalizedLoyaltyDiscountId != null && (redeemedOffersPresenceMap?.[normalizedLoyaltyDiscountId] ?? 0) > 0;
|
|
671
|
+
if (!hasRedeemedEntryForLoyalty) {
|
|
672
|
+
clearOrderLevelDiscount('loyalty');
|
|
673
|
+
}
|
|
674
|
+
else if (unlockedOffersMap[loyaltyDiscountId] == null || unlockedOffersMap[loyaltyDiscountId] <= 0) {
|
|
663
675
|
clearOrderLevelDiscount('loyalty');
|
|
664
676
|
}
|
|
665
677
|
else {
|
|
666
|
-
|
|
667
|
-
max_discount_amount
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
if (shouldNormalizeToStatic) {
|
|
677
|
-
if (discountBaseAmount <= 0) {
|
|
678
|
+
if (loyaltyOffer.reward_discount != null) {
|
|
679
|
+
const { discount_value, excluded_refs, is_discount_percentage, max_discount_amount, max_discount_percentage, } = loyaltyOffer.reward_discount;
|
|
680
|
+
const { subtotal: eligibleSubtotal, hasExcludedRefs } = excluded_refs != null && excluded_refs.length > 0
|
|
681
|
+
? (0, cart_actions_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs)
|
|
682
|
+
: {
|
|
683
|
+
subtotal: orderLevelDiscountBaseAmount,
|
|
684
|
+
hasExcludedRefs: false,
|
|
685
|
+
};
|
|
686
|
+
// Static discounts with exclusions are not supported - silently skip
|
|
687
|
+
if (hasExcludedRefs && !is_discount_percentage) {
|
|
678
688
|
clearOrderLevelDiscount('loyalty');
|
|
679
689
|
}
|
|
680
690
|
else {
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
691
|
+
const hasRelevantCap = is_discount_percentage &&
|
|
692
|
+
max_discount_amount != null &&
|
|
693
|
+
Number.isFinite(max_discount_amount) &&
|
|
694
|
+
max_discount_amount >= 0;
|
|
695
|
+
const hasRelevantPercentageCap = !is_discount_percentage &&
|
|
696
|
+
max_discount_percentage != null &&
|
|
697
|
+
Number.isFinite(max_discount_percentage) &&
|
|
698
|
+
max_discount_percentage >= 0;
|
|
699
|
+
const shouldNormalizeToStatic = hasExcludedRefs || hasRelevantCap || hasRelevantPercentageCap;
|
|
700
|
+
const discountBaseAmount = hasExcludedRefs ? eligibleSubtotal : orderLevelDiscountBaseAmount;
|
|
701
|
+
if (shouldNormalizeToStatic) {
|
|
702
|
+
if (discountBaseAmount <= 0) {
|
|
703
|
+
clearOrderLevelDiscount('loyalty');
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
const calculatedDiscount = (0, common_1.getCappedOfferDiscountAmount)({
|
|
707
|
+
baseAmount: discountBaseAmount,
|
|
708
|
+
discountValue: discount_value,
|
|
709
|
+
isDiscountPercentage: is_discount_percentage,
|
|
710
|
+
maxDiscountAmount: max_discount_amount,
|
|
711
|
+
maxDiscountPercentage: max_discount_percentage,
|
|
712
|
+
});
|
|
713
|
+
order_discount_details = {
|
|
714
|
+
...order_discount_details,
|
|
715
|
+
loyalty_discount: (0, common_1.parseNum)(calculatedDiscount),
|
|
716
|
+
is_loyalty_discount_percentage: false,
|
|
717
|
+
};
|
|
718
|
+
hasChanges = true;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
694
721
|
}
|
|
695
722
|
}
|
|
723
|
+
unlockedOffersMap[loyaltyDiscountId] -= 1;
|
|
696
724
|
}
|
|
697
725
|
}
|
|
698
|
-
unlockedOffersMap[loyaltyDiscountId] -= 1;
|
|
699
726
|
}
|
|
700
727
|
}
|
|
701
728
|
const voucherDiscountId = order_discount_details.voucher_discount_id;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@managesome/eposmatic-toolkit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.317",
|
|
4
4
|
"description": "A Toolkit Library for Eposmatic",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "jest --config jestconfig.json",
|
|
9
|
-
"build": "tsc",
|
|
9
|
+
"build": "npm run test && tsc",
|
|
10
10
|
"prepare": "npm run build",
|
|
11
11
|
"prepublishOnly": "npm run lint",
|
|
12
12
|
"preversion": "npm run lint",
|