@forklaunch/implementation-billing-stripe 0.0.1
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/LICENSE +21 -0
- package/lib/domain/index.d.mts +189 -0
- package/lib/domain/index.d.ts +189 -0
- package/lib/domain/index.js +231 -0
- package/lib/domain/index.mjs +201 -0
- package/lib/eject/domain/schemas/billingPortal.schema.ts +37 -0
- package/lib/eject/domain/schemas/checkoutSession.schema.ts +74 -0
- package/lib/eject/domain/schemas/index.ts +5 -0
- package/lib/eject/domain/schemas/paymentLink.schema.ts +62 -0
- package/lib/eject/domain/schemas/plan.schema.ts +68 -0
- package/lib/eject/domain/schemas/subscription.schema.ts +78 -0
- package/lib/eject/services/billingPortal.service.ts +185 -0
- package/lib/eject/services/checkoutSession.service.ts +179 -0
- package/lib/eject/services/index.ts +6 -0
- package/lib/eject/services/paymentLink.service.ts +239 -0
- package/lib/eject/services/plan.service.ts +219 -0
- package/lib/eject/services/subscription.service.ts +285 -0
- package/lib/eject/services/webhook.service.ts +272 -0
- package/lib/eject/types/index.ts +2 -0
- package/lib/eject/types/stripe.dto.types.ts +214 -0
- package/lib/eject/types/stripe.entity.types.ts +83 -0
- package/lib/schemas/index.d.mts +376 -0
- package/lib/schemas/index.d.ts +376 -0
- package/lib/schemas/index.js +704 -0
- package/lib/schemas/index.mjs +737 -0
- package/lib/services/index.d.mts +223 -0
- package/lib/services/index.d.ts +223 -0
- package/lib/services/index.js +788 -0
- package/lib/services/index.mjs +776 -0
- package/lib/types/index.d.mts +121 -0
- package/lib/types/index.d.ts +121 -0
- package/lib/types/index.js +18 -0
- package/lib/types/index.mjs +0 -0
- package/package.json +74 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MetricsDefinition,
|
|
3
|
+
OpenTelemetryCollector
|
|
4
|
+
} from '@forklaunch/core/http';
|
|
5
|
+
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
6
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
7
|
+
import Stripe from 'stripe';
|
|
8
|
+
import { BillingProviderEnum } from '../domain/enums/billingProvider.enum';
|
|
9
|
+
import { CurrencyEnum } from '../domain/enums/currency.enum';
|
|
10
|
+
import { PaymentMethodEnum } from '../domain/enums/paymentMethod.enum';
|
|
11
|
+
import { PlanCadenceEnum } from '../domain/enums/planCadence.enum';
|
|
12
|
+
import {
|
|
13
|
+
StripeBillingPortalEntities,
|
|
14
|
+
StripeCheckoutSessionEntities,
|
|
15
|
+
StripePaymentLinkEntities,
|
|
16
|
+
StripePlanEntities,
|
|
17
|
+
StripeSubscriptionEntities
|
|
18
|
+
} from '../types/stripe.entity.types';
|
|
19
|
+
import { StripeBillingPortalService } from './billingPortal.service';
|
|
20
|
+
import { StripeCheckoutSessionService } from './checkoutSession.service';
|
|
21
|
+
import { StripePaymentLinkService } from './paymentLink.service';
|
|
22
|
+
import { StripePlanService } from './plan.service';
|
|
23
|
+
import { StripeSubscriptionService } from './subscription.service';
|
|
24
|
+
|
|
25
|
+
export class StripeWebhookService<
|
|
26
|
+
SchemaValidator extends AnySchemaValidator,
|
|
27
|
+
StatusEnum,
|
|
28
|
+
PartyEnum,
|
|
29
|
+
BillingPortalEntities extends
|
|
30
|
+
StripeBillingPortalEntities = StripeBillingPortalEntities,
|
|
31
|
+
CheckoutSessionEntities extends
|
|
32
|
+
StripeCheckoutSessionEntities<StatusEnum> = StripeCheckoutSessionEntities<StatusEnum>,
|
|
33
|
+
PaymentLinkEntities extends
|
|
34
|
+
StripePaymentLinkEntities<StatusEnum> = StripePaymentLinkEntities<StatusEnum>,
|
|
35
|
+
PlanEntities extends StripePlanEntities = StripePlanEntities,
|
|
36
|
+
SubscriptionEntities extends
|
|
37
|
+
StripeSubscriptionEntities<PartyEnum> = StripeSubscriptionEntities<PartyEnum>
|
|
38
|
+
> {
|
|
39
|
+
constructor(
|
|
40
|
+
protected readonly stripeClient: Stripe,
|
|
41
|
+
protected readonly em: EntityManager,
|
|
42
|
+
protected readonly schemaValidator: SchemaValidator,
|
|
43
|
+
protected readonly openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
|
|
44
|
+
protected readonly billingPortalService: StripeBillingPortalService<
|
|
45
|
+
SchemaValidator,
|
|
46
|
+
BillingPortalEntities
|
|
47
|
+
>,
|
|
48
|
+
protected readonly checkoutSessionService: StripeCheckoutSessionService<
|
|
49
|
+
SchemaValidator,
|
|
50
|
+
StatusEnum,
|
|
51
|
+
CheckoutSessionEntities
|
|
52
|
+
>,
|
|
53
|
+
protected readonly paymentLinkService: StripePaymentLinkService<
|
|
54
|
+
SchemaValidator,
|
|
55
|
+
StatusEnum,
|
|
56
|
+
PaymentLinkEntities
|
|
57
|
+
>,
|
|
58
|
+
protected readonly planService: StripePlanService<
|
|
59
|
+
SchemaValidator,
|
|
60
|
+
PlanEntities
|
|
61
|
+
>,
|
|
62
|
+
protected readonly subscriptionService: StripeSubscriptionService<
|
|
63
|
+
SchemaValidator,
|
|
64
|
+
PartyEnum,
|
|
65
|
+
SubscriptionEntities
|
|
66
|
+
>
|
|
67
|
+
) {}
|
|
68
|
+
|
|
69
|
+
async handleWebhookEvent(event: Stripe.Event): Promise<void> {
|
|
70
|
+
if (this.openTelemetryCollector) {
|
|
71
|
+
this.openTelemetryCollector.info('Handling webhook event', event);
|
|
72
|
+
}
|
|
73
|
+
const eventType = event.type;
|
|
74
|
+
|
|
75
|
+
switch (eventType) {
|
|
76
|
+
case 'billing_portal.session.created': {
|
|
77
|
+
this.billingPortalService.baseBillingPortalService.createBillingPortalSession(
|
|
78
|
+
{
|
|
79
|
+
id: event.data.object.id,
|
|
80
|
+
customerId: event.data.object.customer,
|
|
81
|
+
expiresAt: new Date(event.data.object.created + 5 * 60 * 1000),
|
|
82
|
+
uri: event.data.object.url,
|
|
83
|
+
providerFields: event.data.object
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
case 'checkout.session.expired': {
|
|
90
|
+
this.checkoutSessionService.handleCheckoutFailure({
|
|
91
|
+
id: event.data.object.id
|
|
92
|
+
});
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
case 'checkout.session.completed': {
|
|
97
|
+
this.checkoutSessionService.handleCheckoutSuccess({
|
|
98
|
+
id: event.data.object.id
|
|
99
|
+
});
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
case 'payment_link.created':
|
|
104
|
+
{
|
|
105
|
+
this.paymentLinkService.basePaymentLinkService.createPaymentLink({
|
|
106
|
+
id: event.data.object.id,
|
|
107
|
+
amount:
|
|
108
|
+
event.data.object.line_items?.data.reduce<number>(
|
|
109
|
+
(total, item) => total + item.amount_total,
|
|
110
|
+
0
|
|
111
|
+
) ?? 0,
|
|
112
|
+
paymentMethods: event.data.object
|
|
113
|
+
.payment_method_types as PaymentMethodEnum[],
|
|
114
|
+
status: 'CREATED' as StatusEnum[keyof StatusEnum],
|
|
115
|
+
currency: event.data.object.currency as CurrencyEnum,
|
|
116
|
+
providerFields: event.data.object
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
|
|
121
|
+
case 'payment_link.updated': {
|
|
122
|
+
this.paymentLinkService.basePaymentLinkService.updatePaymentLink({
|
|
123
|
+
id: event.data.object.id,
|
|
124
|
+
amount:
|
|
125
|
+
event.data.object.line_items?.data.reduce<number>(
|
|
126
|
+
(total, item) => total + item.amount_total,
|
|
127
|
+
0
|
|
128
|
+
) ?? 0,
|
|
129
|
+
paymentMethods: event.data.object
|
|
130
|
+
.payment_method_types as PaymentMethodEnum[],
|
|
131
|
+
status: 'UPDATED' as StatusEnum[keyof StatusEnum],
|
|
132
|
+
currency: event.data.object.currency as CurrencyEnum,
|
|
133
|
+
providerFields: event.data.object
|
|
134
|
+
});
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
case 'plan.created': {
|
|
139
|
+
if (
|
|
140
|
+
typeof event.data.object.product === 'object' &&
|
|
141
|
+
event.data.object.product != null &&
|
|
142
|
+
event.data.object.amount != null
|
|
143
|
+
) {
|
|
144
|
+
this.planService.basePlanService.createPlan({
|
|
145
|
+
id: event.data.object.id,
|
|
146
|
+
billingProvider: BillingProviderEnum.STRIPE,
|
|
147
|
+
cadence: event.data.object.interval as PlanCadenceEnum,
|
|
148
|
+
currency: event.data.object.currency as CurrencyEnum,
|
|
149
|
+
active: true,
|
|
150
|
+
name:
|
|
151
|
+
typeof event.data.object.product === 'string'
|
|
152
|
+
? event.data.object.product
|
|
153
|
+
: event.data.object.product?.id,
|
|
154
|
+
price: event.data.object.amount,
|
|
155
|
+
externalId: event.data.object.id,
|
|
156
|
+
providerFields: event.data.object
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
throw new Error('Invalid plan');
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
case 'plan.updated': {
|
|
165
|
+
if (
|
|
166
|
+
typeof event.data.object.product === 'object' &&
|
|
167
|
+
event.data.object.product != null &&
|
|
168
|
+
event.data.object.amount != null
|
|
169
|
+
) {
|
|
170
|
+
this.planService.basePlanService.updatePlan({
|
|
171
|
+
id: event.data.object.id,
|
|
172
|
+
billingProvider: BillingProviderEnum.STRIPE,
|
|
173
|
+
cadence: event.data.object.interval as PlanCadenceEnum,
|
|
174
|
+
currency: event.data.object.currency as CurrencyEnum,
|
|
175
|
+
active: true,
|
|
176
|
+
name:
|
|
177
|
+
typeof event.data.object.product === 'string'
|
|
178
|
+
? event.data.object.product
|
|
179
|
+
: event.data.object.product?.id,
|
|
180
|
+
price: event.data.object.amount,
|
|
181
|
+
externalId: event.data.object.id,
|
|
182
|
+
providerFields: event.data.object
|
|
183
|
+
});
|
|
184
|
+
} else {
|
|
185
|
+
throw new Error('Invalid plan');
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
case 'plan.deleted': {
|
|
191
|
+
this.planService.deletePlan({
|
|
192
|
+
id: event.data.object.id
|
|
193
|
+
});
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
case 'customer.subscription.created': {
|
|
198
|
+
this.subscriptionService.baseSubscriptionService.createSubscription({
|
|
199
|
+
id: event.data.object.id,
|
|
200
|
+
partyId:
|
|
201
|
+
typeof event.data.object.customer === 'string'
|
|
202
|
+
? event.data.object.customer
|
|
203
|
+
: event.data.object.customer.id,
|
|
204
|
+
partyType: 'USER' as PartyEnum[keyof PartyEnum],
|
|
205
|
+
description: event.data.object.description ?? undefined,
|
|
206
|
+
active: true,
|
|
207
|
+
productId: event.data.object.items.data[0].plan.id,
|
|
208
|
+
providerFields: event.data.object,
|
|
209
|
+
externalId: event.data.object.id,
|
|
210
|
+
billingProvider: BillingProviderEnum.STRIPE,
|
|
211
|
+
startDate: new Date(event.data.object.created),
|
|
212
|
+
endDate: event.data.object.cancel_at
|
|
213
|
+
? new Date(event.data.object.cancel_at)
|
|
214
|
+
: new Date(Infinity),
|
|
215
|
+
status: event.data.object.status
|
|
216
|
+
});
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
case 'customer.subscription.updated': {
|
|
221
|
+
this.subscriptionService.baseSubscriptionService.updateSubscription({
|
|
222
|
+
id: event.data.object.id,
|
|
223
|
+
partyId:
|
|
224
|
+
typeof event.data.object.customer === 'string'
|
|
225
|
+
? event.data.object.customer
|
|
226
|
+
: event.data.object.customer.id,
|
|
227
|
+
partyType: 'USER' as PartyEnum[keyof PartyEnum],
|
|
228
|
+
description: event.data.object.description ?? undefined,
|
|
229
|
+
active: true,
|
|
230
|
+
providerFields: event.data.object,
|
|
231
|
+
externalId: event.data.object.id,
|
|
232
|
+
billingProvider: BillingProviderEnum.STRIPE,
|
|
233
|
+
startDate: new Date(event.data.object.created),
|
|
234
|
+
endDate: event.data.object.cancel_at
|
|
235
|
+
? new Date(event.data.object.cancel_at)
|
|
236
|
+
: new Date(Infinity),
|
|
237
|
+
productId: event.data.object.items.data[0].plan.id,
|
|
238
|
+
status: event.data.object.status
|
|
239
|
+
});
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
case 'customer.subscription.deleted': {
|
|
244
|
+
this.subscriptionService.deleteSubscription({
|
|
245
|
+
id: event.data.object.id
|
|
246
|
+
});
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
case 'customer.subscription.paused': {
|
|
251
|
+
this.subscriptionService.cancelSubscription({
|
|
252
|
+
id: event.data.object.id
|
|
253
|
+
});
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
case 'customer.subscription.resumed': {
|
|
258
|
+
this.subscriptionService.resumeSubscription({
|
|
259
|
+
id: event.data.object.id
|
|
260
|
+
});
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
default:
|
|
265
|
+
this.openTelemetryCollector.info(
|
|
266
|
+
'Unprocessed stripe event type',
|
|
267
|
+
eventType
|
|
268
|
+
);
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BillingPortalDto,
|
|
3
|
+
CheckoutSessionDto,
|
|
4
|
+
CreateBillingPortalDto,
|
|
5
|
+
CreateCheckoutSessionDto,
|
|
6
|
+
CreatePaymentLinkDto,
|
|
7
|
+
CreatePlanDto,
|
|
8
|
+
CreateSubscriptionDto,
|
|
9
|
+
PaymentLinkDto,
|
|
10
|
+
PlanDto,
|
|
11
|
+
SubscriptionDto,
|
|
12
|
+
UpdateBillingPortalDto,
|
|
13
|
+
UpdateCheckoutSessionDto,
|
|
14
|
+
UpdatePaymentLinkDto,
|
|
15
|
+
UpdatePlanDto,
|
|
16
|
+
UpdateSubscriptionDto
|
|
17
|
+
} from '@forklaunch/interfaces-billing/types';
|
|
18
|
+
import Stripe from 'stripe';
|
|
19
|
+
import { BillingProviderEnum } from '../domain/enums/billingProvider.enum';
|
|
20
|
+
import { CurrencyEnum } from '../domain/enums/currency.enum';
|
|
21
|
+
import { PaymentMethodEnum } from '../domain/enums/paymentMethod.enum';
|
|
22
|
+
import { PlanCadenceEnum } from '../domain/enums/planCadence.enum';
|
|
23
|
+
|
|
24
|
+
// Billing Portal Types
|
|
25
|
+
type BillingPortalOmissions = 'customer';
|
|
26
|
+
|
|
27
|
+
export type StripeCreateBillingPortalDto = Omit<
|
|
28
|
+
CreateBillingPortalDto,
|
|
29
|
+
'providerFields'
|
|
30
|
+
> & {
|
|
31
|
+
stripeFields: Omit<
|
|
32
|
+
Stripe.BillingPortal.SessionCreateParams,
|
|
33
|
+
BillingPortalOmissions
|
|
34
|
+
>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type StripeUpdateBillingPortalDto = Omit<
|
|
38
|
+
UpdateBillingPortalDto,
|
|
39
|
+
'providerFields'
|
|
40
|
+
> & {
|
|
41
|
+
stripeFields?: Omit<
|
|
42
|
+
Stripe.BillingPortal.SessionCreateParams,
|
|
43
|
+
BillingPortalOmissions
|
|
44
|
+
>;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type StripeBillingPortalDto = Omit<
|
|
48
|
+
BillingPortalDto,
|
|
49
|
+
'providerFields'
|
|
50
|
+
> & {
|
|
51
|
+
stripeFields: Stripe.BillingPortal.Session;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type StripeBillingPortalDtos = {
|
|
55
|
+
BillingPortalMapper: StripeBillingPortalDto;
|
|
56
|
+
CreateBillingPortalMapper: StripeCreateBillingPortalDto;
|
|
57
|
+
UpdateBillingPortalMapper: StripeUpdateBillingPortalDto;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Checkout Session Types
|
|
61
|
+
type CheckoutSessionOmissions =
|
|
62
|
+
| 'payment_method_types'
|
|
63
|
+
| 'currency'
|
|
64
|
+
| 'success_url'
|
|
65
|
+
| 'cancel_url';
|
|
66
|
+
|
|
67
|
+
export type StripeCreateCheckoutSessionDto<StatusEnum> = Omit<
|
|
68
|
+
CreateCheckoutSessionDto<
|
|
69
|
+
typeof PaymentMethodEnum,
|
|
70
|
+
typeof CurrencyEnum,
|
|
71
|
+
StatusEnum
|
|
72
|
+
>,
|
|
73
|
+
'providerFields'
|
|
74
|
+
> & {
|
|
75
|
+
stripeFields: Omit<
|
|
76
|
+
Stripe.Checkout.SessionCreateParams,
|
|
77
|
+
CheckoutSessionOmissions
|
|
78
|
+
>;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type StripeUpdateCheckoutSessionDto<StatusEnum> = Omit<
|
|
82
|
+
UpdateCheckoutSessionDto<
|
|
83
|
+
typeof PaymentMethodEnum,
|
|
84
|
+
typeof CurrencyEnum,
|
|
85
|
+
StatusEnum
|
|
86
|
+
>,
|
|
87
|
+
'providerFields'
|
|
88
|
+
> & {
|
|
89
|
+
stripeFields?: Omit<
|
|
90
|
+
Stripe.Checkout.SessionCreateParams,
|
|
91
|
+
CheckoutSessionOmissions
|
|
92
|
+
>;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export type StripeCheckoutSessionDto<StatusEnum> = Omit<
|
|
96
|
+
CheckoutSessionDto<typeof PaymentMethodEnum, typeof CurrencyEnum, StatusEnum>,
|
|
97
|
+
'providerFields'
|
|
98
|
+
> & {
|
|
99
|
+
stripeFields: Stripe.Checkout.Session;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export type StripeCheckoutSessionDtos<StatusEnum> = {
|
|
103
|
+
CheckoutSessionMapper: StripeCheckoutSessionDto<StatusEnum>;
|
|
104
|
+
CreateCheckoutSessionMapper: StripeCreateCheckoutSessionDto<StatusEnum>;
|
|
105
|
+
UpdateCheckoutSessionMapper: StripeUpdateCheckoutSessionDto<StatusEnum>;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Payment Link Types
|
|
109
|
+
export type StripeCreatePaymentLinkDto<StatusEnum> = Omit<
|
|
110
|
+
CreatePaymentLinkDto<
|
|
111
|
+
typeof PaymentMethodEnum,
|
|
112
|
+
typeof CurrencyEnum,
|
|
113
|
+
StatusEnum
|
|
114
|
+
>,
|
|
115
|
+
'providerFields'
|
|
116
|
+
> & {
|
|
117
|
+
stripeFields: Stripe.PaymentLinkCreateParams;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export type StripeUpdatePaymentLinkDto<StatusEnum> = Omit<
|
|
121
|
+
UpdatePaymentLinkDto<
|
|
122
|
+
typeof PaymentMethodEnum,
|
|
123
|
+
typeof CurrencyEnum,
|
|
124
|
+
StatusEnum
|
|
125
|
+
>,
|
|
126
|
+
'providerFields'
|
|
127
|
+
> & {
|
|
128
|
+
stripeFields?: Stripe.PaymentLinkUpdateParams;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export type StripePaymentLinkDto<StatusEnum> = Omit<
|
|
132
|
+
PaymentLinkDto<typeof PaymentMethodEnum, typeof CurrencyEnum, StatusEnum>,
|
|
133
|
+
'providerFields'
|
|
134
|
+
> & {
|
|
135
|
+
stripeFields: Stripe.PaymentLink;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export type StripePaymentLinkDtos<StatusEnum> = {
|
|
139
|
+
PaymentLinkMapper: StripePaymentLinkDto<StatusEnum>;
|
|
140
|
+
CreatePaymentLinkMapper: StripeCreatePaymentLinkDto<StatusEnum>;
|
|
141
|
+
UpdatePaymentLinkMapper: StripeUpdatePaymentLinkDto<StatusEnum>;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// Plan Types
|
|
145
|
+
type PlanOmissions = 'product' | 'interval' | 'currency';
|
|
146
|
+
|
|
147
|
+
export type StripeCreatePlanDto = Omit<
|
|
148
|
+
CreatePlanDto<
|
|
149
|
+
typeof PlanCadenceEnum,
|
|
150
|
+
typeof CurrencyEnum,
|
|
151
|
+
typeof BillingProviderEnum
|
|
152
|
+
>,
|
|
153
|
+
'providerFields'
|
|
154
|
+
> & {
|
|
155
|
+
stripeFields: Omit<Stripe.PlanCreateParams, PlanOmissions>;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export type StripeUpdatePlanDto = Omit<
|
|
159
|
+
UpdatePlanDto<
|
|
160
|
+
typeof PlanCadenceEnum,
|
|
161
|
+
typeof CurrencyEnum,
|
|
162
|
+
typeof BillingProviderEnum
|
|
163
|
+
>,
|
|
164
|
+
'providerFields'
|
|
165
|
+
> & {
|
|
166
|
+
stripeFields?: Omit<Stripe.PlanUpdateParams, PlanOmissions>;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export type StripePlanDto = Omit<
|
|
170
|
+
PlanDto<
|
|
171
|
+
typeof PlanCadenceEnum,
|
|
172
|
+
typeof CurrencyEnum,
|
|
173
|
+
typeof BillingProviderEnum
|
|
174
|
+
>,
|
|
175
|
+
'providerFields'
|
|
176
|
+
> & {
|
|
177
|
+
stripeFields: Stripe.Plan;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export type StripePlanDtos = {
|
|
181
|
+
PlanMapper: StripePlanDto;
|
|
182
|
+
CreatePlanMapper: StripeCreatePlanDto;
|
|
183
|
+
UpdatePlanMapper: StripeUpdatePlanDto;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Subscription Types
|
|
187
|
+
type SubscriptionOmissions = 'items' | 'customer';
|
|
188
|
+
|
|
189
|
+
export type StripeCreateSubscriptionDto<PartyType> = Omit<
|
|
190
|
+
CreateSubscriptionDto<PartyType, typeof BillingProviderEnum>,
|
|
191
|
+
'providerFields'
|
|
192
|
+
> & {
|
|
193
|
+
stripeFields: Omit<Stripe.SubscriptionCreateParams, SubscriptionOmissions>;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export type StripeUpdateSubscriptionDto<PartyType> = Omit<
|
|
197
|
+
UpdateSubscriptionDto<PartyType, typeof BillingProviderEnum>,
|
|
198
|
+
'providerFields'
|
|
199
|
+
> & {
|
|
200
|
+
stripeFields?: Omit<Stripe.SubscriptionUpdateParams, SubscriptionOmissions>;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export type StripeSubscriptionDto<PartyType> = Omit<
|
|
204
|
+
SubscriptionDto<PartyType, typeof BillingProviderEnum>,
|
|
205
|
+
'providerFields'
|
|
206
|
+
> & {
|
|
207
|
+
stripeFields: Stripe.Subscription;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export type StripeSubscriptionDtos<PartyType> = {
|
|
211
|
+
SubscriptionMapper: StripeSubscriptionDto<PartyType>;
|
|
212
|
+
CreateSubscriptionMapper: StripeCreateSubscriptionDto<PartyType>;
|
|
213
|
+
UpdateSubscriptionMapper: StripeUpdateSubscriptionDto<PartyType>;
|
|
214
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BillingPortalDto,
|
|
3
|
+
CheckoutSessionDto,
|
|
4
|
+
PaymentLinkDto,
|
|
5
|
+
PlanDto,
|
|
6
|
+
SubscriptionDto
|
|
7
|
+
} from '@forklaunch/interfaces-billing/types';
|
|
8
|
+
import Stripe from 'stripe';
|
|
9
|
+
import { BillingProviderEnum } from '../domain/enums/billingProvider.enum';
|
|
10
|
+
import { CurrencyEnum } from '../domain/enums/currency.enum';
|
|
11
|
+
import { PaymentMethodEnum } from '../domain/enums/paymentMethod.enum';
|
|
12
|
+
import { PlanCadenceEnum } from '../domain/enums/planCadence.enum';
|
|
13
|
+
|
|
14
|
+
// Billing Portal Types
|
|
15
|
+
export type StripeBillingPortalEntity = BillingPortalDto & {
|
|
16
|
+
providerFields: Stripe.BillingPortal.Session;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type StripeBillingPortalEntities = {
|
|
20
|
+
BillingPortalMapper: StripeBillingPortalEntity;
|
|
21
|
+
CreateBillingPortalMapper: StripeBillingPortalEntity;
|
|
22
|
+
UpdateBillingPortalMapper: StripeBillingPortalEntity;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Checkout Session Types
|
|
26
|
+
|
|
27
|
+
export type StripeCheckoutSessionEntity<StatusEnum> = CheckoutSessionDto<
|
|
28
|
+
typeof PaymentMethodEnum,
|
|
29
|
+
typeof CurrencyEnum,
|
|
30
|
+
StatusEnum
|
|
31
|
+
> & {
|
|
32
|
+
providerFields: Stripe.Checkout.Session;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type StripeCheckoutSessionEntities<StatusEnum> = {
|
|
36
|
+
CheckoutSessionMapper: StripeCheckoutSessionEntity<StatusEnum>;
|
|
37
|
+
CreateCheckoutSessionMapper: StripeCheckoutSessionEntity<StatusEnum>;
|
|
38
|
+
UpdateCheckoutSessionMapper: StripeCheckoutSessionEntity<StatusEnum>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Payment Link Types
|
|
42
|
+
export type StripePaymentLinkEntity<StatusEnum> = PaymentLinkDto<
|
|
43
|
+
typeof PaymentMethodEnum,
|
|
44
|
+
typeof CurrencyEnum,
|
|
45
|
+
StatusEnum
|
|
46
|
+
> & {
|
|
47
|
+
providerFields: Stripe.PaymentLink;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type StripePaymentLinkEntities<StatusEnum> = {
|
|
51
|
+
PaymentLinkMapper: StripePaymentLinkEntity<StatusEnum>;
|
|
52
|
+
CreatePaymentLinkMapper: StripePaymentLinkEntity<StatusEnum>;
|
|
53
|
+
UpdatePaymentLinkMapper: StripePaymentLinkEntity<StatusEnum>;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Plan Types
|
|
57
|
+
export type StripePlanEntity = PlanDto<
|
|
58
|
+
typeof PlanCadenceEnum,
|
|
59
|
+
typeof CurrencyEnum,
|
|
60
|
+
typeof BillingProviderEnum
|
|
61
|
+
> & {
|
|
62
|
+
providerFields: Stripe.Plan;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type StripePlanEntities = {
|
|
66
|
+
PlanMapper: StripePlanEntity;
|
|
67
|
+
CreatePlanMapper: StripePlanEntity;
|
|
68
|
+
UpdatePlanMapper: StripePlanEntity;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Subscription Types
|
|
72
|
+
export type StripeSubscriptionEntity<PartyType> = SubscriptionDto<
|
|
73
|
+
PartyType,
|
|
74
|
+
typeof BillingProviderEnum
|
|
75
|
+
> & {
|
|
76
|
+
providerFields: Stripe.Subscription;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type StripeSubscriptionEntities<PartyType> = {
|
|
80
|
+
SubscriptionMapper: StripeSubscriptionEntity<PartyType>;
|
|
81
|
+
CreateSubscriptionMapper: StripeSubscriptionEntity<PartyType>;
|
|
82
|
+
UpdateSubscriptionMapper: StripeSubscriptionEntity<PartyType>;
|
|
83
|
+
};
|