@sellout/models 0.0.341 → 0.0.342
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/.dist/sellout-proto.js +22 -0
- package/.dist/utils/OrderUtil.js +4 -4
- package/.dist/utils/OrderUtil.js.map +1 -1
- package/.dist/utils/PaymentUtil.js +10 -398
- package/.dist/utils/PaymentUtil.js.map +1 -1
- package/package.json +3 -3
- package/src/proto/email.proto +1 -0
- package/src/utils/OrderUtil.ts +4 -2
- package/src/utils/PaymentUtil.ts +9 -844
|
@@ -8,96 +8,6 @@ const IFee_1 = require("../interfaces/IFee");
|
|
|
8
8
|
const PaymentMethodTypeEnum_1 = require("../enums/PaymentMethodTypeEnum");
|
|
9
9
|
const IEventPromotion_1 = require("../interfaces/IEventPromotion");
|
|
10
10
|
class PaymentUtil {
|
|
11
|
-
// calculateOrderItemPrices(params: IPaymentCalculatorParams): IOrderItems {
|
|
12
|
-
// let {
|
|
13
|
-
// tickets = [],
|
|
14
|
-
// upgrades = [],
|
|
15
|
-
// fees = [],
|
|
16
|
-
// paymentMethodType,
|
|
17
|
-
// } = params;
|
|
18
|
-
// // Filter fees
|
|
19
|
-
// fees = fees.filter((fee: IFee) => {
|
|
20
|
-
// // Ignore card reader fees for non card reader payemnts
|
|
21
|
-
// if (fee.filters && fee.filters.includes(FeeFiltersEnum.CardReader) && paymentMethodType !== PaymentMethodTypeEnum.CardReader) {
|
|
22
|
-
// return false;
|
|
23
|
-
// }
|
|
24
|
-
// // Ignore card entry fees for non card entry payemnts
|
|
25
|
-
// if (fee.filters && fee.filters.includes(FeeFiltersEnum.CardEntry) && paymentMethodType !== PaymentMethodTypeEnum.CardEntry) {
|
|
26
|
-
// return false;
|
|
27
|
-
// }
|
|
28
|
-
// return true;
|
|
29
|
-
// });
|
|
30
|
-
// const ticketFees = fees.filter(f => f.appliedTo === FeeAppliedToEnum.Ticket)
|
|
31
|
-
// .sort(({ type }) => {
|
|
32
|
-
// if (type === FeeTypeEnum.Flat) return -1;
|
|
33
|
-
// else return 1;
|
|
34
|
-
// });
|
|
35
|
-
// const upgradeFees = fees.filter(f => f.appliedTo === FeeAppliedToEnum.Upgrade);
|
|
36
|
-
// // Orders mattes here. Flat type fees must be applied before Percent type fees
|
|
37
|
-
// const orderFees = fees.filter(f => f.appliedTo === FeeAppliedToEnum.Order)
|
|
38
|
-
// .sort(({ type }) => {
|
|
39
|
-
// if (type === FeeTypeEnum.Percent) return -1;
|
|
40
|
-
// else return 1;
|
|
41
|
-
// })
|
|
42
|
-
// .map(fee => {
|
|
43
|
-
// if(fee.type === FeeTypeEnum.Flat) {
|
|
44
|
-
// return {
|
|
45
|
-
// ...fee,
|
|
46
|
-
// value: fee.value / tickets.length,
|
|
47
|
-
// }
|
|
48
|
-
// }
|
|
49
|
-
// else return fee;
|
|
50
|
-
// });
|
|
51
|
-
// const reverseApplyFee = (price: number, ticket: ICreateOrderTicketParams, fee: IFee): number => {
|
|
52
|
-
// // Ignore seated fees
|
|
53
|
-
// if (fee.filters && fee.filters.includes(FeeFiltersEnum.Seated) && !ticket.seat) {
|
|
54
|
-
// return price;
|
|
55
|
-
// }
|
|
56
|
-
// const minFee = fee.minAppliedToPrice || 0;
|
|
57
|
-
// const maxFee = fee.maxAppliedToPrice || Infinity;
|
|
58
|
-
// if (minFee <= price && price <= maxFee) {
|
|
59
|
-
// console.log(fee);
|
|
60
|
-
// if (fee.type === FeeTypeEnum.Flat) {
|
|
61
|
-
// return price - fee.value;
|
|
62
|
-
// } if (fee.type === FeeTypeEnum.Percent) {
|
|
63
|
-
// return price * (1 - fee.value / 100);
|
|
64
|
-
// }
|
|
65
|
-
// }
|
|
66
|
-
// // if(fee.type === FeeTypeEnum.Percent) {
|
|
67
|
-
// // return price * (1 - fee.value / 100);
|
|
68
|
-
// // }
|
|
69
|
-
// // if(fee.type === FeeTypeEnum.Flat) {
|
|
70
|
-
// // return price - fee.value;
|
|
71
|
-
// // }
|
|
72
|
-
// return price;
|
|
73
|
-
// }
|
|
74
|
-
// function calculateTicketPrice(ticket: ICreateOrderTicketParams): number {
|
|
75
|
-
// if(!ticket.rollFees) return ticket.price;
|
|
76
|
-
// const allFees = [...orderFees, ...ticketFees];
|
|
77
|
-
// return allFees.reduce((cur, fee) => {
|
|
78
|
-
// const next = reverseApplyFee(cur, ticket, fee);
|
|
79
|
-
// return next;
|
|
80
|
-
// }, ticket.price);
|
|
81
|
-
// }
|
|
82
|
-
// tickets = tickets.map((ticket: ICreateOrderTicketParams): ICreateOrderTicketParams => {
|
|
83
|
-
// const price = Math.floor(calculateTicketPrice(ticket));
|
|
84
|
-
// console.log(`Ticket Price: `, price);
|
|
85
|
-
// return {
|
|
86
|
-
// ...ticket,
|
|
87
|
-
// price,
|
|
88
|
-
// }
|
|
89
|
-
// });
|
|
90
|
-
// // upgrades = upgrades.map((upgrade: ICreateOrderUpgradeParams): ICreateOrderUpgradeParams => {
|
|
91
|
-
// // return {
|
|
92
|
-
// // ...upgrade,
|
|
93
|
-
// // price: calculateUpgradePrice(upgrade),
|
|
94
|
-
// // }
|
|
95
|
-
// // });
|
|
96
|
-
// return {
|
|
97
|
-
// tickets,
|
|
98
|
-
// upgrades,
|
|
99
|
-
// };
|
|
100
|
-
// },
|
|
101
11
|
calculatePaymentTotal(params) {
|
|
102
12
|
var _a, _b;
|
|
103
13
|
let { tickets = [], upgrades = [], fees = [], paymentMethodType, promotions = [], } = params;
|
|
@@ -173,58 +83,6 @@ class PaymentUtil {
|
|
|
173
83
|
else {
|
|
174
84
|
return false;
|
|
175
85
|
}
|
|
176
|
-
// fee.paymentMethods.includes(paymentMethodType)
|
|
177
|
-
// fee?.paymentMethods?.includes(paymentMethodType)
|
|
178
|
-
// let isPayment = paymentMethodType !== fee?.paymentMethods?.includes(paymentMethodType) || PaymentMethodTypeEnum.Check || PaymentMethodTypeEnum.None || PaymentMethodTypeEnum.CardReader ? true: false;
|
|
179
|
-
// console.log("isPayment ++++>>",isPayment)
|
|
180
|
-
// if (
|
|
181
|
-
// fee.paymentMethods &&
|
|
182
|
-
// fee.paymentMethods.includes(FeePaymentMethodEnum.CardReader) &&
|
|
183
|
-
// paymentMethodType !== PaymentMethodTypeEnum.CardReader
|
|
184
|
-
// ) {
|
|
185
|
-
// return false;
|
|
186
|
-
// }
|
|
187
|
-
// if (
|
|
188
|
-
// fee.paymentMethods &&
|
|
189
|
-
// fee.paymentMethods.includes(FeePaymentMethodEnum.CardEntry) &&
|
|
190
|
-
// paymentMethodType !== PaymentMethodTypeEnum.CardEntry
|
|
191
|
-
// ) {
|
|
192
|
-
// return false;
|
|
193
|
-
// }
|
|
194
|
-
// if (
|
|
195
|
-
// fee.paymentMethods &&
|
|
196
|
-
// fee.paymentMethods.includes(FeePaymentMethodEnum.Cash) &&
|
|
197
|
-
// paymentMethodType !== PaymentMethodTypeEnum.Cash
|
|
198
|
-
// ) {
|
|
199
|
-
// return false;
|
|
200
|
-
// }
|
|
201
|
-
// if (
|
|
202
|
-
// fee.paymentMethods &&
|
|
203
|
-
// fee.paymentMethods.includes(FeePaymentMethodEnum.Check) &&
|
|
204
|
-
// paymentMethodType !== PaymentMethodTypeEnum.Check
|
|
205
|
-
// ) {
|
|
206
|
-
// return false;
|
|
207
|
-
// }
|
|
208
|
-
// Ignore card reader fees for non card reader payemnts
|
|
209
|
-
// if (
|
|
210
|
-
// fee.filters &&
|
|
211
|
-
// fee.filters.includes(FeeFiltersEnum.CardReader) &&
|
|
212
|
-
// paymentMethodType !== PaymentMethodTypeEnum.CardReader
|
|
213
|
-
// ) {
|
|
214
|
-
// return false;
|
|
215
|
-
// }
|
|
216
|
-
// if (fee.appliedBy == FeeAppliedByEnum.Stripe && (paymentMethodType == PaymentMethodTypeEnum.Cash || paymentMethodType == PaymentMethodTypeEnum.Check)) {
|
|
217
|
-
// return false;
|
|
218
|
-
// }
|
|
219
|
-
// // Ignore card entry fees for non card entry payemnts
|
|
220
|
-
// if (
|
|
221
|
-
// fee.filters &&
|
|
222
|
-
// fee.filters.includes(FeeFiltersEnum.CardEntry) &&
|
|
223
|
-
// paymentMethodType !== PaymentMethodTypeEnum.CardEntry
|
|
224
|
-
// ) {
|
|
225
|
-
// return false;
|
|
226
|
-
// }
|
|
227
|
-
// return true;
|
|
228
86
|
});
|
|
229
87
|
let guestFees = fees.filter((fee) => fee.filters && fee.filters[0] == IFee_1.FeeFiltersEnum.GuestTicket);
|
|
230
88
|
fees = fees.filter((fee) => fee.filters && fee.filters[0] !== IFee_1.FeeFiltersEnum.GuestTicket);
|
|
@@ -255,21 +113,6 @@ class PaymentUtil {
|
|
|
255
113
|
}
|
|
256
114
|
const ticketFeesPromoCodeFlat = promotions === null || promotions === void 0 ? void 0 : promotions.filter((f) => f.appliesTo === IEventPromotion_1.EventPromotionAppliesToEnum.PerTicket &&
|
|
257
115
|
f.discountType === IEventPromotion_1.EventPromotionDiscountTypeEnum.Flat);
|
|
258
|
-
// const ticketFeesPromoCodePercent = promotions?.filter(
|
|
259
|
-
// (f) =>
|
|
260
|
-
// f.appliesTo === EventPromotionAppliesToEnum.PerTicket &&
|
|
261
|
-
// f.discountType === EventPromotionDiscountTypeEnum.Percent
|
|
262
|
-
// );
|
|
263
|
-
// const ticketFeesPromoCodeFlatPerOrder = promotions?.filter(
|
|
264
|
-
// (f) =>
|
|
265
|
-
// f.appliesTo === EventPromotionAppliesToEnum.PerOrder &&
|
|
266
|
-
// f.discountType === EventPromotionDiscountTypeEnum.Flat
|
|
267
|
-
// );
|
|
268
|
-
// const ticketFeesPromoCodePercentPerOrder = promotions?.filter(
|
|
269
|
-
// (f) =>
|
|
270
|
-
// f.appliesTo === EventPromotionAppliesToEnum.PerOrder &&
|
|
271
|
-
// f.discountType === EventPromotionDiscountTypeEnum.Percent
|
|
272
|
-
// );
|
|
273
116
|
// Fees applied
|
|
274
117
|
const ticketFeesPromotersFlat = fees.filter((f) => f.appliedTo === IFee_1.FeeAppliedToEnum.Ticket &&
|
|
275
118
|
f.appliedBy == IFee_1.FeeAppliedByEnum.Organization &&
|
|
@@ -288,9 +131,7 @@ class PaymentUtil {
|
|
|
288
131
|
f.appliedBy == IFee_1.FeeAppliedByEnum.Organization);
|
|
289
132
|
const upgradeFeesSelloutFees = fees.filter((f) => f.appliedTo === IFee_1.FeeAppliedToEnum.Upgrade &&
|
|
290
133
|
f.appliedBy == IFee_1.FeeAppliedByEnum.Sellout);
|
|
291
|
-
const selloutFees = fees.filter((f) => f.appliedBy == IFee_1.FeeAppliedByEnum.Sellout
|
|
292
|
-
// (f) => f.appliedTo === FeeAppliedToEnum.Upgrade && f.appliedBy == FeeAppliedByEnum.Sellout
|
|
293
|
-
);
|
|
134
|
+
const selloutFees = fees.filter((f) => f.appliedBy == IFee_1.FeeAppliedByEnum.Sellout);
|
|
294
135
|
// sales tax fee
|
|
295
136
|
const salesTaxFees = fees.find((f) => f.name == "Sales tax");
|
|
296
137
|
const stripeFees = fees.filter((f) => f.appliedBy == IFee_1.FeeAppliedByEnum.Stripe);
|
|
@@ -316,46 +157,6 @@ class PaymentUtil {
|
|
|
316
157
|
return value;
|
|
317
158
|
}, 0)));
|
|
318
159
|
}, 0);
|
|
319
|
-
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerTicketTotal);
|
|
320
|
-
// const discountFeePercentPerTicketTotal = tickets?.reduce((cur, ticket) => {
|
|
321
|
-
// return (
|
|
322
|
-
// cur +
|
|
323
|
-
// ticketFeesPromoCodePercent?.reduce((cur, promotion) => {
|
|
324
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
325
|
-
// return value;
|
|
326
|
-
// }, 0)
|
|
327
|
-
// );
|
|
328
|
-
// }, 0);
|
|
329
|
-
// console.log(
|
|
330
|
-
// "++++++++++++eee+>>>>>>>>>>>>",
|
|
331
|
-
// discountFeePercentPerTicketTotal
|
|
332
|
-
// );
|
|
333
|
-
// const discountFeeFlatPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
334
|
-
// return (
|
|
335
|
-
// cur +
|
|
336
|
-
// ticketFeesPromoCodeFlatPerOrder?.reduce((cur, promotion) => {
|
|
337
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
338
|
-
// return value;
|
|
339
|
-
// }, 0)
|
|
340
|
-
// );
|
|
341
|
-
// }, 0);
|
|
342
|
-
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerOrderTotal);
|
|
343
|
-
// const discountFeePercentPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
344
|
-
// return (
|
|
345
|
-
// cur +
|
|
346
|
-
// ticketFeesPromoCodePercentPerOrder?.reduce((cur, promotion) => {
|
|
347
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
348
|
-
// return value;
|
|
349
|
-
// }, 0)
|
|
350
|
-
// );
|
|
351
|
-
// }, 0);
|
|
352
|
-
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeePercentPerOrderTotal);
|
|
353
|
-
// const promoterFeeFlatPerOrderTotal = promoterOrderFees.reduce(
|
|
354
|
-
// (acc, fee: any) => {
|
|
355
|
-
// return fee.type == FeeTypeEnum.Flat ? acc + getFeeAmount(fee) : acc;
|
|
356
|
-
// },
|
|
357
|
-
// 0
|
|
358
|
-
// );
|
|
359
160
|
const discountFeeFlatPerOrderAmt = promotions === null || promotions === void 0 ? void 0 : promotions.reduce((cur, promotion) => {
|
|
360
161
|
if (promotion.discountType == IEventPromotion_1.EventPromotionDiscountTypeEnum.Flat &&
|
|
361
162
|
promotion.appliesTo === IEventPromotion_1.EventPromotionAppliesToEnum.PerOrder) {
|
|
@@ -364,7 +165,6 @@ class PaymentUtil {
|
|
|
364
165
|
}
|
|
365
166
|
return cur;
|
|
366
167
|
}, 0);
|
|
367
|
-
// console.log("Amt flat per order",discountFeeFlatPerOrderAmt)
|
|
368
168
|
const discountFeePercentPerOrderAmt = promotions === null || promotions === void 0 ? void 0 : promotions.reduce((cur, promotion) => {
|
|
369
169
|
if (promotion.discountType == IEventPromotion_1.EventPromotionDiscountTypeEnum.Percent &&
|
|
370
170
|
promotion.appliesTo === IEventPromotion_1.EventPromotionAppliesToEnum.PerOrder) {
|
|
@@ -373,14 +173,12 @@ class PaymentUtil {
|
|
|
373
173
|
}
|
|
374
174
|
return cur;
|
|
375
175
|
}, 0);
|
|
376
|
-
// console.log("Amt percent per order",discountFeePercentPerOrderAmt)
|
|
377
176
|
const discount = Math.round(discountFeeFlatPerTicketTotal || 0 + discountFeePercentPerTicketTotal || 0) || 0;
|
|
378
177
|
const discountOrder = Math.round(discountFeeFlatPerOrderAmt || 0 + discountFeePercentPerOrderAmt || 0) || 0;
|
|
379
178
|
const totalTicketAndUpgrades = Math.round(ticketTotal - discountOrder || 0) + Math.round(upgradeTotal);
|
|
380
179
|
const promoterFeeFlatPerOrderTotal = promoterOrderFees.reduce((acc, fee) => {
|
|
381
|
-
return fee.type == IFee_1.FeeTypeEnum.Flat ? acc +
|
|
180
|
+
return fee.type == IFee_1.FeeTypeEnum.Flat ? acc + getFeeAmtRangeBased(fee) : acc;
|
|
382
181
|
}, 0);
|
|
383
|
-
//
|
|
384
182
|
const promoterFeeFlatPerTicketTotal = tickets.reduce((cur, ticket) => {
|
|
385
183
|
return (cur +
|
|
386
184
|
ticketFeesPromotersFlat.reduce((cur, fee) => {
|
|
@@ -388,85 +186,6 @@ class PaymentUtil {
|
|
|
388
186
|
return value;
|
|
389
187
|
}, 0));
|
|
390
188
|
}, 0);
|
|
391
|
-
// discount
|
|
392
|
-
// const discountTickets = tickets.filter(
|
|
393
|
-
// (obj, index) =>
|
|
394
|
-
// tickets.findIndex((item) => item.ticketTypeId === obj.ticketTypeId) ===
|
|
395
|
-
// index
|
|
396
|
-
// );
|
|
397
|
-
// console.log(discountTickets, "discountTickets");
|
|
398
|
-
// const discountFeeFlatPerTicketTotal = tickets?.reduce((cur, ticket) => {
|
|
399
|
-
// return (
|
|
400
|
-
// cur +
|
|
401
|
-
// ticketFeesPromoCodeFlat?.reduce((cur, promotion) => {
|
|
402
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
403
|
-
// return value;
|
|
404
|
-
// }, 0)
|
|
405
|
-
// );
|
|
406
|
-
// }, 0);
|
|
407
|
-
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerTicketTotal);
|
|
408
|
-
// const discountFeePercentPerTicketTotal = tickets?.reduce((cur, ticket) => {
|
|
409
|
-
// return (
|
|
410
|
-
// cur +
|
|
411
|
-
// ticketFeesPromoCodePercent?.reduce((cur, promotion) => {
|
|
412
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
413
|
-
// return value;
|
|
414
|
-
// }, 0)
|
|
415
|
-
// );
|
|
416
|
-
// }, 0);
|
|
417
|
-
// console.log(
|
|
418
|
-
// "++++++++++++eee+>>>>>>>>>>>>",
|
|
419
|
-
// discountFeePercentPerTicketTotal
|
|
420
|
-
// );
|
|
421
|
-
// // const discountFeeFlatPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
422
|
-
// // return (
|
|
423
|
-
// // cur +
|
|
424
|
-
// // ticketFeesPromoCodeFlatPerOrder?.reduce((cur, promotion) => {
|
|
425
|
-
// // const value = cur + applyTicketDiscount(ticket, promotion);
|
|
426
|
-
// // return value;
|
|
427
|
-
// // }, 0)
|
|
428
|
-
// // );
|
|
429
|
-
// // }, 0);
|
|
430
|
-
// // console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerOrderTotal);
|
|
431
|
-
// const discountFeePercentPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
432
|
-
// return (
|
|
433
|
-
// cur +
|
|
434
|
-
// ticketFeesPromoCodePercentPerOrder?.reduce((cur, promotion) => {
|
|
435
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
436
|
-
// return value;
|
|
437
|
-
// }, 0)
|
|
438
|
-
// );
|
|
439
|
-
// }, 0);
|
|
440
|
-
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeePercentPerOrderTotal);
|
|
441
|
-
// // const promoterFeeFlatPerOrderTotal = promoterOrderFees.reduce(
|
|
442
|
-
// // (acc, fee: any) => {
|
|
443
|
-
// // return fee.type == FeeTypeEnum.Flat ? acc + getFeeAmount(fee) : acc;
|
|
444
|
-
// // },
|
|
445
|
-
// // 0
|
|
446
|
-
// // );
|
|
447
|
-
// const discountFeeFlatPerOrderAmt = promotions?.reduce(
|
|
448
|
-
// (cur: number,promotion: IEventPromotion) => {
|
|
449
|
-
// if (
|
|
450
|
-
// promotion.discountType == EventPromotionDiscountTypeEnum.Flat &&
|
|
451
|
-
// promotion.appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
452
|
-
// ) {
|
|
453
|
-
// const value = cur + promotion.discountValue;
|
|
454
|
-
// return value;
|
|
455
|
-
// }
|
|
456
|
-
// return cur;
|
|
457
|
-
// },
|
|
458
|
-
// 0
|
|
459
|
-
// );
|
|
460
|
-
// console.log("Amt flat per order",discountFeeFlatPerOrderAmt)
|
|
461
|
-
// const discountPercentFeesAmt = promotions.reduce((acc, promotion) => {
|
|
462
|
-
// if (promotion.discountType == EventPromotionDiscountTypeEnum.Percent &&
|
|
463
|
-
// promotion.appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
464
|
-
// ) {
|
|
465
|
-
// return acc + getFeeAmount(promotion, promoterTotal);
|
|
466
|
-
// }
|
|
467
|
-
// return acc;
|
|
468
|
-
// }, 0);
|
|
469
|
-
// console.log("order amt percent",discountPercentFeesAmt)
|
|
470
189
|
const promoterFeeFlatPerUpgradeTotal = upgrades.reduce((cur, upgrade) => {
|
|
471
190
|
return (cur +
|
|
472
191
|
upgradeFeesPromotersFees.reduce((cur, fee) => {
|
|
@@ -507,7 +226,7 @@ class PaymentUtil {
|
|
|
507
226
|
selloutFeePercentPerTicketTotal = Math.round(selloutFeePercentPerTicketTotal);
|
|
508
227
|
const promoterFeePercentPerOrder = promoterOrderFees.reduce((acc, fee) => {
|
|
509
228
|
if (fee.type == IFee_1.FeeTypeEnum.Percent) {
|
|
510
|
-
return acc +
|
|
229
|
+
return acc + getFeeAmtRangeBased(fee, totalTicketAndUpgrades);
|
|
511
230
|
}
|
|
512
231
|
return acc;
|
|
513
232
|
}, 0);
|
|
@@ -530,25 +249,13 @@ class PaymentUtil {
|
|
|
530
249
|
return value;
|
|
531
250
|
}, 0));
|
|
532
251
|
}, 0);
|
|
533
|
-
// const discount =
|
|
534
|
-
// Math.round(
|
|
535
|
-
// discountFeeFlatPerTicketTotal ||
|
|
536
|
-
// 0 + discountFeePercentPerTicketTotal ||
|
|
537
|
-
// 0 + discountFeeFlatPerOrderAmt ||
|
|
538
|
-
// 0 + discountFeePercentPerOrderTotal ||
|
|
539
|
-
// 0
|
|
540
|
-
// ) || 0;
|
|
541
|
-
// console.log(discount);
|
|
542
252
|
const orderSubtotal = Math.round(totalTicketAndUpgrades +
|
|
543
|
-
// upgradeTotal +
|
|
544
253
|
promoterFeeFlatPerTicketTotal +
|
|
545
254
|
promoterFeeFlatPerOrderTotal +
|
|
546
255
|
promoterFeePercentPerTicketTotal1 +
|
|
547
256
|
promoterFeePercentPerOrder1 +
|
|
548
257
|
ticketGuestFeeTotalForPromoter +
|
|
549
258
|
promoterFeeFlatPerUpgradeTotal);
|
|
550
|
-
// const discountValue = Math.round(orderSubtotal);
|
|
551
|
-
// console.log(discountValue, "discountValue");
|
|
552
259
|
const salesTaxAmount = salesTaxFees
|
|
553
260
|
? (orderSubtotal * salesTaxFees.value) / 100
|
|
554
261
|
: 0;
|
|
@@ -557,18 +264,10 @@ class PaymentUtil {
|
|
|
557
264
|
const selloutPercentFeesAmt = selloutFees.reduce((acc, fee) => {
|
|
558
265
|
if (fee.type == IFee_1.FeeTypeEnum.Percent && fee.appliedTo == IFee_1.FeeAppliedToEnum.Order) {
|
|
559
266
|
// return acc + getFeeAmount(fee, promoterTotal);
|
|
560
|
-
return acc +
|
|
267
|
+
return acc + getFeeAmtRangeBased(fee, totalTicketAndUpgrades);
|
|
561
268
|
}
|
|
562
269
|
return acc;
|
|
563
270
|
}, 0);
|
|
564
|
-
//
|
|
565
|
-
// const discountPercentFeesAmt = promotions.reduce((acc, promotion) => {
|
|
566
|
-
// if (promotion.discountType == EventPromotionDiscountTypeEnum.Percent) {
|
|
567
|
-
// return acc + getFeeAmount(promotion, promoterTotal);
|
|
568
|
-
// }
|
|
569
|
-
// return acc;
|
|
570
|
-
// }, 0);
|
|
571
|
-
// console.log(discountPercentFeesAmt)
|
|
572
271
|
const selloutFeeFlatPerTicketAmt = tickets.reduce((cur, ticket) => {
|
|
573
272
|
return (cur +
|
|
574
273
|
selloutFees.reduce((cur, fee) => {
|
|
@@ -585,29 +284,11 @@ class PaymentUtil {
|
|
|
585
284
|
const selloutFeeFlatPerOrderAmt = selloutFees.reduce((cur, fee) => {
|
|
586
285
|
if (fee.type === IFee_1.FeeTypeEnum.Flat &&
|
|
587
286
|
fee.appliedTo === IFee_1.FeeAppliedToEnum.Order) {
|
|
588
|
-
const value = cur + fee
|
|
287
|
+
const value = cur + getFeeAmtRangeBased(fee, totalTicketAndUpgrades);
|
|
589
288
|
return value;
|
|
590
289
|
}
|
|
591
290
|
return cur;
|
|
592
291
|
}, 0);
|
|
593
|
-
// if (fee.type === FeeTypeEnum.Percent) {
|
|
594
|
-
// return amt * (fee.value / 100);
|
|
595
|
-
// }
|
|
596
|
-
// const discountFeeFlatPerOrderAmt = promotions?.reduce(
|
|
597
|
-
// (cur: number,promotion: IEventPromotion) => {
|
|
598
|
-
// if (
|
|
599
|
-
// promotion.discountType == EventPromotionDiscountTypeEnum.Percent &&
|
|
600
|
-
// promotion.appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
601
|
-
// ) {
|
|
602
|
-
// // const value = cur + promotion.discountValue;
|
|
603
|
-
// // return value;
|
|
604
|
-
// return amt * (promotion.discountType / 100);
|
|
605
|
-
// }
|
|
606
|
-
// return cur;
|
|
607
|
-
// },
|
|
608
|
-
// 0
|
|
609
|
-
// );
|
|
610
|
-
// console.log(discountFeeFlatPerOrderAmt)
|
|
611
292
|
const selloutSeatedFeeAmt = tickets.reduce((cur, ticket) => {
|
|
612
293
|
return (cur +
|
|
613
294
|
selloutFees.reduce((cur, fee) => {
|
|
@@ -658,12 +339,9 @@ class PaymentUtil {
|
|
|
658
339
|
}
|
|
659
340
|
return 0;
|
|
660
341
|
}
|
|
661
|
-
//
|
|
662
342
|
function applyTicketDiscount(ticket, promotion) {
|
|
663
343
|
if (promotion.ticketTypeIds.includes(ticket === null || ticket === void 0 ? void 0 : ticket.ticketTypeId) ||
|
|
664
|
-
promotion.ticketTypeIds.length == 0
|
|
665
|
-
// promotions[0]?.ticketTypeIds.includes(ticket?.ticketTypeId) || promotion.ticketTypeIds.length == 0
|
|
666
|
-
) {
|
|
344
|
+
promotion.ticketTypeIds.length == 0) {
|
|
667
345
|
if ((promotion === null || promotion === void 0 ? void 0 : promotion.discountType) === IEventPromotion_1.EventPromotionDiscountTypeEnum.Flat) {
|
|
668
346
|
return promotion.discountValue;
|
|
669
347
|
}
|
|
@@ -680,7 +358,6 @@ class PaymentUtil {
|
|
|
680
358
|
const maxFee = fee.maxAppliedToPrice || Infinity;
|
|
681
359
|
if (minFee <= upgrade.price && upgrade.price <= maxFee) {
|
|
682
360
|
if (fee.type === IFee_1.FeeTypeEnum.Flat) {
|
|
683
|
-
// return upgrade.price + fee.value;
|
|
684
361
|
return fee.value;
|
|
685
362
|
}
|
|
686
363
|
if (fee.type === IFee_1.FeeTypeEnum.Percent) {
|
|
@@ -692,32 +369,14 @@ class PaymentUtil {
|
|
|
692
369
|
}
|
|
693
370
|
return 0;
|
|
694
371
|
}
|
|
695
|
-
// function getDiscount(promotion: IEventPromotion, amt = 0) {
|
|
696
|
-
// if (promotion?.discountType === EventPromotionDiscountTypeEnum.Flat) {
|
|
697
|
-
// return (amt -);
|
|
698
|
-
// }
|
|
699
|
-
// if (promotion?.discountType === EventPromotionDiscountTypeEnum.Percent) {
|
|
700
|
-
// return amt * (promotion.discountValue/ 100);
|
|
701
|
-
// }
|
|
702
|
-
// }
|
|
703
|
-
// console.log(getDiscount)
|
|
704
|
-
// return Calculated fees amount based on type
|
|
705
|
-
function getFeeAmount(fee, amt = 0) {
|
|
706
|
-
if (fee.type === IFee_1.FeeTypeEnum.Flat) {
|
|
707
|
-
return fee.value;
|
|
708
|
-
}
|
|
709
|
-
if (fee.type === IFee_1.FeeTypeEnum.Percent) {
|
|
710
|
-
return amt * (fee.value / 100);
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
372
|
let promoterFeeAmount = promoterFeeFlatPerTicketTotal +
|
|
714
373
|
promoterFeeFlatPerOrderTotal +
|
|
715
374
|
promoterFeePercentPerTicketTotal1 +
|
|
716
375
|
promoterFeePercentPerOrder1 +
|
|
717
376
|
ticketGuestFeeTotalForPromoter +
|
|
718
377
|
promoterFeeFlatPerUpgradeTotal;
|
|
719
|
-
// calculate
|
|
720
|
-
function
|
|
378
|
+
// calculate fee based on min and max
|
|
379
|
+
function getFeeAmtRangeBased(fee, amt = 0) {
|
|
721
380
|
const minFee = fee.minAppliedToPrice || 0;
|
|
722
381
|
const maxFee = fee.maxAppliedToPrice || Infinity;
|
|
723
382
|
if (amt < minFee || amt > maxFee) {
|
|
@@ -731,38 +390,6 @@ class PaymentUtil {
|
|
|
731
390
|
}
|
|
732
391
|
return 0;
|
|
733
392
|
}
|
|
734
|
-
// let total = {
|
|
735
|
-
// salesTax: Math.round(salesTaxAmount || 0),
|
|
736
|
-
// total: isDiscount && discount > 0
|
|
737
|
-
// ? Math.round(orderSubtotal - discount) +
|
|
738
|
-
// Math.round(
|
|
739
|
-
// promoterFeeAmount +
|
|
740
|
-
// (isDiscount && discount > 0 ? stripeDiscountFeeAmt : stripeFeeAmt) +
|
|
741
|
-
// selloutFeesTotal +
|
|
742
|
-
// salesTaxAmount || 0
|
|
743
|
-
// )
|
|
744
|
-
// : Math.round(preStripeTotal) + Math.round(isDiscount ? stripeDiscountFeeAmt : stripeFeeAmt) || 0,
|
|
745
|
-
// promoterFees: Math.round(promoterFeeAmount || 0),
|
|
746
|
-
// stripeFees: Math.round(isDiscount ? stripeDiscountFeeAmt : stripeFeeAmt || 0),
|
|
747
|
-
// selloutFees: Math.round(selloutFeesTotal || 0),
|
|
748
|
-
// orderSubtotal: Math.round(orderSubtotal || 0),
|
|
749
|
-
// subTotal: isDiscount && discount > 0
|
|
750
|
-
// ? Math.round(orderSubtotal - discount || 0)
|
|
751
|
-
// : Math.round(totalTicketAndUpgrades || 0),
|
|
752
|
-
// // subTotal: Math.round(totalTicketAndUpgrades || 0),
|
|
753
|
-
// totalFees: Math.round(
|
|
754
|
-
// promoterFeeAmount +
|
|
755
|
-
// stripeDiscountFeeAmt +
|
|
756
|
-
// selloutFeesTotal +
|
|
757
|
-
// salesTaxAmount || 0
|
|
758
|
-
// ),
|
|
759
|
-
// totalWithoutTaxFees: Math.round(
|
|
760
|
-
// promoterFeeAmount + stripeFeeAmt + selloutFeesTotal || 0
|
|
761
|
-
// ),
|
|
762
|
-
// guestFeeForPromoter: Math.round(ticketGuestFeeTotalForPromoter || 0),
|
|
763
|
-
// guestFeeForSellout: Math.round(ticketGuestFeeTotalForSellout || 0),
|
|
764
|
-
// discountAmount: Math.round(discount) || 0,
|
|
765
|
-
// };
|
|
766
393
|
let total = {
|
|
767
394
|
salesTax: Math.round(salesTaxAmount || 0),
|
|
768
395
|
total: Math.round(preStripeTotal) + Math.round(stripeFeeAmt) || 0,
|
|
@@ -777,14 +404,10 @@ class PaymentUtil {
|
|
|
777
404
|
guestFeeForSellout: Math.round(ticketGuestFeeTotalForSellout || 0),
|
|
778
405
|
discountAmount: Math.round(discount || discountOrder) || 0,
|
|
779
406
|
};
|
|
780
|
-
// console.log(total, "total");
|
|
781
407
|
return total;
|
|
782
408
|
}
|
|
783
409
|
calculatePaymentSubtotal(params) {
|
|
784
|
-
let { tickets = [], upgrades = [], paymentMethodType,
|
|
785
|
-
// fees
|
|
786
|
-
// promotions = [],
|
|
787
|
-
} = params;
|
|
410
|
+
let { tickets = [], upgrades = [], paymentMethodType, } = params;
|
|
788
411
|
if (paymentMethodType === PaymentMethodTypeEnum_1.PaymentMethodTypeEnum.None)
|
|
789
412
|
return 0;
|
|
790
413
|
const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price, 0); // + (ticket.price * tax/100)
|
|
@@ -792,11 +415,7 @@ class PaymentUtil {
|
|
|
792
415
|
return ticketTotal + upgradeTotal;
|
|
793
416
|
}
|
|
794
417
|
calculatePaymentSubtotalValue(params) {
|
|
795
|
-
let { tickets = [], upgrades = [],
|
|
796
|
-
// paymentMethodType,
|
|
797
|
-
// fees
|
|
798
|
-
} = params;
|
|
799
|
-
// if (paymentMethodType === PaymentMethodTypeEnum.None) return 0;
|
|
418
|
+
let { tickets = [], upgrades = [], } = params;
|
|
800
419
|
const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price, 0); // + (ticket.price * tax/100)
|
|
801
420
|
const upgradeTotal = upgrades.reduce((cur, upgrade) => cur + upgrade.price, 0); // + (upgrade.price * tax/100)
|
|
802
421
|
return ticketTotal + upgradeTotal;
|
|
@@ -812,8 +431,6 @@ class PaymentUtil {
|
|
|
812
431
|
}
|
|
813
432
|
calculateFeeWithoutTax(params) {
|
|
814
433
|
const total = this.calculatePaymentTotal(params);
|
|
815
|
-
// let subtotal = this.calculatePaymentSubtotal(params);
|
|
816
|
-
// return Math.round(total - subtotal);
|
|
817
434
|
return total;
|
|
818
435
|
}
|
|
819
436
|
calculateOrganizationFee(params) {
|
|
@@ -859,11 +476,6 @@ class PaymentUtil {
|
|
|
859
476
|
const organizationFee = this.calculateOrganizationFee(params);
|
|
860
477
|
return total - subtotal - organizationFee;
|
|
861
478
|
}
|
|
862
|
-
// calculateTaxFee(params: IPaymentCalculatorParams): number {
|
|
863
|
-
// const organizationFee = this.calculateTaxFee(params);
|
|
864
|
-
// console.log(organizationFee,'............................salesTax..')
|
|
865
|
-
// return organizationFee;
|
|
866
|
-
// }
|
|
867
479
|
calculateGuestFee(tickets, event) {
|
|
868
480
|
var _a, _b;
|
|
869
481
|
let guestTicketFees = event === null || event === void 0 ? void 0 : event.fees.filter((fee) => fee.filters && fee.filters[0] === IFee_1.FeeFiltersEnum.GuestTicket);
|