@managesome/eposmatic-toolkit 0.2.317 → 0.2.319

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.
@@ -44,19 +44,33 @@ function getOrderWalletRedemptions(walletRedemptions) {
44
44
  if (Number.isFinite(cashbackAmount) && cashbackAmount > 0) {
45
45
  normalizedWalletRedemptions.cashback_amount = cashbackAmount;
46
46
  }
47
- const giftCardRedemption = walletRedemptions.gift_cards;
48
- if (giftCardRedemption != null) {
49
- const giftCardId = giftCardRedemption.gift_card_id?.toString().trim();
50
- const valueRedeemed = Number(giftCardRedemption.value_redeemed);
51
- if (giftCardId != null && giftCardId.length > 0 && Number.isFinite(valueRedeemed) && valueRedeemed > 0) {
52
- normalizedWalletRedemptions.gift_cards = {
47
+ const giftCardRedemptions = walletRedemptions.gift_cards;
48
+ if (Array.isArray(giftCardRedemptions)) {
49
+ const normalizedGiftCardRedemptionsMap = {};
50
+ for (let i = 0; i < giftCardRedemptions.length; i++) {
51
+ const giftCardRedemption = giftCardRedemptions[i];
52
+ const giftCardId = giftCardRedemption.gift_card_id?.toString().trim();
53
+ const legacyValueRedeemed = giftCardRedemption.value_redeemed;
54
+ const rawRedeemedTimes = giftCardRedemption.redeemed_times ?? legacyValueRedeemed;
55
+ const redeemedTimes = Number(rawRedeemedTimes);
56
+ if (giftCardId == null || giftCardId.length === 0 || !Number.isFinite(redeemedTimes) || redeemedTimes <= 0) {
57
+ continue;
58
+ }
59
+ const existingRedemption = normalizedGiftCardRedemptionsMap[giftCardId];
60
+ normalizedGiftCardRedemptionsMap[giftCardId] = {
53
61
  gift_card_id: giftCardId,
54
- value_redeemed: valueRedeemed,
62
+ redeemed_times: (existingRedemption?.redeemed_times ?? 0) + Math.floor(redeemedTimes),
55
63
  ...(giftCardRedemption.mystery_gift_type != null
56
64
  ? { mystery_gift_type: giftCardRedemption.mystery_gift_type }
57
- : {}),
65
+ : existingRedemption?.mystery_gift_type != null
66
+ ? { mystery_gift_type: existingRedemption.mystery_gift_type }
67
+ : {}),
58
68
  };
59
69
  }
70
+ const normalizedGiftCardRedemptions = Object.values(normalizedGiftCardRedemptionsMap);
71
+ if (normalizedGiftCardRedemptions.length > 0) {
72
+ normalizedWalletRedemptions.gift_cards = normalizedGiftCardRedemptions;
73
+ }
60
74
  }
61
75
  return Object.keys(normalizedWalletRedemptions).length > 0 ? normalizedWalletRedemptions : null;
62
76
  }
@@ -1,5 +1,5 @@
1
- import { ORDER_STATUS_ENUM, PLATFORMS_ENUM, SORT_TYPE_ENUM } from '../../constants';
2
- import { ICourse, IDiscountDetails, IGeneralItem, IItem, IModifier, IOrder, IOrderCategory, IOrderCourse, IOrderDeliveryDetails, IOrderItem, IOrderIteration } from '../../schemas';
1
+ import { GIFT_CARD_REWARD_TYPE_ENUM, 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';
3
3
  import { ICartListnerSettings } from '../types';
4
4
  import { ICartItemsObj } from '../types/cart-actions';
5
5
  interface IGetItemQuantityChangeResultsParams {
@@ -38,13 +38,21 @@ interface ICalculateGstForItem {
38
38
  apply_service_fee_on_original_price: boolean | undefined;
39
39
  }
40
40
  export declare function calculateGstForItem({ subtotal, totalOrderDiscount, applyGSTOnOriginalPrice, is_gst_inclusive, gst, totalItemsDiscount, grossAmount, netAmount, payablePrice, originalItemsPrice, surcharge, is_surcharge_taxable, is_surcharge_percentage, service_fee, is_service_fee_taxable, is_service_fee_percentage, apply_service_fee_on_original_price, }: ICalculateGstForItem): number;
41
- export declare function calculateCartOrderInfoAndSyncData<T extends IOrder | Partial<IOrder>>(data: T, courses?: ICourse[], listnerSettings?: ICartListnerSettings, calculateItemMetadata?: boolean): T;
41
+ export interface ICartOfferSyncContext {
42
+ unlockedOffersApplicableTimes: Record<string, number>;
43
+ offers: IOffer[];
44
+ }
45
+ export declare function calculateCartOrderInfoAndSyncData<T extends IOrder | Partial<IOrder>>(data: T, courses?: ICourse[], listnerSettings?: ICartListnerSettings, calculateItemMetadata?: boolean, syncContext?: ICartOfferSyncContext): T;
42
46
  export interface ISetAddItemToCartActionPayload {
43
47
  name: string;
44
48
  category_id: string;
45
49
  item: IOrderItem;
46
50
  chosen_course_id: string | null;
47
51
  replace_id?: string;
52
+ walletGiftCardClaim?: {
53
+ giftCardId: string;
54
+ mysteryGiftType?: GIFT_CARD_REWARD_TYPE_ENUM | null;
55
+ };
48
56
  }
49
57
  export declare const getOrderItemComaparableData: (item: IOrderItem) => Partial<IOrderItem>;
50
58
  export declare function getAddItemToCartData(data: Partial<IOrder>, payload: ISetAddItemToCartActionPayload, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
@@ -152,6 +160,7 @@ export interface IGetCartItemsObjPayload {
152
160
  export declare function getCartItemsObj({ currentIterationCategories, currentDineinCourses, previousIterationCategories, previousDineinCourses, mappedItems, shouldSortItemsViaId, platform, isAnEdit, sortType, }: IGetCartItemsObjPayload): ICartItemsObj;
153
161
  export declare function getRemoveOfferFromCartData(data: Partial<IOrder>, offer_id: string, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
154
162
  export declare function getRemoveAllOffersFromCartData(data: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings, offerIds: string[] | undefined): Partial<IOrder>;
163
+ export declare function getClearVoucherCodeAndOffersFromCartData(data: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings, offerIds: string[] | undefined): Partial<IOrder>;
155
164
  /**
156
165
  * Calculate the eligible subtotal by excluding items/categories in excluded_refs
157
166
  */