@bash-app/bash-common 30.219.0 → 30.220.0
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/definitions.d.ts +2 -2
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js.map +1 -1
- package/dist/extendedSchemas.d.ts +14 -1
- package/dist/extendedSchemas.d.ts.map +1 -1
- package/dist/extendedSchemas.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/partnerStoreTypes.d.ts +37 -0
- package/dist/partnerStoreTypes.d.ts.map +1 -0
- package/dist/partnerStoreTypes.js +2 -0
- package/dist/partnerStoreTypes.js.map +1 -0
- package/dist/utils/__tests__/paymentUtils.test.js +54 -1
- package/dist/utils/__tests__/paymentUtils.test.js.map +1 -1
- package/dist/utils/paymentUtils.d.ts +37 -0
- package/dist/utils/paymentUtils.d.ts.map +1 -1
- package/dist/utils/paymentUtils.js +61 -0
- package/dist/utils/paymentUtils.js.map +1 -1
- package/package.json +2 -2
- package/prisma/schema.prisma +155 -1
- package/src/definitions.ts +7 -2
- package/src/extendedSchemas.ts +17 -0
- package/src/index.ts +5 -0
- package/src/partnerStoreTypes.ts +36 -0
- package/src/utils/__tests__/paymentUtils.test.ts +65 -0
- package/src/utils/paymentUtils.ts +88 -0
|
@@ -15,6 +15,10 @@ import {
|
|
|
15
15
|
calculateTotalBashPoints,
|
|
16
16
|
calculateStripeDonationFee,
|
|
17
17
|
calculateServiceFeeWithMembershipDiscount,
|
|
18
|
+
calculateBashPlatformFeeCents,
|
|
19
|
+
splitBashPlatformFeeForTicketCheckout,
|
|
20
|
+
computeTicketApplicationFeeAmountCents,
|
|
21
|
+
userHasActiveBashPass,
|
|
18
22
|
} from "../paymentUtils.js";
|
|
19
23
|
|
|
20
24
|
describe("PaymentUtils - Core Functions", () => {
|
|
@@ -93,6 +97,67 @@ describe("PaymentUtils - Core Functions", () => {
|
|
|
93
97
|
test("calculateStripeFee (dollars) aligns with calculateStripeProcessingFeeCents", () => {
|
|
94
98
|
expect(calculateStripeFee(100)).toBe(3.2);
|
|
95
99
|
});
|
|
100
|
+
|
|
101
|
+
test("calculateBashPlatformFeeCents floors 3% of gross", () => {
|
|
102
|
+
expect(calculateBashPlatformFeeCents(10000, 0.03)).toBe(300);
|
|
103
|
+
expect(calculateBashPlatformFeeCents(100, 0.03)).toBe(3);
|
|
104
|
+
expect(calculateBashPlatformFeeCents(0, 0.03)).toBe(0);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("splitBashPlatformFeeForTicketCheckout respects feeHandling and BashPass", () => {
|
|
108
|
+
const base = {
|
|
109
|
+
grossCents: 10000,
|
|
110
|
+
platformFeeEnabled: true,
|
|
111
|
+
platformFeeRate: 0.03,
|
|
112
|
+
};
|
|
113
|
+
expect(splitBashPlatformFeeForTicketCheckout({ ...base, feeHandling: "HostAbsorbs", bashPassWaivesGuestFee: false })).toEqual({
|
|
114
|
+
totalPlatformCents: 300,
|
|
115
|
+
guestPlatformLineCents: 0,
|
|
116
|
+
});
|
|
117
|
+
expect(splitBashPlatformFeeForTicketCheckout({ ...base, feeHandling: "GuestPays", bashPassWaivesGuestFee: false })).toEqual({
|
|
118
|
+
totalPlatformCents: 300,
|
|
119
|
+
guestPlatformLineCents: 300,
|
|
120
|
+
});
|
|
121
|
+
expect(splitBashPlatformFeeForTicketCheckout({ ...base, feeHandling: "Split", bashPassWaivesGuestFee: false })).toEqual({
|
|
122
|
+
totalPlatformCents: 300,
|
|
123
|
+
guestPlatformLineCents: 150,
|
|
124
|
+
});
|
|
125
|
+
expect(splitBashPlatformFeeForTicketCheckout({ ...base, feeHandling: "GuestPays", bashPassWaivesGuestFee: true })).toEqual({
|
|
126
|
+
totalPlatformCents: 300,
|
|
127
|
+
guestPlatformLineCents: 0,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("computeTicketApplicationFeeAmountCents sums Stripe + Bash platform into application fee", () => {
|
|
132
|
+
const r = computeTicketApplicationFeeAmountCents({
|
|
133
|
+
discountedSubtotalCents: 10000,
|
|
134
|
+
platformFeeEnabled: true,
|
|
135
|
+
platformFeeRate: 0.03,
|
|
136
|
+
feeHandling: "HostAbsorbs",
|
|
137
|
+
bashPassWaivesGuestFee: false,
|
|
138
|
+
});
|
|
139
|
+
expect(r.totalChargedCents).toBe(10000);
|
|
140
|
+
expect(r.bashPlatformTotalCents).toBe(300);
|
|
141
|
+
expect(r.stripeProcessingCents).toBe(calculateStripeProcessingFeeCents(10000));
|
|
142
|
+
expect(r.applicationFeeAmountCents).toBe(r.stripeProcessingCents + 300);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("userHasActiveBashPass", () => {
|
|
146
|
+
expect(userHasActiveBashPass({ bashPassStripeSubscriptionId: null, bashPassCurrentPeriodEnd: null })).toBe(false);
|
|
147
|
+
expect(userHasActiveBashPass({ bashPassStripeSubscriptionId: "sub_1", bashPassCurrentPeriodEnd: null })).toBe(true);
|
|
148
|
+
expect(
|
|
149
|
+
userHasActiveBashPass({
|
|
150
|
+
bashPassStripeSubscriptionId: "sub_1",
|
|
151
|
+
bashPassCurrentPeriodEnd: new Date(Date.now() + 86400000),
|
|
152
|
+
})
|
|
153
|
+
).toBe(true);
|
|
154
|
+
expect(
|
|
155
|
+
userHasActiveBashPass({
|
|
156
|
+
bashPassStripeSubscriptionId: "sub_1",
|
|
157
|
+
bashPassCurrentPeriodEnd: new Date(Date.now() - 86400000),
|
|
158
|
+
})
|
|
159
|
+
).toBe(false);
|
|
160
|
+
});
|
|
96
161
|
});
|
|
97
162
|
|
|
98
163
|
describe("Ticket total price (USD)", () => {
|
|
@@ -221,6 +221,94 @@ export function calculatePartnerFeeWithMembershipDiscount(
|
|
|
221
221
|
return parseFloat(calculatedFee.toFixed(2));
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Bash **platform** take rate on ticket gross (e.g. 3%). Separate from Stripe card processing pass-through.
|
|
226
|
+
*/
|
|
227
|
+
export function calculateBashPlatformFeeCents(grossCents: number, rate: number): number {
|
|
228
|
+
if (grossCents <= 0 || rate <= 0) return 0;
|
|
229
|
+
return Math.floor(grossCents * rate);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export type BashPlatformTicketFeeSplit = {
|
|
233
|
+
totalPlatformCents: number;
|
|
234
|
+
/** Shown as a separate checkout line when greater than 0 */
|
|
235
|
+
guestPlatformLineCents: number;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Split the Bash platform fee between guest line items vs host absorption using `feeHandling`.
|
|
240
|
+
* BashPass waives the **guest-visible** portion only; the host still funds the full platform fee when the guest pays nothing extra.
|
|
241
|
+
*/
|
|
242
|
+
export function splitBashPlatformFeeForTicketCheckout(args: {
|
|
243
|
+
grossCents: number;
|
|
244
|
+
platformFeeEnabled: boolean;
|
|
245
|
+
platformFeeRate: number;
|
|
246
|
+
feeHandling: string | null | undefined;
|
|
247
|
+
bashPassWaivesGuestFee: boolean;
|
|
248
|
+
}): BashPlatformTicketFeeSplit {
|
|
249
|
+
const { grossCents, platformFeeEnabled, platformFeeRate, feeHandling, bashPassWaivesGuestFee } = args;
|
|
250
|
+
const total = platformFeeEnabled
|
|
251
|
+
? calculateBashPlatformFeeCents(grossCents, platformFeeRate)
|
|
252
|
+
: 0;
|
|
253
|
+
if (total <= 0) {
|
|
254
|
+
return { totalPlatformCents: 0, guestPlatformLineCents: 0 };
|
|
255
|
+
}
|
|
256
|
+
const mode = feeHandling ?? "HostAbsorbs";
|
|
257
|
+
let guestLine = 0;
|
|
258
|
+
if (mode === "GuestPays") {
|
|
259
|
+
guestLine = total;
|
|
260
|
+
} else if (mode === "Split") {
|
|
261
|
+
guestLine = Math.floor(total / 2);
|
|
262
|
+
}
|
|
263
|
+
if (bashPassWaivesGuestFee && guestLine > 0) {
|
|
264
|
+
guestLine = 0;
|
|
265
|
+
}
|
|
266
|
+
return { totalPlatformCents: total, guestPlatformLineCents: guestLine };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function computeTicketApplicationFeeAmountCents(args: {
|
|
270
|
+
discountedSubtotalCents: number;
|
|
271
|
+
platformFeeEnabled: boolean;
|
|
272
|
+
platformFeeRate: number;
|
|
273
|
+
feeHandling: string | null | undefined;
|
|
274
|
+
bashPassWaivesGuestFee: boolean;
|
|
275
|
+
}): {
|
|
276
|
+
totalChargedCents: number;
|
|
277
|
+
stripeProcessingCents: number;
|
|
278
|
+
bashPlatformTotalCents: number;
|
|
279
|
+
applicationFeeAmountCents: number;
|
|
280
|
+
guestPlatformLineCents: number;
|
|
281
|
+
} {
|
|
282
|
+
const split = splitBashPlatformFeeForTicketCheckout({
|
|
283
|
+
grossCents: args.discountedSubtotalCents,
|
|
284
|
+
platformFeeEnabled: args.platformFeeEnabled,
|
|
285
|
+
platformFeeRate: args.platformFeeRate,
|
|
286
|
+
feeHandling: args.feeHandling,
|
|
287
|
+
bashPassWaivesGuestFee: args.bashPassWaivesGuestFee,
|
|
288
|
+
});
|
|
289
|
+
const guestPlatformLineCents = split.guestPlatformLineCents;
|
|
290
|
+
const bashPlatformTotalCents = split.totalPlatformCents;
|
|
291
|
+
const totalChargedCents = args.discountedSubtotalCents + guestPlatformLineCents;
|
|
292
|
+
const stripeProcessingCents = calculateStripeProcessingFeeCents(totalChargedCents);
|
|
293
|
+
const applicationFeeAmountCents = stripeProcessingCents + bashPlatformTotalCents;
|
|
294
|
+
return {
|
|
295
|
+
totalChargedCents,
|
|
296
|
+
stripeProcessingCents,
|
|
297
|
+
bashPlatformTotalCents,
|
|
298
|
+
applicationFeeAmountCents,
|
|
299
|
+
guestPlatformLineCents,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export function userHasActiveBashPass(user: {
|
|
304
|
+
bashPassStripeSubscriptionId: string | null | undefined;
|
|
305
|
+
bashPassCurrentPeriodEnd: Date | null | undefined;
|
|
306
|
+
}): boolean {
|
|
307
|
+
if (!user.bashPassStripeSubscriptionId) return false;
|
|
308
|
+
if (!user.bashPassCurrentPeriodEnd) return true;
|
|
309
|
+
return user.bashPassCurrentPeriodEnd > new Date();
|
|
310
|
+
}
|
|
311
|
+
|
|
224
312
|
// ============================================
|
|
225
313
|
// VENUE PRICING PLANS
|
|
226
314
|
// ============================================
|