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