@sellout/models 0.0.188-alpha.0 → 0.0.191
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/order.fragment.js +1 -0
- package/.dist/graphql/fragments/order.fragment.js.map +1 -1
- package/.dist/graphql/mutations/generateActivityReport.mutation.d.ts +2 -0
- package/.dist/graphql/mutations/generateActivityReport.mutation.js +18 -0
- package/.dist/graphql/mutations/generateActivityReport.mutation.js.map +1 -0
- package/.dist/graphql/mutations/refundOrder.mutation.js +13 -0
- package/.dist/graphql/mutations/refundOrder.mutation.js.map +1 -1
- package/.dist/graphql/mutations/sendSeasonOrderReceiptEmail.mutation.d.ts +2 -0
- package/.dist/graphql/mutations/sendSeasonOrderReceiptEmail.mutation.js +13 -0
- package/.dist/graphql/mutations/sendSeasonOrderReceiptEmail.mutation.js.map +1 -0
- package/.dist/graphql/queries/order.query.js +12 -0
- package/.dist/graphql/queries/order.query.js.map +1 -1
- package/.dist/graphql/queries/orders.query.js +1 -0
- package/.dist/graphql/queries/orders.query.js.map +1 -1
- package/.dist/graphql/queries/userProfilesAdmin.query.js +2 -5
- package/.dist/graphql/queries/userProfilesAdmin.query.js.map +1 -1
- package/.dist/interfaces/ICreateOrderParams.d.ts +2 -0
- package/.dist/interfaces/IFee.d.ts +1 -0
- package/.dist/interfaces/IOrder.d.ts +3 -1
- package/.dist/interfaces/IOrder.js.map +1 -1
- package/.dist/interfaces/IOrderQuery.d.ts +1 -0
- package/.dist/interfaces/IOrderSummary.d.ts +1 -0
- package/.dist/interfaces/IPagination.d.ts +1 -2
- package/.dist/interfaces/IPagination.js +0 -1
- package/.dist/interfaces/IPagination.js.map +1 -1
- package/.dist/interfaces/IRefundModal.d.ts +1 -0
- package/.dist/interfaces/ISeason.d.ts +1 -0
- package/.dist/schemas/Order.d.ts +107 -0
- package/.dist/schemas/Order.js +84 -0
- package/.dist/schemas/Order.js.map +1 -1
- package/.dist/sellout-proto.js +1369 -122
- package/.dist/utils/AnalyticsUtil.js +99 -20
- package/.dist/utils/AnalyticsUtil.js.map +1 -1
- package/.dist/utils/OrderUtil.js +111 -195
- package/.dist/utils/OrderUtil.js.map +1 -1
- package/.dist/utils/PaymentUtil.d.ts +3 -3
- package/.dist/utils/PaymentUtil.js +146 -206
- package/.dist/utils/PaymentUtil.js.map +1 -1
- package/package.json +3 -3
- package/src/graphql/fragments/order.fragment.ts +1 -0
- package/src/graphql/mutations/generateActivityReport.mutation.ts +14 -0
- package/src/graphql/mutations/refundOrder.mutation.ts +13 -0
- package/src/graphql/mutations/sendSeasonOrderReceiptEmail.mutation.ts +9 -0
- package/src/graphql/queries/order.query.ts +12 -0
- package/src/graphql/queries/orders.query.ts +1 -0
- package/src/graphql/queries/userProfilesAdmin.query.ts +2 -5
- package/src/interfaces/ICreateOrderParams.ts +2 -0
- package/src/interfaces/IFee.ts +2 -0
- package/src/interfaces/IOrder.ts +3 -1
- package/src/interfaces/IOrderQuery.ts +1 -0
- package/src/interfaces/IOrderSummary.ts +1 -0
- package/src/interfaces/IPagination.ts +6 -7
- package/src/interfaces/IRefundModal.ts +1 -0
- package/src/interfaces/ISeason.ts +1 -0
- package/src/proto/email.proto +9 -0
- package/src/proto/event.proto +1 -3
- package/src/proto/fee.proto +1 -0
- package/src/proto/order.proto +39 -1
- package/src/schemas/Order.ts +84 -0
- package/src/utils/AnalyticsUtil.ts +141 -58
- package/src/utils/OrderUtil.ts +128 -219
- package/src/utils/PaymentUtil.ts +190 -290
package/src/utils/PaymentUtil.ts
CHANGED
|
@@ -10,6 +10,7 @@ import IFee, {
|
|
|
10
10
|
FeeAppliedByEnum
|
|
11
11
|
} from "../interfaces/IFee";
|
|
12
12
|
import { PaymentMethodTypeEnum } from "../enums/PaymentMethodTypeEnum";
|
|
13
|
+
// import Fee from "src/schemas/Fee";
|
|
13
14
|
|
|
14
15
|
interface IPaymentCalculatorParams {
|
|
15
16
|
tickets: ICreateOrderTicketParams[];
|
|
@@ -134,7 +135,7 @@ class PaymentUtil {
|
|
|
134
135
|
// };
|
|
135
136
|
// },
|
|
136
137
|
|
|
137
|
-
calculatePaymentTotal(params: IPaymentCalculatorParams):
|
|
138
|
+
calculatePaymentTotal(params: IPaymentCalculatorParams): any {
|
|
138
139
|
let { tickets = [], upgrades = [], fees = [], paymentMethodType } = params;
|
|
139
140
|
|
|
140
141
|
// No items, total is always 0
|
|
@@ -151,6 +152,10 @@ class PaymentUtil {
|
|
|
151
152
|
return false;
|
|
152
153
|
}
|
|
153
154
|
|
|
155
|
+
if (fee.appliedBy == FeeAppliedByEnum.Stripe && paymentMethodType == PaymentMethodTypeEnum.Cash) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
154
159
|
// Ignore card entry fees for non card entry payemnts
|
|
155
160
|
if (
|
|
156
161
|
fee.filters &&
|
|
@@ -167,12 +172,13 @@ class PaymentUtil {
|
|
|
167
172
|
(fee: IFee) =>
|
|
168
173
|
fee.filters && fee.filters[0] == FeeFiltersEnum.GuestTicket
|
|
169
174
|
);
|
|
170
|
-
|
|
175
|
+
|
|
171
176
|
fees = fees.filter(
|
|
172
177
|
(fee: IFee) =>
|
|
173
178
|
fee.filters && fee.filters[0] !== FeeFiltersEnum.GuestTicket
|
|
174
179
|
);
|
|
175
180
|
|
|
181
|
+
|
|
176
182
|
function applyGuestTicketFee(
|
|
177
183
|
ticket: ICreateOrderTicketParams,
|
|
178
184
|
fee: IFee
|
|
@@ -181,12 +187,12 @@ class PaymentUtil {
|
|
|
181
187
|
if (
|
|
182
188
|
fee.filters &&
|
|
183
189
|
fee.filters.includes(FeeFiltersEnum.Seated) &&
|
|
184
|
-
!ticket.seat
|
|
190
|
+
!ticket.seat
|
|
185
191
|
) {
|
|
186
192
|
return 0;
|
|
187
193
|
}
|
|
188
194
|
|
|
189
|
-
if(!ticket.guestTicket){
|
|
195
|
+
if (!ticket.guestTicket) {
|
|
190
196
|
return 0;
|
|
191
197
|
}
|
|
192
198
|
|
|
@@ -206,262 +212,189 @@ class PaymentUtil {
|
|
|
206
212
|
|
|
207
213
|
return 0;
|
|
208
214
|
}
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
// Fees applied
|
|
216
|
+
const ticketFeesPromotersFlat = fees
|
|
217
|
+
.filter((f) => f.appliedTo === FeeAppliedToEnum.Ticket &&
|
|
218
|
+
f.appliedBy == FeeAppliedByEnum.Organization && f.type === FeeTypeEnum.Flat)
|
|
219
|
+
const ticketFeesPromotersPercent = fees
|
|
220
|
+
.filter((f) => f.appliedTo === FeeAppliedToEnum.Ticket &&
|
|
221
|
+
f.appliedBy == FeeAppliedByEnum.Organization && f.type === FeeTypeEnum.Percent);
|
|
222
|
+
|
|
223
|
+
const upgradeFeesPromotersFees = fees.filter(
|
|
224
|
+
(f) => f.appliedTo === FeeAppliedToEnum.Upgrade && f.appliedBy == FeeAppliedByEnum.Organization
|
|
225
|
+
);
|
|
219
226
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
const upgradeFeesSelloutFees = fees.filter(
|
|
228
|
+
(f) => f.appliedTo === FeeAppliedToEnum.Upgrade && f.appliedBy == FeeAppliedByEnum.Sellout
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const selloutFees: any = fees.filter(
|
|
232
|
+
(f) => f.appliedBy == FeeAppliedByEnum.Sellout
|
|
233
|
+
// (f) => f.appliedTo === FeeAppliedToEnum.Upgrade && f.appliedBy == FeeAppliedByEnum.Sellout
|
|
234
|
+
);
|
|
235
|
+
// sales tax fee
|
|
236
|
+
const salesTaxFees = fees.find((f) => f.name == "Sales tax");
|
|
237
|
+
const stripeFees = fees.filter(
|
|
238
|
+
(f) => f.appliedBy == FeeAppliedByEnum.Stripe
|
|
229
239
|
);
|
|
230
240
|
// Orders mattes here. Flat type fees must be applied before Percent type fees
|
|
231
|
-
const
|
|
241
|
+
const promoterOrderFees = fees
|
|
232
242
|
.filter(
|
|
233
|
-
(f) => f.appliedTo === FeeAppliedToEnum.Order && f.name != "Sales tax"
|
|
243
|
+
(f) => f.appliedTo === FeeAppliedToEnum.Order && f.name != "Sales tax" && f.appliedBy == FeeAppliedByEnum.Organization
|
|
234
244
|
)
|
|
235
245
|
.sort(({ type }) => {
|
|
236
246
|
if (type === "Flat") return -1;
|
|
237
247
|
else return 1;
|
|
238
248
|
});
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
function applyTicketFee(
|
|
242
|
-
ticket: ICreateOrderTicketParams,
|
|
243
|
-
fee: IFee
|
|
244
|
-
): number {
|
|
245
|
-
// Ignore seated fees if not seated
|
|
246
|
-
if (
|
|
247
|
-
fee.filters &&
|
|
248
|
-
fee.filters.includes(FeeFiltersEnum.Seated) &&
|
|
249
|
-
!ticket.seat
|
|
250
|
-
) {
|
|
251
|
-
return 0;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const minFee = fee.minAppliedToPrice || 0;
|
|
255
|
-
const maxFee = fee.maxAppliedToPrice || Infinity;
|
|
256
|
-
|
|
257
|
-
if (minFee <= ticket.price && ticket.price <= maxFee) {
|
|
258
|
-
if (fee.type === FeeTypeEnum.Flat) {
|
|
259
|
-
return fee.value;
|
|
260
|
-
}
|
|
261
|
-
if (fee.type === FeeTypeEnum.Percent) {
|
|
262
|
-
return (ticket.price * fee.value) / 100;
|
|
263
|
-
}
|
|
264
|
-
} else {
|
|
265
|
-
return 0;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return 0;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function applyUpgradeFee(
|
|
272
|
-
upgrade: ICreateOrderUpgradeParams,
|
|
273
|
-
fee: IFee
|
|
274
|
-
): number {
|
|
275
|
-
const minFee = fee.minAppliedToPrice || 0;
|
|
276
|
-
const maxFee = fee.maxAppliedToPrice || Infinity;
|
|
277
|
-
|
|
278
|
-
if (minFee <= upgrade.price && upgrade.price <= maxFee) {
|
|
279
|
-
if (fee.type === FeeTypeEnum.Flat) {
|
|
280
|
-
return upgrade.price + fee.value;
|
|
281
|
-
}
|
|
282
|
-
if (fee.type === FeeTypeEnum.Percent) {
|
|
283
|
-
return (upgrade.price * fee.value) / 100;
|
|
284
|
-
}
|
|
285
|
-
} else {
|
|
286
|
-
return 0;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return 0;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function applyOrderFee(orderSubtotal, fee) {
|
|
293
|
-
if (fee.type === FeeTypeEnum.Flat) {
|
|
294
|
-
return orderSubtotal + fee.value;
|
|
295
|
-
}
|
|
296
|
-
if (fee.type === FeeTypeEnum.Percent) {
|
|
297
|
-
return orderSubtotal / (1 - fee.value / 100);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
249
|
+
// Caclualtions
|
|
301
250
|
const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price, 0);
|
|
302
|
-
|
|
251
|
+
const upgradeTotal = upgrades.reduce((cur, upgrade) => cur + upgrade.price, 0);
|
|
252
|
+
const totalTicketAndUpgrades = ticketTotal + upgradeTotal
|
|
303
253
|
|
|
304
|
-
const
|
|
254
|
+
const promoterFeeFlatPerOrderTotal = promoterOrderFees.reduce((acc, fee: any) => {
|
|
255
|
+
return fee.type == FeeTypeEnum.Flat ? (acc + getFeeAmount(fee)) : acc
|
|
256
|
+
}, 0)
|
|
257
|
+
|
|
258
|
+
const promoterFeeFlatPerTicketTotal = tickets.reduce((cur, ticket) => {
|
|
305
259
|
return (
|
|
306
260
|
cur +
|
|
307
|
-
|
|
261
|
+
ticketFeesPromotersFlat.reduce((cur, fee) => {
|
|
308
262
|
const value = cur + applyTicketFee(ticket, fee);
|
|
309
263
|
return value;
|
|
310
264
|
}, 0)
|
|
311
265
|
);
|
|
312
266
|
}, 0);
|
|
313
|
-
|
|
267
|
+
|
|
268
|
+
const promoterFeeFlatPerUpgradeTotal = upgrades.reduce((cur, upgrade) => {
|
|
314
269
|
return (
|
|
315
270
|
cur +
|
|
316
|
-
|
|
317
|
-
const value = cur +
|
|
271
|
+
upgradeFeesPromotersFees.reduce((cur, fee) => {
|
|
272
|
+
const value = cur + applyUpgradeFee(upgrade, fee);
|
|
318
273
|
return value;
|
|
319
274
|
}, 0)
|
|
320
275
|
);
|
|
321
276
|
}, 0);
|
|
322
277
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const upgradeTotal = upgrades.reduce(
|
|
327
|
-
(cur, upgrade) => cur + upgrade.price,
|
|
328
|
-
0
|
|
329
|
-
);
|
|
330
|
-
|
|
331
|
-
const upgradeTaxFeeTotal = upgrades.reduce((cur, upgrade) => {
|
|
278
|
+
const SelloutFeeFlatPerUpgradeTotal = upgrades.reduce((cur, upgrade) => {
|
|
332
279
|
return (
|
|
333
280
|
cur +
|
|
334
|
-
|
|
281
|
+
upgradeFeesSelloutFees.reduce((cur, fee) => {
|
|
282
|
+
const value = cur + applyUpgradeFee(upgrade, fee);
|
|
283
|
+
return value;
|
|
284
|
+
}, 0)
|
|
335
285
|
);
|
|
336
286
|
}, 0);
|
|
337
287
|
|
|
338
|
-
const
|
|
288
|
+
const promoterFeePercentPerTicketTotal = tickets.reduce((cur, ticket) => {
|
|
339
289
|
return (
|
|
340
290
|
cur +
|
|
341
|
-
|
|
291
|
+
ticketFeesPromotersPercent.reduce((cur, fee) => {
|
|
292
|
+
const value = cur + applyTicketFee(ticket, fee);
|
|
293
|
+
return value;
|
|
294
|
+
}, 0)
|
|
342
295
|
);
|
|
343
296
|
}, 0);
|
|
344
|
-
const orderSubtotal = Math.round(
|
|
345
|
-
ticketTotal +
|
|
346
|
-
ticketTaxFeeTotal +
|
|
347
|
-
// ticketFeeTotal +
|
|
348
|
-
ticketFeeTotal +
|
|
349
|
-
upgradeTaxFeeTotal + ticketGuestFeeTotal +
|
|
350
|
-
upgradeTotal +
|
|
351
|
-
upgradeFeeTotal
|
|
352
|
-
);
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const orderTotal = orderFees.reduce((cur, fee) => {
|
|
356
|
-
return applyOrderFee(cur, fee);
|
|
357
|
-
}, orderSubtotal);
|
|
358
297
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
calculatePaymentTotalDublicate(params: IPaymentCalculatorParams): number {
|
|
364
|
-
let { tickets = [], upgrades = [], fees = [], paymentMethodType } = params;
|
|
365
|
-
|
|
366
|
-
// No items, total is always 0
|
|
367
|
-
if (!tickets.length && !upgrades.length) return 0;
|
|
368
|
-
|
|
369
|
-
// Filter fees
|
|
370
|
-
fees = fees.filter((fee: IFee) => {
|
|
371
|
-
// Ignore card reader fees for non card reader payemnts
|
|
372
|
-
if (
|
|
373
|
-
fee.filters &&
|
|
374
|
-
fee.filters.includes(FeeFiltersEnum.CardReader) &&
|
|
375
|
-
paymentMethodType !== PaymentMethodTypeEnum.CardReader
|
|
376
|
-
) {
|
|
377
|
-
return false;
|
|
298
|
+
const promoterFeePercentPerOrder = promoterOrderFees.reduce((acc, fee) => {
|
|
299
|
+
if (fee.type == FeeTypeEnum.Percent) {
|
|
300
|
+
return acc + getFeeAmount(fee, totalTicketAndUpgrades)
|
|
378
301
|
}
|
|
302
|
+
return acc
|
|
303
|
+
}, 0)
|
|
379
304
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
305
|
+
const ticketGuestFeeTotalForPromoter = tickets.reduce((cur, ticket) => {
|
|
306
|
+
return (
|
|
307
|
+
cur +
|
|
308
|
+
guestFees.reduce((cur, fee) => {
|
|
309
|
+
const value = fee.appliedBy == FeeAppliedByEnum.Organization ? cur + applyGuestTicketFee(ticket, fee) : 0;
|
|
310
|
+
return value;
|
|
311
|
+
}, 0)
|
|
312
|
+
);
|
|
313
|
+
}, 0);
|
|
388
314
|
|
|
389
|
-
|
|
390
|
-
|
|
315
|
+
const ticketGuestFeeTotalForSellout = tickets.reduce((cur, ticket) => {
|
|
316
|
+
return (
|
|
317
|
+
cur +
|
|
318
|
+
guestFees.reduce((cur, fee) => {
|
|
319
|
+
const value = fee.appliedBy == FeeAppliedByEnum.Sellout ? cur + applyGuestTicketFee(ticket, fee) : 0;
|
|
320
|
+
return value;
|
|
321
|
+
}, 0)
|
|
322
|
+
);
|
|
323
|
+
}, 0);
|
|
391
324
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
)
|
|
325
|
+
const orderSubtotal = Math.round(
|
|
326
|
+
ticketTotal +
|
|
327
|
+
upgradeTotal +
|
|
328
|
+
promoterFeeFlatPerTicketTotal +
|
|
329
|
+
promoterFeeFlatPerOrderTotal +
|
|
330
|
+
promoterFeePercentPerTicketTotal +
|
|
331
|
+
promoterFeePercentPerOrder +
|
|
332
|
+
ticketGuestFeeTotalForPromoter + promoterFeeFlatPerUpgradeTotal
|
|
333
|
+
)
|
|
334
|
+
const salesTaxAmount = salesTaxFees ? (orderSubtotal * salesTaxFees.value) / 100 : 0;
|
|
401
335
|
|
|
402
|
-
|
|
403
|
-
ticket: ICreateOrderTicketParams,
|
|
404
|
-
fee: IFee
|
|
405
|
-
): number {
|
|
406
|
-
// Ignore seated fees if not seated
|
|
407
|
-
if (
|
|
408
|
-
fee.filters &&
|
|
409
|
-
fee.filters.includes(FeeFiltersEnum.Seated) &&
|
|
410
|
-
!ticket.seat
|
|
411
|
-
) {
|
|
412
|
-
return 0;
|
|
413
|
-
}
|
|
336
|
+
const promoterTotal = orderSubtotal + salesTaxAmount;
|
|
414
337
|
|
|
415
|
-
|
|
416
|
-
|
|
338
|
+
const selloutPercentFeesAmt = selloutFees.reduce((acc, fee) => {
|
|
339
|
+
if (fee.type == FeeTypeEnum.Percent) {
|
|
340
|
+
return acc + getFeeAmount(fee, promoterTotal)
|
|
417
341
|
}
|
|
342
|
+
return acc
|
|
343
|
+
}, 0)
|
|
418
344
|
|
|
419
|
-
|
|
420
|
-
|
|
345
|
+
const selloutFeeFlatPerTicketAmt = tickets.reduce((cur: number, ticket: any) => {
|
|
346
|
+
return (
|
|
347
|
+
cur +
|
|
348
|
+
selloutFees.reduce((cur: number, fee: IFee) => {
|
|
349
|
+
if (fee.type == FeeTypeEnum.Flat && fee.appliedTo === FeeAppliedToEnum.Ticket &&
|
|
350
|
+
!fee?.filters?.includes(FeeFiltersEnum.Seated)
|
|
351
|
+
) {
|
|
352
|
+
const value = cur + applyTicketFee(ticket, fee);
|
|
353
|
+
return value;
|
|
354
|
+
}
|
|
355
|
+
return cur
|
|
356
|
+
}, 0)
|
|
357
|
+
);
|
|
358
|
+
}, 0);
|
|
421
359
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
if (fee.type === FeeTypeEnum.Percent) {
|
|
427
|
-
return (ticket.price * fee.value) / 100;
|
|
428
|
-
}
|
|
429
|
-
} else {
|
|
430
|
-
return 0;
|
|
360
|
+
const selloutFeeFlatPerOrderAmt = selloutFees.reduce((cur: number, fee: IFee) => {
|
|
361
|
+
if (fee.type === FeeTypeEnum.Flat && fee.appliedTo === FeeAppliedToEnum.Order) {
|
|
362
|
+
const value = cur + fee.value;
|
|
363
|
+
return value;
|
|
431
364
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const ticketGuestFeeTotal = tickets.reduce((cur, ticket) => {
|
|
365
|
+
return cur
|
|
366
|
+
}, 0)
|
|
367
|
+
const selloutSeatedFeeAmt = tickets.reduce((cur: number, ticket: any) => {
|
|
437
368
|
return (
|
|
438
369
|
cur +
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
370
|
+
selloutFees.reduce((cur: number, fee: IFee) => {
|
|
371
|
+
if (fee.type == FeeTypeEnum.Flat && fee.appliedTo === FeeAppliedToEnum.Ticket &&
|
|
372
|
+
fee?.filters?.includes(FeeFiltersEnum.Seated)
|
|
373
|
+
) {
|
|
374
|
+
const value = cur + applyTicketFee(ticket, fee);
|
|
375
|
+
return value;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return cur
|
|
379
|
+
|
|
442
380
|
}, 0)
|
|
443
381
|
);
|
|
444
382
|
}, 0);
|
|
445
383
|
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
});
|
|
452
|
-
const upgradeFees = fees.filter(
|
|
453
|
-
(f) => f.appliedTo === FeeAppliedToEnum.Upgrade
|
|
454
|
-
);
|
|
455
|
-
// Orders mattes here. Flat type fees must be applied before Percent type fees
|
|
456
|
-
const orderFees = fees
|
|
457
|
-
.filter(
|
|
458
|
-
(f) => f.appliedTo === FeeAppliedToEnum.Order && f.name != "Sales tax"
|
|
384
|
+
const selloutFeesTotal = Math.round(
|
|
385
|
+
selloutPercentFeesAmt +
|
|
386
|
+
selloutFeeFlatPerTicketAmt +
|
|
387
|
+
selloutFeeFlatPerOrderAmt +
|
|
388
|
+
selloutSeatedFeeAmt + ticketGuestFeeTotalForSellout + SelloutFeeFlatPerUpgradeTotal
|
|
459
389
|
)
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
const
|
|
390
|
+
const preStripeTotal = promoterTotal + selloutFeesTotal
|
|
391
|
+
|
|
392
|
+
let stripeFeeAmt = 0
|
|
393
|
+
|
|
394
|
+
const stripeFeePercentage = stripeFees.find(fee => fee.type == FeeTypeEnum.Percent)?.value || 0
|
|
395
|
+
const stripeFeeFlat = stripeFees.find(fee => fee.type == FeeTypeEnum.Flat)?.value || 0
|
|
396
|
+
stripeFeeAmt = (preStripeTotal + (stripeFeeFlat)) / (1 - (stripeFeePercentage / 100)) - preStripeTotal
|
|
397
|
+
// stripeFeeAmt = ((preStripeTotal + (stripeFeeFlat)) * (stripeFeePercentage / 100)) - preStripeTotal
|
|
465
398
|
|
|
466
399
|
function applyTicketFee(
|
|
467
400
|
ticket: ICreateOrderTicketParams,
|
|
@@ -502,7 +435,8 @@ class PaymentUtil {
|
|
|
502
435
|
|
|
503
436
|
if (minFee <= upgrade.price && upgrade.price <= maxFee) {
|
|
504
437
|
if (fee.type === FeeTypeEnum.Flat) {
|
|
505
|
-
return upgrade.price + fee.value;
|
|
438
|
+
// return upgrade.price + fee.value;
|
|
439
|
+
return fee.value;
|
|
506
440
|
}
|
|
507
441
|
if (fee.type === FeeTypeEnum.Percent) {
|
|
508
442
|
return (upgrade.price * fee.value) / 100;
|
|
@@ -514,100 +448,62 @@ class PaymentUtil {
|
|
|
514
448
|
return 0;
|
|
515
449
|
}
|
|
516
450
|
|
|
517
|
-
|
|
451
|
+
// return Calculated fees amount based on type
|
|
452
|
+
function getFeeAmount(fee, amt = 0) {
|
|
518
453
|
if (fee.type === FeeTypeEnum.Flat) {
|
|
519
|
-
return
|
|
454
|
+
return fee.value;
|
|
520
455
|
}
|
|
521
456
|
if (fee.type === FeeTypeEnum.Percent) {
|
|
522
|
-
return
|
|
457
|
+
return amt * (fee.value / 100);
|
|
523
458
|
}
|
|
524
459
|
}
|
|
525
|
-
|
|
526
|
-
|
|
460
|
+
let promoterFeeAmount = promoterFeeFlatPerTicketTotal + promoterFeeFlatPerOrderTotal + promoterFeePercentPerTicketTotal +
|
|
461
|
+
promoterFeePercentPerOrder + ticketGuestFeeTotalForPromoter + promoterFeeFlatPerUpgradeTotal;
|
|
527
462
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
)
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
// ticketFees.reduce((cur, fee) => {
|
|
543
|
-
// const value = cur + applyTicketFee(ticket, fee);
|
|
544
|
-
// return value;
|
|
545
|
-
// }, 0)
|
|
546
|
-
// );
|
|
547
|
-
// }, 0);
|
|
548
|
-
|
|
549
|
-
// applyGuestTicketFee
|
|
550
|
-
|
|
463
|
+
|
|
464
|
+
let total = {
|
|
465
|
+
salesTax: Math.round(salesTaxAmount || 0),
|
|
466
|
+
total: Math.round((preStripeTotal + stripeFeeAmt) || 0),
|
|
467
|
+
promoterFees: Math.round((promoterFeeAmount) || 0),
|
|
468
|
+
stripeFees: Math.round(stripeFeeAmt || 0),
|
|
469
|
+
selloutFees: Math.round(selloutFeesTotal || 0),
|
|
470
|
+
orderSubtotal: Math.round(orderSubtotal || 0),
|
|
471
|
+
subTotal: Math.round(totalTicketAndUpgrades || 0),
|
|
472
|
+
totalFees: Math.round((promoterFeeAmount + stripeFeeAmt + selloutFeesTotal + salesTaxAmount) || 0),
|
|
473
|
+
totalWithoutTaxFees: Math.round((promoterFeeAmount + stripeFeeAmt + selloutFeesTotal) || 0)
|
|
474
|
+
}
|
|
475
|
+
return total
|
|
476
|
+
}
|
|
551
477
|
|
|
552
478
|
|
|
479
|
+
calculatePaymentSubtotal(params: IPaymentCalculatorParams): number {
|
|
480
|
+
let {
|
|
481
|
+
tickets = [],
|
|
482
|
+
upgrades = [],
|
|
483
|
+
paymentMethodType,
|
|
484
|
+
// fees
|
|
485
|
+
} = params;
|
|
553
486
|
|
|
554
|
-
|
|
555
|
-
return (
|
|
556
|
-
cur +
|
|
557
|
-
ticketFees.reduce((cur, fee) => {
|
|
558
|
-
const value = cur + applyTicketFee(ticket, fee);
|
|
559
|
-
return value;
|
|
560
|
-
}, 0)
|
|
561
|
-
);
|
|
562
|
-
}, 0);
|
|
487
|
+
if (paymentMethodType === PaymentMethodTypeEnum.None) return 0;
|
|
563
488
|
|
|
489
|
+
const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price, 0); // + (ticket.price * tax/100)
|
|
564
490
|
const upgradeTotal = upgrades.reduce(
|
|
565
491
|
(cur, upgrade) => cur + upgrade.price,
|
|
566
492
|
0
|
|
567
|
-
);
|
|
568
|
-
|
|
569
|
-
const upgradeTaxFeeTotal = upgrades.reduce((cur, upgrade) => {
|
|
570
|
-
return (
|
|
571
|
-
cur +
|
|
572
|
-
salesTax.reduce((curr, fee) => curr + applyUpgradeFee(upgrade, fee), 0)
|
|
573
|
-
);
|
|
574
|
-
}, 0);
|
|
575
|
-
|
|
576
|
-
const upgradeFeeTotal = upgrades.reduce((cur, upgrade) => {
|
|
577
|
-
return (
|
|
578
|
-
cur +
|
|
579
|
-
upgradeFees.reduce((cur, fee) => cur + applyUpgradeFee(upgrade, fee), 0)
|
|
580
|
-
);
|
|
581
|
-
}, 0);
|
|
582
|
-
const orderSubtotal = Math.round(
|
|
583
|
-
ticketTotal +
|
|
584
|
-
ticketTaxFeeTotal +
|
|
585
|
-
ticketFeeTotal +
|
|
586
|
-
upgradeTaxFeeTotal + ticketGuestFeeTotal +
|
|
587
|
-
upgradeTotal +
|
|
588
|
-
upgradeFeeTotal
|
|
589
|
-
);
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
const orderTotal = orderFees.reduce((cur, fee) => {
|
|
593
|
-
return applyOrderFee(cur, fee);
|
|
594
|
-
}, orderSubtotal);
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
return Math.round(orderTotal);
|
|
493
|
+
); // + (upgrade.price * tax/100)
|
|
494
|
+
return ticketTotal + upgradeTotal;
|
|
598
495
|
}
|
|
599
496
|
|
|
600
497
|
|
|
601
|
-
|
|
602
|
-
calculatePaymentSubtotal(params: IPaymentCalculatorParams): number {
|
|
498
|
+
calculatePaymentSubtotalValue(params: any): number {
|
|
603
499
|
let {
|
|
604
500
|
tickets = [],
|
|
605
501
|
upgrades = [],
|
|
606
|
-
paymentMethodType,
|
|
502
|
+
// paymentMethodType,
|
|
607
503
|
// fees
|
|
608
504
|
} = params;
|
|
609
505
|
|
|
610
|
-
if (paymentMethodType === PaymentMethodTypeEnum.None) return 0;
|
|
506
|
+
// if (paymentMethodType === PaymentMethodTypeEnum.None) return 0;
|
|
611
507
|
|
|
612
508
|
const ticketTotal = tickets.reduce((cur, ticket) => cur + ticket.price, 0); // + (ticket.price * tax/100)
|
|
613
509
|
const upgradeTotal = upgrades.reduce(
|
|
@@ -616,20 +512,24 @@ class PaymentUtil {
|
|
|
616
512
|
); // + (upgrade.price * tax/100)
|
|
617
513
|
return ticketTotal + upgradeTotal;
|
|
618
514
|
}
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
619
518
|
calculateFee(params: IPaymentCalculatorParams): number {
|
|
620
519
|
let { fees } = params;
|
|
621
520
|
const salesTax = fees.filter((f) => f.name == "Sales tax");
|
|
622
521
|
const tax = salesTax.length > 0 ? salesTax[0].value : 0;
|
|
623
|
-
const total = this.calculatePaymentTotal(params);
|
|
522
|
+
const total = this.calculatePaymentTotal(params).total;
|
|
624
523
|
let subtotal = this.calculatePaymentSubtotal(params);
|
|
625
524
|
subtotal = subtotal + (subtotal * tax) / 100;
|
|
626
525
|
return Math.round(total - subtotal);
|
|
627
526
|
}
|
|
628
527
|
|
|
629
|
-
calculateFeeWithoutTax(params: IPaymentCalculatorParams):
|
|
528
|
+
calculateFeeWithoutTax(params: IPaymentCalculatorParams): any {
|
|
630
529
|
const total = this.calculatePaymentTotal(params);
|
|
631
|
-
let subtotal = this.calculatePaymentSubtotal(params);
|
|
632
|
-
return Math.round(total - subtotal);
|
|
530
|
+
// let subtotal = this.calculatePaymentSubtotal(params);
|
|
531
|
+
// return Math.round(total - subtotal);
|
|
532
|
+
return total
|
|
633
533
|
}
|
|
634
534
|
calculateOrganizationFee(params: IPaymentCalculatorParams): number {
|
|
635
535
|
let { tickets = [], upgrades = [], fees = [], paymentMethodType } = params;
|
|
@@ -667,14 +567,14 @@ class PaymentUtil {
|
|
|
667
567
|
});
|
|
668
568
|
}
|
|
669
569
|
calculateStripeFee(params: IPaymentCalculatorParams): number {
|
|
670
|
-
const total = this.calculatePaymentTotal(params);
|
|
570
|
+
const total = this.calculatePaymentTotal(params).total;
|
|
671
571
|
const subtotal = this.calculatePaymentSubtotal(params);
|
|
672
572
|
const platformFees = this.calculatePlatformFee(params);
|
|
673
573
|
const organizationFee = this.calculateOrganizationFee(params);
|
|
674
574
|
return total - subtotal - platformFees - organizationFee;
|
|
675
575
|
}
|
|
676
576
|
calculateProcessingFee(params: IPaymentCalculatorParams): number {
|
|
677
|
-
const total = this.calculatePaymentTotal(params);
|
|
577
|
+
const total = this.calculatePaymentTotal(params).total;
|
|
678
578
|
const subtotal = this.calculatePaymentSubtotal(params);
|
|
679
579
|
const organizationFee = this.calculateOrganizationFee(params);
|
|
680
580
|
return total - subtotal - organizationFee;
|
|
@@ -686,7 +586,7 @@ class PaymentUtil {
|
|
|
686
586
|
// }
|
|
687
587
|
|
|
688
588
|
calculateGuestFee(tickets: any, event: any): number {
|
|
689
|
-
|
|
589
|
+
|
|
690
590
|
let guestTicketFees = event?.fees.filter(
|
|
691
591
|
(fee: IFee) =>
|
|
692
592
|
fee.filters && fee.filters[0] === FeeFiltersEnum.GuestTicket
|
|
@@ -702,10 +602,10 @@ class PaymentUtil {
|
|
|
702
602
|
let guestMembers = tickets.filter((a) => a.guestTicket).length;
|
|
703
603
|
let guestFees = (guestFeesValue as number) * guestMembers;
|
|
704
604
|
return guestTicketFees.length > 0 && event.organization.isTegIntegration
|
|
705
|
-
? guestFees + guestFees * stripeFeesValue/100
|
|
605
|
+
? guestFees + guestFees * stripeFeesValue / 100
|
|
706
606
|
: 0;
|
|
707
607
|
}
|
|
708
|
-
|
|
608
|
+
|
|
709
609
|
}
|
|
710
610
|
|
|
711
611
|
export default new PaymentUtil();
|