@forklaunch/implementation-billing-stripe 0.3.0 → 0.3.2

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.
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -8,18 +8,14 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if ((from && typeof from === 'object') || typeof from === 'function') {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, '__esModule', { value: true }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
19
 
24
20
  // services/index.ts
25
21
  var services_exports = {};
@@ -34,17 +30,9 @@ __export(services_exports, {
34
30
  module.exports = __toCommonJS(services_exports);
35
31
 
36
32
  // services/billingPortal.service.ts
37
- var import_services = require('@forklaunch/implementation-billing-base/services');
33
+ var import_services = require("@forklaunch/implementation-billing-base/services");
38
34
  var StripeBillingPortalService = class {
39
- constructor(
40
- stripeClient,
41
- em,
42
- cache,
43
- openTelemetryCollector,
44
- schemaValidator,
45
- mappers,
46
- options
47
- ) {
35
+ constructor(stripeClient, em, cache, openTelemetryCollector, schemaValidator, mappers, options) {
48
36
  this.options = options;
49
37
  this.stripeClient = stripeClient;
50
38
  this.em = em;
@@ -52,15 +40,14 @@ var StripeBillingPortalService = class {
52
40
  this.openTelemetryCollector = openTelemetryCollector;
53
41
  this.schemaValidator = schemaValidator;
54
42
  this.mappers = mappers;
55
- this.baseBillingPortalService =
56
- new import_services.BaseBillingPortalService(
57
- em,
58
- cache,
59
- openTelemetryCollector,
60
- schemaValidator,
61
- mappers,
62
- options
63
- );
43
+ this.baseBillingPortalService = new import_services.BaseBillingPortalService(
44
+ em,
45
+ cache,
46
+ openTelemetryCollector,
47
+ schemaValidator,
48
+ mappers,
49
+ options
50
+ );
64
51
  }
65
52
  baseBillingPortalService;
66
53
  stripeClient;
@@ -96,10 +83,9 @@ var StripeBillingPortalService = class {
96
83
  return this.baseBillingPortalService.expireBillingPortalSession(idDto);
97
84
  }
98
85
  async updateBillingPortalSession(billingPortalDto, ...args) {
99
- const existingSession =
100
- await this.baseBillingPortalService.getBillingPortalSession({
101
- id: billingPortalDto.id
102
- });
86
+ const existingSession = await this.baseBillingPortalService.getBillingPortalSession({
87
+ id: billingPortalDto.id
88
+ });
103
89
  const session = await this.stripeClient.billingPortal.sessions.create({
104
90
  ...billingPortalDto.stripeFields,
105
91
  customer: existingSession.customerId
@@ -121,17 +107,9 @@ var StripeBillingPortalService = class {
121
107
  };
122
108
 
123
109
  // services/checkoutSession.service.ts
124
- var import_services2 = require('@forklaunch/implementation-billing-base/services');
110
+ var import_services2 = require("@forklaunch/implementation-billing-base/services");
125
111
  var StripeCheckoutSessionService = class {
126
- constructor(
127
- stripeClient,
128
- em,
129
- cache,
130
- openTelemetryCollector,
131
- schemaValidator,
132
- mappers,
133
- options
134
- ) {
112
+ constructor(stripeClient, em, cache, openTelemetryCollector, schemaValidator, mappers, options) {
135
113
  this.options = options;
136
114
  this.stripeClient = stripeClient;
137
115
  this.em = em;
@@ -139,15 +117,14 @@ var StripeCheckoutSessionService = class {
139
117
  this.openTelemetryCollector = openTelemetryCollector;
140
118
  this.schemaValidator = schemaValidator;
141
119
  this.mappers = mappers;
142
- this.baseCheckoutSessionService =
143
- new import_services2.BaseCheckoutSessionService(
144
- em,
145
- cache,
146
- openTelemetryCollector,
147
- schemaValidator,
148
- mappers,
149
- options
150
- );
120
+ this.baseCheckoutSessionService = new import_services2.BaseCheckoutSessionService(
121
+ em,
122
+ cache,
123
+ openTelemetryCollector,
124
+ schemaValidator,
125
+ mappers,
126
+ options
127
+ );
151
128
  }
152
129
  baseCheckoutSessionService;
153
130
  stripeClient;
@@ -181,8 +158,7 @@ var StripeCheckoutSessionService = class {
181
158
  const session = await this.stripeClient.checkout.sessions.retrieve(
182
159
  idDto.id
183
160
  );
184
- const databaseCheckoutSession =
185
- await this.baseCheckoutSessionService.getCheckoutSession(idDto);
161
+ const databaseCheckoutSession = await this.baseCheckoutSessionService.getCheckoutSession(idDto);
186
162
  databaseCheckoutSession.stripeFields = session;
187
163
  return databaseCheckoutSession;
188
164
  }
@@ -193,7 +169,7 @@ var StripeCheckoutSessionService = class {
193
169
  async handleCheckoutSuccess({ id }) {
194
170
  await this.stripeClient.checkout.sessions.update(id, {
195
171
  metadata: {
196
- status: 'SUCCESS'
172
+ status: "SUCCESS"
197
173
  }
198
174
  });
199
175
  await this.baseCheckoutSessionService.handleCheckoutSuccess({ id });
@@ -201,7 +177,7 @@ var StripeCheckoutSessionService = class {
201
177
  async handleCheckoutFailure({ id }) {
202
178
  await this.stripeClient.checkout.sessions.update(id, {
203
179
  metadata: {
204
- status: 'FAILED'
180
+ status: "FAILED"
205
181
  }
206
182
  });
207
183
  await this.baseCheckoutSessionService.handleCheckoutFailure({ id });
@@ -209,17 +185,9 @@ var StripeCheckoutSessionService = class {
209
185
  };
210
186
 
211
187
  // services/paymentLink.service.ts
212
- var import_services3 = require('@forklaunch/implementation-billing-base/services');
188
+ var import_services3 = require("@forklaunch/implementation-billing-base/services");
213
189
  var StripePaymentLinkService = class {
214
- constructor(
215
- stripeClient,
216
- em,
217
- cache,
218
- openTelemetryCollector,
219
- schemaValidator,
220
- mappers,
221
- options
222
- ) {
190
+ constructor(stripeClient, em, cache, openTelemetryCollector, schemaValidator, mappers, options) {
223
191
  this.options = options;
224
192
  this.stripeClient = stripeClient;
225
193
  this.em = em;
@@ -253,11 +221,10 @@ var StripePaymentLinkService = class {
253
221
  {
254
222
  ...paymentLinkDto,
255
223
  id: session.id,
256
- amount:
257
- session.line_items?.data.reduce(
258
- (total, item) => total + item.amount_total,
259
- 0
260
- ) ?? 0
224
+ amount: session.line_items?.data.reduce(
225
+ (total, item) => total + item.amount_total,
226
+ 0
227
+ ) ?? 0
261
228
  },
262
229
  this.em,
263
230
  session,
@@ -279,11 +246,10 @@ var StripePaymentLinkService = class {
279
246
  {
280
247
  ...paymentLinkDto,
281
248
  id: session.id,
282
- amount:
283
- session.line_items?.data.reduce(
284
- (total, item) => total + item.amount_total,
285
- 0
286
- ) ?? 0
249
+ amount: session.line_items?.data.reduce(
250
+ (total, item) => total + item.amount_total,
251
+ 0
252
+ ) ?? 0
287
253
  },
288
254
  this.em,
289
255
  session
@@ -295,15 +261,14 @@ var StripePaymentLinkService = class {
295
261
  }
296
262
  async getPaymentLink({ id }) {
297
263
  const stripePaymentLink = await this.stripeClient.paymentLinks.retrieve(id);
298
- const databasePaymentLink =
299
- await this.basePaymentLinkService.getPaymentLink({ id });
264
+ const databasePaymentLink = await this.basePaymentLinkService.getPaymentLink({ id });
300
265
  databasePaymentLink.stripeFields = stripePaymentLink;
301
266
  return databasePaymentLink;
302
267
  }
303
268
  async expirePaymentLink({ id }) {
304
269
  await this.stripeClient.paymentLinks.update(id, {
305
270
  metadata: {
306
- status: 'EXPIRED'
271
+ status: "EXPIRED"
307
272
  }
308
273
  });
309
274
  await this.basePaymentLinkService.expirePaymentLink({ id });
@@ -311,7 +276,7 @@ var StripePaymentLinkService = class {
311
276
  async handlePaymentSuccess({ id }) {
312
277
  await this.stripeClient.paymentLinks.update(id, {
313
278
  metadata: {
314
- status: 'COMPLETED'
279
+ status: "COMPLETED"
315
280
  }
316
281
  });
317
282
  await this.basePaymentLinkService.handlePaymentSuccess({ id });
@@ -319,7 +284,7 @@ var StripePaymentLinkService = class {
319
284
  async handlePaymentFailure({ id }) {
320
285
  await this.stripeClient.paymentLinks.update(id, {
321
286
  metadata: {
322
- status: 'FAILED'
287
+ status: "FAILED"
323
288
  }
324
289
  });
325
290
  await this.basePaymentLinkService.handlePaymentFailure({ id });
@@ -328,8 +293,7 @@ var StripePaymentLinkService = class {
328
293
  const stripePaymentLinks = await this.stripeClient.paymentLinks.list({
329
294
  active: true
330
295
  });
331
- const databasePaymentLinks =
332
- await this.basePaymentLinkService.listPaymentLinks(idsDto);
296
+ const databasePaymentLinks = await this.basePaymentLinkService.listPaymentLinks(idsDto);
333
297
  return await Promise.all(
334
298
  databasePaymentLinks.map(async (paymentLink) => {
335
299
  const stripePaymentLink = stripePaymentLinks.data.find(
@@ -348,16 +312,9 @@ var StripePaymentLinkService = class {
348
312
  };
349
313
 
350
314
  // services/plan.service.ts
351
- var import_services4 = require('@forklaunch/implementation-billing-base/services');
315
+ var import_services4 = require("@forklaunch/implementation-billing-base/services");
352
316
  var StripePlanService = class {
353
- constructor(
354
- stripeClient,
355
- em,
356
- openTelemetryCollector,
357
- schemaValidator,
358
- mappers,
359
- options
360
- ) {
317
+ constructor(stripeClient, em, openTelemetryCollector, schemaValidator, mappers, options) {
361
318
  this.options = options;
362
319
  this.stripeClient = stripeClient;
363
320
  this.em = em;
@@ -389,7 +346,7 @@ var StripePlanService = class {
389
346
  {
390
347
  ...planDto,
391
348
  externalId: stripePlan.id,
392
- billingProvider: 'stripe'
349
+ billingProvider: "stripe"
393
350
  },
394
351
  em ?? this.em,
395
352
  stripePlan
@@ -398,13 +355,12 @@ var StripePlanService = class {
398
355
  }
399
356
  async getPlan(idDto, em) {
400
357
  const plan = await this.stripeClient.plans.retrieve(idDto.id);
401
- const id = (
402
- await em?.findOne(this.options?.databaseTableName ?? 'plan', {
403
- externalId: idDto.id
404
- })
405
- )?.id;
358
+ const id = (await em?.findOne(
359
+ this.options?.databaseTableName ?? "plan",
360
+ { externalId: idDto.id }
361
+ ))?.id;
406
362
  if (!id) {
407
- throw new Error('Plan not found');
363
+ throw new Error("Plan not found");
408
364
  }
409
365
  const planEntity = await this.basePlanService.getPlan({ id }, em);
410
366
  planEntity.stripeFields = plan;
@@ -412,8 +368,8 @@ var StripePlanService = class {
412
368
  }
413
369
  async updatePlan(planDto, em) {
414
370
  const existingPlan = await this.stripeClient.plans.retrieve(planDto.id);
415
- const plan = await this.stripeClient.plans.del(planDto.id).then(() =>
416
- this.stripeClient.plans.create({
371
+ const plan = await this.stripeClient.plans.del(planDto.id).then(
372
+ () => this.stripeClient.plans.create({
417
373
  ...planDto.stripeFields,
418
374
  interval: planDto.cadence ?? existingPlan.interval,
419
375
  product: planDto.name,
@@ -425,7 +381,7 @@ var StripePlanService = class {
425
381
  {
426
382
  ...planDto,
427
383
  externalId: plan.id,
428
- billingProvider: 'stripe'
384
+ billingProvider: "stripe"
429
385
  },
430
386
  em ?? this.em,
431
387
  plan
@@ -443,15 +399,12 @@ var StripePlanService = class {
443
399
  const plans = await this.stripeClient.plans.list({
444
400
  active: true
445
401
  });
446
- const planIds = (
447
- await em?.findAll(this.options?.databaseTableName ?? 'plan', {
448
- where: { externalId: { $in: plans.data.map((plan) => plan.id) } }
449
- })
450
- )
451
- ?.filter((s) => idsDto?.ids?.includes(s.id))
452
- ?.map((s) => s.id);
402
+ const planIds = (await em?.findAll(
403
+ this.options?.databaseTableName ?? "plan",
404
+ { where: { externalId: { $in: plans.data.map((plan) => plan.id) } } }
405
+ ))?.filter((s) => idsDto?.ids?.includes(s.id))?.map((s) => s.id);
453
406
  if (!planIds) {
454
- throw new Error('Plans not found');
407
+ throw new Error("Plans not found");
455
408
  }
456
409
  return await Promise.all(
457
410
  (await this.basePlanService.listPlans({ ids: planIds }, em)).map(
@@ -467,16 +420,9 @@ var StripePlanService = class {
467
420
  };
468
421
 
469
422
  // services/subscription.service.ts
470
- var import_services5 = require('@forklaunch/implementation-billing-base/services');
423
+ var import_services5 = require("@forklaunch/implementation-billing-base/services");
471
424
  var StripeSubscriptionService = class {
472
- constructor(
473
- stripeClient,
474
- em,
475
- openTelemetryCollector,
476
- schemaValidator,
477
- mappers,
478
- options
479
- ) {
425
+ constructor(stripeClient, em, openTelemetryCollector, schemaValidator, mappers, options) {
480
426
  this.options = options;
481
427
  this.stripeClient = stripeClient;
482
428
  this.em = em;
@@ -511,15 +457,14 @@ var StripeSubscriptionService = class {
511
457
  {
512
458
  ...subscriptionDto,
513
459
  externalId: subscription.id,
514
- billingProvider: 'stripe'
460
+ billingProvider: "stripe"
515
461
  },
516
462
  em ?? this.em,
517
463
  subscription
518
464
  );
519
465
  }
520
466
  async getSubscription(idDto, em) {
521
- const subscriptionEntity =
522
- await this.baseSubscriptionService.getSubscription(idDto, em);
467
+ const subscriptionEntity = await this.baseSubscriptionService.getSubscription(idDto, em);
523
468
  const stripeSubscription = await this.stripeClient.subscriptions.retrieve(
524
469
  idDto.id
525
470
  );
@@ -527,8 +472,7 @@ var StripeSubscriptionService = class {
527
472
  return subscriptionEntity;
528
473
  }
529
474
  async getUserSubscription(idDto, em) {
530
- const subscriptionEntity =
531
- await this.baseSubscriptionService.getUserSubscription(idDto, em);
475
+ const subscriptionEntity = await this.baseSubscriptionService.getUserSubscription(idDto, em);
532
476
  const stripeSubscription = await this.stripeClient.subscriptions.retrieve(
533
477
  idDto.id
534
478
  );
@@ -536,19 +480,17 @@ var StripeSubscriptionService = class {
536
480
  return subscriptionEntity;
537
481
  }
538
482
  async getOrganizationSubscription(idDto, em) {
539
- const id = (
540
- await em?.findOne(this.options?.databaseTableName ?? 'subscription', {
541
- externalId: idDto.id
542
- })
543
- )?.id;
483
+ const id = (await em?.findOne(
484
+ this.options?.databaseTableName ?? "subscription",
485
+ { externalId: idDto.id }
486
+ ))?.id;
544
487
  if (!id) {
545
- throw new Error('Subscription not found');
488
+ throw new Error("Subscription not found");
546
489
  }
547
- const subscriptionEntity =
548
- await this.baseSubscriptionService.getOrganizationSubscription(
549
- { id },
550
- em
551
- );
490
+ const subscriptionEntity = await this.baseSubscriptionService.getOrganizationSubscription(
491
+ { id },
492
+ em
493
+ );
552
494
  const stripeSubscription = await this.stripeClient.subscriptions.retrieve(
553
495
  idDto.id
554
496
  );
@@ -571,7 +513,7 @@ var StripeSubscriptionService = class {
571
513
  {
572
514
  ...subscriptionDto,
573
515
  externalId: subscription.id,
574
- billingProvider: 'stripe',
516
+ billingProvider: "stripe",
575
517
  providerFields: subscription
576
518
  },
577
519
  em ?? this.em,
@@ -583,18 +525,15 @@ var StripeSubscriptionService = class {
583
525
  await this.baseSubscriptionService.deleteSubscription(idDto, em);
584
526
  }
585
527
  async listSubscriptions(idsDto, em) {
586
- const subscriptions = (
587
- await this.stripeClient.subscriptions.list({
588
- status: 'active'
589
- })
590
- ).data.filter((s) => idsDto.ids?.includes(s.id));
591
- const ids = (
592
- await em?.findAll(this.options?.databaseTableName ?? 'subscription', {
593
- where: { externalId: { $in: subscriptions.map((s) => s.id) } }
594
- })
595
- )?.map((s) => s.id);
528
+ const subscriptions = (await this.stripeClient.subscriptions.list({
529
+ status: "active"
530
+ })).data.filter((s) => idsDto.ids?.includes(s.id));
531
+ const ids = (await em?.findAll(
532
+ this.options?.databaseTableName ?? "subscription",
533
+ { where: { externalId: { $in: subscriptions.map((s) => s.id) } } }
534
+ ))?.map((s) => s.id);
596
535
  if (!ids) {
597
- throw new Error('Subscriptions not found');
536
+ throw new Error("Subscriptions not found");
598
537
  }
599
538
  return await Promise.all(
600
539
  (await this.baseSubscriptionService.listSubscriptions({ ids }, em)).map(
@@ -620,7 +559,7 @@ var StripeSubscriptionService = class {
620
559
 
621
560
  // domain/enum/billingProvider.enum.ts
622
561
  var BillingProviderEnum = {
623
- STRIPE: 'stripe'
562
+ STRIPE: "stripe"
624
563
  };
625
564
 
626
565
  // services/webhook.service.ts
@@ -634,17 +573,7 @@ var StripeWebhookService = class {
634
573
  paymentLinkService;
635
574
  planService;
636
575
  subscriptionService;
637
- constructor(
638
- stripeClient,
639
- em,
640
- schemaValidator,
641
- openTelemetryCollector,
642
- billingPortalService,
643
- checkoutSessionService,
644
- paymentLinkService,
645
- planService,
646
- subscriptionService
647
- ) {
576
+ constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService) {
648
577
  this.stripeClient = stripeClient;
649
578
  this.em = em;
650
579
  this.schemaValidator = schemaValidator;
@@ -657,11 +586,11 @@ var StripeWebhookService = class {
657
586
  }
658
587
  async handleWebhookEvent(event) {
659
588
  if (this.openTelemetryCollector) {
660
- this.openTelemetryCollector.info('Handling webhook event', event);
589
+ this.openTelemetryCollector.info("Handling webhook event", event);
661
590
  }
662
591
  const eventType = event.type;
663
592
  switch (eventType) {
664
- case 'billing_portal.session.created': {
593
+ case "billing_portal.session.created": {
665
594
  this.billingPortalService.baseBillingPortalService.createBillingPortalSession(
666
595
  {
667
596
  id: event.data.object.id,
@@ -672,156 +601,130 @@ var StripeWebhookService = class {
672
601
  );
673
602
  break;
674
603
  }
675
- case 'checkout.session.expired': {
604
+ case "checkout.session.expired": {
676
605
  this.checkoutSessionService.handleCheckoutFailure({
677
606
  id: event.data.object.id
678
607
  });
679
608
  break;
680
609
  }
681
- case 'checkout.session.completed': {
610
+ case "checkout.session.completed": {
682
611
  this.checkoutSessionService.handleCheckoutSuccess({
683
612
  id: event.data.object.id
684
613
  });
685
614
  break;
686
615
  }
687
- case 'payment_link.created':
616
+ case "payment_link.created":
688
617
  {
689
618
  this.paymentLinkService.basePaymentLinkService.createPaymentLink({
690
619
  id: event.data.object.id,
691
- amount:
692
- event.data.object.line_items?.data.reduce(
693
- (total, item) => total + item.amount_total,
694
- 0
695
- ) ?? 0,
620
+ amount: event.data.object.line_items?.data.reduce(
621
+ (total, item) => total + item.amount_total,
622
+ 0
623
+ ) ?? 0,
696
624
  paymentMethods: event.data.object.payment_method_types,
697
- status: 'CREATED',
625
+ status: "CREATED",
698
626
  currency: event.data.object.currency
699
627
  });
700
628
  }
701
629
  break;
702
- case 'payment_link.updated': {
630
+ case "payment_link.updated": {
703
631
  this.paymentLinkService.basePaymentLinkService.updatePaymentLink({
704
632
  id: event.data.object.id,
705
- amount:
706
- event.data.object.line_items?.data.reduce(
707
- (total, item) => total + item.amount_total,
708
- 0
709
- ) ?? 0,
633
+ amount: event.data.object.line_items?.data.reduce(
634
+ (total, item) => total + item.amount_total,
635
+ 0
636
+ ) ?? 0,
710
637
  paymentMethods: event.data.object.payment_method_types,
711
- status: 'UPDATED',
638
+ status: "UPDATED",
712
639
  currency: event.data.object.currency
713
640
  });
714
641
  break;
715
642
  }
716
- case 'plan.created': {
717
- if (
718
- typeof event.data.object.product === 'object' &&
719
- event.data.object.product != null &&
720
- event.data.object.amount != null
721
- ) {
643
+ case "plan.created": {
644
+ if (typeof event.data.object.product === "object" && event.data.object.product != null && event.data.object.amount != null) {
722
645
  this.planService.basePlanService.createPlan({
723
646
  id: event.data.object.id,
724
647
  billingProvider: BillingProviderEnum.STRIPE,
725
648
  cadence: event.data.object.interval,
726
649
  currency: event.data.object.currency,
727
650
  active: true,
728
- name:
729
- typeof event.data.object.product === 'string'
730
- ? event.data.object.product
731
- : event.data.object.product?.id,
651
+ name: typeof event.data.object.product === "string" ? event.data.object.product : event.data.object.product?.id,
732
652
  price: event.data.object.amount,
733
653
  externalId: event.data.object.id
734
654
  });
735
655
  } else {
736
- throw new Error('Invalid plan');
656
+ throw new Error("Invalid plan");
737
657
  }
738
658
  break;
739
659
  }
740
- case 'plan.updated': {
741
- if (
742
- typeof event.data.object.product === 'object' &&
743
- event.data.object.product != null &&
744
- event.data.object.amount != null
745
- ) {
660
+ case "plan.updated": {
661
+ if (typeof event.data.object.product === "object" && event.data.object.product != null && event.data.object.amount != null) {
746
662
  this.planService.basePlanService.updatePlan({
747
663
  id: event.data.object.id,
748
664
  billingProvider: BillingProviderEnum.STRIPE,
749
665
  cadence: event.data.object.interval,
750
666
  currency: event.data.object.currency,
751
667
  active: true,
752
- name:
753
- typeof event.data.object.product === 'string'
754
- ? event.data.object.product
755
- : event.data.object.product?.id,
668
+ name: typeof event.data.object.product === "string" ? event.data.object.product : event.data.object.product?.id,
756
669
  price: event.data.object.amount,
757
670
  externalId: event.data.object.id
758
671
  });
759
672
  } else {
760
- throw new Error('Invalid plan');
673
+ throw new Error("Invalid plan");
761
674
  }
762
675
  break;
763
676
  }
764
- case 'plan.deleted': {
677
+ case "plan.deleted": {
765
678
  this.planService.deletePlan({
766
679
  id: event.data.object.id
767
680
  });
768
681
  break;
769
682
  }
770
- case 'customer.subscription.created': {
683
+ case "customer.subscription.created": {
771
684
  this.subscriptionService.baseSubscriptionService.createSubscription({
772
685
  id: event.data.object.id,
773
- partyId:
774
- typeof event.data.object.customer === 'string'
775
- ? event.data.object.customer
776
- : event.data.object.customer.id,
777
- partyType: 'USER',
686
+ partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
687
+ partyType: "USER",
778
688
  description: event.data.object.description ?? void 0,
779
689
  active: true,
780
690
  productId: event.data.object.items.data[0].plan.id,
781
691
  externalId: event.data.object.id,
782
692
  billingProvider: BillingProviderEnum.STRIPE,
783
693
  startDate: new Date(event.data.object.created),
784
- endDate: event.data.object.cancel_at
785
- ? new Date(event.data.object.cancel_at)
786
- : /* @__PURE__ */ new Date(Infinity),
694
+ endDate: event.data.object.cancel_at ? new Date(event.data.object.cancel_at) : /* @__PURE__ */ new Date(Infinity),
787
695
  status: event.data.object.status
788
696
  });
789
697
  break;
790
698
  }
791
- case 'customer.subscription.updated': {
699
+ case "customer.subscription.updated": {
792
700
  this.subscriptionService.baseSubscriptionService.updateSubscription({
793
701
  id: event.data.object.id,
794
- partyId:
795
- typeof event.data.object.customer === 'string'
796
- ? event.data.object.customer
797
- : event.data.object.customer.id,
798
- partyType: 'USER',
702
+ partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
703
+ partyType: "USER",
799
704
  description: event.data.object.description ?? void 0,
800
705
  active: true,
801
706
  externalId: event.data.object.id,
802
707
  billingProvider: BillingProviderEnum.STRIPE,
803
708
  startDate: new Date(event.data.object.created),
804
- endDate: event.data.object.cancel_at
805
- ? new Date(event.data.object.cancel_at)
806
- : /* @__PURE__ */ new Date(Infinity),
709
+ endDate: event.data.object.cancel_at ? new Date(event.data.object.cancel_at) : /* @__PURE__ */ new Date(Infinity),
807
710
  productId: event.data.object.items.data[0].plan.id,
808
711
  status: event.data.object.status
809
712
  });
810
713
  break;
811
714
  }
812
- case 'customer.subscription.deleted': {
715
+ case "customer.subscription.deleted": {
813
716
  this.subscriptionService.deleteSubscription({
814
717
  id: event.data.object.id
815
718
  });
816
719
  break;
817
720
  }
818
- case 'customer.subscription.paused': {
721
+ case "customer.subscription.paused": {
819
722
  this.subscriptionService.cancelSubscription({
820
723
  id: event.data.object.id
821
724
  });
822
725
  break;
823
726
  }
824
- case 'customer.subscription.resumed': {
727
+ case "customer.subscription.resumed": {
825
728
  this.subscriptionService.resumeSubscription({
826
729
  id: event.data.object.id
827
730
  });
@@ -829,7 +732,7 @@ var StripeWebhookService = class {
829
732
  }
830
733
  default:
831
734
  this.openTelemetryCollector.info(
832
- 'Unprocessed stripe event type',
735
+ "Unprocessed stripe event type",
833
736
  eventType
834
737
  );
835
738
  break;
@@ -837,12 +740,11 @@ var StripeWebhookService = class {
837
740
  }
838
741
  };
839
742
  // Annotate the CommonJS export names for ESM import in node:
840
- 0 &&
841
- (module.exports = {
842
- StripeBillingPortalService,
843
- StripeCheckoutSessionService,
844
- StripePaymentLinkService,
845
- StripePlanService,
846
- StripeSubscriptionService,
847
- StripeWebhookService
848
- });
743
+ 0 && (module.exports = {
744
+ StripeBillingPortalService,
745
+ StripeCheckoutSessionService,
746
+ StripePaymentLinkService,
747
+ StripePlanService,
748
+ StripeSubscriptionService,
749
+ StripeWebhookService
750
+ });