@managesome/eposmatic-toolkit 0.2.319 → 0.2.321
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.
|
@@ -68,6 +68,7 @@ export * from './void-warehouse-invoice-items-helpers';
|
|
|
68
68
|
export * from './void-warehouse-invoice-items-report-helpers';
|
|
69
69
|
export * from './voidations-summary-report-helpers';
|
|
70
70
|
export * from './wallet-helpers';
|
|
71
|
+
export * from './wallet-redemption-helpers';
|
|
71
72
|
export * from './warehouse-catalog-conversion';
|
|
72
73
|
export * from './warehouse-inventory';
|
|
73
74
|
export * from './warehouse-invoice-order-engine';
|
|
@@ -84,6 +84,7 @@ __exportStar(require("./void-warehouse-invoice-items-helpers"), exports);
|
|
|
84
84
|
__exportStar(require("./void-warehouse-invoice-items-report-helpers"), exports);
|
|
85
85
|
__exportStar(require("./voidations-summary-report-helpers"), exports);
|
|
86
86
|
__exportStar(require("./wallet-helpers"), exports);
|
|
87
|
+
__exportStar(require("./wallet-redemption-helpers"), exports);
|
|
87
88
|
__exportStar(require("./warehouse-catalog-conversion"), exports);
|
|
88
89
|
__exportStar(require("./warehouse-inventory"), exports);
|
|
89
90
|
__exportStar(require("./warehouse-invoice-order-engine"), exports);
|
|
@@ -214,6 +214,34 @@ function buildOfferCashbackUpdate({ offer, orderDiscountDetails, categories, })
|
|
|
214
214
|
// === (for GIFT_CARDS and VOUCHER reward types — post-order) === //
|
|
215
215
|
// ================================><================================= //
|
|
216
216
|
function buildOfferRewardUpdate({ offer, orderDiscountDetails, }) {
|
|
217
|
+
const isGiftCardReward = offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS;
|
|
218
|
+
const isVoucherReward = offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER;
|
|
219
|
+
// This helper is intentionally for deferred rewards only.
|
|
220
|
+
// It records redeemed-offer intent while leaving active discount/wallet state unchanged.
|
|
221
|
+
if (!isGiftCardReward && !isVoucherReward) {
|
|
222
|
+
return {
|
|
223
|
+
success: false,
|
|
224
|
+
discountDetails: null,
|
|
225
|
+
errorMessage: 'Offer reward helper supports only GIFT_CARDS and VOUCHER rewards.',
|
|
226
|
+
redeemedOfferId: null,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
if (isGiftCardReward && offer.reward_gift_cards == null) {
|
|
230
|
+
return {
|
|
231
|
+
success: false,
|
|
232
|
+
discountDetails: null,
|
|
233
|
+
errorMessage: 'Gift-card reward data is not available right now.',
|
|
234
|
+
redeemedOfferId: null,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
if (isVoucherReward && offer.reward_voucher == null) {
|
|
238
|
+
return {
|
|
239
|
+
success: false,
|
|
240
|
+
discountDetails: null,
|
|
241
|
+
errorMessage: 'Voucher reward data is not available right now.',
|
|
242
|
+
redeemedOfferId: null,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
217
245
|
const discountDetails = orderDiscountDetails ?? null;
|
|
218
246
|
return {
|
|
219
247
|
success: true,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { GIFT_CARD_REWARD_TYPE_ENUM } from '../../constants';
|
|
2
|
+
export interface IWalletGiftCardRedemptionCompat {
|
|
3
|
+
gift_card_id?: string | null;
|
|
4
|
+
mystery_gift_type?: GIFT_CARD_REWARD_TYPE_ENUM | null;
|
|
5
|
+
redeemed_times?: number | null;
|
|
6
|
+
value_redeemed?: number | null;
|
|
7
|
+
}
|
|
8
|
+
export type TWalletGiftCardRedemptionsCompatInput = IWalletGiftCardRedemptionCompat | IWalletGiftCardRedemptionCompat[] | null | undefined;
|
|
9
|
+
export interface IWalletGiftCardClaim {
|
|
10
|
+
gift_card_id: string;
|
|
11
|
+
redeemed_times: number;
|
|
12
|
+
mystery_gift_type?: GIFT_CARD_REWARD_TYPE_ENUM | null;
|
|
13
|
+
}
|
|
14
|
+
export declare function getWalletGiftCardRedemptionClaims(walletGiftCardRedemptions: TWalletGiftCardRedemptionsCompatInput): IWalletGiftCardClaim[];
|
|
15
|
+
export declare function buildWalletGiftCardRedemptionCompatPayload({ currentWalletGiftCardRedemptions, nextWalletGiftCardClaims, }: {
|
|
16
|
+
currentWalletGiftCardRedemptions: TWalletGiftCardRedemptionsCompatInput;
|
|
17
|
+
nextWalletGiftCardClaims: IWalletGiftCardClaim[];
|
|
18
|
+
}): IWalletGiftCardRedemptionCompat | IWalletGiftCardClaim[] | null;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWalletGiftCardRedemptionClaims = getWalletGiftCardRedemptionClaims;
|
|
4
|
+
exports.buildWalletGiftCardRedemptionCompatPayload = buildWalletGiftCardRedemptionCompatPayload;
|
|
5
|
+
function getWalletGiftCardRedemptionClaims(walletGiftCardRedemptions) {
|
|
6
|
+
const normalizedWalletGiftCardRedemptions = Array.isArray(walletGiftCardRedemptions)
|
|
7
|
+
? walletGiftCardRedemptions
|
|
8
|
+
: walletGiftCardRedemptions != null
|
|
9
|
+
? [walletGiftCardRedemptions]
|
|
10
|
+
: [];
|
|
11
|
+
const claimsByGiftCardId = {};
|
|
12
|
+
for (let i = 0; i < normalizedWalletGiftCardRedemptions.length; i++) {
|
|
13
|
+
const walletGiftCardRedemption = normalizedWalletGiftCardRedemptions[i];
|
|
14
|
+
const giftCardId = walletGiftCardRedemption.gift_card_id?.trim();
|
|
15
|
+
const redeemedTimes = Number(walletGiftCardRedemption.redeemed_times ?? walletGiftCardRedemption.value_redeemed ?? 0);
|
|
16
|
+
if (giftCardId == null || giftCardId.length === 0 || !Number.isFinite(redeemedTimes) || redeemedTimes <= 0) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const existingClaim = claimsByGiftCardId[giftCardId];
|
|
20
|
+
claimsByGiftCardId[giftCardId] = {
|
|
21
|
+
gift_card_id: giftCardId,
|
|
22
|
+
redeemed_times: (existingClaim?.redeemed_times ?? 0) + Math.floor(redeemedTimes),
|
|
23
|
+
...(walletGiftCardRedemption.mystery_gift_type != null
|
|
24
|
+
? {
|
|
25
|
+
mystery_gift_type: walletGiftCardRedemption.mystery_gift_type,
|
|
26
|
+
}
|
|
27
|
+
: existingClaim?.mystery_gift_type != null
|
|
28
|
+
? {
|
|
29
|
+
mystery_gift_type: existingClaim.mystery_gift_type,
|
|
30
|
+
}
|
|
31
|
+
: {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return Object.values(claimsByGiftCardId);
|
|
35
|
+
}
|
|
36
|
+
function buildWalletGiftCardRedemptionCompatPayload({ currentWalletGiftCardRedemptions, nextWalletGiftCardClaims, }) {
|
|
37
|
+
if (Array.isArray(currentWalletGiftCardRedemptions)) {
|
|
38
|
+
return nextWalletGiftCardClaims;
|
|
39
|
+
}
|
|
40
|
+
const nextWalletGiftCardClaim = nextWalletGiftCardClaims[0];
|
|
41
|
+
if (nextWalletGiftCardClaim == null) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
gift_card_id: nextWalletGiftCardClaim.gift_card_id,
|
|
46
|
+
mystery_gift_type: nextWalletGiftCardClaim.mystery_gift_type,
|
|
47
|
+
value_redeemed: nextWalletGiftCardClaim.redeemed_times,
|
|
48
|
+
redeemed_times: nextWalletGiftCardClaim.redeemed_times,
|
|
49
|
+
};
|
|
50
|
+
}
|