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