@managesome/eposmatic-toolkit 0.2.312 → 0.2.314

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.
@@ -1,5 +1,5 @@
1
1
  import { ORDER_STATUS_ENUM, PLATFORMS_ENUM, SORT_TYPE_ENUM } from '../../constants';
2
- import { ICourse, IDiscountDetails, IGeneralItem, IItem, IModifier, IOffer, IOrder, IOrderCategory, IOrderCourse, IOrderDeliveryDetails, IOrderItem, IOrderIteration } from '../../schemas';
2
+ import { ICourse, IDiscountDetails, IGeneralItem, IItem, IModifier, IOrder, IOrderCategory, IOrderCourse, IOrderDeliveryDetails, IOrderItem, IOrderIteration } from '../../schemas';
3
3
  import { ICartListnerSettings } from '../types';
4
4
  import { ICartItemsObj } from '../types/cart-actions';
5
5
  interface IGetItemQuantityChangeResultsParams {
@@ -159,6 +159,4 @@ export declare function calculateEligibleOfferDiscountDetails(categories: IOrder
159
159
  subtotal: number;
160
160
  hasExcludedRefs: boolean;
161
161
  };
162
- export declare function getSyncOffersWithCartData(data: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings, unlockedOffersApplicableTimes: Record<string, number>, // Record<offer_id, times can be applied>
163
- offers: IOffer[]): Partial<IOrder>;
164
162
  export {};
@@ -28,12 +28,12 @@ exports.getCartItemsObj = getCartItemsObj;
28
28
  exports.getRemoveOfferFromCartData = getRemoveOfferFromCartData;
29
29
  exports.getRemoveAllOffersFromCartData = getRemoveAllOffersFromCartData;
30
30
  exports.calculateEligibleOfferDiscountDetails = calculateEligibleOfferDiscountDetails;
31
- exports.getSyncOffersWithCartData = getSyncOffersWithCartData;
32
31
  const bson_objectid_1 = __importDefault(require("bson-objectid"));
33
32
  const lodash_1 = require("lodash");
34
33
  const constants_1 = require("../../constants");
35
34
  const utils_1 = require("../utils");
36
35
  const platform_catalog_1 = require("../utils/platform-catalog");
36
+ const WALLET_CASHBACK_SPECIAL_DISCOUNT_ID = 'wallet_cashback_redemption';
37
37
  function getItemQuantityChangeResults({ prevQuantity, newQuantity, prevItemDiscountDetails, }) {
38
38
  let item_discount_details = prevItemDiscountDetails;
39
39
  const getScaledFixedDiscount = (discountValue, isPercentage) => {
@@ -505,7 +505,7 @@ function getReconciledRedeemedOffersMap({ existingRedeemedOffers, categories, of
505
505
  function getRedeemedOffersMap(existingRedeemedOffers) {
506
506
  return getNormalizedRedeemedOffersMap(existingRedeemedOffers);
507
507
  }
508
- function getNormalizedWalletRedemptionsMap(walletRedemptions) {
508
+ function getWalletRedemptionsMap(walletRedemptions) {
509
509
  if (walletRedemptions == null)
510
510
  return null;
511
511
  const normalized = {};
@@ -529,8 +529,41 @@ function getNormalizedWalletRedemptionsMap(walletRedemptions) {
529
529
  }
530
530
  return Object.keys(normalized).length > 0 ? normalized : null;
531
531
  }
532
- function getWalletRedemptionsMap(existingWalletRedemptions) {
533
- return getNormalizedWalletRedemptionsMap(existingWalletRedemptions);
532
+ function isWalletCashbackSpecialDiscount(orderDiscountDetails) {
533
+ return orderDiscountDetails?.special_discount_id === WALLET_CASHBACK_SPECIAL_DISCOUNT_ID;
534
+ }
535
+ function getWalletCashbackAmountFromOrderData({ orderDiscountDetails, walletRedemptions, }) {
536
+ if (!isWalletCashbackSpecialDiscount(orderDiscountDetails)) {
537
+ return 0;
538
+ }
539
+ const specialDiscountAmount = Number(orderDiscountDetails?.special_discount ?? 0);
540
+ if (Number.isFinite(specialDiscountAmount) && specialDiscountAmount > 0) {
541
+ return specialDiscountAmount;
542
+ }
543
+ const walletRedemptionAmount = Number(walletRedemptions?.cashback_amount ?? 0);
544
+ return Number.isFinite(walletRedemptionAmount) && walletRedemptionAmount > 0 ? walletRedemptionAmount : 0;
545
+ }
546
+ function getSyncedWalletCashbackOrderDiscountDetails({ orderDiscountDetails, walletCashbackAmount, }) {
547
+ if (orderDiscountDetails == null) {
548
+ return orderDiscountDetails;
549
+ }
550
+ if (walletCashbackAmount <= 0) {
551
+ return {
552
+ ...orderDiscountDetails,
553
+ special_discount_id: undefined,
554
+ special_discount_name: undefined,
555
+ special_discount: undefined,
556
+ is_special_discount_percentage: false,
557
+ special_reference_number: undefined,
558
+ total_discount: 0,
559
+ };
560
+ }
561
+ return {
562
+ ...orderDiscountDetails,
563
+ special_discount_id: WALLET_CASHBACK_SPECIAL_DISCOUNT_ID,
564
+ special_discount: (0, utils_1.parseNum)(walletCashbackAmount),
565
+ is_special_discount_percentage: false,
566
+ };
534
567
  }
535
568
  function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calculateItemMetadata) {
536
569
  const isCompleted = data.order_status === constants_1.ORDER_STATUS_ENUM.COMPLETED;
@@ -569,8 +602,35 @@ function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calcu
569
602
  items: newItems,
570
603
  });
571
604
  }
605
+ let syncedOrderDiscountDetails = data.order_discount_details;
606
+ let syncedWalletRedemptions = getWalletRedemptionsMap(data.wallet_redemptions);
607
+ const hasWalletCashbackSpecialDiscount = isWalletCashbackSpecialDiscount(syncedOrderDiscountDetails);
608
+ const hasWalletCashbackMetadata = Number(syncedWalletRedemptions?.cashback_amount ?? 0) > 0;
609
+ if (hasWalletCashbackSpecialDiscount) {
610
+ const requestedWalletCashbackAmount = getWalletCashbackAmountFromOrderData({
611
+ orderDiscountDetails: syncedOrderDiscountDetails,
612
+ walletRedemptions: syncedWalletRedemptions,
613
+ });
614
+ const maxApplicableWalletCashback = (0, utils_1.parseNum)(Math.max(0, subtotal));
615
+ const syncedWalletCashbackAmount = (0, utils_1.parseNum)(Math.min(requestedWalletCashbackAmount, maxApplicableWalletCashback));
616
+ syncedOrderDiscountDetails = getSyncedWalletCashbackOrderDiscountDetails({
617
+ orderDiscountDetails: syncedOrderDiscountDetails,
618
+ walletCashbackAmount: syncedWalletCashbackAmount,
619
+ });
620
+ syncedWalletRedemptions = getWalletRedemptionsMap({
621
+ ...(syncedWalletRedemptions ?? {}),
622
+ cashback_amount: syncedWalletCashbackAmount > 0 ? syncedWalletCashbackAmount : undefined,
623
+ });
624
+ }
625
+ else if (hasWalletCashbackMetadata) {
626
+ // Offers cannot create an active cashback order discount; keep cashback metadata consistent.
627
+ syncedWalletRedemptions = getWalletRedemptionsMap({
628
+ ...(syncedWalletRedemptions ?? {}),
629
+ cashback_amount: undefined,
630
+ });
631
+ }
572
632
  const applyGSTOnOriginalPrice = data.exclude_discount_from_gst;
573
- const order_discount_details = getDiscountDetails(data.order_discount_details, subtotal);
633
+ const order_discount_details = getDiscountDetails(syncedOrderDiscountDetails, subtotal);
574
634
  // This can be both negative or positive
575
635
  const orderDiscount = order_discount_details?.total_discount ?? 0;
576
636
  // However total order discount can never be negative
@@ -801,7 +861,7 @@ function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calcu
801
861
  categories,
802
862
  order_discount_details,
803
863
  redeemed_offers: getRedeemedOffersMap(data.redeemed_offers),
804
- wallet_redemptions: getWalletRedemptionsMap(data.wallet_redemptions),
864
+ wallet_redemptions: syncedWalletRedemptions,
805
865
  total_discount_applied,
806
866
  delivery_details,
807
867
  tax_amount,
@@ -2153,272 +2213,3 @@ function calculateEligibleOfferDiscountDetails(categories, excluded_refs) {
2153
2213
  }
2154
2214
  return { subtotal: eligibleSubtotal, hasExcludedRefs };
2155
2215
  }
2156
- // ================================><================================= //
2157
- function getSyncOffersWithCartData(data, courses, listnerSettings, unlockedOffersApplicableTimes, // Record<offer_id, times can be applied>
2158
- offers) {
2159
- const unlockedOffersMap = {
2160
- ...unlockedOffersApplicableTimes,
2161
- };
2162
- const removedOfferIds = new Set();
2163
- let hasChanges = false;
2164
- const categories = data.categories ?? [];
2165
- const orderLevelDiscountBaseAmount = (0, utils_1.getOrderSubtotalFromCategories)(categories);
2166
- let order_discount_details = data.order_discount_details;
2167
- let redeemed_offers = getNormalizedRedeemedOffersMap(data.redeemed_offers);
2168
- if (!isRedeemedOffersMapNormalized(data.redeemed_offers)) {
2169
- hasChanges = true;
2170
- }
2171
- const redeemedOffersPresenceMap = getReconciledRedeemedOffersMap({
2172
- existingRedeemedOffers: redeemed_offers,
2173
- categories,
2174
- offers,
2175
- removedOfferIds: new Set(),
2176
- unlockedOffersApplicableTimes,
2177
- });
2178
- const clearOrderLevelDiscount = (discountType) => {
2179
- if (order_discount_details == null) {
2180
- return;
2181
- }
2182
- const appliedOfferId = discountType === 'loyalty'
2183
- ? order_discount_details.loyalty_discount_id
2184
- : order_discount_details.voucher_discount_id;
2185
- const normalizedAppliedOfferId = getNormalizedOfferId(appliedOfferId);
2186
- if (normalizedAppliedOfferId != null) {
2187
- removedOfferIds.add(normalizedAppliedOfferId);
2188
- }
2189
- if (discountType === 'loyalty') {
2190
- order_discount_details = {
2191
- ...order_discount_details,
2192
- loyalty_discount_id: undefined,
2193
- loyalty_discount_name: undefined,
2194
- loyalty_discount: undefined,
2195
- is_loyalty_discount_percentage: false,
2196
- };
2197
- }
2198
- else {
2199
- order_discount_details = {
2200
- ...order_discount_details,
2201
- voucher_discount_id: undefined,
2202
- voucher_discount_name: undefined,
2203
- voucher_discount: undefined,
2204
- is_voucher_discount_percentage: false,
2205
- };
2206
- }
2207
- hasChanges = true;
2208
- };
2209
- if (order_discount_details != null) {
2210
- // we check if either the loyalty_discount_id or voucher_discount_id
2211
- const loyaltyDiscountId = order_discount_details.loyalty_discount_id;
2212
- if (loyaltyDiscountId != null) {
2213
- const normalizedLoyaltyDiscountId = getNormalizedOfferId(loyaltyDiscountId);
2214
- const hasRedeemedEntryForLoyalty = normalizedLoyaltyDiscountId != null && (redeemedOffersPresenceMap?.[normalizedLoyaltyDiscountId] ?? 0) > 0;
2215
- if (!hasRedeemedEntryForLoyalty) {
2216
- clearOrderLevelDiscount('loyalty');
2217
- }
2218
- else if (unlockedOffersMap[loyaltyDiscountId] == null || unlockedOffersMap[loyaltyDiscountId] <= 0) {
2219
- clearOrderLevelDiscount('loyalty');
2220
- }
2221
- else {
2222
- // Find the offer to check for excluded_refs
2223
- const loyaltyOffer = offers.find((o) => o._id === loyaltyDiscountId);
2224
- if (loyaltyOffer?.reward_discount != null) {
2225
- const { discount_value, excluded_refs, is_discount_percentage, max_discount_amount, max_discount_percentage, } = loyaltyOffer.reward_discount;
2226
- const { subtotal: eligibleSubtotal, hasExcludedRefs } = excluded_refs != null && excluded_refs.length > 0
2227
- ? calculateEligibleOfferDiscountDetails(categories, excluded_refs)
2228
- : {
2229
- subtotal: orderLevelDiscountBaseAmount,
2230
- hasExcludedRefs: false,
2231
- };
2232
- // Static discounts with exclusions are not supported - silently skip
2233
- if (hasExcludedRefs && !is_discount_percentage) {
2234
- clearOrderLevelDiscount('loyalty');
2235
- }
2236
- else {
2237
- const hasRelevantCap = is_discount_percentage &&
2238
- max_discount_amount != null &&
2239
- Number.isFinite(max_discount_amount) &&
2240
- max_discount_amount >= 0;
2241
- const hasRelevantPercentageCap = !is_discount_percentage &&
2242
- max_discount_percentage != null &&
2243
- Number.isFinite(max_discount_percentage) &&
2244
- max_discount_percentage >= 0;
2245
- const shouldNormalizeToStatic = hasExcludedRefs || hasRelevantCap || hasRelevantPercentageCap;
2246
- const discountBaseAmount = hasExcludedRefs ? eligibleSubtotal : orderLevelDiscountBaseAmount;
2247
- if (shouldNormalizeToStatic) {
2248
- if (discountBaseAmount <= 0) {
2249
- clearOrderLevelDiscount('loyalty');
2250
- }
2251
- else {
2252
- const calculatedDiscount = (0, utils_1.getCappedOfferDiscountAmount)({
2253
- baseAmount: discountBaseAmount,
2254
- discountValue: discount_value,
2255
- isDiscountPercentage: is_discount_percentage,
2256
- maxDiscountAmount: max_discount_amount,
2257
- maxDiscountPercentage: max_discount_percentage,
2258
- });
2259
- order_discount_details = {
2260
- ...order_discount_details,
2261
- loyalty_discount: (0, utils_1.parseNum)(calculatedDiscount),
2262
- is_loyalty_discount_percentage: false,
2263
- };
2264
- hasChanges = true;
2265
- }
2266
- }
2267
- }
2268
- }
2269
- unlockedOffersMap[loyaltyDiscountId] -= 1;
2270
- }
2271
- }
2272
- const voucherDiscountId = order_discount_details.voucher_discount_id;
2273
- if (voucherDiscountId != null) {
2274
- const normalizedVoucherDiscountId = getNormalizedOfferId(voucherDiscountId);
2275
- const hasRedeemedEntryForVoucher = normalizedVoucherDiscountId != null && (redeemedOffersPresenceMap?.[normalizedVoucherDiscountId] ?? 0) > 0;
2276
- if (!hasRedeemedEntryForVoucher) {
2277
- clearOrderLevelDiscount('voucher');
2278
- }
2279
- else if (unlockedOffersMap[voucherDiscountId] == null || unlockedOffersMap[voucherDiscountId] <= 0) {
2280
- clearOrderLevelDiscount('voucher');
2281
- }
2282
- else {
2283
- // Find the offer to check for excluded_refs
2284
- const voucherOffer = offers.find((o) => o._id === voucherDiscountId);
2285
- if (voucherOffer?.reward_discount != null) {
2286
- const { discount_value, excluded_refs, is_discount_percentage, max_discount_amount, max_discount_percentage, } = voucherOffer.reward_discount;
2287
- const { subtotal: eligibleSubtotal, hasExcludedRefs } = excluded_refs != null && excluded_refs.length > 0
2288
- ? calculateEligibleOfferDiscountDetails(categories, excluded_refs)
2289
- : {
2290
- subtotal: orderLevelDiscountBaseAmount,
2291
- hasExcludedRefs: false,
2292
- };
2293
- // Static discounts with exclusions are not supported - silently skip
2294
- if (hasExcludedRefs && !is_discount_percentage) {
2295
- clearOrderLevelDiscount('voucher');
2296
- }
2297
- else {
2298
- const hasRelevantCap = is_discount_percentage &&
2299
- max_discount_amount != null &&
2300
- Number.isFinite(max_discount_amount) &&
2301
- max_discount_amount >= 0;
2302
- const hasRelevantPercentageCap = !is_discount_percentage &&
2303
- max_discount_percentage != null &&
2304
- Number.isFinite(max_discount_percentage) &&
2305
- max_discount_percentage >= 0;
2306
- const shouldNormalizeToStatic = hasExcludedRefs || hasRelevantCap || hasRelevantPercentageCap;
2307
- const discountBaseAmount = hasExcludedRefs ? eligibleSubtotal : orderLevelDiscountBaseAmount;
2308
- if (shouldNormalizeToStatic) {
2309
- if (discountBaseAmount <= 0) {
2310
- clearOrderLevelDiscount('voucher');
2311
- }
2312
- else {
2313
- const calculatedDiscount = (0, utils_1.getCappedOfferDiscountAmount)({
2314
- baseAmount: discountBaseAmount,
2315
- discountValue: discount_value,
2316
- isDiscountPercentage: is_discount_percentage,
2317
- maxDiscountAmount: max_discount_amount,
2318
- maxDiscountPercentage: max_discount_percentage,
2319
- });
2320
- order_discount_details = {
2321
- ...order_discount_details,
2322
- voucher_discount: (0, utils_1.parseNum)(calculatedDiscount),
2323
- is_voucher_discount_percentage: false,
2324
- };
2325
- hasChanges = true;
2326
- }
2327
- }
2328
- }
2329
- }
2330
- unlockedOffersMap[voucherDiscountId] -= 1;
2331
- }
2332
- }
2333
- }
2334
- const newCategories = [];
2335
- for (let i = 0; i < categories.length; i++) {
2336
- const category = categories[i];
2337
- const newItems = [];
2338
- for (let j = 0; j < category.items.length; j++) {
2339
- const item = category.items[j];
2340
- // we check if either the loyalty_discount_id or voucher_discount_id
2341
- // is present in the item_discount_details
2342
- // if it is then we remove the items from cart
2343
- if (item.item_discount_details != null) {
2344
- const loyaltyDiscountId = item.item_discount_details.loyalty_discount_id;
2345
- if (loyaltyDiscountId != null) {
2346
- const normalizedLoyaltyDiscountId = getNormalizedOfferId(loyaltyDiscountId);
2347
- const hasRedeemedEntryForLoyalty = normalizedLoyaltyDiscountId != null && (redeemedOffersPresenceMap?.[normalizedLoyaltyDiscountId] ?? 0) > 0;
2348
- if (!hasRedeemedEntryForLoyalty) {
2349
- hasChanges = true;
2350
- if (normalizedLoyaltyDiscountId != null) {
2351
- removedOfferIds.add(normalizedLoyaltyDiscountId);
2352
- }
2353
- continue;
2354
- }
2355
- if (unlockedOffersMap[loyaltyDiscountId] == null || unlockedOffersMap[loyaltyDiscountId] <= 0) {
2356
- hasChanges = true;
2357
- if (normalizedLoyaltyDiscountId != null) {
2358
- removedOfferIds.add(normalizedLoyaltyDiscountId);
2359
- }
2360
- continue;
2361
- }
2362
- else {
2363
- unlockedOffersMap[loyaltyDiscountId] -= toPositiveInteger(item.quantity, 1);
2364
- }
2365
- }
2366
- const voucherDiscountId = item.item_discount_details.voucher_discount_id;
2367
- if (voucherDiscountId != null) {
2368
- const normalizedVoucherDiscountId = getNormalizedOfferId(voucherDiscountId);
2369
- const hasRedeemedEntryForVoucher = normalizedVoucherDiscountId != null && (redeemedOffersPresenceMap?.[normalizedVoucherDiscountId] ?? 0) > 0;
2370
- if (!hasRedeemedEntryForVoucher) {
2371
- hasChanges = true;
2372
- if (normalizedVoucherDiscountId != null) {
2373
- removedOfferIds.add(normalizedVoucherDiscountId);
2374
- }
2375
- continue;
2376
- }
2377
- if (unlockedOffersMap[voucherDiscountId] == null || unlockedOffersMap[voucherDiscountId] <= 0) {
2378
- hasChanges = true;
2379
- if (normalizedVoucherDiscountId != null) {
2380
- removedOfferIds.add(normalizedVoucherDiscountId);
2381
- }
2382
- continue;
2383
- }
2384
- else {
2385
- unlockedOffersMap[voucherDiscountId] -= toPositiveInteger(item.quantity, 1);
2386
- }
2387
- }
2388
- newItems.push(item);
2389
- }
2390
- else {
2391
- newItems.push(item);
2392
- }
2393
- }
2394
- newCategories.push({
2395
- ...category,
2396
- items: newItems,
2397
- });
2398
- }
2399
- const reconciledRedeemedOffers = getReconciledRedeemedOffersMap({
2400
- existingRedeemedOffers: redeemed_offers,
2401
- categories: newCategories,
2402
- offers,
2403
- removedOfferIds,
2404
- unlockedOffersApplicableTimes,
2405
- });
2406
- if (!areRedeemedOffersEqual(redeemed_offers, reconciledRedeemedOffers)) {
2407
- redeemed_offers = reconciledRedeemedOffers;
2408
- hasChanges = true;
2409
- }
2410
- if (hasChanges) {
2411
- const order = {
2412
- ...data,
2413
- categories: newCategories,
2414
- order_discount_details,
2415
- redeemed_offers,
2416
- wallet_redemptions: getWalletRedemptionsMap(data.wallet_redemptions),
2417
- };
2418
- const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
2419
- return newData;
2420
- }
2421
- else {
2422
- return data;
2423
- }
2424
- }
@@ -0,0 +1,12 @@
1
+ import { IGiftCard } from '../../schemas';
2
+ export declare function getGiftCardRewardPreviewText({ giftCard, currencySymbol, }: {
3
+ giftCard: IGiftCard;
4
+ currencySymbol: string | undefined;
5
+ }): string;
6
+ export declare function getGiftCardPostOrderRewardDetail({ giftCard, currencySymbol, }: {
7
+ giftCard: IGiftCard;
8
+ currencySymbol: string | undefined;
9
+ }): {
10
+ detail: string;
11
+ snackbarMessage: string;
12
+ };
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGiftCardRewardPreviewText = getGiftCardRewardPreviewText;
4
+ exports.getGiftCardPostOrderRewardDetail = getGiftCardPostOrderRewardDetail;
5
+ const constants_1 = require("../../constants");
6
+ const common_1 = require("./common");
7
+ function formatGiftCardRewardTypeText(rewardType) {
8
+ return rewardType.toLowerCase().replace(/_/g, ' ');
9
+ }
10
+ function formatCountLabel(count, singular, plural) {
11
+ return `${count} ${count === 1 ? singular : plural}`;
12
+ }
13
+ function getGiftCardRewardPreviewText({ giftCard, currencySymbol, }) {
14
+ switch (giftCard.reward_type) {
15
+ case constants_1.GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT: {
16
+ const reward = giftCard.reward_discount;
17
+ if (reward == null)
18
+ return 'Discount reward';
19
+ return reward.is_discount_percentage
20
+ ? `${(0, common_1.parseNum)(reward.discount_value)}% off`
21
+ : `${(0, common_1.localeAmount)(currencySymbol, reward.discount_value)} off`;
22
+ }
23
+ case constants_1.GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT_ITEMS: {
24
+ const reward = giftCard.reward_discount_items;
25
+ if (reward == null)
26
+ return 'Item discount reward';
27
+ const itemCount = Math.max(1, Number(reward.num_of_items ?? 1));
28
+ const discountText = reward.is_discount_percentage
29
+ ? `${(0, common_1.parseNum)(reward.discount_value)}% off`
30
+ : `${(0, common_1.localeAmount)(currencySymbol, reward.discount_value)} off`;
31
+ return `${formatCountLabel(itemCount, 'item', 'items')} at ${discountText}`;
32
+ }
33
+ case constants_1.GIFT_CARD_REWARD_TYPE_ENUM.ITEMS: {
34
+ const reward = giftCard.reward_items;
35
+ if (reward == null)
36
+ return 'Free item reward';
37
+ const itemCount = Math.max(1, Number(reward.num_of_items ?? 1));
38
+ return `${formatCountLabel(itemCount, 'free item', 'free items')}`;
39
+ }
40
+ case constants_1.GIFT_CARD_REWARD_TYPE_ENUM.POINTS: {
41
+ const reward = giftCard.reward_points;
42
+ if (reward == null)
43
+ return 'Points reward';
44
+ const points = (0, common_1.parseNum)(Number(reward.num_of_points ?? 0));
45
+ return `${formatCountLabel(points, 'point', 'points')}`;
46
+ }
47
+ case constants_1.GIFT_CARD_REWARD_TYPE_ENUM.CASHBACK: {
48
+ const reward = giftCard.reward_cashback;
49
+ if (reward == null)
50
+ return 'Cashback reward';
51
+ if (reward.is_cashback_percentage) {
52
+ const percentageText = `${(0, common_1.parseNum)(reward.cashback_value)}% cashback`;
53
+ if (reward.max_cashback_amount != null && Number.isFinite(Number(reward.max_cashback_amount))) {
54
+ return `${percentageText} up to ${(0, common_1.localeAmount)(currencySymbol, Number(reward.max_cashback_amount))}`;
55
+ }
56
+ return percentageText;
57
+ }
58
+ return `${(0, common_1.localeAmount)(currencySymbol, reward.cashback_value)} cashback`;
59
+ }
60
+ case constants_1.GIFT_CARD_REWARD_TYPE_ENUM.VOUCHER: {
61
+ const reward = giftCard.reward_voucher;
62
+ if (reward == null)
63
+ return 'Voucher reward';
64
+ const voucherCount = Object.keys(reward.voucher_ids ?? {}).length;
65
+ return voucherCount > 0 ? `${formatCountLabel(voucherCount, 'voucher', 'vouchers')} reward` : 'Voucher reward';
66
+ }
67
+ case constants_1.GIFT_CARD_REWARD_TYPE_ENUM.MYSTERY_GIFT: {
68
+ const reward = giftCard.reward_mystery_gift;
69
+ if (reward == null)
70
+ return 'Mystery reward';
71
+ const choices = reward.choice_of_rewards ?? [];
72
+ if (choices.length === 0) {
73
+ return 'Mystery reward';
74
+ }
75
+ const formattedChoices = choices.map((choice) => formatGiftCardRewardTypeText(choice)).join(', ');
76
+ return `Mystery reward (${formattedChoices})`;
77
+ }
78
+ }
79
+ return 'reward';
80
+ }
81
+ function getGiftCardPostOrderRewardDetail({ giftCard, currencySymbol, }) {
82
+ const rewardSummary = getGiftCardRewardPreviewText({
83
+ giftCard,
84
+ currencySymbol,
85
+ });
86
+ if (giftCard.reward_type === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.MYSTERY_GIFT) {
87
+ return {
88
+ detail: 'Mystery reward will be revealed after your order',
89
+ snackbarMessage: 'Mystery reward will be revealed after your order 🎉',
90
+ };
91
+ }
92
+ if (giftCard.reward_type === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.ITEMS ||
93
+ giftCard.reward_type === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
94
+ return {
95
+ detail: `${rewardSummary} will be applied after your order`,
96
+ snackbarMessage: `${rewardSummary} will be applied after your order 🎉`,
97
+ };
98
+ }
99
+ return {
100
+ detail: `${rewardSummary} will be credited after your order`,
101
+ snackbarMessage: `${rewardSummary} will be credited after your order 🎉`,
102
+ };
103
+ }
@@ -13,6 +13,7 @@ export * from './email-helpers';
13
13
  export * from './error-helpers';
14
14
  export * from './expense';
15
15
  export * from './getFormFieldsDiff';
16
+ export * from './gift-card-helpers';
16
17
  export * from './halfhalf-setup-helpers';
17
18
  export * from './hourly-comparison-report-helpers';
18
19
  export * from './hubrise-utils';
@@ -29,6 +29,7 @@ __exportStar(require("./email-helpers"), exports);
29
29
  __exportStar(require("./error-helpers"), exports);
30
30
  __exportStar(require("./expense"), exports);
31
31
  __exportStar(require("./getFormFieldsDiff"), exports);
32
+ __exportStar(require("./gift-card-helpers"), exports);
32
33
  __exportStar(require("./halfhalf-setup-helpers"), exports);
33
34
  __exportStar(require("./hourly-comparison-report-helpers"), exports);
34
35
  __exportStar(require("./hubrise-utils"), exports);
@@ -1,6 +1,6 @@
1
- import { IDiscountDetails, IGiftCard, IOffer, IOrderCategory } from '../../schemas';
2
- export declare function getOrderSubtotalFromCategories(categories: IOrderCategory[] | undefined): number;
3
- export interface IApplyDiscountResult {
1
+ import { ICourse, IDiscountDetails, IGiftCard, IOffer, IOrder, IOrderCategory } from '../../schemas';
2
+ import { ICartListnerSettings } from '../types';
3
+ interface IApplyDiscountResult {
4
4
  success: boolean;
5
5
  discountDetails: IDiscountDetails | null;
6
6
  errorMessage: string | null;
@@ -33,3 +33,6 @@ export declare function buildVoucherDiscountUpdate({ code, orderDiscountDetails,
33
33
  code: string;
34
34
  orderDiscountDetails: IDiscountDetails | null | undefined;
35
35
  }): IDiscountDetails;
36
+ export declare function getSyncOffersWithCartData(data: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings, unlockedOffersApplicableTimes: Record<string, number>, // Record<offer_id, times can be applied>
37
+ offers: IOffer[]): Partial<IOrder>;
38
+ export {};