@forklaunch/implementation-billing-stripe 0.5.8 → 0.5.10
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/lib/eject/services/webhook.service.ts +83 -58
- package/lib/services/index.js +68 -46
- package/lib/services/index.mjs +68 -46
- package/package.json +11 -11
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
6
6
|
import { EntityManager } from '@mikro-orm/core';
|
|
7
7
|
import Stripe from 'stripe';
|
|
8
|
+
import { PartyEnum } from '../../../../billing-base/domain/enum/party.enum';
|
|
8
9
|
import { BillingProviderEnum } from '../domain/enum/billingProvider.enum';
|
|
9
10
|
import { CurrencyEnum } from '../domain/enum/currency.enum';
|
|
10
11
|
import { PaymentMethodEnum } from '../domain/enum/paymentMethod.enum';
|
|
@@ -122,7 +123,7 @@ export class StripeWebhookService<
|
|
|
122
123
|
|
|
123
124
|
switch (eventType) {
|
|
124
125
|
case 'billing_portal.session.created': {
|
|
125
|
-
this.billingPortalService.baseBillingPortalService.createBillingPortalSession(
|
|
126
|
+
await this.billingPortalService.baseBillingPortalService.createBillingPortalSession(
|
|
126
127
|
{
|
|
127
128
|
id: event.data.object.id,
|
|
128
129
|
customerId: event.data.object.customer,
|
|
@@ -134,14 +135,14 @@ export class StripeWebhookService<
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
case 'checkout.session.expired': {
|
|
137
|
-
this.checkoutSessionService.handleCheckoutFailure({
|
|
138
|
+
await this.checkoutSessionService.handleCheckoutFailure({
|
|
138
139
|
id: event.data.object.id
|
|
139
140
|
});
|
|
140
141
|
break;
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
case 'checkout.session.completed': {
|
|
144
|
-
this.checkoutSessionService.handleCheckoutSuccess({
|
|
145
|
+
await this.checkoutSessionService.handleCheckoutSuccess({
|
|
145
146
|
id: event.data.object.id
|
|
146
147
|
});
|
|
147
148
|
break;
|
|
@@ -149,23 +150,25 @@ export class StripeWebhookService<
|
|
|
149
150
|
|
|
150
151
|
case 'payment_link.created':
|
|
151
152
|
{
|
|
152
|
-
this.paymentLinkService.basePaymentLinkService.createPaymentLink(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
153
|
+
await this.paymentLinkService.basePaymentLinkService.createPaymentLink(
|
|
154
|
+
{
|
|
155
|
+
id: event.data.object.id,
|
|
156
|
+
amount:
|
|
157
|
+
event.data.object.line_items?.data.reduce<number>(
|
|
158
|
+
(total, item) => total + item.amount_total,
|
|
159
|
+
0
|
|
160
|
+
) ?? 0,
|
|
161
|
+
paymentMethods: event.data.object
|
|
162
|
+
.payment_method_types as PaymentMethodEnum[],
|
|
163
|
+
status: 'CREATED' as StatusEnum[keyof StatusEnum],
|
|
164
|
+
currency: event.data.object.currency as CurrencyEnum
|
|
165
|
+
}
|
|
166
|
+
);
|
|
164
167
|
}
|
|
165
168
|
break;
|
|
166
169
|
|
|
167
170
|
case 'payment_link.updated': {
|
|
168
|
-
this.paymentLinkService.basePaymentLinkService.updatePaymentLink({
|
|
171
|
+
await this.paymentLinkService.basePaymentLinkService.updatePaymentLink({
|
|
169
172
|
id: event.data.object.id,
|
|
170
173
|
amount:
|
|
171
174
|
event.data.object.line_items?.data.reduce<number>(
|
|
@@ -186,7 +189,7 @@ export class StripeWebhookService<
|
|
|
186
189
|
event.data.object.product != null &&
|
|
187
190
|
event.data.object.amount != null
|
|
188
191
|
) {
|
|
189
|
-
this.planService.basePlanService.createPlan({
|
|
192
|
+
await this.planService.basePlanService.createPlan({
|
|
190
193
|
id: event.data.object.id,
|
|
191
194
|
billingProvider: BillingProviderEnum.STRIPE,
|
|
192
195
|
cadence: event.data.object.interval as PlanCadenceEnum,
|
|
@@ -211,7 +214,7 @@ export class StripeWebhookService<
|
|
|
211
214
|
event.data.object.product != null &&
|
|
212
215
|
event.data.object.amount != null
|
|
213
216
|
) {
|
|
214
|
-
this.planService.basePlanService.updatePlan({
|
|
217
|
+
await this.planService.basePlanService.updatePlan({
|
|
215
218
|
id: event.data.object.id,
|
|
216
219
|
billingProvider: BillingProviderEnum.STRIPE,
|
|
217
220
|
cadence: event.data.object.interval as PlanCadenceEnum,
|
|
@@ -231,72 +234,94 @@ export class StripeWebhookService<
|
|
|
231
234
|
}
|
|
232
235
|
|
|
233
236
|
case 'plan.deleted': {
|
|
234
|
-
this.planService.deletePlan({
|
|
237
|
+
await this.planService.deletePlan({
|
|
235
238
|
id: event.data.object.id
|
|
236
239
|
});
|
|
237
240
|
break;
|
|
238
241
|
}
|
|
239
242
|
|
|
240
243
|
case 'customer.subscription.created': {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
244
|
+
if (
|
|
245
|
+
!event.data.object.items?.data ||
|
|
246
|
+
event.data.object.items.data.length === 0 ||
|
|
247
|
+
!event.data.object.items.data[0]?.plan?.id
|
|
248
|
+
) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
`Invalid subscription: missing items or plan ID for subscription ${event.data.object.id}`
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
await this.subscriptionService.baseSubscriptionService.createSubscription(
|
|
254
|
+
{
|
|
255
|
+
id: event.data.object.id,
|
|
256
|
+
partyId:
|
|
257
|
+
typeof event.data.object.customer === 'string'
|
|
258
|
+
? event.data.object.customer
|
|
259
|
+
: event.data.object.customer.id,
|
|
260
|
+
partyType: PartyEnum.USER as PartyEnum[keyof PartyEnum],
|
|
261
|
+
description: event.data.object.description ?? undefined,
|
|
262
|
+
active: true,
|
|
263
|
+
productId: event.data.object.items.data[0].plan.id,
|
|
264
|
+
externalId: event.data.object.id,
|
|
265
|
+
billingProvider: BillingProviderEnum.STRIPE,
|
|
266
|
+
startDate: new Date(event.data.object.created * 1000),
|
|
267
|
+
endDate: event.data.object.cancel_at
|
|
268
|
+
? new Date(event.data.object.cancel_at * 1000)
|
|
269
|
+
: undefined,
|
|
270
|
+
status: event.data.object.status
|
|
271
|
+
}
|
|
272
|
+
);
|
|
259
273
|
break;
|
|
260
274
|
}
|
|
261
275
|
|
|
262
276
|
case 'customer.subscription.updated': {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
277
|
+
if (
|
|
278
|
+
!event.data.object.items?.data ||
|
|
279
|
+
event.data.object.items.data.length === 0 ||
|
|
280
|
+
!event.data.object.items.data[0]?.plan?.id
|
|
281
|
+
) {
|
|
282
|
+
throw new Error(
|
|
283
|
+
`Invalid subscription: missing items or plan ID for subscription ${event.data.object.id}`
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
await this.subscriptionService.baseSubscriptionService.updateSubscription(
|
|
287
|
+
{
|
|
288
|
+
id: event.data.object.id,
|
|
289
|
+
partyId:
|
|
290
|
+
typeof event.data.object.customer === 'string'
|
|
291
|
+
? event.data.object.customer
|
|
292
|
+
: event.data.object.customer.id,
|
|
293
|
+
partyType: PartyEnum.USER as PartyEnum[keyof PartyEnum],
|
|
294
|
+
description: event.data.object.description ?? undefined,
|
|
295
|
+
active: true,
|
|
296
|
+
externalId: event.data.object.id,
|
|
297
|
+
billingProvider: BillingProviderEnum.STRIPE,
|
|
298
|
+
startDate: new Date(event.data.object.created * 1000),
|
|
299
|
+
endDate: event.data.object.cancel_at
|
|
300
|
+
? new Date(event.data.object.cancel_at * 1000)
|
|
301
|
+
: undefined,
|
|
302
|
+
productId: event.data.object.items.data[0].plan.id,
|
|
303
|
+
status: event.data.object.status
|
|
304
|
+
}
|
|
305
|
+
);
|
|
281
306
|
break;
|
|
282
307
|
}
|
|
283
308
|
|
|
284
309
|
case 'customer.subscription.deleted': {
|
|
285
|
-
this.subscriptionService.deleteSubscription({
|
|
310
|
+
await this.subscriptionService.deleteSubscription({
|
|
286
311
|
id: event.data.object.id
|
|
287
312
|
});
|
|
288
313
|
break;
|
|
289
314
|
}
|
|
290
315
|
|
|
291
316
|
case 'customer.subscription.paused': {
|
|
292
|
-
this.subscriptionService.cancelSubscription({
|
|
317
|
+
await this.subscriptionService.cancelSubscription({
|
|
293
318
|
id: event.data.object.id
|
|
294
319
|
});
|
|
295
320
|
break;
|
|
296
321
|
}
|
|
297
322
|
|
|
298
323
|
case 'customer.subscription.resumed': {
|
|
299
|
-
this.subscriptionService.resumeSubscription({
|
|
324
|
+
await this.subscriptionService.resumeSubscription({
|
|
300
325
|
id: event.data.object.id
|
|
301
326
|
});
|
|
302
327
|
break;
|
package/lib/services/index.js
CHANGED
|
@@ -599,6 +599,12 @@ var StripeSubscriptionService = class {
|
|
|
599
599
|
}
|
|
600
600
|
};
|
|
601
601
|
|
|
602
|
+
// ../../../billing-base/domain/enum/party.enum.ts
|
|
603
|
+
var PartyEnum = {
|
|
604
|
+
USER: "user",
|
|
605
|
+
ORGANIZATION: "organization"
|
|
606
|
+
};
|
|
607
|
+
|
|
602
608
|
// domain/enum/billingProvider.enum.ts
|
|
603
609
|
var BillingProviderEnum = {
|
|
604
610
|
STRIPE: "stripe"
|
|
@@ -642,7 +648,7 @@ var StripeWebhookService = class {
|
|
|
642
648
|
const eventType = event.type;
|
|
643
649
|
switch (eventType) {
|
|
644
650
|
case "billing_portal.session.created": {
|
|
645
|
-
this.billingPortalService.baseBillingPortalService.createBillingPortalSession(
|
|
651
|
+
await this.billingPortalService.baseBillingPortalService.createBillingPortalSession(
|
|
646
652
|
{
|
|
647
653
|
id: event.data.object.id,
|
|
648
654
|
customerId: event.data.object.customer,
|
|
@@ -653,33 +659,35 @@ var StripeWebhookService = class {
|
|
|
653
659
|
break;
|
|
654
660
|
}
|
|
655
661
|
case "checkout.session.expired": {
|
|
656
|
-
this.checkoutSessionService.handleCheckoutFailure({
|
|
662
|
+
await this.checkoutSessionService.handleCheckoutFailure({
|
|
657
663
|
id: event.data.object.id
|
|
658
664
|
});
|
|
659
665
|
break;
|
|
660
666
|
}
|
|
661
667
|
case "checkout.session.completed": {
|
|
662
|
-
this.checkoutSessionService.handleCheckoutSuccess({
|
|
668
|
+
await this.checkoutSessionService.handleCheckoutSuccess({
|
|
663
669
|
id: event.data.object.id
|
|
664
670
|
});
|
|
665
671
|
break;
|
|
666
672
|
}
|
|
667
673
|
case "payment_link.created":
|
|
668
674
|
{
|
|
669
|
-
this.paymentLinkService.basePaymentLinkService.createPaymentLink(
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
675
|
+
await this.paymentLinkService.basePaymentLinkService.createPaymentLink(
|
|
676
|
+
{
|
|
677
|
+
id: event.data.object.id,
|
|
678
|
+
amount: event.data.object.line_items?.data.reduce(
|
|
679
|
+
(total, item) => total + item.amount_total,
|
|
680
|
+
0
|
|
681
|
+
) ?? 0,
|
|
682
|
+
paymentMethods: event.data.object.payment_method_types,
|
|
683
|
+
status: "CREATED",
|
|
684
|
+
currency: event.data.object.currency
|
|
685
|
+
}
|
|
686
|
+
);
|
|
679
687
|
}
|
|
680
688
|
break;
|
|
681
689
|
case "payment_link.updated": {
|
|
682
|
-
this.paymentLinkService.basePaymentLinkService.updatePaymentLink({
|
|
690
|
+
await this.paymentLinkService.basePaymentLinkService.updatePaymentLink({
|
|
683
691
|
id: event.data.object.id,
|
|
684
692
|
amount: event.data.object.line_items?.data.reduce(
|
|
685
693
|
(total, item) => total + item.amount_total,
|
|
@@ -693,7 +701,7 @@ var StripeWebhookService = class {
|
|
|
693
701
|
}
|
|
694
702
|
case "plan.created": {
|
|
695
703
|
if (typeof event.data.object.product === "object" && event.data.object.product != null && event.data.object.amount != null) {
|
|
696
|
-
this.planService.basePlanService.createPlan({
|
|
704
|
+
await this.planService.basePlanService.createPlan({
|
|
697
705
|
id: event.data.object.id,
|
|
698
706
|
billingProvider: BillingProviderEnum.STRIPE,
|
|
699
707
|
cadence: event.data.object.interval,
|
|
@@ -710,7 +718,7 @@ var StripeWebhookService = class {
|
|
|
710
718
|
}
|
|
711
719
|
case "plan.updated": {
|
|
712
720
|
if (typeof event.data.object.product === "object" && event.data.object.product != null && event.data.object.amount != null) {
|
|
713
|
-
this.planService.basePlanService.updatePlan({
|
|
721
|
+
await this.planService.basePlanService.updatePlan({
|
|
714
722
|
id: event.data.object.id,
|
|
715
723
|
billingProvider: BillingProviderEnum.STRIPE,
|
|
716
724
|
cadence: event.data.object.interval,
|
|
@@ -726,57 +734,71 @@ var StripeWebhookService = class {
|
|
|
726
734
|
break;
|
|
727
735
|
}
|
|
728
736
|
case "plan.deleted": {
|
|
729
|
-
this.planService.deletePlan({
|
|
737
|
+
await this.planService.deletePlan({
|
|
730
738
|
id: event.data.object.id
|
|
731
739
|
});
|
|
732
740
|
break;
|
|
733
741
|
}
|
|
734
742
|
case "customer.subscription.created": {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
743
|
+
if (!event.data.object.items?.data || event.data.object.items.data.length === 0 || !event.data.object.items.data[0]?.plan?.id) {
|
|
744
|
+
throw new Error(
|
|
745
|
+
`Invalid subscription: missing items or plan ID for subscription ${event.data.object.id}`
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
await this.subscriptionService.baseSubscriptionService.createSubscription(
|
|
749
|
+
{
|
|
750
|
+
id: event.data.object.id,
|
|
751
|
+
partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
|
|
752
|
+
partyType: PartyEnum.USER,
|
|
753
|
+
description: event.data.object.description ?? void 0,
|
|
754
|
+
active: true,
|
|
755
|
+
productId: event.data.object.items.data[0].plan.id,
|
|
756
|
+
externalId: event.data.object.id,
|
|
757
|
+
billingProvider: BillingProviderEnum.STRIPE,
|
|
758
|
+
startDate: new Date(event.data.object.created * 1e3),
|
|
759
|
+
endDate: event.data.object.cancel_at ? new Date(event.data.object.cancel_at * 1e3) : void 0,
|
|
760
|
+
status: event.data.object.status
|
|
761
|
+
}
|
|
762
|
+
);
|
|
748
763
|
break;
|
|
749
764
|
}
|
|
750
765
|
case "customer.subscription.updated": {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
766
|
+
if (!event.data.object.items?.data || event.data.object.items.data.length === 0 || !event.data.object.items.data[0]?.plan?.id) {
|
|
767
|
+
throw new Error(
|
|
768
|
+
`Invalid subscription: missing items or plan ID for subscription ${event.data.object.id}`
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
await this.subscriptionService.baseSubscriptionService.updateSubscription(
|
|
772
|
+
{
|
|
773
|
+
id: event.data.object.id,
|
|
774
|
+
partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
|
|
775
|
+
partyType: PartyEnum.USER,
|
|
776
|
+
description: event.data.object.description ?? void 0,
|
|
777
|
+
active: true,
|
|
778
|
+
externalId: event.data.object.id,
|
|
779
|
+
billingProvider: BillingProviderEnum.STRIPE,
|
|
780
|
+
startDate: new Date(event.data.object.created * 1e3),
|
|
781
|
+
endDate: event.data.object.cancel_at ? new Date(event.data.object.cancel_at * 1e3) : void 0,
|
|
782
|
+
productId: event.data.object.items.data[0].plan.id,
|
|
783
|
+
status: event.data.object.status
|
|
784
|
+
}
|
|
785
|
+
);
|
|
764
786
|
break;
|
|
765
787
|
}
|
|
766
788
|
case "customer.subscription.deleted": {
|
|
767
|
-
this.subscriptionService.deleteSubscription({
|
|
789
|
+
await this.subscriptionService.deleteSubscription({
|
|
768
790
|
id: event.data.object.id
|
|
769
791
|
});
|
|
770
792
|
break;
|
|
771
793
|
}
|
|
772
794
|
case "customer.subscription.paused": {
|
|
773
|
-
this.subscriptionService.cancelSubscription({
|
|
795
|
+
await this.subscriptionService.cancelSubscription({
|
|
774
796
|
id: event.data.object.id
|
|
775
797
|
});
|
|
776
798
|
break;
|
|
777
799
|
}
|
|
778
800
|
case "customer.subscription.resumed": {
|
|
779
|
-
this.subscriptionService.resumeSubscription({
|
|
801
|
+
await this.subscriptionService.resumeSubscription({
|
|
780
802
|
id: event.data.object.id
|
|
781
803
|
});
|
|
782
804
|
break;
|
package/lib/services/index.mjs
CHANGED
|
@@ -567,6 +567,12 @@ var StripeSubscriptionService = class {
|
|
|
567
567
|
}
|
|
568
568
|
};
|
|
569
569
|
|
|
570
|
+
// ../../../billing-base/domain/enum/party.enum.ts
|
|
571
|
+
var PartyEnum = {
|
|
572
|
+
USER: "user",
|
|
573
|
+
ORGANIZATION: "organization"
|
|
574
|
+
};
|
|
575
|
+
|
|
570
576
|
// domain/enum/billingProvider.enum.ts
|
|
571
577
|
var BillingProviderEnum = {
|
|
572
578
|
STRIPE: "stripe"
|
|
@@ -610,7 +616,7 @@ var StripeWebhookService = class {
|
|
|
610
616
|
const eventType = event.type;
|
|
611
617
|
switch (eventType) {
|
|
612
618
|
case "billing_portal.session.created": {
|
|
613
|
-
this.billingPortalService.baseBillingPortalService.createBillingPortalSession(
|
|
619
|
+
await this.billingPortalService.baseBillingPortalService.createBillingPortalSession(
|
|
614
620
|
{
|
|
615
621
|
id: event.data.object.id,
|
|
616
622
|
customerId: event.data.object.customer,
|
|
@@ -621,33 +627,35 @@ var StripeWebhookService = class {
|
|
|
621
627
|
break;
|
|
622
628
|
}
|
|
623
629
|
case "checkout.session.expired": {
|
|
624
|
-
this.checkoutSessionService.handleCheckoutFailure({
|
|
630
|
+
await this.checkoutSessionService.handleCheckoutFailure({
|
|
625
631
|
id: event.data.object.id
|
|
626
632
|
});
|
|
627
633
|
break;
|
|
628
634
|
}
|
|
629
635
|
case "checkout.session.completed": {
|
|
630
|
-
this.checkoutSessionService.handleCheckoutSuccess({
|
|
636
|
+
await this.checkoutSessionService.handleCheckoutSuccess({
|
|
631
637
|
id: event.data.object.id
|
|
632
638
|
});
|
|
633
639
|
break;
|
|
634
640
|
}
|
|
635
641
|
case "payment_link.created":
|
|
636
642
|
{
|
|
637
|
-
this.paymentLinkService.basePaymentLinkService.createPaymentLink(
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
643
|
+
await this.paymentLinkService.basePaymentLinkService.createPaymentLink(
|
|
644
|
+
{
|
|
645
|
+
id: event.data.object.id,
|
|
646
|
+
amount: event.data.object.line_items?.data.reduce(
|
|
647
|
+
(total, item) => total + item.amount_total,
|
|
648
|
+
0
|
|
649
|
+
) ?? 0,
|
|
650
|
+
paymentMethods: event.data.object.payment_method_types,
|
|
651
|
+
status: "CREATED",
|
|
652
|
+
currency: event.data.object.currency
|
|
653
|
+
}
|
|
654
|
+
);
|
|
647
655
|
}
|
|
648
656
|
break;
|
|
649
657
|
case "payment_link.updated": {
|
|
650
|
-
this.paymentLinkService.basePaymentLinkService.updatePaymentLink({
|
|
658
|
+
await this.paymentLinkService.basePaymentLinkService.updatePaymentLink({
|
|
651
659
|
id: event.data.object.id,
|
|
652
660
|
amount: event.data.object.line_items?.data.reduce(
|
|
653
661
|
(total, item) => total + item.amount_total,
|
|
@@ -661,7 +669,7 @@ var StripeWebhookService = class {
|
|
|
661
669
|
}
|
|
662
670
|
case "plan.created": {
|
|
663
671
|
if (typeof event.data.object.product === "object" && event.data.object.product != null && event.data.object.amount != null) {
|
|
664
|
-
this.planService.basePlanService.createPlan({
|
|
672
|
+
await this.planService.basePlanService.createPlan({
|
|
665
673
|
id: event.data.object.id,
|
|
666
674
|
billingProvider: BillingProviderEnum.STRIPE,
|
|
667
675
|
cadence: event.data.object.interval,
|
|
@@ -678,7 +686,7 @@ var StripeWebhookService = class {
|
|
|
678
686
|
}
|
|
679
687
|
case "plan.updated": {
|
|
680
688
|
if (typeof event.data.object.product === "object" && event.data.object.product != null && event.data.object.amount != null) {
|
|
681
|
-
this.planService.basePlanService.updatePlan({
|
|
689
|
+
await this.planService.basePlanService.updatePlan({
|
|
682
690
|
id: event.data.object.id,
|
|
683
691
|
billingProvider: BillingProviderEnum.STRIPE,
|
|
684
692
|
cadence: event.data.object.interval,
|
|
@@ -694,57 +702,71 @@ var StripeWebhookService = class {
|
|
|
694
702
|
break;
|
|
695
703
|
}
|
|
696
704
|
case "plan.deleted": {
|
|
697
|
-
this.planService.deletePlan({
|
|
705
|
+
await this.planService.deletePlan({
|
|
698
706
|
id: event.data.object.id
|
|
699
707
|
});
|
|
700
708
|
break;
|
|
701
709
|
}
|
|
702
710
|
case "customer.subscription.created": {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
711
|
+
if (!event.data.object.items?.data || event.data.object.items.data.length === 0 || !event.data.object.items.data[0]?.plan?.id) {
|
|
712
|
+
throw new Error(
|
|
713
|
+
`Invalid subscription: missing items or plan ID for subscription ${event.data.object.id}`
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
await this.subscriptionService.baseSubscriptionService.createSubscription(
|
|
717
|
+
{
|
|
718
|
+
id: event.data.object.id,
|
|
719
|
+
partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
|
|
720
|
+
partyType: PartyEnum.USER,
|
|
721
|
+
description: event.data.object.description ?? void 0,
|
|
722
|
+
active: true,
|
|
723
|
+
productId: event.data.object.items.data[0].plan.id,
|
|
724
|
+
externalId: event.data.object.id,
|
|
725
|
+
billingProvider: BillingProviderEnum.STRIPE,
|
|
726
|
+
startDate: new Date(event.data.object.created * 1e3),
|
|
727
|
+
endDate: event.data.object.cancel_at ? new Date(event.data.object.cancel_at * 1e3) : void 0,
|
|
728
|
+
status: event.data.object.status
|
|
729
|
+
}
|
|
730
|
+
);
|
|
716
731
|
break;
|
|
717
732
|
}
|
|
718
733
|
case "customer.subscription.updated": {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
734
|
+
if (!event.data.object.items?.data || event.data.object.items.data.length === 0 || !event.data.object.items.data[0]?.plan?.id) {
|
|
735
|
+
throw new Error(
|
|
736
|
+
`Invalid subscription: missing items or plan ID for subscription ${event.data.object.id}`
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
await this.subscriptionService.baseSubscriptionService.updateSubscription(
|
|
740
|
+
{
|
|
741
|
+
id: event.data.object.id,
|
|
742
|
+
partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
|
|
743
|
+
partyType: PartyEnum.USER,
|
|
744
|
+
description: event.data.object.description ?? void 0,
|
|
745
|
+
active: true,
|
|
746
|
+
externalId: event.data.object.id,
|
|
747
|
+
billingProvider: BillingProviderEnum.STRIPE,
|
|
748
|
+
startDate: new Date(event.data.object.created * 1e3),
|
|
749
|
+
endDate: event.data.object.cancel_at ? new Date(event.data.object.cancel_at * 1e3) : void 0,
|
|
750
|
+
productId: event.data.object.items.data[0].plan.id,
|
|
751
|
+
status: event.data.object.status
|
|
752
|
+
}
|
|
753
|
+
);
|
|
732
754
|
break;
|
|
733
755
|
}
|
|
734
756
|
case "customer.subscription.deleted": {
|
|
735
|
-
this.subscriptionService.deleteSubscription({
|
|
757
|
+
await this.subscriptionService.deleteSubscription({
|
|
736
758
|
id: event.data.object.id
|
|
737
759
|
});
|
|
738
760
|
break;
|
|
739
761
|
}
|
|
740
762
|
case "customer.subscription.paused": {
|
|
741
|
-
this.subscriptionService.cancelSubscription({
|
|
763
|
+
await this.subscriptionService.cancelSubscription({
|
|
742
764
|
id: event.data.object.id
|
|
743
765
|
});
|
|
744
766
|
break;
|
|
745
767
|
}
|
|
746
768
|
case "customer.subscription.resumed": {
|
|
747
|
-
this.subscriptionService.resumeSubscription({
|
|
769
|
+
await this.subscriptionService.resumeSubscription({
|
|
748
770
|
id: event.data.object.id
|
|
749
771
|
});
|
|
750
772
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forklaunch/implementation-billing-stripe",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"description": "Stripe implementation for forklaunch billing",
|
|
5
5
|
"homepage": "https://github.com/forklaunch/forklaunch-js#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -42,22 +42,22 @@
|
|
|
42
42
|
"lib/**"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@forklaunch/common": "^0.6.
|
|
46
|
-
"@forklaunch/core": "^0.17.
|
|
47
|
-
"@forklaunch/internal": "^0.3.
|
|
48
|
-
"@forklaunch/validator": "^0.10.
|
|
49
|
-
"@mikro-orm/core": "^6.6.
|
|
45
|
+
"@forklaunch/common": "^0.6.27",
|
|
46
|
+
"@forklaunch/core": "^0.17.3",
|
|
47
|
+
"@forklaunch/internal": "^0.3.27",
|
|
48
|
+
"@forklaunch/validator": "^0.10.27",
|
|
49
|
+
"@mikro-orm/core": "^6.6.5",
|
|
50
50
|
"@sinclair/typebox": "^0.34.47",
|
|
51
51
|
"ajv": "^8.17.1",
|
|
52
52
|
"stripe": "^20.2.0",
|
|
53
|
-
"zod": "^4.3.
|
|
54
|
-
"@forklaunch/implementation-billing-base": "0.8.
|
|
55
|
-
"@forklaunch/interfaces-billing": "0.8.
|
|
53
|
+
"zod": "^4.3.6",
|
|
54
|
+
"@forklaunch/implementation-billing-base": "0.8.10",
|
|
55
|
+
"@forklaunch/interfaces-billing": "0.8.10"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
58
|
+
"@typescript/native-preview": "7.0.0-dev.20260122.4",
|
|
59
59
|
"depcheck": "^1.4.7",
|
|
60
|
-
"prettier": "^3.8.
|
|
60
|
+
"prettier": "^3.8.1",
|
|
61
61
|
"typedoc": "^0.28.16"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|