@sellout/models 0.0.233 → 0.0.237
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/graphql/fragments/event.fragment.js +2 -0
- package/.dist/graphql/fragments/event.fragment.js.map +1 -1
- package/.dist/graphql/fragments/order.fragment.d.ts +1 -0
- package/.dist/graphql/fragments/order.fragment.js +23 -0
- package/.dist/graphql/fragments/order.fragment.js.map +1 -1
- package/.dist/graphql/mutations/createOrder.mutation.js +1 -0
- package/.dist/graphql/mutations/createOrder.mutation.js.map +1 -1
- package/.dist/graphql/queries/discountCodeVerify.query.d.ts +2 -0
- package/.dist/graphql/queries/discountCodeVerify.query.js +34 -0
- package/.dist/graphql/queries/discountCodeVerify.query.js.map +1 -0
- package/.dist/graphql/queries/order.query.js +4 -0
- package/.dist/graphql/queries/order.query.js.map +1 -1
- package/.dist/interfaces/IAnalytics.d.ts +3 -0
- package/.dist/interfaces/IAnalytics.js +3 -0
- package/.dist/interfaces/IAnalytics.js.map +1 -1
- package/.dist/interfaces/ICreateOrderParams.d.ts +3 -0
- package/.dist/interfaces/IEventPromotion.d.ts +5 -0
- package/.dist/interfaces/IEventPromotion.js +6 -1
- package/.dist/interfaces/IEventPromotion.js.map +1 -1
- package/.dist/interfaces/IFee.d.ts +3 -8
- package/.dist/interfaces/IFee.js +4 -10
- package/.dist/interfaces/IFee.js.map +1 -1
- package/.dist/interfaces/IOrder.d.ts +2 -0
- package/.dist/interfaces/IOrder.js.map +1 -1
- package/.dist/interfaces/IOrderSummary.d.ts +1 -0
- package/.dist/interfaces/IOrderTicket.d.ts +1 -0
- package/.dist/interfaces/IPayment.d.ts +2 -0
- package/.dist/schemas/Event.d.ts +4 -0
- package/.dist/schemas/Event.js +4 -0
- package/.dist/schemas/Event.js.map +1 -1
- package/.dist/schemas/Order.d.ts +21 -0
- package/.dist/schemas/Order.js +21 -0
- package/.dist/schemas/Order.js.map +1 -1
- package/.dist/sellout-proto.js +705 -6
- package/.dist/utils/AnalyticsUtil.d.ts +2 -0
- package/.dist/utils/AnalyticsUtil.js +72 -0
- package/.dist/utils/AnalyticsUtil.js.map +1 -1
- package/.dist/utils/OrderUtil.js +1 -1
- package/.dist/utils/OrderUtil.js.map +1 -1
- package/.dist/utils/PaymentUtil.d.ts +2 -0
- package/.dist/utils/PaymentUtil.js +382 -33
- package/.dist/utils/PaymentUtil.js.map +1 -1
- package/package.json +3 -3
- package/src/graphql/fragments/event.fragment.ts +2 -0
- package/src/graphql/fragments/order.fragment.ts +24 -0
- package/src/graphql/mutations/createOrder.mutation.ts +1 -0
- package/src/graphql/queries/discountCodeVerify.query.ts +30 -0
- package/src/graphql/queries/order.query.ts +4 -0
- package/src/interfaces/IAnalytics.ts +3 -0
- package/src/interfaces/ICreateOrderParams.ts +4 -0
- package/src/interfaces/IEventPromotion.ts +7 -0
- package/src/interfaces/IFee.ts +3 -10
- package/src/interfaces/IOrder.ts +2 -0
- package/src/interfaces/IOrderSummary.ts +1 -0
- package/src/interfaces/IOrderTicket.ts +1 -0
- package/src/interfaces/IPayment.ts +3 -1
- package/src/proto/email.proto +1 -0
- package/src/proto/event.proto +18 -1
- package/src/proto/order.proto +15 -0
- package/src/schemas/Event.ts +4 -0
- package/src/schemas/Order.ts +21 -0
- package/src/utils/AnalyticsUtil.ts +123 -2
- package/src/utils/OrderUtil.ts +2 -1
- package/src/utils/PaymentUtil.ts +595 -96
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const FeeUtil_1 = __importDefault(require("./FeeUtil"));
|
|
7
7
|
const IFee_1 = require("../interfaces/IFee");
|
|
8
8
|
const PaymentMethodTypeEnum_1 = require("../enums/PaymentMethodTypeEnum");
|
|
9
|
+
const IEventPromotion_1 = require("../interfaces/IEventPromotion");
|
|
9
10
|
// interface IOrderItems {
|
|
10
11
|
// tickets: ICreateOrderTicketParams[];
|
|
11
12
|
// upgrades: ICreateOrderUpgradeParams[];
|
|
@@ -104,10 +105,56 @@ class PaymentUtil {
|
|
|
104
105
|
// },
|
|
105
106
|
calculatePaymentTotal(params) {
|
|
106
107
|
var _a, _b;
|
|
107
|
-
let { tickets = [], upgrades = [], fees = [], paymentMethodType } = params;
|
|
108
|
+
let { tickets = [], upgrades = [], fees = [], paymentMethodType, promotions = [], } = params;
|
|
108
109
|
// No items, total is always 0
|
|
109
110
|
if (!tickets.length && !upgrades.length)
|
|
110
111
|
return 0;
|
|
112
|
+
const ticketFeesPromoCodePercent = promotions === null || promotions === void 0 ? void 0 : promotions.filter((f) => f.appliesTo === IEventPromotion_1.EventPromotionAppliesToEnum.PerTicket &&
|
|
113
|
+
f.discountType === IEventPromotion_1.EventPromotionDiscountTypeEnum.Percent);
|
|
114
|
+
const discountFeePercentPerTicketTotal = tickets === null || tickets === void 0 ? void 0 : tickets.reduce((cur, ticket) => {
|
|
115
|
+
return (cur +
|
|
116
|
+
(ticketFeesPromoCodePercent === null || ticketFeesPromoCodePercent === void 0 ? void 0 : ticketFeesPromoCodePercent.reduce((cur, promotion) => {
|
|
117
|
+
const value = cur + applyTicketDiscount(ticket, promotion);
|
|
118
|
+
return value;
|
|
119
|
+
}, 0)));
|
|
120
|
+
}, 0);
|
|
121
|
+
// console.log(
|
|
122
|
+
// "++++++++++++eee+>>>>>>>>>>>>",
|
|
123
|
+
// discountFeePercentPerTicketTotal
|
|
124
|
+
// );
|
|
125
|
+
if (promotions === null || promotions === void 0 ? void 0 : promotions.length) {
|
|
126
|
+
tickets = tickets.map(ticket => {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
if (promotions && promotions[0].discountType === "Flat") {
|
|
129
|
+
if ((_a = promotions[0]) === null || _a === void 0 ? void 0 : _a.ticketTypeIds.includes(ticket === null || ticket === void 0 ? void 0 : ticket.ticketTypeId)) {
|
|
130
|
+
const discountValue = Number(promotions[0].discountValue);
|
|
131
|
+
const originalPrice = tickets[0].price;
|
|
132
|
+
const discountedPrice = originalPrice - discountValue;
|
|
133
|
+
return Object.assign(Object.assign({}, ticket), { price: discountedPrice });
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const originalPrice = tickets[0].price;
|
|
137
|
+
return Object.assign(Object.assign({}, ticket), { price: originalPrice });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (promotions && promotions[0].discountType === "Percent") {
|
|
141
|
+
if ((_b = promotions[0]) === null || _b === void 0 ? void 0 : _b.ticketTypeIds.includes(ticket === null || ticket === void 0 ? void 0 : ticket.ticketTypeId)) {
|
|
142
|
+
const discountValue = Number(promotions[0].discountValue);
|
|
143
|
+
const percentTicketValue = (ticket.origionalPrice * discountValue) / 100;
|
|
144
|
+
const originalPrice = tickets[0].price;
|
|
145
|
+
const discountPercentPrice = originalPrice - percentTicketValue;
|
|
146
|
+
// const discountedPrice = originalPrice
|
|
147
|
+
console.log("percentTicketValue", percentTicketValue);
|
|
148
|
+
return Object.assign(Object.assign({}, ticket), { price: discountPercentPrice });
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const originalPrice = tickets[0].price;
|
|
152
|
+
return Object.assign(Object.assign({}, ticket), { price: originalPrice });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return ticket;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
111
158
|
// Filter fees
|
|
112
159
|
fees = fees.filter((fee) => {
|
|
113
160
|
var _a, _b;
|
|
@@ -200,15 +247,37 @@ class PaymentUtil {
|
|
|
200
247
|
}
|
|
201
248
|
return 0;
|
|
202
249
|
}
|
|
250
|
+
// Discount codes apply
|
|
251
|
+
const isDiscount = promotions === null || promotions === void 0 ? void 0 : promotions.filter((f) => f.discountValue);
|
|
252
|
+
console.log(isDiscount, "isDiscount");
|
|
253
|
+
const ticketFeesPromoCodeFlat = promotions === null || promotions === void 0 ? void 0 : promotions.filter((f) => f.appliesTo === IEventPromotion_1.EventPromotionAppliesToEnum.PerTicket &&
|
|
254
|
+
f.discountType === IEventPromotion_1.EventPromotionDiscountTypeEnum.Flat);
|
|
255
|
+
// const ticketFeesPromoCodePercent = promotions?.filter(
|
|
256
|
+
// (f) =>
|
|
257
|
+
// f.appliesTo === EventPromotionAppliesToEnum.PerTicket &&
|
|
258
|
+
// f.discountType === EventPromotionDiscountTypeEnum.Percent
|
|
259
|
+
// );
|
|
260
|
+
// const ticketFeesPromoCodeFlatPerOrder = promotions?.filter(
|
|
261
|
+
// (f) =>
|
|
262
|
+
// f.appliesTo === EventPromotionAppliesToEnum.PerOrder &&
|
|
263
|
+
// f.discountType === EventPromotionDiscountTypeEnum.Flat
|
|
264
|
+
// );
|
|
265
|
+
// const ticketFeesPromoCodePercentPerOrder = promotions?.filter(
|
|
266
|
+
// (f) =>
|
|
267
|
+
// f.appliesTo === EventPromotionAppliesToEnum.PerOrder &&
|
|
268
|
+
// f.discountType === EventPromotionDiscountTypeEnum.Percent
|
|
269
|
+
// );
|
|
203
270
|
// Fees applied
|
|
204
|
-
const ticketFeesPromotersFlat = fees
|
|
205
|
-
|
|
206
|
-
f.
|
|
207
|
-
const ticketFeesPromotersPercent = fees
|
|
208
|
-
|
|
209
|
-
f.
|
|
210
|
-
const upgradeFeesPromotersFees = fees.filter((f) => f.appliedTo === IFee_1.FeeAppliedToEnum.Upgrade &&
|
|
211
|
-
|
|
271
|
+
const ticketFeesPromotersFlat = fees.filter((f) => f.appliedTo === IFee_1.FeeAppliedToEnum.Ticket &&
|
|
272
|
+
f.appliedBy == IFee_1.FeeAppliedByEnum.Organization &&
|
|
273
|
+
f.type === IFee_1.FeeTypeEnum.Flat);
|
|
274
|
+
const ticketFeesPromotersPercent = fees.filter((f) => f.appliedTo === IFee_1.FeeAppliedToEnum.Ticket &&
|
|
275
|
+
f.appliedBy == IFee_1.FeeAppliedByEnum.Organization &&
|
|
276
|
+
f.type === IFee_1.FeeTypeEnum.Percent);
|
|
277
|
+
const upgradeFeesPromotersFees = fees.filter((f) => f.appliedTo === IFee_1.FeeAppliedToEnum.Upgrade &&
|
|
278
|
+
f.appliedBy == IFee_1.FeeAppliedByEnum.Organization);
|
|
279
|
+
const upgradeFeesSelloutFees = fees.filter((f) => f.appliedTo === IFee_1.FeeAppliedToEnum.Upgrade &&
|
|
280
|
+
f.appliedBy == IFee_1.FeeAppliedByEnum.Sellout);
|
|
212
281
|
const selloutFees = fees.filter((f) => f.appliedBy == IFee_1.FeeAppliedByEnum.Sellout
|
|
213
282
|
// (f) => f.appliedTo === FeeAppliedToEnum.Upgrade && f.appliedBy == FeeAppliedByEnum.Sellout
|
|
214
283
|
);
|
|
@@ -217,20 +286,93 @@ class PaymentUtil {
|
|
|
217
286
|
const stripeFees = fees.filter((f) => f.appliedBy == IFee_1.FeeAppliedByEnum.Stripe);
|
|
218
287
|
// Orders mattes here. Flat type fees must be applied before Percent type fees
|
|
219
288
|
const promoterOrderFees = fees
|
|
220
|
-
.filter((f) => f.appliedTo === IFee_1.FeeAppliedToEnum.Order &&
|
|
289
|
+
.filter((f) => f.appliedTo === IFee_1.FeeAppliedToEnum.Order &&
|
|
290
|
+
f.name != "Sales tax" &&
|
|
291
|
+
f.appliedBy == IFee_1.FeeAppliedByEnum.Organization)
|
|
221
292
|
.sort(({ type }) => {
|
|
222
293
|
if (type === "Flat")
|
|
223
294
|
return -1;
|
|
224
295
|
else
|
|
225
296
|
return 1;
|
|
226
297
|
});
|
|
227
|
-
// Caclualtions
|
|
298
|
+
// Caclualtions
|
|
228
299
|
const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price, 0);
|
|
229
300
|
const upgradeTotal = upgrades.reduce((cur, upgrade) => cur + upgrade.price, 0);
|
|
230
|
-
const
|
|
301
|
+
const totalTicketUpgrade = ticketTotal + upgradeTotal;
|
|
302
|
+
const discountFeeFlatPerTicketTotal = tickets === null || tickets === void 0 ? void 0 : tickets.reduce((cur, ticket) => {
|
|
303
|
+
return (cur +
|
|
304
|
+
(ticketFeesPromoCodeFlat === null || ticketFeesPromoCodeFlat === void 0 ? void 0 : ticketFeesPromoCodeFlat.reduce((cur, promotion) => {
|
|
305
|
+
const value = cur + applyTicketDiscount(ticket, promotion);
|
|
306
|
+
return value;
|
|
307
|
+
}, 0)));
|
|
308
|
+
}, 0);
|
|
309
|
+
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerTicketTotal);
|
|
310
|
+
// const discountFeePercentPerTicketTotal = tickets?.reduce((cur, ticket) => {
|
|
311
|
+
// return (
|
|
312
|
+
// cur +
|
|
313
|
+
// ticketFeesPromoCodePercent?.reduce((cur, promotion) => {
|
|
314
|
+
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
315
|
+
// return value;
|
|
316
|
+
// }, 0)
|
|
317
|
+
// );
|
|
318
|
+
// }, 0);
|
|
319
|
+
// console.log(
|
|
320
|
+
// "++++++++++++eee+>>>>>>>>>>>>",
|
|
321
|
+
// discountFeePercentPerTicketTotal
|
|
322
|
+
// );
|
|
323
|
+
// const discountFeeFlatPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
324
|
+
// return (
|
|
325
|
+
// cur +
|
|
326
|
+
// ticketFeesPromoCodeFlatPerOrder?.reduce((cur, promotion) => {
|
|
327
|
+
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
328
|
+
// return value;
|
|
329
|
+
// }, 0)
|
|
330
|
+
// );
|
|
331
|
+
// }, 0);
|
|
332
|
+
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerOrderTotal);
|
|
333
|
+
// const discountFeePercentPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
334
|
+
// return (
|
|
335
|
+
// cur +
|
|
336
|
+
// ticketFeesPromoCodePercentPerOrder?.reduce((cur, promotion) => {
|
|
337
|
+
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
338
|
+
// return value;
|
|
339
|
+
// }, 0)
|
|
340
|
+
// );
|
|
341
|
+
// }, 0);
|
|
342
|
+
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeePercentPerOrderTotal);
|
|
343
|
+
// const promoterFeeFlatPerOrderTotal = promoterOrderFees.reduce(
|
|
344
|
+
// (acc, fee: any) => {
|
|
345
|
+
// return fee.type == FeeTypeEnum.Flat ? acc + getFeeAmount(fee) : acc;
|
|
346
|
+
// },
|
|
347
|
+
// 0
|
|
348
|
+
// );
|
|
349
|
+
const discountFeeFlatPerOrderAmt = promotions === null || promotions === void 0 ? void 0 : promotions.reduce((cur, promotion) => {
|
|
350
|
+
if (promotion.discountType == IEventPromotion_1.EventPromotionDiscountTypeEnum.Flat &&
|
|
351
|
+
promotion.appliesTo === IEventPromotion_1.EventPromotionAppliesToEnum.PerOrder) {
|
|
352
|
+
const value = cur + promotion.discountValue;
|
|
353
|
+
return value;
|
|
354
|
+
}
|
|
355
|
+
return cur;
|
|
356
|
+
}, 0);
|
|
357
|
+
// console.log("Amt flat per order",discountFeeFlatPerOrderAmt)
|
|
358
|
+
const discountFeePercentPerOrderAmt = promotions === null || promotions === void 0 ? void 0 : promotions.reduce((cur, promotion) => {
|
|
359
|
+
if (promotion.discountType == IEventPromotion_1.EventPromotionDiscountTypeEnum.Percent &&
|
|
360
|
+
promotion.appliesTo === IEventPromotion_1.EventPromotionAppliesToEnum.PerOrder) {
|
|
361
|
+
const value = cur + (totalTicketUpgrade * promotion.discountValue) / 100;
|
|
362
|
+
return value;
|
|
363
|
+
}
|
|
364
|
+
return cur;
|
|
365
|
+
}, 0);
|
|
366
|
+
// console.log("Amt percent per order",discountFeePercentPerOrderAmt)
|
|
367
|
+
const discount = Math.round(discountFeeFlatPerTicketTotal || 0 + discountFeePercentPerTicketTotal || 0) || 0;
|
|
368
|
+
console.log(discount);
|
|
369
|
+
const discountOrder = Math.round(discountFeeFlatPerOrderAmt || 0 + discountFeePercentPerOrderAmt || 0) || 0;
|
|
370
|
+
console.log(discountOrder);
|
|
371
|
+
const totalTicketAndUpgrades = Math.round(ticketTotal - discountOrder || 0) + Math.round(upgradeTotal);
|
|
231
372
|
const promoterFeeFlatPerOrderTotal = promoterOrderFees.reduce((acc, fee) => {
|
|
232
|
-
return fee.type == IFee_1.FeeTypeEnum.Flat ?
|
|
373
|
+
return fee.type == IFee_1.FeeTypeEnum.Flat ? acc + getFeeAmount(fee) : acc;
|
|
233
374
|
}, 0);
|
|
375
|
+
//
|
|
234
376
|
const promoterFeeFlatPerTicketTotal = tickets.reduce((cur, ticket) => {
|
|
235
377
|
return (cur +
|
|
236
378
|
ticketFeesPromotersFlat.reduce((cur, fee) => {
|
|
@@ -238,6 +380,85 @@ class PaymentUtil {
|
|
|
238
380
|
return value;
|
|
239
381
|
}, 0));
|
|
240
382
|
}, 0);
|
|
383
|
+
// discount
|
|
384
|
+
// const discountTickets = tickets.filter(
|
|
385
|
+
// (obj, index) =>
|
|
386
|
+
// tickets.findIndex((item) => item.ticketTypeId === obj.ticketTypeId) ===
|
|
387
|
+
// index
|
|
388
|
+
// );
|
|
389
|
+
// console.log(discountTickets, "discountTickets");
|
|
390
|
+
// const discountFeeFlatPerTicketTotal = tickets?.reduce((cur, ticket) => {
|
|
391
|
+
// return (
|
|
392
|
+
// cur +
|
|
393
|
+
// ticketFeesPromoCodeFlat?.reduce((cur, promotion) => {
|
|
394
|
+
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
395
|
+
// return value;
|
|
396
|
+
// }, 0)
|
|
397
|
+
// );
|
|
398
|
+
// }, 0);
|
|
399
|
+
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerTicketTotal);
|
|
400
|
+
// const discountFeePercentPerTicketTotal = tickets?.reduce((cur, ticket) => {
|
|
401
|
+
// return (
|
|
402
|
+
// cur +
|
|
403
|
+
// ticketFeesPromoCodePercent?.reduce((cur, promotion) => {
|
|
404
|
+
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
405
|
+
// return value;
|
|
406
|
+
// }, 0)
|
|
407
|
+
// );
|
|
408
|
+
// }, 0);
|
|
409
|
+
// console.log(
|
|
410
|
+
// "++++++++++++eee+>>>>>>>>>>>>",
|
|
411
|
+
// discountFeePercentPerTicketTotal
|
|
412
|
+
// );
|
|
413
|
+
// // const discountFeeFlatPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
414
|
+
// // return (
|
|
415
|
+
// // cur +
|
|
416
|
+
// // ticketFeesPromoCodeFlatPerOrder?.reduce((cur, promotion) => {
|
|
417
|
+
// // const value = cur + applyTicketDiscount(ticket, promotion);
|
|
418
|
+
// // return value;
|
|
419
|
+
// // }, 0)
|
|
420
|
+
// // );
|
|
421
|
+
// // }, 0);
|
|
422
|
+
// // console.log("+++++++++++++>>>>>>>>>>>>", discountFeeFlatPerOrderTotal);
|
|
423
|
+
// const discountFeePercentPerOrderTotal = tickets?.reduce((cur, ticket) => {
|
|
424
|
+
// return (
|
|
425
|
+
// cur +
|
|
426
|
+
// ticketFeesPromoCodePercentPerOrder?.reduce((cur, promotion) => {
|
|
427
|
+
// const value = cur + applyTicketDiscount(ticket, promotion);
|
|
428
|
+
// return value;
|
|
429
|
+
// }, 0)
|
|
430
|
+
// );
|
|
431
|
+
// }, 0);
|
|
432
|
+
// console.log("+++++++++++++>>>>>>>>>>>>", discountFeePercentPerOrderTotal);
|
|
433
|
+
// // const promoterFeeFlatPerOrderTotal = promoterOrderFees.reduce(
|
|
434
|
+
// // (acc, fee: any) => {
|
|
435
|
+
// // return fee.type == FeeTypeEnum.Flat ? acc + getFeeAmount(fee) : acc;
|
|
436
|
+
// // },
|
|
437
|
+
// // 0
|
|
438
|
+
// // );
|
|
439
|
+
// const discountFeeFlatPerOrderAmt = promotions?.reduce(
|
|
440
|
+
// (cur: number,promotion: IEventPromotion) => {
|
|
441
|
+
// if (
|
|
442
|
+
// promotion.discountType == EventPromotionDiscountTypeEnum.Flat &&
|
|
443
|
+
// promotion.appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
444
|
+
// ) {
|
|
445
|
+
// const value = cur + promotion.discountValue;
|
|
446
|
+
// return value;
|
|
447
|
+
// }
|
|
448
|
+
// return cur;
|
|
449
|
+
// },
|
|
450
|
+
// 0
|
|
451
|
+
// );
|
|
452
|
+
// console.log("Amt flat per order",discountFeeFlatPerOrderAmt)
|
|
453
|
+
// const discountPercentFeesAmt = promotions.reduce((acc, promotion) => {
|
|
454
|
+
// if (promotion.discountType == EventPromotionDiscountTypeEnum.Percent &&
|
|
455
|
+
// promotion.appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
456
|
+
// ) {
|
|
457
|
+
// return acc + getFeeAmount(promotion, promoterTotal);
|
|
458
|
+
// }
|
|
459
|
+
// return acc;
|
|
460
|
+
// }, 0);
|
|
461
|
+
// console.log("order amt percent",discountPercentFeesAmt)
|
|
241
462
|
const promoterFeeFlatPerUpgradeTotal = upgrades.reduce((cur, upgrade) => {
|
|
242
463
|
return (cur +
|
|
243
464
|
upgradeFeesPromotersFees.reduce((cur, fee) => {
|
|
@@ -268,37 +489,64 @@ class PaymentUtil {
|
|
|
268
489
|
const ticketGuestFeeTotalForPromoter = tickets.reduce((cur, ticket) => {
|
|
269
490
|
return (cur +
|
|
270
491
|
guestFees.reduce((cur, fee) => {
|
|
271
|
-
const value = fee.appliedBy == IFee_1.FeeAppliedByEnum.Organization
|
|
492
|
+
const value = fee.appliedBy == IFee_1.FeeAppliedByEnum.Organization
|
|
493
|
+
? cur + applyGuestTicketFee(ticket, fee)
|
|
494
|
+
: 0;
|
|
272
495
|
return value;
|
|
273
496
|
}, 0));
|
|
274
497
|
}, 0);
|
|
275
498
|
const ticketGuestFeeTotalForSellout = tickets.reduce((cur, ticket) => {
|
|
276
499
|
return (cur +
|
|
277
500
|
guestFees.reduce((cur, fee) => {
|
|
278
|
-
const value = fee.appliedBy == IFee_1.FeeAppliedByEnum.Sellout
|
|
501
|
+
const value = fee.appliedBy == IFee_1.FeeAppliedByEnum.Sellout
|
|
502
|
+
? cur + applyGuestTicketFee(ticket, fee)
|
|
503
|
+
: 0;
|
|
279
504
|
return value;
|
|
280
505
|
}, 0));
|
|
281
506
|
}, 0);
|
|
282
|
-
const
|
|
283
|
-
|
|
507
|
+
// const discount =
|
|
508
|
+
// Math.round(
|
|
509
|
+
// discountFeeFlatPerTicketTotal ||
|
|
510
|
+
// 0 + discountFeePercentPerTicketTotal ||
|
|
511
|
+
// 0 + discountFeeFlatPerOrderAmt ||
|
|
512
|
+
// 0 + discountFeePercentPerOrderTotal ||
|
|
513
|
+
// 0
|
|
514
|
+
// ) || 0;
|
|
515
|
+
// console.log(discount);
|
|
516
|
+
const orderSubtotal = Math.round(totalTicketAndUpgrades +
|
|
517
|
+
// upgradeTotal +
|
|
284
518
|
promoterFeeFlatPerTicketTotal +
|
|
285
519
|
promoterFeeFlatPerOrderTotal +
|
|
286
520
|
promoterFeePercentPerTicketTotal +
|
|
287
|
-
promoterFeePercentPerOrder +
|
|
288
|
-
ticketGuestFeeTotalForPromoter +
|
|
289
|
-
|
|
290
|
-
const
|
|
521
|
+
Math.round(promoterFeePercentPerOrder) +
|
|
522
|
+
ticketGuestFeeTotalForPromoter +
|
|
523
|
+
promoterFeeFlatPerUpgradeTotal);
|
|
524
|
+
const discountValue = Math.round(orderSubtotal);
|
|
525
|
+
console.log(discountValue, "discountValue");
|
|
526
|
+
const salesTaxAmount = salesTaxFees
|
|
527
|
+
? (orderSubtotal * salesTaxFees.value) / 100
|
|
528
|
+
: 0;
|
|
529
|
+
const promoterTotal = orderSubtotal + Math.round(salesTaxAmount);
|
|
291
530
|
const selloutPercentFeesAmt = selloutFees.reduce((acc, fee) => {
|
|
292
531
|
if (fee.type == IFee_1.FeeTypeEnum.Percent) {
|
|
293
532
|
return acc + getFeeAmount(fee, promoterTotal);
|
|
294
533
|
}
|
|
295
534
|
return acc;
|
|
296
535
|
}, 0);
|
|
536
|
+
//
|
|
537
|
+
// const discountPercentFeesAmt = promotions.reduce((acc, promotion) => {
|
|
538
|
+
// if (promotion.discountType == EventPromotionDiscountTypeEnum.Percent) {
|
|
539
|
+
// return acc + getFeeAmount(promotion, promoterTotal);
|
|
540
|
+
// }
|
|
541
|
+
// return acc;
|
|
542
|
+
// }, 0);
|
|
543
|
+
// console.log(discountPercentFeesAmt)
|
|
297
544
|
const selloutFeeFlatPerTicketAmt = tickets.reduce((cur, ticket) => {
|
|
298
545
|
return (cur +
|
|
299
546
|
selloutFees.reduce((cur, fee) => {
|
|
300
547
|
var _a;
|
|
301
|
-
if (fee.type == IFee_1.FeeTypeEnum.Flat &&
|
|
548
|
+
if (fee.type == IFee_1.FeeTypeEnum.Flat &&
|
|
549
|
+
fee.appliedTo === IFee_1.FeeAppliedToEnum.Ticket &&
|
|
302
550
|
!((_a = fee === null || fee === void 0 ? void 0 : fee.filters) === null || _a === void 0 ? void 0 : _a.includes(IFee_1.FeeFiltersEnum.Seated))) {
|
|
303
551
|
const value = cur + applyTicketFee(ticket, fee);
|
|
304
552
|
return value;
|
|
@@ -307,17 +555,37 @@ class PaymentUtil {
|
|
|
307
555
|
}, 0));
|
|
308
556
|
}, 0);
|
|
309
557
|
const selloutFeeFlatPerOrderAmt = selloutFees.reduce((cur, fee) => {
|
|
310
|
-
if (fee.type === IFee_1.FeeTypeEnum.Flat &&
|
|
558
|
+
if (fee.type === IFee_1.FeeTypeEnum.Flat &&
|
|
559
|
+
fee.appliedTo === IFee_1.FeeAppliedToEnum.Order) {
|
|
311
560
|
const value = cur + fee.value;
|
|
312
561
|
return value;
|
|
313
562
|
}
|
|
314
563
|
return cur;
|
|
315
564
|
}, 0);
|
|
565
|
+
// if (fee.type === FeeTypeEnum.Percent) {
|
|
566
|
+
// return amt * (fee.value / 100);
|
|
567
|
+
// }
|
|
568
|
+
// const discountFeeFlatPerOrderAmt = promotions?.reduce(
|
|
569
|
+
// (cur: number,promotion: IEventPromotion) => {
|
|
570
|
+
// if (
|
|
571
|
+
// promotion.discountType == EventPromotionDiscountTypeEnum.Percent &&
|
|
572
|
+
// promotion.appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
573
|
+
// ) {
|
|
574
|
+
// // const value = cur + promotion.discountValue;
|
|
575
|
+
// // return value;
|
|
576
|
+
// return amt * (promotion.discountType / 100);
|
|
577
|
+
// }
|
|
578
|
+
// return cur;
|
|
579
|
+
// },
|
|
580
|
+
// 0
|
|
581
|
+
// );
|
|
582
|
+
// console.log(discountFeeFlatPerOrderAmt)
|
|
316
583
|
const selloutSeatedFeeAmt = tickets.reduce((cur, ticket) => {
|
|
317
584
|
return (cur +
|
|
318
585
|
selloutFees.reduce((cur, fee) => {
|
|
319
586
|
var _a;
|
|
320
|
-
if (fee.type == IFee_1.FeeTypeEnum.Flat &&
|
|
587
|
+
if (fee.type == IFee_1.FeeTypeEnum.Flat &&
|
|
588
|
+
fee.appliedTo === IFee_1.FeeAppliedToEnum.Ticket &&
|
|
321
589
|
((_a = fee === null || fee === void 0 ? void 0 : fee.filters) === null || _a === void 0 ? void 0 : _a.includes(IFee_1.FeeFiltersEnum.Seated))) {
|
|
322
590
|
const value = cur + applyTicketFee(ticket, fee);
|
|
323
591
|
return value;
|
|
@@ -328,13 +596,16 @@ class PaymentUtil {
|
|
|
328
596
|
const selloutFeesTotal = Math.round(selloutPercentFeesAmt +
|
|
329
597
|
selloutFeeFlatPerTicketAmt +
|
|
330
598
|
selloutFeeFlatPerOrderAmt +
|
|
331
|
-
selloutSeatedFeeAmt +
|
|
599
|
+
selloutSeatedFeeAmt +
|
|
600
|
+
ticketGuestFeeTotalForSellout +
|
|
601
|
+
SelloutFeeFlatPerUpgradeTotal);
|
|
332
602
|
const preStripeTotal = promoterTotal + selloutFeesTotal;
|
|
333
603
|
let stripeFeeAmt = 0;
|
|
334
|
-
const stripeFeePercentage = ((_a = stripeFees.find(fee => fee.type == IFee_1.FeeTypeEnum.Percent)) === null || _a === void 0 ? void 0 : _a.value) || 0;
|
|
335
|
-
const stripeFeeFlat = ((_b = stripeFees.find(fee => fee.type == IFee_1.FeeTypeEnum.Flat)) === null || _b === void 0 ? void 0 : _b.value) || 0;
|
|
336
|
-
stripeFeeAmt =
|
|
337
|
-
|
|
604
|
+
const stripeFeePercentage = ((_a = stripeFees.find((fee) => fee.type == IFee_1.FeeTypeEnum.Percent)) === null || _a === void 0 ? void 0 : _a.value) || 0;
|
|
605
|
+
const stripeFeeFlat = ((_b = stripeFees.find((fee) => fee.type == IFee_1.FeeTypeEnum.Flat)) === null || _b === void 0 ? void 0 : _b.value) || 0;
|
|
606
|
+
stripeFeeAmt =
|
|
607
|
+
(preStripeTotal + stripeFeeFlat) / (1 - stripeFeePercentage / 100) -
|
|
608
|
+
preStripeTotal;
|
|
338
609
|
function applyTicketFee(ticket, fee) {
|
|
339
610
|
// Ignore seated fees if not seated
|
|
340
611
|
if (fee.filters &&
|
|
@@ -357,6 +628,21 @@ class PaymentUtil {
|
|
|
357
628
|
}
|
|
358
629
|
return 0;
|
|
359
630
|
}
|
|
631
|
+
//
|
|
632
|
+
function applyTicketDiscount(ticket, promotion) {
|
|
633
|
+
if (promotion.ticketTypeIds.includes(ticket === null || ticket === void 0 ? void 0 : ticket.ticketTypeId) ||
|
|
634
|
+
promotion.ticketTypeIds.length == 0) {
|
|
635
|
+
if ((promotion === null || promotion === void 0 ? void 0 : promotion.discountType) === IEventPromotion_1.EventPromotionDiscountTypeEnum.Flat) {
|
|
636
|
+
return promotion.discountValue;
|
|
637
|
+
}
|
|
638
|
+
if (promotion.discountType === IEventPromotion_1.EventPromotionDiscountTypeEnum.Percent) {
|
|
639
|
+
return (ticket.origionalPrice * promotion.discountValue) / 100;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
return 0;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
360
646
|
function applyUpgradeFee(upgrade, fee) {
|
|
361
647
|
const minFee = fee.minAppliedToPrice || 0;
|
|
362
648
|
const maxFee = fee.maxAppliedToPrice || Infinity;
|
|
@@ -374,6 +660,15 @@ class PaymentUtil {
|
|
|
374
660
|
}
|
|
375
661
|
return 0;
|
|
376
662
|
}
|
|
663
|
+
// function getDiscount(promotion: IEventPromotion, amt = 0) {
|
|
664
|
+
// if (promotion?.discountType === EventPromotionDiscountTypeEnum.Flat) {
|
|
665
|
+
// return (amt -);
|
|
666
|
+
// }
|
|
667
|
+
// if (promotion?.discountType === EventPromotionDiscountTypeEnum.Percent) {
|
|
668
|
+
// return amt * (promotion.discountValue/ 100);
|
|
669
|
+
// }
|
|
670
|
+
// }
|
|
671
|
+
// console.log(getDiscount)
|
|
377
672
|
// return Calculated fees amount based on type
|
|
378
673
|
function getFeeAmount(fee, amt = 0) {
|
|
379
674
|
if (fee.type === IFee_1.FeeTypeEnum.Flat) {
|
|
@@ -383,8 +678,44 @@ class PaymentUtil {
|
|
|
383
678
|
return amt * (fee.value / 100);
|
|
384
679
|
}
|
|
385
680
|
}
|
|
386
|
-
let promoterFeeAmount = promoterFeeFlatPerTicketTotal +
|
|
387
|
-
|
|
681
|
+
let promoterFeeAmount = promoterFeeFlatPerTicketTotal +
|
|
682
|
+
promoterFeeFlatPerOrderTotal +
|
|
683
|
+
promoterFeePercentPerTicketTotal +
|
|
684
|
+
promoterFeePercentPerOrder +
|
|
685
|
+
ticketGuestFeeTotalForPromoter +
|
|
686
|
+
promoterFeeFlatPerUpgradeTotal;
|
|
687
|
+
// let total = {
|
|
688
|
+
// salesTax: Math.round(salesTaxAmount || 0),
|
|
689
|
+
// total: isDiscount && discount > 0
|
|
690
|
+
// ? Math.round(orderSubtotal - discount) +
|
|
691
|
+
// Math.round(
|
|
692
|
+
// promoterFeeAmount +
|
|
693
|
+
// (isDiscount && discount > 0 ? stripeDiscountFeeAmt : stripeFeeAmt) +
|
|
694
|
+
// selloutFeesTotal +
|
|
695
|
+
// salesTaxAmount || 0
|
|
696
|
+
// )
|
|
697
|
+
// : Math.round(preStripeTotal) + Math.round(isDiscount ? stripeDiscountFeeAmt : stripeFeeAmt) || 0,
|
|
698
|
+
// promoterFees: Math.round(promoterFeeAmount || 0),
|
|
699
|
+
// stripeFees: Math.round(isDiscount ? stripeDiscountFeeAmt : stripeFeeAmt || 0),
|
|
700
|
+
// selloutFees: Math.round(selloutFeesTotal || 0),
|
|
701
|
+
// orderSubtotal: Math.round(orderSubtotal || 0),
|
|
702
|
+
// subTotal: isDiscount && discount > 0
|
|
703
|
+
// ? Math.round(orderSubtotal - discount || 0)
|
|
704
|
+
// : Math.round(totalTicketAndUpgrades || 0),
|
|
705
|
+
// // subTotal: Math.round(totalTicketAndUpgrades || 0),
|
|
706
|
+
// totalFees: Math.round(
|
|
707
|
+
// promoterFeeAmount +
|
|
708
|
+
// stripeDiscountFeeAmt +
|
|
709
|
+
// selloutFeesTotal +
|
|
710
|
+
// salesTaxAmount || 0
|
|
711
|
+
// ),
|
|
712
|
+
// totalWithoutTaxFees: Math.round(
|
|
713
|
+
// promoterFeeAmount + stripeFeeAmt + selloutFeesTotal || 0
|
|
714
|
+
// ),
|
|
715
|
+
// guestFeeForPromoter: Math.round(ticketGuestFeeTotalForPromoter || 0),
|
|
716
|
+
// guestFeeForSellout: Math.round(ticketGuestFeeTotalForSellout || 0),
|
|
717
|
+
// discountAmount: Math.round(discount) || 0,
|
|
718
|
+
// };
|
|
388
719
|
let total = {
|
|
389
720
|
salesTax: Math.round(salesTaxAmount || 0),
|
|
390
721
|
total: Math.round(preStripeTotal) + Math.round(stripeFeeAmt) || 0,
|
|
@@ -397,17 +728,34 @@ class PaymentUtil {
|
|
|
397
728
|
totalWithoutTaxFees: Math.round((promoterFeeAmount + stripeFeeAmt + selloutFeesTotal) || 0),
|
|
398
729
|
guestFeeForPromoter: Math.round(ticketGuestFeeTotalForPromoter || 0),
|
|
399
730
|
guestFeeForSellout: Math.round(ticketGuestFeeTotalForSellout || 0),
|
|
731
|
+
discountAmount: Math.round(discount || discountOrder) || 0,
|
|
400
732
|
};
|
|
733
|
+
// console.log(total, "total");
|
|
401
734
|
return total;
|
|
402
735
|
}
|
|
403
736
|
calculatePaymentSubtotal(params) {
|
|
404
737
|
let { tickets = [], upgrades = [], paymentMethodType,
|
|
405
738
|
// fees
|
|
739
|
+
// promotions
|
|
406
740
|
} = params;
|
|
407
741
|
if (paymentMethodType === PaymentMethodTypeEnum_1.PaymentMethodTypeEnum.None)
|
|
408
742
|
return 0;
|
|
409
743
|
const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price, 0); // + (ticket.price * tax/100)
|
|
410
744
|
const upgradeTotal = upgrades.reduce((cur, upgrade) => cur + upgrade.price, 0); // + (upgrade.price * tax/100)
|
|
745
|
+
// const discountFeeFlatPerOrderAmt = promotions?.reduce(
|
|
746
|
+
// (cur: number,promotion: IEventPromotion) => {
|
|
747
|
+
// if (
|
|
748
|
+
// promotion.discountType == EventPromotionDiscountTypeEnum.Flat &&
|
|
749
|
+
// promotion.appliesTo === EventPromotionAppliesToEnum.PerOrder
|
|
750
|
+
// ) {
|
|
751
|
+
// const value = cur + promotion.discountValue;
|
|
752
|
+
// return value;
|
|
753
|
+
// }
|
|
754
|
+
// return cur;
|
|
755
|
+
// },
|
|
756
|
+
// 0
|
|
757
|
+
// );
|
|
758
|
+
// const totalTicketUpgrade = ticketTotal + upgradeTotal
|
|
411
759
|
return ticketTotal + upgradeTotal;
|
|
412
760
|
}
|
|
413
761
|
calculatePaymentSubtotalValue(params) {
|
|
@@ -486,13 +834,14 @@ class PaymentUtil {
|
|
|
486
834
|
calculateGuestFee(tickets, event) {
|
|
487
835
|
var _a, _b;
|
|
488
836
|
let guestTicketFees = event === null || event === void 0 ? void 0 : event.fees.filter((fee) => fee.filters && fee.filters[0] === IFee_1.FeeFiltersEnum.GuestTicket);
|
|
489
|
-
let stripeFees = event === null || event === void 0 ? void 0 : event.fees.filter((fee) => fee.appliedBy === IFee_1.FeeAppliedByEnum.Stripe &&
|
|
837
|
+
let stripeFees = event === null || event === void 0 ? void 0 : event.fees.filter((fee) => fee.appliedBy === IFee_1.FeeAppliedByEnum.Stripe &&
|
|
838
|
+
fee.type === IFee_1.FeeTypeEnum.Percent);
|
|
490
839
|
let guestFeesValue = guestTicketFees && ((_a = guestTicketFees[0]) === null || _a === void 0 ? void 0 : _a.value);
|
|
491
840
|
let stripeFeesValue = stripeFees && ((_b = stripeFees[0]) === null || _b === void 0 ? void 0 : _b.value);
|
|
492
841
|
let guestMembers = tickets.filter((a) => a.guestTicket).length;
|
|
493
842
|
let guestFees = guestFeesValue * guestMembers;
|
|
494
843
|
return guestTicketFees.length > 0 && event.organization.isTegIntegration
|
|
495
|
-
? guestFees + guestFees * stripeFeesValue / 100
|
|
844
|
+
? guestFees + (guestFees * stripeFeesValue) / 100
|
|
496
845
|
: 0;
|
|
497
846
|
}
|
|
498
847
|
}
|