@managesome/eposmatic-toolkit 0.2.351 → 0.2.354
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.
- package/lib/constants/ENUMS.d.ts +1 -0
- package/lib/constants/ENUMS.js +2 -0
- package/lib/constants/SWITCHPAY.d.ts +11 -4
- package/lib/constants/SWITCHPAY.js +26 -3
- package/lib/helpers/types/switchpay.d.ts +23 -3
- package/lib/helpers/types/workers.d.ts +17 -1
- package/lib/helpers/utils/minified-catalog.js +2 -1
- package/lib/helpers/utils/receipt-engine.js +2 -2
- package/lib/schemas/models/item.d.ts +3 -0
- package/lib/schemas/models/item.js +5 -0
- package/lib/schemas/types/item.d.ts +1 -0
- package/package.json +1 -1
- package/lib/helpers/utils/offer-apply-helpers.test.d.ts +0 -1
- package/lib/helpers/utils/offer-apply-helpers.test.js +0 -110
- package/lib/helpers/utils/offers-helpers.test.d.ts +0 -1
- package/lib/helpers/utils/offers-helpers.test.js +0 -157
- package/lib/schemas/models/purchase_order_receipts.d.ts +0 -165
- package/lib/schemas/models/purchase_order_receipts.js +0 -151
- package/lib/schemas/models/purchase_order_rfq.d.ts +0 -1938
- package/lib/schemas/models/purchase_order_rfq.js +0 -309
- package/lib/schemas/models/purchase_order_vendor_returns.d.ts +0 -234
- package/lib/schemas/models/purchase_order_vendor_returns.js +0 -188
- package/lib/schemas/types/customer_wallet_assignments.d.ts +0 -61
- package/lib/schemas/types/customer_wallet_assignments.js +0 -23
- package/lib/schemas/types/purchase_order_common.d.ts +0 -39
- package/lib/schemas/types/purchase_order_common.js +0 -2
- package/lib/schemas/types/purchase_order_receipts.d.ts +0 -33
- package/lib/schemas/types/purchase_order_receipts.js +0 -2
- package/lib/schemas/types/purchase_order_rfq.d.ts +0 -25
- package/lib/schemas/types/purchase_order_rfq.js +0 -2
- package/lib/schemas/types/purchase_order_vendor_returns.d.ts +0 -42
- package/lib/schemas/types/purchase_order_vendor_returns.js +0 -2
package/lib/constants/ENUMS.d.ts
CHANGED
|
@@ -128,6 +128,7 @@ export declare enum PAYMENT_TYPE_ENUM {
|
|
|
128
128
|
CARD = "CARD",
|
|
129
129
|
JAZZCASH_PAY = "JAZZCASH_PAY",
|
|
130
130
|
EASYPAISA_PAY = "EASYPAISA_PAY",
|
|
131
|
+
RAAST_PAY = "RAAST_PAY",
|
|
131
132
|
TERMINAL = "TERMINAL",
|
|
132
133
|
MARKED_PAID = "MARKED_PAID",
|
|
133
134
|
COMPLIMENTARY = "COMPLIMENTARY"
|
package/lib/constants/ENUMS.js
CHANGED
|
@@ -249,6 +249,7 @@ var PAYMENT_TYPE_ENUM;
|
|
|
249
249
|
PAYMENT_TYPE_ENUM["CARD"] = "CARD";
|
|
250
250
|
PAYMENT_TYPE_ENUM["JAZZCASH_PAY"] = "JAZZCASH_PAY";
|
|
251
251
|
PAYMENT_TYPE_ENUM["EASYPAISA_PAY"] = "EASYPAISA_PAY";
|
|
252
|
+
PAYMENT_TYPE_ENUM["RAAST_PAY"] = "RAAST_PAY";
|
|
252
253
|
PAYMENT_TYPE_ENUM["TERMINAL"] = "TERMINAL";
|
|
253
254
|
PAYMENT_TYPE_ENUM["MARKED_PAID"] = "MARKED_PAID";
|
|
254
255
|
PAYMENT_TYPE_ENUM["COMPLIMENTARY"] = "COMPLIMENTARY";
|
|
@@ -260,6 +261,7 @@ exports.PaymentTypeDescriptions = {
|
|
|
260
261
|
[PAYMENT_TYPE_ENUM.CARD]: 'Pay using credit/debit card 💳',
|
|
261
262
|
[PAYMENT_TYPE_ENUM.JAZZCASH_PAY]: 'Pay using JazzCash mobile wallet 📱',
|
|
262
263
|
[PAYMENT_TYPE_ENUM.EASYPAISA_PAY]: 'Pay using EasyPaisa mobile wallet 📱',
|
|
264
|
+
[PAYMENT_TYPE_ENUM.RAAST_PAY]: 'Pay using Raast transfer 📲',
|
|
263
265
|
[PAYMENT_TYPE_ENUM.TERMINAL]: 'Payment via terminal device 🏧',
|
|
264
266
|
[PAYMENT_TYPE_ENUM.MARKED_PAID]: 'Externally confirmed as paid ✅',
|
|
265
267
|
[PAYMENT_TYPE_ENUM.COMPLIMENTARY]: 'Free, no charge 🎁',
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { PAYMENT_TYPE_ENUM } from './ENUMS';
|
|
2
|
+
export type TSwitchpayPaymentType = PAYMENT_TYPE_ENUM.EASYPAISA_PAY | PAYMENT_TYPE_ENUM.JAZZCASH_PAY | PAYMENT_TYPE_ENUM.RAAST_PAY;
|
|
3
|
+
export interface ISwitchpayMethodConfig {
|
|
4
|
+
payment_type: TSwitchpayPaymentType;
|
|
5
|
+
channel_id: number;
|
|
6
|
+
category_id: number;
|
|
7
|
+
display_name: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const SWITCHPAY_METHODS: Record<TSwitchpayPaymentType, ISwitchpayMethodConfig>;
|
|
10
|
+
export declare const SWITCHPAY_CHANNEL: Record<TSwitchpayPaymentType, number>;
|
|
11
|
+
export declare const ALL_SWITCHPAY_PAYMENT_TYPES: TSwitchpayPaymentType[];
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SWITCHPAY_CHANNEL = void 0;
|
|
3
|
+
exports.ALL_SWITCHPAY_PAYMENT_TYPES = exports.SWITCHPAY_CHANNEL = exports.SWITCHPAY_METHODS = void 0;
|
|
4
4
|
const ENUMS_1 = require("./ENUMS");
|
|
5
|
+
exports.SWITCHPAY_METHODS = {
|
|
6
|
+
[ENUMS_1.PAYMENT_TYPE_ENUM.EASYPAISA_PAY]: {
|
|
7
|
+
payment_type: ENUMS_1.PAYMENT_TYPE_ENUM.EASYPAISA_PAY,
|
|
8
|
+
channel_id: 8,
|
|
9
|
+
category_id: 2,
|
|
10
|
+
display_name: 'Easypaisa',
|
|
11
|
+
},
|
|
12
|
+
[ENUMS_1.PAYMENT_TYPE_ENUM.JAZZCASH_PAY]: {
|
|
13
|
+
payment_type: ENUMS_1.PAYMENT_TYPE_ENUM.JAZZCASH_PAY,
|
|
14
|
+
channel_id: 10,
|
|
15
|
+
category_id: 2,
|
|
16
|
+
display_name: 'JazzCash',
|
|
17
|
+
},
|
|
18
|
+
[ENUMS_1.PAYMENT_TYPE_ENUM.RAAST_PAY]: {
|
|
19
|
+
payment_type: ENUMS_1.PAYMENT_TYPE_ENUM.RAAST_PAY,
|
|
20
|
+
channel_id: 20,
|
|
21
|
+
category_id: 2,
|
|
22
|
+
display_name: 'Raast',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
// Backward-compatible export used by existing integrations.
|
|
5
26
|
exports.SWITCHPAY_CHANNEL = {
|
|
6
|
-
[ENUMS_1.PAYMENT_TYPE_ENUM.EASYPAISA_PAY]:
|
|
7
|
-
[ENUMS_1.PAYMENT_TYPE_ENUM.JAZZCASH_PAY]:
|
|
27
|
+
[ENUMS_1.PAYMENT_TYPE_ENUM.EASYPAISA_PAY]: exports.SWITCHPAY_METHODS[ENUMS_1.PAYMENT_TYPE_ENUM.EASYPAISA_PAY].channel_id,
|
|
28
|
+
[ENUMS_1.PAYMENT_TYPE_ENUM.JAZZCASH_PAY]: exports.SWITCHPAY_METHODS[ENUMS_1.PAYMENT_TYPE_ENUM.JAZZCASH_PAY].channel_id,
|
|
29
|
+
[ENUMS_1.PAYMENT_TYPE_ENUM.RAAST_PAY]: exports.SWITCHPAY_METHODS[ENUMS_1.PAYMENT_TYPE_ENUM.RAAST_PAY].channel_id,
|
|
8
30
|
};
|
|
31
|
+
exports.ALL_SWITCHPAY_PAYMENT_TYPES = Object.keys(exports.SWITCHPAY_METHODS);
|
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
export interface ISwitchPayEWalletRequestBody {
|
|
2
2
|
customerTransactionId: string;
|
|
3
|
-
categoryId:
|
|
3
|
+
categoryId: number;
|
|
4
4
|
channelId: number;
|
|
5
5
|
item: string;
|
|
6
6
|
amount: number;
|
|
7
7
|
msisdn: string;
|
|
8
|
-
cnic
|
|
9
|
-
email
|
|
8
|
+
cnic?: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
billReferenceNo?: string;
|
|
11
|
+
currency?: string;
|
|
12
|
+
remoteIPAddress?: string;
|
|
13
|
+
ucid?: string;
|
|
14
|
+
discountAmount?: number;
|
|
15
|
+
convertedAmount?: number;
|
|
16
|
+
discountableAmount?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ISwitchPayRefundRequestBody {
|
|
19
|
+
orderId: string;
|
|
20
|
+
reason: string;
|
|
21
|
+
amount: number;
|
|
22
|
+
}
|
|
23
|
+
export interface ISwitchPayRefundResponseBody {
|
|
24
|
+
code?: number | string;
|
|
25
|
+
status?: string;
|
|
26
|
+
orderId?: string;
|
|
27
|
+
transactionId?: string | number;
|
|
28
|
+
message?: string;
|
|
29
|
+
timestamp?: string | Date;
|
|
10
30
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CARD_PROCESSING_PROVIDERS_ENUM, CURRENCY_SYMBOL_ENUM, DELIVERY_STATUS_ENUM, ORDER_STATUS_ENUM, PLATFORM_TYPE_ENUM, PLATFORMS_ENUM, VOID_ORDER_ITEM_TYPE_ENUM, WALLET_ASSET_TYPE_ENUM, WALLET_ASSIGNMENT_BEHAVIOR_ENUM, WAREHOUSE_INVOICE_STATUS_ENUM } from '../../constants';
|
|
2
2
|
import { IDineinTableFingerprint, IInternalLead, IModifierExtra, IOrder, IOrderItem, IOrderPayment, IPurchaseOrder, IWarehouseClientInvoice } from '../../schemas';
|
|
3
|
-
import { ISwitchPayEWalletRequestBody } from './switchpay';
|
|
3
|
+
import { ISwitchPayEWalletRequestBody, ISwitchPayRefundRequestBody } from './switchpay';
|
|
4
4
|
export interface IWorker_CreateDelivery {
|
|
5
5
|
order: IOrder;
|
|
6
6
|
tenant_name: string;
|
|
@@ -127,12 +127,28 @@ export interface IWorker_ProcessSwitchpayPaymentForOrder {
|
|
|
127
127
|
card_processing_provider: CARD_PROCESSING_PROVIDERS_ENUM;
|
|
128
128
|
body: ISwitchPayEWalletRequestBody;
|
|
129
129
|
}
|
|
130
|
+
export interface IWorker_ProcessSwitchpayRefundForOrder {
|
|
131
|
+
order_id: string;
|
|
132
|
+
payment_slot_id: string;
|
|
133
|
+
tenant_id: string;
|
|
134
|
+
_card_processing_account_token: string;
|
|
135
|
+
card_processing_account_id: string;
|
|
136
|
+
card_processing_provider: CARD_PROCESSING_PROVIDERS_ENUM;
|
|
137
|
+
body: ISwitchPayRefundRequestBody;
|
|
138
|
+
}
|
|
130
139
|
export interface IWorker_SyncSwitchpayPaymentSuccess {
|
|
131
140
|
order_id: string;
|
|
132
141
|
payment_id: string;
|
|
133
142
|
pId: string;
|
|
134
143
|
amount: number;
|
|
135
144
|
}
|
|
145
|
+
export interface IWorker_SyncSwitchpayPaymentStatus {
|
|
146
|
+
order_id: string;
|
|
147
|
+
payment_id: string;
|
|
148
|
+
pId: string;
|
|
149
|
+
amount: number;
|
|
150
|
+
status: string;
|
|
151
|
+
}
|
|
136
152
|
export interface IWorker_ProcessStripePaymentPolling {
|
|
137
153
|
order_id: string;
|
|
138
154
|
tenant_id: string;
|
|
@@ -158,7 +158,7 @@ function convertMinifiedCategoryToOriginalCategory(category) {
|
|
|
158
158
|
function convertMinifiedItemToOriginalItem(item, tenantId) {
|
|
159
159
|
const {
|
|
160
160
|
// Optional properties
|
|
161
|
-
brand_id = 'xxx', tenants = [], ingredients = null, createdAt = new Date(), updatedAt = new Date(), hide_name = false, caveats = [], dietary_preferences = [], is_featured = false, featured_sort_id = 0, display_price = null, show_starting_from = false, keywords = [], is_discount_percentage = false,
|
|
161
|
+
brand_id = 'xxx', tenants = [], ingredients = null, createdAt = new Date(), updatedAt = new Date(), hide_name = false, caveats = [], dietary_preferences = [], is_featured = false, featured_sort_id = 0, display_price = null, show_starting_from = false, use_source_ingredients = false, keywords = [], is_discount_percentage = false,
|
|
162
162
|
// Changed properties
|
|
163
163
|
// sold_out,
|
|
164
164
|
// price,
|
|
@@ -185,6 +185,7 @@ function convertMinifiedItemToOriginalItem(item, tenantId) {
|
|
|
185
185
|
featured_sort_id,
|
|
186
186
|
display_price,
|
|
187
187
|
show_starting_from,
|
|
188
|
+
use_source_ingredients,
|
|
188
189
|
is_discount_percentage,
|
|
189
190
|
// changed properties
|
|
190
191
|
price,
|
|
@@ -229,11 +229,11 @@ function getReceiptEngineFooterDetails(order, settings) {
|
|
|
229
229
|
right,
|
|
230
230
|
});
|
|
231
231
|
}
|
|
232
|
-
// 16. Card Charges
|
|
232
|
+
// 16. Card Charges
|
|
233
233
|
if (cardCharges > 0) {
|
|
234
234
|
const right = (0, common_1.localeAmount)(currencySymbol, cardCharges);
|
|
235
235
|
details.push({
|
|
236
|
-
left: 'Card Charges
|
|
236
|
+
left: 'Card Charges',
|
|
237
237
|
right,
|
|
238
238
|
});
|
|
239
239
|
}
|
|
@@ -3964,6 +3964,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
3964
3964
|
featured_sort_id: number;
|
|
3965
3965
|
display_price: number;
|
|
3966
3966
|
show_starting_from?: boolean | null | undefined;
|
|
3967
|
+
use_source_ingredients?: boolean | null | undefined;
|
|
3967
3968
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
3968
3969
|
createdAt: NativeDate;
|
|
3969
3970
|
updatedAt: NativeDate;
|
|
@@ -7611,6 +7612,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
7611
7612
|
featured_sort_id: number;
|
|
7612
7613
|
display_price: number;
|
|
7613
7614
|
show_starting_from?: boolean | null | undefined;
|
|
7615
|
+
use_source_ingredients?: boolean | null | undefined;
|
|
7614
7616
|
}>> & import("mongoose").FlatRecord<{
|
|
7615
7617
|
createdAt: NativeDate;
|
|
7616
7618
|
updatedAt: NativeDate;
|
|
@@ -11258,6 +11260,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
11258
11260
|
featured_sort_id: number;
|
|
11259
11261
|
display_price: number;
|
|
11260
11262
|
show_starting_from?: boolean | null | undefined;
|
|
11263
|
+
use_source_ingredients?: boolean | null | undefined;
|
|
11261
11264
|
}> & Required<{
|
|
11262
11265
|
_id: import("mongoose").Types.ObjectId;
|
|
11263
11266
|
}> & {
|
|
@@ -303,6 +303,11 @@ exports.ItemSchema = new mongoose_1.Schema({
|
|
|
303
303
|
type: Boolean,
|
|
304
304
|
required: false,
|
|
305
305
|
},
|
|
306
|
+
use_source_ingredients: {
|
|
307
|
+
type: Boolean,
|
|
308
|
+
required: false,
|
|
309
|
+
default: false,
|
|
310
|
+
},
|
|
306
311
|
// =====><=====
|
|
307
312
|
createdAt: {
|
|
308
313
|
type: mongoose_1.Schema.Types.Date,
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cart_actions_1 = require("../store/cart-actions");
|
|
4
|
-
const offer_apply_helpers_1 = require("./offer-apply-helpers");
|
|
5
|
-
const OFFER_ID = 'offer-reward-threshold';
|
|
6
|
-
const POST_ORDER_REWARD_TYPES = ['POINTS', 'CASHBACK', 'VOUCHER', 'GIFT_CARDS'];
|
|
7
|
-
function makeCategories({ itemDiscountDetails = null, quantity = 1, subtotal = 699, } = {}) {
|
|
8
|
-
return [
|
|
9
|
-
{
|
|
10
|
-
category_id: 'category-pizza',
|
|
11
|
-
items: [
|
|
12
|
-
{
|
|
13
|
-
_id: 'cart-item-1',
|
|
14
|
-
item_id: 'item-classic-euro',
|
|
15
|
-
name: 'Classic Euro',
|
|
16
|
-
quantity,
|
|
17
|
-
subtotal,
|
|
18
|
-
modifiers: [],
|
|
19
|
-
item_discount_details: itemDiscountDetails,
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
},
|
|
23
|
-
];
|
|
24
|
-
}
|
|
25
|
-
function makeOrder(overrides = {}) {
|
|
26
|
-
return {
|
|
27
|
-
categories: makeCategories(),
|
|
28
|
-
order_discount_details: null,
|
|
29
|
-
redeemed_offers: {
|
|
30
|
-
[OFFER_ID]: 1,
|
|
31
|
-
},
|
|
32
|
-
wallet_redemptions: null,
|
|
33
|
-
platform: 'WEB_TAKE-AWAY',
|
|
34
|
-
...overrides,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function makeOffer(rewardType, overrides = {}) {
|
|
38
|
-
const offer = {
|
|
39
|
-
_id: OFFER_ID,
|
|
40
|
-
name: `${rewardType} threshold reward`,
|
|
41
|
-
active: true,
|
|
42
|
-
reward_type: rewardType,
|
|
43
|
-
pathway_to_unlock_type: 'ORDERS',
|
|
44
|
-
pathway_to_unlock_type_orders: {
|
|
45
|
-
total_amount: 1000,
|
|
46
|
-
max_claims: null,
|
|
47
|
-
max_uses_per_customer: null,
|
|
48
|
-
},
|
|
49
|
-
...overrides,
|
|
50
|
-
};
|
|
51
|
-
if (rewardType === 'POINTS') {
|
|
52
|
-
offer.reward_points = { points: 100, once_per_order: true };
|
|
53
|
-
}
|
|
54
|
-
if (rewardType === 'CASHBACK') {
|
|
55
|
-
offer.reward_cashback = { cashback_value: 10, is_cashback_percentage: false };
|
|
56
|
-
}
|
|
57
|
-
if (rewardType === 'VOUCHER') {
|
|
58
|
-
offer.reward_voucher = { voucher_ids: { 'voucher-april28': true } };
|
|
59
|
-
}
|
|
60
|
-
if (rewardType === 'GIFT_CARDS') {
|
|
61
|
-
offer.reward_gift_cards = { gift_card_ids: { 'gift-card-reward': true } };
|
|
62
|
-
}
|
|
63
|
-
if (rewardType === 'ITEMS') {
|
|
64
|
-
offer.reward_items = {
|
|
65
|
-
num_of_items: 1,
|
|
66
|
-
item_ids: ['item-classic-euro'],
|
|
67
|
-
excluded_refs: [],
|
|
68
|
-
exclusive_refs: [],
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
return offer;
|
|
72
|
-
}
|
|
73
|
-
describe('offer redeemed_offers sync', () => {
|
|
74
|
-
test.each(POST_ORDER_REWARD_TYPES)('getSyncOffersWithCartData clears stale %s reward claims when unlock context reports zero availability', (rewardType) => {
|
|
75
|
-
const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeOrder(), [], {}, {}, [makeOffer(rewardType)]);
|
|
76
|
-
expect(result.redeemed_offers?.[OFFER_ID]).toBeUndefined();
|
|
77
|
-
});
|
|
78
|
-
test.each(POST_ORDER_REWARD_TYPES)('calculateCartOrderInfoAndSyncData clears stale %s reward claims when unlock context reports zero availability', (rewardType) => {
|
|
79
|
-
const result = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)(makeOrder(), [], {}, undefined, {
|
|
80
|
-
unlockedOffersApplicableTimes: {},
|
|
81
|
-
offers: [makeOffer(rewardType)],
|
|
82
|
-
});
|
|
83
|
-
expect(result.redeemed_offers?.[OFFER_ID]).toBeUndefined();
|
|
84
|
-
});
|
|
85
|
-
it('getSyncOffersWithCartData preserves selected item reward evidence while the item reward remains unlocked', () => {
|
|
86
|
-
const result = (0, offer_apply_helpers_1.getSyncOffersWithCartData)(makeOrder({
|
|
87
|
-
categories: makeCategories({
|
|
88
|
-
itemDiscountDetails: {
|
|
89
|
-
loyalty_discount_id: OFFER_ID,
|
|
90
|
-
},
|
|
91
|
-
}),
|
|
92
|
-
redeemed_offers: null,
|
|
93
|
-
}), [], {}, { [OFFER_ID]: 1 }, [makeOffer('ITEMS')]);
|
|
94
|
-
expect(result.redeemed_offers?.[OFFER_ID]).toBe(1);
|
|
95
|
-
});
|
|
96
|
-
it('calculateCartOrderInfoAndSyncData preserves selected item reward evidence while the item reward remains unlocked', () => {
|
|
97
|
-
const result = (0, cart_actions_1.calculateCartOrderInfoAndSyncData)(makeOrder({
|
|
98
|
-
categories: makeCategories({
|
|
99
|
-
itemDiscountDetails: {
|
|
100
|
-
loyalty_discount_id: OFFER_ID,
|
|
101
|
-
},
|
|
102
|
-
}),
|
|
103
|
-
redeemed_offers: null,
|
|
104
|
-
}), [], {}, undefined, {
|
|
105
|
-
unlockedOffersApplicableTimes: { [OFFER_ID]: 1 },
|
|
106
|
-
offers: [makeOffer('ITEMS')],
|
|
107
|
-
});
|
|
108
|
-
expect(result.redeemed_offers?.[OFFER_ID]).toBe(1);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const constants_1 = require("../../constants");
|
|
4
|
-
const offers_helpers_1 = require("./offers-helpers");
|
|
5
|
-
const OFFER_ID = 'offer-orders-discount';
|
|
6
|
-
function makeCategories(subtotal) {
|
|
7
|
-
return [
|
|
8
|
-
{
|
|
9
|
-
category_id: 'category-pizza',
|
|
10
|
-
items: [
|
|
11
|
-
{
|
|
12
|
-
_id: 'cart-item-1',
|
|
13
|
-
item_id: 'item-classic',
|
|
14
|
-
name: 'Classic',
|
|
15
|
-
quantity: 1,
|
|
16
|
-
subtotal,
|
|
17
|
-
modifiers: [],
|
|
18
|
-
item_discount_details: null,
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
},
|
|
22
|
-
];
|
|
23
|
-
}
|
|
24
|
-
function makeOrdersDiscountOffer(overrides = {}) {
|
|
25
|
-
return {
|
|
26
|
-
_id: OFFER_ID,
|
|
27
|
-
name: 'Spend threshold discount',
|
|
28
|
-
active: true,
|
|
29
|
-
auto_apply: false,
|
|
30
|
-
sort_id: 1,
|
|
31
|
-
included_platforms: [constants_1.PLATFORMS_ENUM.WEB_TAKE_AWAY],
|
|
32
|
-
pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS,
|
|
33
|
-
pathway_to_unlock_type_orders: {
|
|
34
|
-
scope: constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL,
|
|
35
|
-
min_num_of_orders: 0,
|
|
36
|
-
max_num_of_orders: null,
|
|
37
|
-
total_amount: 1000,
|
|
38
|
-
max_amount: null,
|
|
39
|
-
orders_between_unlocks: null,
|
|
40
|
-
max_claims: null,
|
|
41
|
-
max_uses_per_customer: null,
|
|
42
|
-
},
|
|
43
|
-
reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT,
|
|
44
|
-
reward_discount: {
|
|
45
|
-
discount_value: 20,
|
|
46
|
-
is_discount_percentage: true,
|
|
47
|
-
max_discount_amount: null,
|
|
48
|
-
max_discount_percentage: null,
|
|
49
|
-
excluded_refs: [],
|
|
50
|
-
},
|
|
51
|
-
...overrides,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function getSingleOfferStats(options = {}) {
|
|
55
|
-
const offer = options.offer ?? makeOrdersDiscountOffer();
|
|
56
|
-
const categories = Object.prototype.hasOwnProperty.call(options, 'categories')
|
|
57
|
-
? options.categories
|
|
58
|
-
: makeCategories(1000);
|
|
59
|
-
const orderDiscountDetails = options.orderDiscountDetails ?? null;
|
|
60
|
-
const redeemedOffers = options.redeemedOffers ?? null;
|
|
61
|
-
const currentItemsPrice = options.currentItemsPrice ?? 1000;
|
|
62
|
-
const totalDiscountApplied = options.totalDiscountApplied ?? 0;
|
|
63
|
-
return (0, offers_helpers_1.getOffersWithStats)({
|
|
64
|
-
offers: [offer],
|
|
65
|
-
customer: {
|
|
66
|
-
total_orders: 1,
|
|
67
|
-
},
|
|
68
|
-
vouchers: undefined,
|
|
69
|
-
giftCards: undefined,
|
|
70
|
-
customerOfferRedemptionCounts: undefined,
|
|
71
|
-
redeemed_offers: redeemedOffers,
|
|
72
|
-
platform: constants_1.PLATFORMS_ENUM.WEB_TAKE_AWAY,
|
|
73
|
-
currency_symbol: constants_1.CURRENCY_SYMBOL_ENUM.$,
|
|
74
|
-
categories,
|
|
75
|
-
currentItemsPrice,
|
|
76
|
-
totalDiscountApplied,
|
|
77
|
-
order_discount_details: orderDiscountDetails,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
describe('getOffersWithStats spend qualification', () => {
|
|
81
|
-
it('uses item-net subtotal instead of original item price', () => {
|
|
82
|
-
const result = getSingleOfferStats({
|
|
83
|
-
categories: makeCategories(500),
|
|
84
|
-
currentItemsPrice: 1000,
|
|
85
|
-
totalDiscountApplied: 500,
|
|
86
|
-
});
|
|
87
|
-
const stats = result.offersWithStats[0].stats;
|
|
88
|
-
expect(stats.claimable).toBe(false);
|
|
89
|
-
expect(stats.progress).toBe(50);
|
|
90
|
-
expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}500`);
|
|
91
|
-
expect(result.totalClaimableOffers).not.toContain(OFFER_ID);
|
|
92
|
-
});
|
|
93
|
-
it('uses item-discount fallback pricing when categories are not available', () => {
|
|
94
|
-
const result = getSingleOfferStats({
|
|
95
|
-
categories: undefined,
|
|
96
|
-
currentItemsPrice: 1000,
|
|
97
|
-
totalDiscountApplied: 500,
|
|
98
|
-
});
|
|
99
|
-
const stats = result.offersWithStats[0].stats;
|
|
100
|
-
expect(stats.claimable).toBe(false);
|
|
101
|
-
expect(stats.progress).toBe(50);
|
|
102
|
-
expect(result.totalClaimableOffers).not.toContain(OFFER_ID);
|
|
103
|
-
});
|
|
104
|
-
it('does not gross up an unclaimed orders discount reward threshold', () => {
|
|
105
|
-
const result = getSingleOfferStats({
|
|
106
|
-
categories: makeCategories(1000),
|
|
107
|
-
currentItemsPrice: 1000,
|
|
108
|
-
totalDiscountApplied: 0,
|
|
109
|
-
});
|
|
110
|
-
const stats = result.offersWithStats[0].stats;
|
|
111
|
-
expect(stats.claimable).toBe(true);
|
|
112
|
-
expect(stats.progress).toBe(100);
|
|
113
|
-
expect(result.totalClaimableOffers).toContain(OFFER_ID);
|
|
114
|
-
});
|
|
115
|
-
it('adds back the applied offer discount when re-checking its own orders threshold', () => {
|
|
116
|
-
const result = getSingleOfferStats({
|
|
117
|
-
categories: makeCategories(1000),
|
|
118
|
-
currentItemsPrice: 1000,
|
|
119
|
-
totalDiscountApplied: 200,
|
|
120
|
-
redeemedOffers: {
|
|
121
|
-
[OFFER_ID]: 1,
|
|
122
|
-
},
|
|
123
|
-
orderDiscountDetails: {
|
|
124
|
-
loyalty_discount_id: OFFER_ID,
|
|
125
|
-
loyalty_discount_name: 'Spend threshold discount',
|
|
126
|
-
loyalty_discount: 20,
|
|
127
|
-
is_loyalty_discount_percentage: true,
|
|
128
|
-
total_discount: 200,
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
const stats = result.offersWithStats[0].stats;
|
|
132
|
-
expect(stats.progress).toBe(100);
|
|
133
|
-
expect(stats.claimable).toBe(false);
|
|
134
|
-
expect(stats.redeemed_times).toBe(1);
|
|
135
|
-
expect(stats.message).toBe('This offer is redeemed ✅');
|
|
136
|
-
expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
|
|
137
|
-
});
|
|
138
|
-
it('counts unrelated order-level discounts against the orders threshold', () => {
|
|
139
|
-
const result = getSingleOfferStats({
|
|
140
|
-
categories: makeCategories(1000),
|
|
141
|
-
currentItemsPrice: 1000,
|
|
142
|
-
totalDiscountApplied: 200,
|
|
143
|
-
orderDiscountDetails: {
|
|
144
|
-
special_discount_id: 'manual-discount',
|
|
145
|
-
special_discount_name: 'Manual discount',
|
|
146
|
-
special_discount: 200,
|
|
147
|
-
is_special_discount_percentage: false,
|
|
148
|
-
total_discount: 200,
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
const stats = result.offersWithStats[0].stats;
|
|
152
|
-
expect(stats.claimable).toBe(false);
|
|
153
|
-
expect(stats.progress).toBe(80);
|
|
154
|
-
expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}200`);
|
|
155
|
-
expect(result.totalClaimableOffers).not.toContain(OFFER_ID);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { Schema } from 'mongoose';
|
|
2
|
-
import { PURCHASE_ORDER_RECEIPT_STATUS_ENUM } from '../../constants';
|
|
3
|
-
export declare const PurchaseOrderReceiptsSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
4
|
-
timestamps: true;
|
|
5
|
-
versionKey: false;
|
|
6
|
-
minimize: false;
|
|
7
|
-
}, {
|
|
8
|
-
createdAt: NativeDate;
|
|
9
|
-
updatedAt: NativeDate;
|
|
10
|
-
} & {
|
|
11
|
-
_id: import("mongoose").Types.ObjectId;
|
|
12
|
-
createdAt_mins: number;
|
|
13
|
-
createdAt: NativeDate;
|
|
14
|
-
updatedAt: NativeDate;
|
|
15
|
-
items: import("mongoose").Types.DocumentArray<{
|
|
16
|
-
_id: import("mongoose").Types.ObjectId;
|
|
17
|
-
name: string;
|
|
18
|
-
price: number;
|
|
19
|
-
item_id: import("mongoose").Types.ObjectId;
|
|
20
|
-
subtotal: number;
|
|
21
|
-
ordered_quantity: number;
|
|
22
|
-
received_quantity: number;
|
|
23
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
24
|
-
_id: import("mongoose").Types.ObjectId;
|
|
25
|
-
name: string;
|
|
26
|
-
price: number;
|
|
27
|
-
item_id: import("mongoose").Types.ObjectId;
|
|
28
|
-
subtotal: number;
|
|
29
|
-
ordered_quantity: number;
|
|
30
|
-
received_quantity: number;
|
|
31
|
-
}> & {
|
|
32
|
-
_id: import("mongoose").Types.ObjectId;
|
|
33
|
-
name: string;
|
|
34
|
-
price: number;
|
|
35
|
-
item_id: import("mongoose").Types.ObjectId;
|
|
36
|
-
subtotal: number;
|
|
37
|
-
ordered_quantity: number;
|
|
38
|
-
received_quantity: number;
|
|
39
|
-
}>;
|
|
40
|
-
warehouse_id: string;
|
|
41
|
-
vendor_id: import("mongoose").Types.ObjectId;
|
|
42
|
-
vendor_name: string;
|
|
43
|
-
purchase_order_id: import("mongoose").Types.ObjectId;
|
|
44
|
-
receipt_status: PURCHASE_ORDER_RECEIPT_STATUS_ENUM;
|
|
45
|
-
total_received_amount: number;
|
|
46
|
-
cancel_reason?: string | null | undefined;
|
|
47
|
-
notes?: string | null | undefined;
|
|
48
|
-
created_by?: {
|
|
49
|
-
_id: string;
|
|
50
|
-
name: string;
|
|
51
|
-
} | null | undefined;
|
|
52
|
-
validated_by?: {
|
|
53
|
-
_id: string;
|
|
54
|
-
name: string;
|
|
55
|
-
} | null | undefined;
|
|
56
|
-
validated_at?: NativeDate | null | undefined;
|
|
57
|
-
cancelled_at?: NativeDate | null | undefined;
|
|
58
|
-
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
59
|
-
createdAt: NativeDate;
|
|
60
|
-
updatedAt: NativeDate;
|
|
61
|
-
} & {
|
|
62
|
-
_id: import("mongoose").Types.ObjectId;
|
|
63
|
-
createdAt_mins: number;
|
|
64
|
-
createdAt: NativeDate;
|
|
65
|
-
updatedAt: NativeDate;
|
|
66
|
-
items: import("mongoose").Types.DocumentArray<{
|
|
67
|
-
_id: import("mongoose").Types.ObjectId;
|
|
68
|
-
name: string;
|
|
69
|
-
price: number;
|
|
70
|
-
item_id: import("mongoose").Types.ObjectId;
|
|
71
|
-
subtotal: number;
|
|
72
|
-
ordered_quantity: number;
|
|
73
|
-
received_quantity: number;
|
|
74
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
75
|
-
_id: import("mongoose").Types.ObjectId;
|
|
76
|
-
name: string;
|
|
77
|
-
price: number;
|
|
78
|
-
item_id: import("mongoose").Types.ObjectId;
|
|
79
|
-
subtotal: number;
|
|
80
|
-
ordered_quantity: number;
|
|
81
|
-
received_quantity: number;
|
|
82
|
-
}> & {
|
|
83
|
-
_id: import("mongoose").Types.ObjectId;
|
|
84
|
-
name: string;
|
|
85
|
-
price: number;
|
|
86
|
-
item_id: import("mongoose").Types.ObjectId;
|
|
87
|
-
subtotal: number;
|
|
88
|
-
ordered_quantity: number;
|
|
89
|
-
received_quantity: number;
|
|
90
|
-
}>;
|
|
91
|
-
warehouse_id: string;
|
|
92
|
-
vendor_id: import("mongoose").Types.ObjectId;
|
|
93
|
-
vendor_name: string;
|
|
94
|
-
purchase_order_id: import("mongoose").Types.ObjectId;
|
|
95
|
-
receipt_status: PURCHASE_ORDER_RECEIPT_STATUS_ENUM;
|
|
96
|
-
total_received_amount: number;
|
|
97
|
-
cancel_reason?: string | null | undefined;
|
|
98
|
-
notes?: string | null | undefined;
|
|
99
|
-
created_by?: {
|
|
100
|
-
_id: string;
|
|
101
|
-
name: string;
|
|
102
|
-
} | null | undefined;
|
|
103
|
-
validated_by?: {
|
|
104
|
-
_id: string;
|
|
105
|
-
name: string;
|
|
106
|
-
} | null | undefined;
|
|
107
|
-
validated_at?: NativeDate | null | undefined;
|
|
108
|
-
cancelled_at?: NativeDate | null | undefined;
|
|
109
|
-
}>> & import("mongoose").FlatRecord<{
|
|
110
|
-
createdAt: NativeDate;
|
|
111
|
-
updatedAt: NativeDate;
|
|
112
|
-
} & {
|
|
113
|
-
_id: import("mongoose").Types.ObjectId;
|
|
114
|
-
createdAt_mins: number;
|
|
115
|
-
createdAt: NativeDate;
|
|
116
|
-
updatedAt: NativeDate;
|
|
117
|
-
items: import("mongoose").Types.DocumentArray<{
|
|
118
|
-
_id: import("mongoose").Types.ObjectId;
|
|
119
|
-
name: string;
|
|
120
|
-
price: number;
|
|
121
|
-
item_id: import("mongoose").Types.ObjectId;
|
|
122
|
-
subtotal: number;
|
|
123
|
-
ordered_quantity: number;
|
|
124
|
-
received_quantity: number;
|
|
125
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
126
|
-
_id: import("mongoose").Types.ObjectId;
|
|
127
|
-
name: string;
|
|
128
|
-
price: number;
|
|
129
|
-
item_id: import("mongoose").Types.ObjectId;
|
|
130
|
-
subtotal: number;
|
|
131
|
-
ordered_quantity: number;
|
|
132
|
-
received_quantity: number;
|
|
133
|
-
}> & {
|
|
134
|
-
_id: import("mongoose").Types.ObjectId;
|
|
135
|
-
name: string;
|
|
136
|
-
price: number;
|
|
137
|
-
item_id: import("mongoose").Types.ObjectId;
|
|
138
|
-
subtotal: number;
|
|
139
|
-
ordered_quantity: number;
|
|
140
|
-
received_quantity: number;
|
|
141
|
-
}>;
|
|
142
|
-
warehouse_id: string;
|
|
143
|
-
vendor_id: import("mongoose").Types.ObjectId;
|
|
144
|
-
vendor_name: string;
|
|
145
|
-
purchase_order_id: import("mongoose").Types.ObjectId;
|
|
146
|
-
receipt_status: PURCHASE_ORDER_RECEIPT_STATUS_ENUM;
|
|
147
|
-
total_received_amount: number;
|
|
148
|
-
cancel_reason?: string | null | undefined;
|
|
149
|
-
notes?: string | null | undefined;
|
|
150
|
-
created_by?: {
|
|
151
|
-
_id: string;
|
|
152
|
-
name: string;
|
|
153
|
-
} | null | undefined;
|
|
154
|
-
validated_by?: {
|
|
155
|
-
_id: string;
|
|
156
|
-
name: string;
|
|
157
|
-
} | null | undefined;
|
|
158
|
-
validated_at?: NativeDate | null | undefined;
|
|
159
|
-
cancelled_at?: NativeDate | null | undefined;
|
|
160
|
-
}> & Required<{
|
|
161
|
-
_id: import("mongoose").Types.ObjectId;
|
|
162
|
-
}> & {
|
|
163
|
-
__v: number;
|
|
164
|
-
}>;
|
|
165
|
-
export declare const PURCHASE_ORDER_RECEIPTS_COLLECTION_NAME = "purchase_order_receipts";
|