@sellout/models 0.0.339 → 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 +37 -15
- package/.dist/utils/OrderUtil.js +4 -4
- package/.dist/utils/OrderUtil.js.map +1 -1
- package/.dist/utils/PaymentUtil.js +10 -399
- package/.dist/utils/PaymentUtil.js.map +1 -1
- package/package.json +3 -3
- package/src/proto/email.proto +1 -0
- package/src/proto/order.proto +1 -1
- package/src/utils/OrderUtil.ts +4 -2
- package/src/utils/PaymentUtil.ts +9 -845
package/src/utils/PaymentUtil.ts
CHANGED
|
@@ -8,7 +8,6 @@ import IFee, {
|
|
|
8
8
|
FeeFiltersEnum,
|
|
9
9
|
FeeTypeEnum,
|
|
10
10
|
FeeAppliedByEnum,
|
|
11
|
-
// FeePaymentMethodEnum
|
|
12
11
|
} from "../interfaces/IFee";
|
|
13
12
|
import { PaymentMethodTypeEnum } from "../enums/PaymentMethodTypeEnum";
|
|
14
13
|
import IEventPromotion, {
|
|
@@ -25,116 +24,6 @@ interface IPaymentCalculatorParams {
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
class PaymentUtil {
|
|
28
|
-
// DOES NOT WORK! Work in Progress :)
|
|
29
|
-
// calculateOrderItemPrices(params: IPaymentCalculatorParams): IOrderItems {
|
|
30
|
-
|
|
31
|
-
// let {
|
|
32
|
-
// tickets = [],
|
|
33
|
-
// upgrades = [],
|
|
34
|
-
// fees = [],
|
|
35
|
-
// paymentMethodType,
|
|
36
|
-
// } = params;
|
|
37
|
-
|
|
38
|
-
// // Filter fees
|
|
39
|
-
// fees = fees.filter((fee: IFee) => {
|
|
40
|
-
// // Ignore card reader fees for non card reader payemnts
|
|
41
|
-
// if (fee.filters && fee.filters.includes(FeeFiltersEnum.CardReader) && paymentMethodType !== PaymentMethodTypeEnum.CardReader) {
|
|
42
|
-
// return false;
|
|
43
|
-
// }
|
|
44
|
-
|
|
45
|
-
// // Ignore card entry fees for non card entry payemnts
|
|
46
|
-
// if (fee.filters && fee.filters.includes(FeeFiltersEnum.CardEntry) && paymentMethodType !== PaymentMethodTypeEnum.CardEntry) {
|
|
47
|
-
// return false;
|
|
48
|
-
// }
|
|
49
|
-
|
|
50
|
-
// return true;
|
|
51
|
-
// });
|
|
52
|
-
|
|
53
|
-
// const ticketFees = fees.filter(f => f.appliedTo === FeeAppliedToEnum.Ticket)
|
|
54
|
-
// .sort(({ type }) => {
|
|
55
|
-
// if (type === FeeTypeEnum.Flat) return -1;
|
|
56
|
-
// else return 1;
|
|
57
|
-
// });
|
|
58
|
-
// const upgradeFees = fees.filter(f => f.appliedTo === FeeAppliedToEnum.Upgrade);
|
|
59
|
-
// // Orders mattes here. Flat type fees must be applied before Percent type fees
|
|
60
|
-
// const orderFees = fees.filter(f => f.appliedTo === FeeAppliedToEnum.Order)
|
|
61
|
-
// .sort(({ type }) => {
|
|
62
|
-
// if (type === FeeTypeEnum.Percent) return -1;
|
|
63
|
-
// else return 1;
|
|
64
|
-
// })
|
|
65
|
-
// .map(fee => {
|
|
66
|
-
// if(fee.type === FeeTypeEnum.Flat) {
|
|
67
|
-
// return {
|
|
68
|
-
// ...fee,
|
|
69
|
-
// value: fee.value / tickets.length,
|
|
70
|
-
// }
|
|
71
|
-
// }
|
|
72
|
-
// else return fee;
|
|
73
|
-
// });
|
|
74
|
-
|
|
75
|
-
// const reverseApplyFee = (price: number, ticket: ICreateOrderTicketParams, fee: IFee): number => {
|
|
76
|
-
// // Ignore seated fees
|
|
77
|
-
// if (fee.filters && fee.filters.includes(FeeFiltersEnum.Seated) && !ticket.seat) {
|
|
78
|
-
// return price;
|
|
79
|
-
// }
|
|
80
|
-
|
|
81
|
-
// const minFee = fee.minAppliedToPrice || 0;
|
|
82
|
-
// const maxFee = fee.maxAppliedToPrice || Infinity;
|
|
83
|
-
|
|
84
|
-
// if (minFee <= price && price <= maxFee) {
|
|
85
|
-
// console.log(fee);
|
|
86
|
-
// if (fee.type === FeeTypeEnum.Flat) {
|
|
87
|
-
// return price - fee.value;
|
|
88
|
-
// } if (fee.type === FeeTypeEnum.Percent) {
|
|
89
|
-
// return price * (1 - fee.value / 100);
|
|
90
|
-
// }
|
|
91
|
-
// }
|
|
92
|
-
|
|
93
|
-
// // if(fee.type === FeeTypeEnum.Percent) {
|
|
94
|
-
// // return price * (1 - fee.value / 100);
|
|
95
|
-
// // }
|
|
96
|
-
|
|
97
|
-
// // if(fee.type === FeeTypeEnum.Flat) {
|
|
98
|
-
// // return price - fee.value;
|
|
99
|
-
// // }
|
|
100
|
-
|
|
101
|
-
// return price;
|
|
102
|
-
// }
|
|
103
|
-
|
|
104
|
-
// function calculateTicketPrice(ticket: ICreateOrderTicketParams): number {
|
|
105
|
-
// if(!ticket.rollFees) return ticket.price;
|
|
106
|
-
|
|
107
|
-
// const allFees = [...orderFees, ...ticketFees];
|
|
108
|
-
|
|
109
|
-
// return allFees.reduce((cur, fee) => {
|
|
110
|
-
// const next = reverseApplyFee(cur, ticket, fee);
|
|
111
|
-
// return next;
|
|
112
|
-
// }, ticket.price);
|
|
113
|
-
|
|
114
|
-
// }
|
|
115
|
-
|
|
116
|
-
// tickets = tickets.map((ticket: ICreateOrderTicketParams): ICreateOrderTicketParams => {
|
|
117
|
-
// const price = Math.floor(calculateTicketPrice(ticket));
|
|
118
|
-
// console.log(`Ticket Price: `, price);
|
|
119
|
-
// return {
|
|
120
|
-
// ...ticket,
|
|
121
|
-
// price,
|
|
122
|
-
// }
|
|
123
|
-
// });
|
|
124
|
-
|
|
125
|
-
// // upgrades = upgrades.map((upgrade: ICreateOrderUpgradeParams): ICreateOrderUpgradeParams => {
|
|
126
|
-
// // return {
|
|
127
|
-
// // ...upgrade,
|
|
128
|
-
// // price: calculateUpgradePrice(upgrade),
|
|
129
|
-
// // }
|
|
130
|
-
// // });
|
|
131
|
-
|
|
132
|
-
// return {
|
|
133
|
-
// tickets,
|
|
134
|
-
// upgrades,
|
|
135
|
-
// };
|
|
136
|
-
// },
|
|
137
|
-
|
|
138
27
|
calculatePaymentTotal(params: IPaymentCalculatorParams): any {
|
|
139
28
|
let {
|
|
140
29
|
tickets = [],
|
|
@@ -239,69 +128,6 @@ class PaymentUtil {
|
|
|
239
128
|
} else {
|
|
240
129
|
return false;
|
|
241
130
|
}
|
|
242
|
-
|
|
243
|
-
// fee.paymentMethods.includes(paymentMethodType)
|
|
244
|
-
// fee?.paymentMethods?.includes(paymentMethodType)
|
|
245
|
-
|
|
246
|
-
// let isPayment = paymentMethodType !== fee?.paymentMethods?.includes(paymentMethodType) || PaymentMethodTypeEnum.Check || PaymentMethodTypeEnum.None || PaymentMethodTypeEnum.CardReader ? true: false;
|
|
247
|
-
|
|
248
|
-
// console.log("isPayment ++++>>",isPayment)
|
|
249
|
-
|
|
250
|
-
// if (
|
|
251
|
-
// fee.paymentMethods &&
|
|
252
|
-
// fee.paymentMethods.includes(FeePaymentMethodEnum.CardReader) &&
|
|
253
|
-
// paymentMethodType !== PaymentMethodTypeEnum.CardReader
|
|
254
|
-
// ) {
|
|
255
|
-
// return false;
|
|
256
|
-
// }
|
|
257
|
-
|
|
258
|
-
// if (
|
|
259
|
-
// fee.paymentMethods &&
|
|
260
|
-
// fee.paymentMethods.includes(FeePaymentMethodEnum.CardEntry) &&
|
|
261
|
-
// paymentMethodType !== PaymentMethodTypeEnum.CardEntry
|
|
262
|
-
// ) {
|
|
263
|
-
// return false;
|
|
264
|
-
// }
|
|
265
|
-
|
|
266
|
-
// if (
|
|
267
|
-
// fee.paymentMethods &&
|
|
268
|
-
// fee.paymentMethods.includes(FeePaymentMethodEnum.Cash) &&
|
|
269
|
-
// paymentMethodType !== PaymentMethodTypeEnum.Cash
|
|
270
|
-
// ) {
|
|
271
|
-
// return false;
|
|
272
|
-
// }
|
|
273
|
-
|
|
274
|
-
// if (
|
|
275
|
-
// fee.paymentMethods &&
|
|
276
|
-
// fee.paymentMethods.includes(FeePaymentMethodEnum.Check) &&
|
|
277
|
-
// paymentMethodType !== PaymentMethodTypeEnum.Check
|
|
278
|
-
// ) {
|
|
279
|
-
// return false;
|
|
280
|
-
// }
|
|
281
|
-
|
|
282
|
-
// Ignore card reader fees for non card reader payemnts
|
|
283
|
-
// if (
|
|
284
|
-
// fee.filters &&
|
|
285
|
-
// fee.filters.includes(FeeFiltersEnum.CardReader) &&
|
|
286
|
-
// paymentMethodType !== PaymentMethodTypeEnum.CardReader
|
|
287
|
-
// ) {
|
|
288
|
-
// return false;
|
|
289
|
-
// }
|
|
290
|
-
|
|
291
|
-
// if (fee.appliedBy == FeeAppliedByEnum.Stripe && (paymentMethodType == PaymentMethodTypeEnum.Cash || paymentMethodType == PaymentMethodTypeEnum.Check)) {
|
|
292
|
-
// return false;
|
|
293
|
-
// }
|
|
294
|
-
|
|
295
|
-
// // Ignore card entry fees for non card entry payemnts
|
|
296
|
-
// if (
|
|
297
|
-
// fee.filters &&
|
|
298
|
-
// fee.filters.includes(FeeFiltersEnum.CardEntry) &&
|
|
299
|
-
// paymentMethodType !== PaymentMethodTypeEnum.CardEntry
|
|
300
|
-
// ) {
|
|
301
|
-
// return false;
|
|
302
|
-
// }
|
|
303
|
-
|
|
304
|
-
// return true;
|
|
305
131
|
});
|
|
306
132
|
|
|
307
133
|
let guestFees = fees.filter(
|
|
@@ -353,26 +179,6 @@ class PaymentUtil {
|
|
|
353
179
|
f.discountType === EventPromotionDiscountTypeEnum.Flat
|
|
354
180
|
);
|
|
355
181
|
|
|
356
|
-
|
|
357
|
-
// const ticketFeesPromoCodePercent = promotions?.filter(
|
|
358
|
-
// (f) =>
|
|
359
|
-
// f.appliesTo === EventPromotionAppliesToEnum.PerTicket &&
|
|
360
|
-
// f.discountType === EventPromotionDiscountTypeEnum.Percent
|
|
361
|
-
// );
|
|
362
|
-
|
|
363
|
-
// const ticketFeesPromoCodeFlatPerOrder = promotions?.filter(
|
|
364
|
-
// (f) =>
|
|
365
|
-
// f.appliesTo === EventPromotionAppliesToEnum.PerOrder &&
|
|
366
|
-
// f.discountType === EventPromotionDiscountTypeEnum.Flat
|
|
367
|
-
// );
|
|
368
|
-
|
|
369
|
-
// const ticketFeesPromoCodePercentPerOrder = promotions?.filter(
|
|
370
|
-
// (f) =>
|
|
371
|
-
// f.appliesTo === EventPromotionAppliesToEnum.PerOrder &&
|
|
372
|
-
// f.discountType === EventPromotionDiscountTypeEnum.Percent
|
|
373
|
-
// );
|
|
374
|
-
|
|
375
|
-
|
|
376
182
|
// Fees applied
|
|
377
183
|
const ticketFeesPromotersFlat = fees.filter(
|
|
378
184
|
(f) =>
|
|
@@ -415,7 +221,6 @@ class PaymentUtil {
|
|
|
415
221
|
|
|
416
222
|
const selloutFees: any = fees.filter(
|
|
417
223
|
(f) => f.appliedBy == FeeAppliedByEnum.Sellout
|
|
418
|
-
// (f) => f.appliedTo === FeeAppliedToEnum.Upgrade && f.appliedBy == FeeAppliedByEnum.Sellout
|
|
419
224
|
);
|
|
420
225
|
// sales tax fee
|
|
421
226
|
const salesTaxFees = fees.find((f) => f.name == "Sales tax");
|
|
@@ -453,54 +258,6 @@ class PaymentUtil {
|
|
|
453
258
|
);
|
|
454
259
|
}, 0);
|
|
455
260
|
|
|
456
|
-
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerTicketTotal);
|
|
457
|
-
|
|
458
|
-
// const discountFeePercentPerTicketTotal = tickets?.reduce((cur, ticket) => {
|
|
459
|
-
// return (
|
|
460
|
-
// cur +
|
|
461
|
-
// ticketFeesPromoCodePercent?.reduce((cur, promotion) => {
|
|
462
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
463
|
-
// return value;
|
|
464
|
-
// }, 0)
|
|
465
|
-
// );
|
|
466
|
-
// }, 0);
|
|
467
|
-
|
|
468
|
-
// console.log(
|
|
469
|
-
// "++++++++++++eee+>>>>>>>>>>>>",
|
|
470
|
-
// discountFeePercentPerTicketTotal
|
|
471
|
-
// );
|
|
472
|
-
|
|
473
|
-
// const discountFeeFlatPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
474
|
-
// return (
|
|
475
|
-
// cur +
|
|
476
|
-
// ticketFeesPromoCodeFlatPerOrder?.reduce((cur, promotion) => {
|
|
477
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
478
|
-
// return value;
|
|
479
|
-
// }, 0)
|
|
480
|
-
// );
|
|
481
|
-
// }, 0);
|
|
482
|
-
|
|
483
|
-
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerOrderTotal);
|
|
484
|
-
|
|
485
|
-
// const discountFeePercentPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
486
|
-
// return (
|
|
487
|
-
// cur +
|
|
488
|
-
// ticketFeesPromoCodePercentPerOrder?.reduce((cur, promotion) => {
|
|
489
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
490
|
-
// return value;
|
|
491
|
-
// }, 0)
|
|
492
|
-
// );
|
|
493
|
-
// }, 0);
|
|
494
|
-
|
|
495
|
-
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeePercentPerOrderTotal);
|
|
496
|
-
|
|
497
|
-
// const promoterFeeFlatPerOrderTotal = promoterOrderFees.reduce(
|
|
498
|
-
// (acc, fee: any) => {
|
|
499
|
-
// return fee.type == FeeTypeEnum.Flat ? acc + getFeeAmount(fee) : acc;
|
|
500
|
-
// },
|
|
501
|
-
// 0
|
|
502
|
-
// );
|
|
503
|
-
|
|
504
261
|
const discountFeeFlatPerOrderAmt = promotions?.reduce(
|
|
505
262
|
(cur: number, promotion: IEventPromotion) => {
|
|
506
263
|
if (
|
|
@@ -515,9 +272,6 @@ class PaymentUtil {
|
|
|
515
272
|
0
|
|
516
273
|
);
|
|
517
274
|
|
|
518
|
-
// console.log("Amt flat per order",discountFeeFlatPerOrderAmt)
|
|
519
|
-
|
|
520
|
-
|
|
521
275
|
const discountFeePercentPerOrderAmt = promotions?.reduce(
|
|
522
276
|
(cur: number, promotion: IEventPromotion) => {
|
|
523
277
|
if (
|
|
@@ -532,8 +286,6 @@ class PaymentUtil {
|
|
|
532
286
|
0
|
|
533
287
|
);
|
|
534
288
|
|
|
535
|
-
// console.log("Amt percent per order",discountFeePercentPerOrderAmt)
|
|
536
|
-
|
|
537
289
|
const discount =
|
|
538
290
|
Math.round(
|
|
539
291
|
discountFeeFlatPerTicketTotal || 0 + discountFeePercentPerTicketTotal || 0) || 0;
|
|
@@ -543,17 +295,13 @@ class PaymentUtil {
|
|
|
543
295
|
|
|
544
296
|
const totalTicketAndUpgrades = Math.round(ticketTotal - discountOrder || 0) + Math.round(upgradeTotal);
|
|
545
297
|
|
|
546
|
-
|
|
547
|
-
|
|
548
298
|
const promoterFeeFlatPerOrderTotal = promoterOrderFees.reduce(
|
|
549
299
|
(acc, fee: any) => {
|
|
550
|
-
return fee.type == FeeTypeEnum.Flat ? acc +
|
|
300
|
+
return fee.type == FeeTypeEnum.Flat ? acc + getFeeAmtRangeBased(fee) : acc;
|
|
551
301
|
},
|
|
552
302
|
0
|
|
553
303
|
);
|
|
554
304
|
|
|
555
|
-
//
|
|
556
|
-
|
|
557
305
|
const promoterFeeFlatPerTicketTotal = tickets.reduce((cur, ticket) => {
|
|
558
306
|
return (
|
|
559
307
|
cur +
|
|
@@ -564,105 +312,6 @@ class PaymentUtil {
|
|
|
564
312
|
);
|
|
565
313
|
}, 0);
|
|
566
314
|
|
|
567
|
-
// discount
|
|
568
|
-
|
|
569
|
-
// const discountTickets = tickets.filter(
|
|
570
|
-
// (obj, index) =>
|
|
571
|
-
// tickets.findIndex((item) => item.ticketTypeId === obj.ticketTypeId) ===
|
|
572
|
-
// index
|
|
573
|
-
// );
|
|
574
|
-
// console.log(discountTickets, "discountTickets");
|
|
575
|
-
|
|
576
|
-
// const discountFeeFlatPerTicketTotal = tickets?.reduce((cur, ticket) => {
|
|
577
|
-
// return (
|
|
578
|
-
// cur +
|
|
579
|
-
// ticketFeesPromoCodeFlat?.reduce((cur, promotion) => {
|
|
580
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
581
|
-
// return value;
|
|
582
|
-
// }, 0)
|
|
583
|
-
// );
|
|
584
|
-
// }, 0);
|
|
585
|
-
|
|
586
|
-
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerTicketTotal);
|
|
587
|
-
|
|
588
|
-
// const discountFeePercentPerTicketTotal = tickets?.reduce((cur, ticket) => {
|
|
589
|
-
// return (
|
|
590
|
-
// cur +
|
|
591
|
-
// ticketFeesPromoCodePercent?.reduce((cur, promotion) => {
|
|
592
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
593
|
-
// return value;
|
|
594
|
-
// }, 0)
|
|
595
|
-
// );
|
|
596
|
-
// }, 0);
|
|
597
|
-
|
|
598
|
-
// console.log(
|
|
599
|
-
// "++++++++++++eee+>>>>>>>>>>>>",
|
|
600
|
-
// discountFeePercentPerTicketTotal
|
|
601
|
-
// );
|
|
602
|
-
|
|
603
|
-
// // const discountFeeFlatPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
604
|
-
// // return (
|
|
605
|
-
// // cur +
|
|
606
|
-
// // ticketFeesPromoCodeFlatPerOrder?.reduce((cur, promotion) => {
|
|
607
|
-
// // const value = cur + applyTicketDiscount(ticket, promotion);
|
|
608
|
-
// // return value;
|
|
609
|
-
// // }, 0)
|
|
610
|
-
// // );
|
|
611
|
-
// // }, 0);
|
|
612
|
-
|
|
613
|
-
// // console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerOrderTotal);
|
|
614
|
-
|
|
615
|
-
// const discountFeePercentPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
616
|
-
// return (
|
|
617
|
-
// cur +
|
|
618
|
-
// ticketFeesPromoCodePercentPerOrder?.reduce((cur, promotion) => {
|
|
619
|
-
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
620
|
-
// return value;
|
|
621
|
-
// }, 0)
|
|
622
|
-
// );
|
|
623
|
-
// }, 0);
|
|
624
|
-
|
|
625
|
-
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeePercentPerOrderTotal);
|
|
626
|
-
|
|
627
|
-
// // const promoterFeeFlatPerOrderTotal = promoterOrderFees.reduce(
|
|
628
|
-
// // (acc, fee: any) => {
|
|
629
|
-
// // return fee.type == FeeTypeEnum.Flat ? acc + getFeeAmount(fee) : acc;
|
|
630
|
-
// // },
|
|
631
|
-
// // 0
|
|
632
|
-
// // );
|
|
633
|
-
|
|
634
|
-
// const discountFeeFlatPerOrderAmt = promotions?.reduce(
|
|
635
|
-
// (cur: number,promotion: IEventPromotion) => {
|
|
636
|
-
// if (
|
|
637
|
-
// promotion.discountType == EventPromotionDiscountTypeEnum.Flat &&
|
|
638
|
-
// promotion.appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
639
|
-
// ) {
|
|
640
|
-
// const value = cur + promotion.discountValue;
|
|
641
|
-
// return value;
|
|
642
|
-
// }
|
|
643
|
-
// return cur;
|
|
644
|
-
// },
|
|
645
|
-
// 0
|
|
646
|
-
// );
|
|
647
|
-
|
|
648
|
-
// console.log("Amt flat per order",discountFeeFlatPerOrderAmt)
|
|
649
|
-
|
|
650
|
-
// const discountPercentFeesAmt = promotions.reduce((acc, promotion) => {
|
|
651
|
-
// if (promotion.discountType == EventPromotionDiscountTypeEnum.Percent &&
|
|
652
|
-
// promotion.appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
653
|
-
// ) {
|
|
654
|
-
// return acc + getFeeAmount(promotion, promoterTotal);
|
|
655
|
-
// }
|
|
656
|
-
// return acc;
|
|
657
|
-
// }, 0);
|
|
658
|
-
|
|
659
|
-
// console.log("order amt percent",discountPercentFeesAmt)
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
315
|
const promoterFeeFlatPerUpgradeTotal = upgrades.reduce((cur, upgrade) => {
|
|
667
316
|
return (
|
|
668
317
|
cur +
|
|
@@ -723,7 +372,7 @@ class PaymentUtil {
|
|
|
723
372
|
|
|
724
373
|
const promoterFeePercentPerOrder = promoterOrderFees.reduce((acc, fee) => {
|
|
725
374
|
if (fee.type == FeeTypeEnum.Percent) {
|
|
726
|
-
return acc +
|
|
375
|
+
return acc + getFeeAmtRangeBased(fee, totalTicketAndUpgrades);
|
|
727
376
|
}
|
|
728
377
|
return acc;
|
|
729
378
|
}, 0);
|
|
@@ -756,19 +405,8 @@ class PaymentUtil {
|
|
|
756
405
|
);
|
|
757
406
|
}, 0);
|
|
758
407
|
|
|
759
|
-
// const discount =
|
|
760
|
-
// Math.round(
|
|
761
|
-
// discountFeeFlatPerTicketTotal ||
|
|
762
|
-
// 0 + discountFeePercentPerTicketTotal ||
|
|
763
|
-
// 0 + discountFeeFlatPerOrderAmt ||
|
|
764
|
-
// 0 + discountFeePercentPerOrderTotal ||
|
|
765
|
-
// 0
|
|
766
|
-
// ) || 0;
|
|
767
|
-
// console.log(discount);
|
|
768
|
-
|
|
769
408
|
const orderSubtotal = Math.round(
|
|
770
409
|
totalTicketAndUpgrades +
|
|
771
|
-
// upgradeTotal +
|
|
772
410
|
promoterFeeFlatPerTicketTotal +
|
|
773
411
|
promoterFeeFlatPerOrderTotal +
|
|
774
412
|
promoterFeePercentPerTicketTotal1 +
|
|
@@ -777,13 +415,6 @@ class PaymentUtil {
|
|
|
777
415
|
promoterFeeFlatPerUpgradeTotal
|
|
778
416
|
);
|
|
779
417
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
// const discountValue = Math.round(orderSubtotal);
|
|
785
|
-
// console.log(discountValue, "discountValue");
|
|
786
|
-
|
|
787
418
|
const salesTaxAmount = salesTaxFees
|
|
788
419
|
? (orderSubtotal * salesTaxFees.value) / 100
|
|
789
420
|
: 0;
|
|
@@ -794,22 +425,11 @@ class PaymentUtil {
|
|
|
794
425
|
const selloutPercentFeesAmt = selloutFees.reduce((acc, fee) => {
|
|
795
426
|
if (fee.type == FeeTypeEnum.Percent && fee.appliedTo == FeeAppliedToEnum.Order) {
|
|
796
427
|
// return acc + getFeeAmount(fee, promoterTotal);
|
|
797
|
-
return acc +
|
|
428
|
+
return acc + getFeeAmtRangeBased(fee, totalTicketAndUpgrades);
|
|
798
429
|
}
|
|
799
430
|
return acc;
|
|
800
431
|
}, 0);
|
|
801
432
|
|
|
802
|
-
//
|
|
803
|
-
|
|
804
|
-
// const discountPercentFeesAmt = promotions.reduce((acc, promotion) => {
|
|
805
|
-
// if (promotion.discountType == EventPromotionDiscountTypeEnum.Percent) {
|
|
806
|
-
// return acc + getFeeAmount(promotion, promoterTotal);
|
|
807
|
-
// }
|
|
808
|
-
// return acc;
|
|
809
|
-
// }, 0);
|
|
810
|
-
|
|
811
|
-
// console.log(discountPercentFeesAmt)
|
|
812
|
-
|
|
813
433
|
const selloutFeeFlatPerTicketAmt = tickets.reduce(
|
|
814
434
|
(cur: number, ticket: any) => {
|
|
815
435
|
return (
|
|
@@ -836,7 +456,7 @@ class PaymentUtil {
|
|
|
836
456
|
fee.type === FeeTypeEnum.Flat &&
|
|
837
457
|
fee.appliedTo === FeeAppliedToEnum.Order
|
|
838
458
|
) {
|
|
839
|
-
const value = cur + fee
|
|
459
|
+
const value = cur + getFeeAmtRangeBased(fee, totalTicketAndUpgrades);
|
|
840
460
|
return value;
|
|
841
461
|
}
|
|
842
462
|
return cur;
|
|
@@ -844,29 +464,6 @@ class PaymentUtil {
|
|
|
844
464
|
0
|
|
845
465
|
);
|
|
846
466
|
|
|
847
|
-
// if (fee.type === FeeTypeEnum.Percent) {
|
|
848
|
-
// return amt * (fee.value / 100);
|
|
849
|
-
// }
|
|
850
|
-
// const discountFeeFlatPerOrderAmt = promotions?.reduce(
|
|
851
|
-
// (cur: number,promotion: IEventPromotion) => {
|
|
852
|
-
// if (
|
|
853
|
-
// promotion.discountType == EventPromotionDiscountTypeEnum.Percent &&
|
|
854
|
-
// promotion.appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
855
|
-
// ) {
|
|
856
|
-
// // const value = cur + promotion.discountValue;
|
|
857
|
-
// // return value;
|
|
858
|
-
// return amt * (promotion.discountType / 100);
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
// }
|
|
862
|
-
// return cur;
|
|
863
|
-
// },
|
|
864
|
-
// 0
|
|
865
|
-
// );
|
|
866
|
-
|
|
867
|
-
// console.log(discountFeeFlatPerOrderAmt)
|
|
868
|
-
|
|
869
|
-
|
|
870
467
|
const selloutSeatedFeeAmt = tickets.reduce((cur: number, ticket: any) => {
|
|
871
468
|
return (
|
|
872
469
|
cur +
|
|
@@ -938,7 +535,7 @@ class PaymentUtil {
|
|
|
938
535
|
|
|
939
536
|
return 0;
|
|
940
537
|
}
|
|
941
|
-
|
|
538
|
+
|
|
942
539
|
function applyTicketDiscount(
|
|
943
540
|
ticket: ICreateOrderTicketParams,
|
|
944
541
|
promotion: IEventPromotion
|
|
@@ -946,7 +543,6 @@ class PaymentUtil {
|
|
|
946
543
|
if (
|
|
947
544
|
promotion.ticketTypeIds.includes(ticket?.ticketTypeId) ||
|
|
948
545
|
promotion.ticketTypeIds.length == 0
|
|
949
|
-
// promotions[0]?.ticketTypeIds.includes(ticket?.ticketTypeId) || promotion.ticketTypeIds.length == 0
|
|
950
546
|
) {
|
|
951
547
|
if (promotion?.discountType === EventPromotionDiscountTypeEnum.Flat) {
|
|
952
548
|
return promotion.discountValue;
|
|
@@ -968,7 +564,6 @@ class PaymentUtil {
|
|
|
968
564
|
|
|
969
565
|
if (minFee <= upgrade.price && upgrade.price <= maxFee) {
|
|
970
566
|
if (fee.type === FeeTypeEnum.Flat) {
|
|
971
|
-
// return upgrade.price + fee.value;
|
|
972
567
|
return fee.value;
|
|
973
568
|
}
|
|
974
569
|
if (fee.type === FeeTypeEnum.Percent) {
|
|
@@ -980,27 +575,7 @@ class PaymentUtil {
|
|
|
980
575
|
|
|
981
576
|
return 0;
|
|
982
577
|
}
|
|
983
|
-
|
|
984
|
-
// function getDiscount(promotion: IEventPromotion, amt = 0) {
|
|
985
|
-
// if (promotion?.discountType === EventPromotionDiscountTypeEnum.Flat) {
|
|
986
|
-
// return (amt -);
|
|
987
|
-
// }
|
|
988
|
-
// if (promotion?.discountType === EventPromotionDiscountTypeEnum.Percent) {
|
|
989
|
-
// return amt * (promotion.discountValue/ 100);
|
|
990
|
-
// }
|
|
991
|
-
// }
|
|
992
|
-
|
|
993
|
-
// console.log(getDiscount)
|
|
994
|
-
|
|
995
|
-
// return Calculated fees amount based on type
|
|
996
|
-
function getFeeAmount(fee, amt = 0) {
|
|
997
|
-
if (fee.type === FeeTypeEnum.Flat) {
|
|
998
|
-
return fee.value;
|
|
999
|
-
}
|
|
1000
|
-
if (fee.type === FeeTypeEnum.Percent) {
|
|
1001
|
-
return amt * (fee.value / 100);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
578
|
+
|
|
1004
579
|
let promoterFeeAmount =
|
|
1005
580
|
promoterFeeFlatPerTicketTotal +
|
|
1006
581
|
promoterFeeFlatPerOrderTotal +
|
|
@@ -1009,8 +584,8 @@ class PaymentUtil {
|
|
|
1009
584
|
ticketGuestFeeTotalForPromoter +
|
|
1010
585
|
promoterFeeFlatPerUpgradeTotal;
|
|
1011
586
|
|
|
1012
|
-
// calculate
|
|
1013
|
-
function
|
|
587
|
+
// calculate fee based on min and max
|
|
588
|
+
function getFeeAmtRangeBased(fee, amt = 0) {
|
|
1014
589
|
const minFee = fee.minAppliedToPrice || 0;
|
|
1015
590
|
const maxFee = fee.maxAppliedToPrice || Infinity;
|
|
1016
591
|
|
|
@@ -1028,41 +603,7 @@ class PaymentUtil {
|
|
|
1028
603
|
|
|
1029
604
|
return 0;
|
|
1030
605
|
}
|
|
1031
|
-
|
|
1032
|
-
// let total = {
|
|
1033
|
-
// salesTax: Math.round(salesTaxAmount || 0),
|
|
1034
|
-
// total: isDiscount && discount > 0
|
|
1035
|
-
// ? Math.round(orderSubtotal - discount) +
|
|
1036
|
-
// Math.round(
|
|
1037
|
-
// promoterFeeAmount +
|
|
1038
|
-
// (isDiscount && discount > 0 ? stripeDiscountFeeAmt : stripeFeeAmt) +
|
|
1039
|
-
// selloutFeesTotal +
|
|
1040
|
-
// salesTaxAmount || 0
|
|
1041
|
-
// )
|
|
1042
|
-
// : Math.round(preStripeTotal) + Math.round(isDiscount ? stripeDiscountFeeAmt : stripeFeeAmt) || 0,
|
|
1043
|
-
// promoterFees: Math.round(promoterFeeAmount || 0),
|
|
1044
|
-
// stripeFees: Math.round(isDiscount ? stripeDiscountFeeAmt : stripeFeeAmt || 0),
|
|
1045
|
-
// selloutFees: Math.round(selloutFeesTotal || 0),
|
|
1046
|
-
// orderSubtotal: Math.round(orderSubtotal || 0),
|
|
1047
|
-
// subTotal: isDiscount && discount > 0
|
|
1048
|
-
// ? Math.round(orderSubtotal - discount || 0)
|
|
1049
|
-
// : Math.round(totalTicketAndUpgrades || 0),
|
|
1050
|
-
// // subTotal: Math.round(totalTicketAndUpgrades || 0),
|
|
1051
|
-
|
|
1052
|
-
// totalFees: Math.round(
|
|
1053
|
-
// promoterFeeAmount +
|
|
1054
|
-
// stripeDiscountFeeAmt +
|
|
1055
|
-
// selloutFeesTotal +
|
|
1056
|
-
// salesTaxAmount || 0
|
|
1057
|
-
// ),
|
|
1058
|
-
// totalWithoutTaxFees: Math.round(
|
|
1059
|
-
// promoterFeeAmount + stripeFeeAmt + selloutFeesTotal || 0
|
|
1060
|
-
// ),
|
|
1061
|
-
// guestFeeForPromoter: Math.round(ticketGuestFeeTotalForPromoter || 0),
|
|
1062
|
-
// guestFeeForSellout: Math.round(ticketGuestFeeTotalForSellout || 0),
|
|
1063
|
-
// discountAmount: Math.round(discount) || 0,
|
|
1064
|
-
// };
|
|
1065
|
-
|
|
606
|
+
|
|
1066
607
|
let total = {
|
|
1067
608
|
salesTax: Math.round(salesTaxAmount || 0),
|
|
1068
609
|
total: Math.round(preStripeTotal) + Math.round(stripeFeeAmt) || 0,
|
|
@@ -1078,19 +619,14 @@ class PaymentUtil {
|
|
|
1078
619
|
discountAmount: Math.round(discount || discountOrder) || 0,
|
|
1079
620
|
|
|
1080
621
|
}
|
|
1081
|
-
// console.log(total, "total");
|
|
1082
622
|
return total;
|
|
1083
623
|
}
|
|
1084
624
|
|
|
1085
|
-
|
|
1086
625
|
calculatePaymentSubtotal(params: IPaymentCalculatorParams): number {
|
|
1087
626
|
let {
|
|
1088
627
|
tickets = [],
|
|
1089
628
|
upgrades = [],
|
|
1090
629
|
paymentMethodType,
|
|
1091
|
-
// fees
|
|
1092
|
-
// promotions = [],
|
|
1093
|
-
|
|
1094
630
|
} = params;
|
|
1095
631
|
|
|
1096
632
|
if (paymentMethodType === PaymentMethodTypeEnum.None) return 0;
|
|
@@ -1106,12 +642,8 @@ class PaymentUtil {
|
|
|
1106
642
|
let {
|
|
1107
643
|
tickets = [],
|
|
1108
644
|
upgrades = [],
|
|
1109
|
-
// paymentMethodType,
|
|
1110
|
-
// fees
|
|
1111
645
|
} = params;
|
|
1112
646
|
|
|
1113
|
-
// if (paymentMethodType === PaymentMethodTypeEnum.None) return 0;
|
|
1114
|
-
|
|
1115
647
|
const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price, 0); // + (ticket.price * tax/100)
|
|
1116
648
|
const upgradeTotal = upgrades.reduce(
|
|
1117
649
|
(cur, upgrade) => cur + upgrade.price,
|
|
@@ -1133,8 +665,6 @@ class PaymentUtil {
|
|
|
1133
665
|
|
|
1134
666
|
calculateFeeWithoutTax(params: IPaymentCalculatorParams): any {
|
|
1135
667
|
const total = this.calculatePaymentTotal(params);
|
|
1136
|
-
// let subtotal = this.calculatePaymentSubtotal(params);
|
|
1137
|
-
// return Math.round(total - subtotal);
|
|
1138
668
|
return total;
|
|
1139
669
|
}
|
|
1140
670
|
calculateOrganizationFee(params: IPaymentCalculatorParams): number {
|
|
@@ -1185,12 +715,6 @@ class PaymentUtil {
|
|
|
1185
715
|
const organizationFee = this.calculateOrganizationFee(params);
|
|
1186
716
|
return total - subtotal - organizationFee;
|
|
1187
717
|
}
|
|
1188
|
-
// calculateTaxFee(params: IPaymentCalculatorParams): number {
|
|
1189
|
-
// const organizationFee = this.calculateTaxFee(params);
|
|
1190
|
-
// console.log(organizationFee,'............................salesTax..')
|
|
1191
|
-
// return organizationFee;
|
|
1192
|
-
// }
|
|
1193
|
-
|
|
1194
718
|
calculateGuestFee(tickets: any, event: any): number {
|
|
1195
719
|
let guestTicketFees = event?.fees.filter(
|
|
1196
720
|
(fee: IFee) =>
|
|
@@ -1211,366 +735,6 @@ class PaymentUtil {
|
|
|
1211
735
|
? guestFees + (guestFees * stripeFeesValue) / 100
|
|
1212
736
|
: 0;
|
|
1213
737
|
}
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
// CalculatePromoterFeeList = (params: {
|
|
1217
|
-
// tickets;
|
|
1218
|
-
// fees;
|
|
1219
|
-
// promotions;
|
|
1220
|
-
// upgrades;
|
|
1221
|
-
// discountCode;
|
|
1222
|
-
// }) => {
|
|
1223
|
-
|
|
1224
|
-
// let tickets: any = params.tickets;
|
|
1225
|
-
// let upgrades: any = params.upgrades;
|
|
1226
|
-
// let promoterFees: any = [];
|
|
1227
|
-
|
|
1228
|
-
// params.fees.forEach((item) => {
|
|
1229
|
-
// const newItem = { ...item, amount: 0 };
|
|
1230
|
-
// if (newItem.appliedBy === FeeAppliedByEnum.Organization) {
|
|
1231
|
-
// if (newItem.name === "Sales tax") {
|
|
1232
|
-
// } else {
|
|
1233
|
-
// promoterFees.push(newItem);
|
|
1234
|
-
// }
|
|
1235
|
-
// }
|
|
1236
|
-
// });
|
|
1237
|
-
|
|
1238
|
-
// const promotionsCode = params?.promotions?.filter((promo) => {
|
|
1239
|
-
// const promoCode = promo?.code?.toLowerCase();
|
|
1240
|
-
// const discountCode =
|
|
1241
|
-
// typeof params?.discountCode === "string"
|
|
1242
|
-
// ? params.discountCode.toLowerCase()
|
|
1243
|
-
// : "";
|
|
1244
|
-
// return promoCode === discountCode;
|
|
1245
|
-
// });
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
// if (promotionsCode.length != 0) {
|
|
1249
|
-
// tickets = tickets.map((ticket) => {
|
|
1250
|
-
// if (
|
|
1251
|
-
// promotionsCode &&
|
|
1252
|
-
// promotionsCode[0].discountType ===
|
|
1253
|
-
// EventPromotionDiscountTypeEnum.Flat &&
|
|
1254
|
-
// promotionsCode[0].appliesTo === EventPromotionAppliesToEnum.PerTicket
|
|
1255
|
-
// ) {
|
|
1256
|
-
// if (promotionsCode[0]?.ticketTypeIds.length == 0) {
|
|
1257
|
-
// const discountValue = Number(promotionsCode[0].discountValue);
|
|
1258
|
-
// const originalPrice = ticket.price;
|
|
1259
|
-
// const discountedPrice = originalPrice - discountValue;
|
|
1260
|
-
// return {
|
|
1261
|
-
// ...ticket,
|
|
1262
|
-
// price: discountedPrice,
|
|
1263
|
-
// };
|
|
1264
|
-
// } else {
|
|
1265
|
-
// if (
|
|
1266
|
-
// promotionsCode &&
|
|
1267
|
-
// promotionsCode[0].ticketTypeIds.includes(ticket?.ticketTypeId)
|
|
1268
|
-
// ) {
|
|
1269
|
-
// const discountValue = Number(promotionsCode[0].discountValue);
|
|
1270
|
-
// const originalPrice = ticket.price;
|
|
1271
|
-
// const discountedPrice = originalPrice - discountValue;
|
|
1272
|
-
// return {
|
|
1273
|
-
// ...ticket,
|
|
1274
|
-
// price: discountedPrice,
|
|
1275
|
-
// };
|
|
1276
|
-
// } else {
|
|
1277
|
-
// const originalPrice = ticket.price;
|
|
1278
|
-
// return {
|
|
1279
|
-
// ...ticket,
|
|
1280
|
-
// price: originalPrice,
|
|
1281
|
-
// };
|
|
1282
|
-
// }
|
|
1283
|
-
// }
|
|
1284
|
-
// }
|
|
1285
|
-
|
|
1286
|
-
// if (
|
|
1287
|
-
// promotionsCode &&
|
|
1288
|
-
// promotionsCode[0].discountType ===
|
|
1289
|
-
// EventPromotionDiscountTypeEnum.Percent &&
|
|
1290
|
-
// promotionsCode[0].appliesTo === EventPromotionAppliesToEnum.PerTicket
|
|
1291
|
-
// ) {
|
|
1292
|
-
// if (promotionsCode[0]?.ticketTypeIds.length == 0) {
|
|
1293
|
-
// const discountValue = Number(promotionsCode[0].discountValue);
|
|
1294
|
-
// const percentTicketValue =
|
|
1295
|
-
// (ticket.origionalPrice * discountValue) / 100;
|
|
1296
|
-
// const originalPrice = ticket.price;
|
|
1297
|
-
// const discountPercentPrice = originalPrice - percentTicketValue;
|
|
1298
|
-
|
|
1299
|
-
// return {
|
|
1300
|
-
// ...ticket,
|
|
1301
|
-
// price: discountPercentPrice,
|
|
1302
|
-
// };
|
|
1303
|
-
// } else {
|
|
1304
|
-
// if (
|
|
1305
|
-
// promotionsCode[0]?.ticketTypeIds.includes(ticket?.ticketTypeId)
|
|
1306
|
-
// ) {
|
|
1307
|
-
// const discountValue = Number(promotionsCode[0].discountValue);
|
|
1308
|
-
// const percentTicketValue =
|
|
1309
|
-
// (ticket.origionalPrice * discountValue) / 100;
|
|
1310
|
-
// const originalPrice = ticket.price;
|
|
1311
|
-
// const discountPercentPrice = originalPrice - percentTicketValue;
|
|
1312
|
-
|
|
1313
|
-
// return {
|
|
1314
|
-
// ...ticket,
|
|
1315
|
-
// price: discountPercentPrice,
|
|
1316
|
-
// };
|
|
1317
|
-
// } else {
|
|
1318
|
-
// const originalPrice = ticket.price;
|
|
1319
|
-
// return {
|
|
1320
|
-
// ...ticket,
|
|
1321
|
-
// price: originalPrice,
|
|
1322
|
-
// };
|
|
1323
|
-
// }
|
|
1324
|
-
// }
|
|
1325
|
-
// }
|
|
1326
|
-
// return ticket;
|
|
1327
|
-
// });
|
|
1328
|
-
// }
|
|
1329
|
-
|
|
1330
|
-
// const discountFeeFlatPerOrderAmt = promotionsCode?.reduce(
|
|
1331
|
-
// (cur: number, promotion: any) => {
|
|
1332
|
-
// if (
|
|
1333
|
-
// promotionsCode?.length &&
|
|
1334
|
-
// promotionsCode[0].discountType ===
|
|
1335
|
-
// EventPromotionDiscountTypeEnum.Flat &&
|
|
1336
|
-
// promotionsCode[0].appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
1337
|
-
// ) {
|
|
1338
|
-
// const value = cur + promotion.discountValue;
|
|
1339
|
-
// return value;
|
|
1340
|
-
// }
|
|
1341
|
-
// return cur;
|
|
1342
|
-
// },
|
|
1343
|
-
// 0
|
|
1344
|
-
// );
|
|
1345
|
-
// const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price, 0);
|
|
1346
|
-
// const upgradeTotal = upgrades.reduce(
|
|
1347
|
-
// (cur, upgrade) => cur + upgrade.price,
|
|
1348
|
-
// 0
|
|
1349
|
-
// );
|
|
1350
|
-
// const totalTicketUpgrade = ticketTotal + upgradeTotal;
|
|
1351
|
-
|
|
1352
|
-
// const discountFeePercentPerOrderAmt = promotionsCode?.reduce(
|
|
1353
|
-
// (cur: number, promotion: any) => {
|
|
1354
|
-
// if (
|
|
1355
|
-
// promotionsCode?.length &&
|
|
1356
|
-
// promotionsCode[0].discountType ===
|
|
1357
|
-
// EventPromotionDiscountTypeEnum.Percent &&
|
|
1358
|
-
// promotionsCode[0].appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
1359
|
-
// ) {
|
|
1360
|
-
// const value =
|
|
1361
|
-
// cur + (totalTicketUpgrade * promotion.discountValue) / 100;
|
|
1362
|
-
// return value;
|
|
1363
|
-
// }
|
|
1364
|
-
// return cur;
|
|
1365
|
-
// },
|
|
1366
|
-
// 0
|
|
1367
|
-
// );
|
|
1368
|
-
|
|
1369
|
-
// const discountOrder =
|
|
1370
|
-
// Math.round(
|
|
1371
|
-
// discountFeeFlatPerOrderAmt || 0 + discountFeePercentPerOrderAmt || 0
|
|
1372
|
-
// ) || 0;
|
|
1373
|
-
|
|
1374
|
-
// let newSubtotal = this.calculatePaymentSubtotalValue({
|
|
1375
|
-
// tickets: tickets,
|
|
1376
|
-
// upgrades: upgrades,
|
|
1377
|
-
// });
|
|
1378
|
-
|
|
1379
|
-
// let subtotal = newSubtotal - discountOrder;
|
|
1380
|
-
|
|
1381
|
-
// const ticketFeesPromotersPercent = params.fees.filter(
|
|
1382
|
-
// (f) =>
|
|
1383
|
-
// f.appliedTo === FeeAppliedToEnum.Ticket &&
|
|
1384
|
-
// f.appliedBy == FeeAppliedByEnum.Organization &&
|
|
1385
|
-
// f.type === FeeTypeEnum.Percent
|
|
1386
|
-
// );
|
|
1387
|
-
|
|
1388
|
-
// const ticketFeesPromotersFlat = params.fees.filter(
|
|
1389
|
-
// (f) =>
|
|
1390
|
-
// f.appliedTo === FeeAppliedToEnum.Ticket &&
|
|
1391
|
-
// f.appliedBy == FeeAppliedByEnum.Organization &&
|
|
1392
|
-
// f.type === FeeTypeEnum.Flat
|
|
1393
|
-
// );
|
|
1394
|
-
|
|
1395
|
-
// function applyTicketFee(
|
|
1396
|
-
// ticket: ICreateOrderTicketParams,
|
|
1397
|
-
// fee: IFee
|
|
1398
|
-
// ): number {
|
|
1399
|
-
// // Ignore seated fees if not seated
|
|
1400
|
-
// if (
|
|
1401
|
-
// fee.filters &&
|
|
1402
|
-
// fee.filters.includes(FeeFiltersEnum.Seated) &&
|
|
1403
|
-
// !ticket.seat
|
|
1404
|
-
// ) {
|
|
1405
|
-
// return 0;
|
|
1406
|
-
// }
|
|
1407
|
-
|
|
1408
|
-
// const minFee = fee.minAppliedToPrice || 0;
|
|
1409
|
-
// const maxFee = fee.maxAppliedToPrice || Infinity;
|
|
1410
|
-
// if (minFee <= ticket.price && ticket.price <= maxFee) {
|
|
1411
|
-
// if (fee.type === FeeTypeEnum.Flat) {
|
|
1412
|
-
// return fee.value;
|
|
1413
|
-
// }
|
|
1414
|
-
// if (fee.type === FeeTypeEnum.Percent) {
|
|
1415
|
-
// return (ticket.price * fee.value) / 100;
|
|
1416
|
-
// }
|
|
1417
|
-
// } else {
|
|
1418
|
-
// return 0;
|
|
1419
|
-
// }
|
|
1420
|
-
// return 0;
|
|
1421
|
-
// }
|
|
1422
|
-
|
|
1423
|
-
// function getFeeAmount(fee, amt = 0) {
|
|
1424
|
-
// if (fee.type === FeeTypeEnum.Flat) {
|
|
1425
|
-
// return fee.value;
|
|
1426
|
-
// }
|
|
1427
|
-
// if (fee.type === FeeTypeEnum.Percent) {
|
|
1428
|
-
// return amt * (fee.value / 100);
|
|
1429
|
-
// }
|
|
1430
|
-
// }
|
|
1431
|
-
|
|
1432
|
-
// const promoterOrderFees = params.fees
|
|
1433
|
-
// .filter(
|
|
1434
|
-
// (f) =>
|
|
1435
|
-
// f.appliedTo === FeeAppliedToEnum.Order &&
|
|
1436
|
-
// f.name != "Sales tax" &&
|
|
1437
|
-
// f.appliedBy == FeeAppliedByEnum.Organization
|
|
1438
|
-
// )
|
|
1439
|
-
// .sort(({ type }) => {
|
|
1440
|
-
// if (type === "Flat") return -1;
|
|
1441
|
-
// else return 1;
|
|
1442
|
-
// });
|
|
1443
|
-
|
|
1444
|
-
// let promoCodeAdd = 0;
|
|
1445
|
-
// let promoterFeePercentPerOrder11 = 0;
|
|
1446
|
-
|
|
1447
|
-
// promoterFees.map((promo) => {
|
|
1448
|
-
// if (
|
|
1449
|
-
// promo.type === FeeTypeEnum.Percent &&
|
|
1450
|
-
// promo.appliedTo === FeeAppliedToEnum.Ticket
|
|
1451
|
-
// ) {
|
|
1452
|
-
// const promoterFeePercentPerTicketTotal = tickets.reduce(
|
|
1453
|
-
// (cur, ticket) => {
|
|
1454
|
-
// let mainPrice = ticket.price;
|
|
1455
|
-
// return (
|
|
1456
|
-
// cur +
|
|
1457
|
-
// ticketFeesPromotersPercent.reduce((cur, fee) => {
|
|
1458
|
-
// const value = cur + applyTicketFee(ticket, fee);
|
|
1459
|
-
// ticket.price = mainPrice;
|
|
1460
|
-
// return value;
|
|
1461
|
-
// }, 0)
|
|
1462
|
-
// );
|
|
1463
|
-
// },
|
|
1464
|
-
// 0
|
|
1465
|
-
// );
|
|
1466
|
-
// promo.amount = promoterFeePercentPerTicketTotal;
|
|
1467
|
-
// } else if (
|
|
1468
|
-
// promo.type === FeeTypeEnum.Percent &&
|
|
1469
|
-
// promo.appliedTo === FeeAppliedToEnum.Order
|
|
1470
|
-
// ) {
|
|
1471
|
-
// promoterFeePercentPerOrder11 = promoterOrderFees.reduce((acc, fee) => {
|
|
1472
|
-
// if (fee.type == FeeTypeEnum.Percent) {
|
|
1473
|
-
// return acc + getFeeAmount(fee, subtotal);
|
|
1474
|
-
// }
|
|
1475
|
-
// return acc;
|
|
1476
|
-
// }, 0);
|
|
1477
|
-
|
|
1478
|
-
// promo.amount = Math.round(promoterFeePercentPerOrder11);
|
|
1479
|
-
// } else {
|
|
1480
|
-
// if (
|
|
1481
|
-
// promo.appliedTo == FeeAppliedToEnum.Ticket &&
|
|
1482
|
-
// promo.type === FeeTypeEnum.Flat
|
|
1483
|
-
// ) {
|
|
1484
|
-
// let promoterFeeFlatPerTicketTotal = tickets.reduce((cur, ticket) => {
|
|
1485
|
-
// let mainPrice = ticket.price;
|
|
1486
|
-
// ticket.price = ticket.origionalPrice;
|
|
1487
|
-
|
|
1488
|
-
// return (
|
|
1489
|
-
// cur +
|
|
1490
|
-
// ticketFeesPromotersFlat.reduce((cur, fee) => {
|
|
1491
|
-
// const value = cur + applyTicketFee(ticket, fee);
|
|
1492
|
-
// ticket.price = mainPrice;
|
|
1493
|
-
// return value;
|
|
1494
|
-
// }, 0)
|
|
1495
|
-
// );
|
|
1496
|
-
// }, 0);
|
|
1497
|
-
// promo.amount = promoterFeeFlatPerTicketTotal;
|
|
1498
|
-
// } else if (
|
|
1499
|
-
// promo.appliedTo == FeeAppliedToEnum.Order &&
|
|
1500
|
-
// promo.type === FeeTypeEnum.Flat
|
|
1501
|
-
// ) {
|
|
1502
|
-
// let promoterFeeFlatPerOrder = 0;
|
|
1503
|
-
// promoterFeeFlatPerOrder = promoterOrderFees.reduce((acc, fee) => {
|
|
1504
|
-
// if (fee.type == FeeTypeEnum.Flat) {
|
|
1505
|
-
// return acc + getFeeAmount(fee, subtotal);
|
|
1506
|
-
// }
|
|
1507
|
-
// return acc;
|
|
1508
|
-
// }, 0);
|
|
1509
|
-
|
|
1510
|
-
// promo.amount = promoterFeeFlatPerOrder;
|
|
1511
|
-
// }
|
|
1512
|
-
// }
|
|
1513
|
-
// promoCodeAdd += Math.round(promo.amount * 100) / 100 || 0;
|
|
1514
|
-
// });
|
|
1515
|
-
|
|
1516
|
-
// const applyUpgradeFee = (upgrade, fee): number => {
|
|
1517
|
-
// const minFee = fee.minAppliedToPrice || 0;
|
|
1518
|
-
// const maxFee = fee.maxAppliedToPrice || Infinity;
|
|
1519
|
-
|
|
1520
|
-
// if (minFee <= upgrade.price && upgrade.price <= maxFee) {
|
|
1521
|
-
// if (fee.type === FeeTypeEnum.Flat) {
|
|
1522
|
-
// return fee.value;
|
|
1523
|
-
// }
|
|
1524
|
-
// if (fee.type === FeeTypeEnum.Percent) {
|
|
1525
|
-
// let percent = (upgrade.price * fee.value) / 100;
|
|
1526
|
-
// return Math.round(percent * 100) / 100 || 0;
|
|
1527
|
-
// }
|
|
1528
|
-
// } else {
|
|
1529
|
-
// return 0;
|
|
1530
|
-
// }
|
|
1531
|
-
|
|
1532
|
-
// return 0;
|
|
1533
|
-
// };
|
|
1534
|
-
|
|
1535
|
-
// for (let index = 0; index < promoterFees.length; index++) {
|
|
1536
|
-
// let promoterUpgradeFee = promoterFees[index];
|
|
1537
|
-
// if (promoterUpgradeFee?.appliedTo === FeeAppliedToEnum.Upgrade) {
|
|
1538
|
-
// let promoterUpgardeFeeArr = [promoterUpgradeFee];
|
|
1539
|
-
// const promoterFeeFlatPerUpgardeAmt = params.upgrades.reduce(
|
|
1540
|
-
// (cur: number, upgrade: any) => {
|
|
1541
|
-
// return (
|
|
1542
|
-
// cur +
|
|
1543
|
-
// promoterUpgardeFeeArr.reduce((cur, fee) => {
|
|
1544
|
-
// const value = cur + applyUpgradeFee(upgrade, fee);
|
|
1545
|
-
// return value;
|
|
1546
|
-
// }, 0)
|
|
1547
|
-
// );
|
|
1548
|
-
// },
|
|
1549
|
-
// 0
|
|
1550
|
-
// );
|
|
1551
|
-
// promoterUpgradeFee.amount = Math.round(promoterFeeFlatPerUpgardeAmt);
|
|
1552
|
-
// promoCodeAdd += Math.round(promoterUpgradeFee.amount) || 0;
|
|
1553
|
-
// }
|
|
1554
|
-
// }
|
|
1555
|
-
|
|
1556
|
-
// const promoterFeeList = promoterFees
|
|
1557
|
-
// .filter(
|
|
1558
|
-
// (f) =>
|
|
1559
|
-
// f.name !== "Sales tax" &&
|
|
1560
|
-
// f.amount > 0 &&
|
|
1561
|
-
// f.appliedBy === "Organization"
|
|
1562
|
-
// )
|
|
1563
|
-
// .map((f) => ({
|
|
1564
|
-
// name: f.name,
|
|
1565
|
-
// amount: f.amount,
|
|
1566
|
-
// }));
|
|
1567
|
-
// return promoterFeeList;
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
// };
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
738
|
}
|
|
1575
739
|
|
|
1576
740
|
export default new PaymentUtil();
|