@forklaunch/implementation-billing-stripe 0.2.7 → 0.3.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.
@@ -35,7 +35,6 @@ module.exports = __toCommonJS(services_exports);
35
35
 
36
36
  // services/billingPortal.service.ts
37
37
  var import_services = require('@forklaunch/implementation-billing-base/services');
38
- var import_internal = require('@forklaunch/internal');
39
38
  var StripeBillingPortalService = class {
40
39
  constructor(
41
40
  stripeClient,
@@ -53,68 +52,50 @@ var StripeBillingPortalService = class {
53
52
  this.openTelemetryCollector = openTelemetryCollector;
54
53
  this.schemaValidator = schemaValidator;
55
54
  this.mappers = mappers;
56
- this._mappers = (0, import_internal.transformIntoInternalMapper)(
57
- mappers,
58
- schemaValidator
59
- );
60
55
  this.baseBillingPortalService =
61
56
  new import_services.BaseBillingPortalService(
62
57
  em,
63
58
  cache,
64
59
  openTelemetryCollector,
65
60
  schemaValidator,
66
- {
67
- BillingPortalMapper: import_internal.IdentityResponseMapper,
68
- CreateBillingPortalMapper: import_internal.IdentityRequestMapper,
69
- UpdateBillingPortalMapper: import_internal.IdentityRequestMapper
70
- },
61
+ mappers,
71
62
  options
72
63
  );
73
64
  }
74
- billingPortalSessionExpiryDurationMs = 5 * 60 * 1e3;
75
65
  baseBillingPortalService;
76
- _mappers;
77
66
  stripeClient;
78
67
  em;
79
68
  cache;
80
69
  openTelemetryCollector;
81
70
  schemaValidator;
71
+ billingPortalSessionExpiryDurationMs = 5 * 60 * 1e3;
82
72
  mappers;
83
- async createBillingPortalSession(billingPortalDto) {
73
+ async createBillingPortalSession(billingPortalDto, ...args) {
84
74
  const session = await this.stripeClient.billingPortal.sessions.create({
85
75
  ...billingPortalDto.stripeFields,
86
76
  customer: billingPortalDto.customerId
87
77
  });
88
- const billingPortalEntity =
89
- await this.baseBillingPortalService.createBillingPortalSession(
90
- await this._mappers.CreateBillingPortalMapper.deserializeDtoToEntity(
91
- {
92
- ...billingPortalDto,
93
- id: session.id,
94
- uri: session.url,
95
- expiresAt: new Date(
96
- Date.now() + this.billingPortalSessionExpiryDurationMs
97
- )
98
- },
99
- this.em,
100
- session
78
+ return await this.baseBillingPortalService.createBillingPortalSession(
79
+ {
80
+ ...billingPortalDto,
81
+ id: session.id,
82
+ uri: session.url,
83
+ expiresAt: new Date(
84
+ Date.now() + this.billingPortalSessionExpiryDurationMs
101
85
  )
102
- );
103
- return this._mappers.BillingPortalMapper.serializeEntityToDto(
104
- billingPortalEntity
86
+ },
87
+ this.em,
88
+ session,
89
+ ...args
105
90
  );
106
91
  }
107
92
  async getBillingPortalSession(idDto) {
108
- const billingPortalEntity =
109
- await this.baseBillingPortalService.getBillingPortalSession(idDto);
110
- return this._mappers.BillingPortalMapper.serializeEntityToDto(
111
- billingPortalEntity
112
- );
93
+ return await this.baseBillingPortalService.getBillingPortalSession(idDto);
113
94
  }
114
95
  async expireBillingPortalSession(idDto) {
115
96
  return this.baseBillingPortalService.expireBillingPortalSession(idDto);
116
97
  }
117
- async updateBillingPortalSession(billingPortalDto) {
98
+ async updateBillingPortalSession(billingPortalDto, ...args) {
118
99
  const existingSession =
119
100
  await this.baseBillingPortalService.getBillingPortalSession({
120
101
  id: billingPortalDto.id
@@ -123,30 +104,24 @@ var StripeBillingPortalService = class {
123
104
  ...billingPortalDto.stripeFields,
124
105
  customer: existingSession.customerId
125
106
  });
126
- const baseBillingPortalDto =
127
- await this.baseBillingPortalService.updateBillingPortalSession(
128
- await this._mappers.UpdateBillingPortalMapper.deserializeDtoToEntity(
129
- {
130
- ...billingPortalDto,
131
- id: session.id,
132
- uri: session.url,
133
- expiresAt: new Date(
134
- Date.now() + this.billingPortalSessionExpiryDurationMs
135
- )
136
- },
137
- this.em,
138
- session
107
+ return await this.baseBillingPortalService.updateBillingPortalSession(
108
+ {
109
+ ...billingPortalDto,
110
+ id: session.id,
111
+ uri: session.url,
112
+ expiresAt: new Date(
113
+ Date.now() + this.billingPortalSessionExpiryDurationMs
139
114
  )
140
- );
141
- return this._mappers.BillingPortalMapper.serializeEntityToDto(
142
- baseBillingPortalDto
115
+ },
116
+ this.em,
117
+ session,
118
+ ...args
143
119
  );
144
120
  }
145
121
  };
146
122
 
147
123
  // services/checkoutSession.service.ts
148
124
  var import_services2 = require('@forklaunch/implementation-billing-base/services');
149
- var import_internal2 = require('@forklaunch/internal');
150
125
  var StripeCheckoutSessionService = class {
151
126
  constructor(
152
127
  stripeClient,
@@ -164,33 +139,24 @@ var StripeCheckoutSessionService = class {
164
139
  this.openTelemetryCollector = openTelemetryCollector;
165
140
  this.schemaValidator = schemaValidator;
166
141
  this.mappers = mappers;
167
- this._mappers = (0, import_internal2.transformIntoInternalMapper)(
168
- mappers,
169
- schemaValidator
170
- );
171
142
  this.baseCheckoutSessionService =
172
143
  new import_services2.BaseCheckoutSessionService(
173
144
  em,
174
145
  cache,
175
146
  openTelemetryCollector,
176
147
  schemaValidator,
177
- {
178
- CheckoutSessionMapper: import_internal2.IdentityResponseMapper,
179
- CreateCheckoutSessionMapper: import_internal2.IdentityRequestMapper,
180
- UpdateCheckoutSessionMapper: import_internal2.IdentityRequestMapper
181
- },
148
+ mappers,
182
149
  options
183
150
  );
184
151
  }
185
152
  baseCheckoutSessionService;
186
- _mappers;
187
153
  stripeClient;
188
154
  em;
189
155
  cache;
190
156
  openTelemetryCollector;
191
157
  schemaValidator;
192
158
  mappers;
193
- async createCheckoutSession(checkoutSessionDto) {
159
+ async createCheckoutSession(checkoutSessionDto, ...args) {
194
160
  const session = await this.stripeClient.checkout.sessions.create({
195
161
  ...checkoutSessionDto.stripeFields,
196
162
  payment_method_types: checkoutSessionDto.paymentMethods,
@@ -198,33 +164,27 @@ var StripeCheckoutSessionService = class {
198
164
  success_url: checkoutSessionDto.successRedirectUri,
199
165
  cancel_url: checkoutSessionDto.cancelRedirectUri
200
166
  });
201
- const checkoutSessionEntity =
202
- await this.baseCheckoutSessionService.createCheckoutSession(
203
- await this._mappers.CreateCheckoutSessionMapper.deserializeDtoToEntity(
204
- {
205
- ...checkoutSessionDto,
206
- id: session.id,
207
- uri: session.url,
208
- expiresAt: new Date(Date.now() + 5 * 60 * 1e3),
209
- providerFields: session
210
- },
211
- this.em,
212
- session
213
- )
214
- );
215
- return this._mappers.CheckoutSessionMapper.serializeEntityToDto(
216
- checkoutSessionEntity
167
+ return await this.baseCheckoutSessionService.createCheckoutSession(
168
+ {
169
+ ...checkoutSessionDto,
170
+ id: session.id,
171
+ uri: session.url ?? void 0,
172
+ expiresAt: new Date(Date.now() + 5 * 60 * 1e3),
173
+ providerFields: session
174
+ },
175
+ this.em,
176
+ session,
177
+ ...args
217
178
  );
218
179
  }
219
- async getCheckoutSession({ id }) {
180
+ async getCheckoutSession(idDto) {
181
+ const session = await this.stripeClient.checkout.sessions.retrieve(
182
+ idDto.id
183
+ );
220
184
  const databaseCheckoutSession =
221
- await this.baseCheckoutSessionService.getCheckoutSession({ id });
222
- return {
223
- ...this._mappers.CheckoutSessionMapper.serializeEntityToDto(
224
- databaseCheckoutSession
225
- ),
226
- stripeFields: await this.stripeClient.checkout.sessions.retrieve(id)
227
- };
185
+ await this.baseCheckoutSessionService.getCheckoutSession(idDto);
186
+ databaseCheckoutSession.stripeFields = session;
187
+ return databaseCheckoutSession;
228
188
  }
229
189
  async expireCheckoutSession({ id }) {
230
190
  await this.stripeClient.checkout.sessions.expire(id);
@@ -250,7 +210,6 @@ var StripeCheckoutSessionService = class {
250
210
 
251
211
  // services/paymentLink.service.ts
252
212
  var import_services3 = require('@forklaunch/implementation-billing-base/services');
253
- var import_internal3 = require('@forklaunch/internal');
254
213
  var StripePaymentLinkService = class {
255
214
  constructor(
256
215
  stripeClient,
@@ -268,58 +227,46 @@ var StripePaymentLinkService = class {
268
227
  this.openTelemetryCollector = openTelemetryCollector;
269
228
  this.schemaValidator = schemaValidator;
270
229
  this.mappers = mappers;
271
- this._mappers = (0, import_internal3.transformIntoInternalMapper)(
272
- mappers,
273
- schemaValidator
274
- );
275
230
  this.basePaymentLinkService = new import_services3.BasePaymentLinkService(
276
231
  em,
277
232
  cache,
278
233
  openTelemetryCollector,
279
234
  schemaValidator,
280
- {
281
- PaymentLinkMapper: import_internal3.IdentityResponseMapper,
282
- CreatePaymentLinkMapper: import_internal3.IdentityRequestMapper,
283
- UpdatePaymentLinkMapper: import_internal3.IdentityRequestMapper
284
- },
235
+ mappers,
285
236
  options
286
237
  );
287
238
  }
288
239
  basePaymentLinkService;
289
- _mappers;
290
240
  stripeClient;
291
241
  em;
292
242
  cache;
293
243
  openTelemetryCollector;
294
244
  schemaValidator;
295
245
  mappers;
296
- async createPaymentLink(paymentLinkDto) {
246
+ async createPaymentLink(paymentLinkDto, ...args) {
297
247
  const session = await this.stripeClient.paymentLinks.create({
298
248
  ...paymentLinkDto.stripeFields,
299
249
  payment_method_types: paymentLinkDto.paymentMethods,
300
250
  currency: paymentLinkDto.currency
301
251
  });
302
- const paymentLinkEntity =
303
- await this.basePaymentLinkService.createPaymentLink(
304
- await this._mappers.CreatePaymentLinkMapper.deserializeDtoToEntity(
305
- {
306
- ...paymentLinkDto,
307
- id: session.id,
308
- amount:
309
- session.line_items?.data.reduce(
310
- (total, item) => total + item.amount_total,
311
- 0
312
- ) ?? 0
313
- },
314
- this.em,
315
- session
316
- )
317
- );
318
- return this._mappers.PaymentLinkMapper.serializeEntityToDto(
319
- paymentLinkEntity
252
+ const paymentLink = await this.basePaymentLinkService.createPaymentLink(
253
+ {
254
+ ...paymentLinkDto,
255
+ id: session.id,
256
+ amount:
257
+ session.line_items?.data.reduce(
258
+ (total, item) => total + item.amount_total,
259
+ 0
260
+ ) ?? 0
261
+ },
262
+ this.em,
263
+ session,
264
+ ...args
320
265
  );
266
+ paymentLink.stripeFields = session;
267
+ return paymentLink;
321
268
  }
322
- async updatePaymentLink(paymentLinkDto) {
269
+ async updatePaymentLink(paymentLinkDto, ...args) {
323
270
  const session = await this.stripeClient.paymentLinks.update(
324
271
  paymentLinkDto.id,
325
272
  {
@@ -327,35 +274,31 @@ var StripePaymentLinkService = class {
327
274
  payment_method_types: paymentLinkDto.paymentMethods
328
275
  }
329
276
  );
330
- const paymentLinkEntity =
331
- await this.basePaymentLinkService.updatePaymentLink(
332
- await this._mappers.UpdatePaymentLinkMapper.deserializeDtoToEntity(
333
- {
334
- ...paymentLinkDto,
335
- id: session.id,
336
- amount:
337
- session.line_items?.data.reduce(
338
- (total, item) => total + item.amount_total,
339
- 0
340
- ) ?? 0
341
- },
342
- this.em,
343
- session
344
- )
345
- );
346
- return this._mappers.PaymentLinkMapper.serializeEntityToDto(
347
- paymentLinkEntity
277
+ const paymentLink = await this.basePaymentLinkService.updatePaymentLink(
278
+ await this.mappers.UpdatePaymentLinkMapper.toEntity(
279
+ {
280
+ ...paymentLinkDto,
281
+ id: session.id,
282
+ amount:
283
+ session.line_items?.data.reduce(
284
+ (total, item) => total + item.amount_total,
285
+ 0
286
+ ) ?? 0
287
+ },
288
+ this.em,
289
+ session
290
+ ),
291
+ ...args
348
292
  );
293
+ paymentLink.stripeFields = session;
294
+ return paymentLink;
349
295
  }
350
296
  async getPaymentLink({ id }) {
297
+ const stripePaymentLink = await this.stripeClient.paymentLinks.retrieve(id);
351
298
  const databasePaymentLink =
352
299
  await this.basePaymentLinkService.getPaymentLink({ id });
353
- return {
354
- ...this._mappers.PaymentLinkMapper.serializeEntityToDto(
355
- databasePaymentLink
356
- ),
357
- stripeFields: await this.stripeClient.paymentLinks.retrieve(id)
358
- };
300
+ databasePaymentLink.stripeFields = stripePaymentLink;
301
+ return databasePaymentLink;
359
302
  }
360
303
  async expirePaymentLink({ id }) {
361
304
  await this.stripeClient.paymentLinks.update(id, {
@@ -382,27 +325,30 @@ var StripePaymentLinkService = class {
382
325
  await this.basePaymentLinkService.handlePaymentFailure({ id });
383
326
  }
384
327
  async listPaymentLinks(idsDto) {
385
- const paymentLinks = await this.stripeClient.paymentLinks.list({
328
+ const stripePaymentLinks = await this.stripeClient.paymentLinks.list({
386
329
  active: true
387
330
  });
331
+ const databasePaymentLinks =
332
+ await this.basePaymentLinkService.listPaymentLinks(idsDto);
388
333
  return await Promise.all(
389
- (await this.basePaymentLinkService.listPaymentLinks(idsDto)).map(
390
- async (paymentLink) => ({
391
- ...(await this._mappers.PaymentLinkMapper.serializeEntityToDto(
392
- paymentLink
393
- )),
394
- stripeFields: paymentLinks.data.find(
395
- (paymentLink2) => paymentLink2.id === paymentLink2.id
396
- )
397
- })
398
- )
334
+ databasePaymentLinks.map(async (paymentLink) => {
335
+ const stripePaymentLink = stripePaymentLinks.data.find(
336
+ (sp) => sp.id === paymentLink.id
337
+ );
338
+ if (!stripePaymentLink) {
339
+ throw new Error(
340
+ `Stripe payment link not found for id: ${paymentLink.id}`
341
+ );
342
+ }
343
+ paymentLink.stripeFields = stripePaymentLink;
344
+ return paymentLink;
345
+ })
399
346
  );
400
347
  }
401
348
  };
402
349
 
403
350
  // services/plan.service.ts
404
351
  var import_services4 = require('@forklaunch/implementation-billing-base/services');
405
- var import_internal4 = require('@forklaunch/internal');
406
352
  var StripePlanService = class {
407
353
  constructor(
408
354
  stripeClient,
@@ -418,49 +364,37 @@ var StripePlanService = class {
418
364
  this.openTelemetryCollector = openTelemetryCollector;
419
365
  this.schemaValidator = schemaValidator;
420
366
  this.mappers = mappers;
421
- this._mappers = (0, import_internal4.transformIntoInternalMapper)(
422
- mappers,
423
- schemaValidator
424
- );
425
367
  this.basePlanService = new import_services4.BasePlanService(
426
368
  em,
427
369
  openTelemetryCollector,
428
370
  schemaValidator,
429
- {
430
- PlanMapper: import_internal4.IdentityResponseMapper,
431
- CreatePlanMapper: import_internal4.IdentityRequestMapper,
432
- UpdatePlanMapper: import_internal4.IdentityRequestMapper
433
- },
371
+ mappers,
434
372
  options
435
373
  );
436
374
  }
437
375
  basePlanService;
438
- _mappers;
439
376
  stripeClient;
440
377
  em;
441
378
  openTelemetryCollector;
442
379
  schemaValidator;
443
380
  mappers;
444
381
  async createPlan(planDto, em) {
445
- const plan = await this.stripeClient.plans.create({
382
+ const stripePlan = await this.stripeClient.plans.create({
446
383
  ...planDto.stripeFields,
447
384
  interval: planDto.cadence,
448
385
  product: planDto.name,
449
386
  currency: planDto.currency
450
387
  });
451
- const planEntity = await this.basePlanService.createPlan(
452
- await this._mappers.CreatePlanMapper.deserializeDtoToEntity(
453
- {
454
- ...planDto,
455
- externalId: plan.id,
456
- billingProvider: 'stripe'
457
- },
458
- em ?? this.em,
459
- plan
460
- ),
461
- em
388
+ const plan = await this.basePlanService.createPlan(
389
+ {
390
+ ...planDto,
391
+ externalId: stripePlan.id,
392
+ billingProvider: 'stripe'
393
+ },
394
+ em ?? this.em,
395
+ stripePlan
462
396
  );
463
- return this._mappers.PlanMapper.serializeEntityToDto(planEntity);
397
+ return plan;
464
398
  }
465
399
  async getPlan(idDto, em) {
466
400
  const plan = await this.stripeClient.plans.retrieve(idDto.id);
@@ -472,12 +406,9 @@ var StripePlanService = class {
472
406
  if (!id) {
473
407
  throw new Error('Plan not found');
474
408
  }
475
- return {
476
- ...(await this._mappers.PlanMapper.serializeEntityToDto(
477
- await this.basePlanService.getPlan({ id }, em)
478
- )),
479
- stripeFields: plan
480
- };
409
+ const planEntity = await this.basePlanService.getPlan({ id }, em);
410
+ planEntity.stripeFields = plan;
411
+ return planEntity;
481
412
  }
482
413
  async updatePlan(planDto, em) {
483
414
  const existingPlan = await this.stripeClient.plans.retrieve(planDto.id);
@@ -490,7 +421,7 @@ var StripePlanService = class {
490
421
  })
491
422
  );
492
423
  const planEntity = await this.basePlanService.updatePlan(
493
- await this._mappers.UpdatePlanMapper.deserializeDtoToEntity(
424
+ await this.mappers.UpdatePlanMapper.toEntity(
494
425
  {
495
426
  ...planDto,
496
427
  externalId: plan.id,
@@ -501,7 +432,8 @@ var StripePlanService = class {
501
432
  ),
502
433
  em
503
434
  );
504
- return this._mappers.PlanMapper.serializeEntityToDto(planEntity);
435
+ planEntity.stripeFields = plan;
436
+ return planEntity;
505
437
  }
506
438
  async deletePlan(idDto, em) {
507
439
  await this.stripeClient.plans.del(idDto.id);
@@ -511,33 +443,34 @@ var StripePlanService = class {
511
443
  const plans = await this.stripeClient.plans.list({
512
444
  active: true
513
445
  });
514
- const ids = (
446
+ const planIds = (
515
447
  await em?.findAll(this.options?.databaseTableName ?? 'plan', {
516
448
  where: { externalId: { $in: plans.data.map((plan) => plan.id) } }
517
449
  })
518
450
  )
519
451
  ?.filter((s) => idsDto?.ids?.includes(s.id))
520
452
  ?.map((s) => s.id);
521
- if (!ids) {
453
+ if (!planIds) {
522
454
  throw new Error('Plans not found');
523
455
  }
524
456
  return await Promise.all(
525
- (await this.basePlanService.listPlans({ ids }, em)).map(async (plan) => ({
526
- ...(await this._mappers.PlanMapper.serializeEntityToDto(plan)),
527
- stripeFields: plans.data.find(
528
- (stripePlan) => stripePlan.id === plan.externalId
529
- )
530
- }))
457
+ (await this.basePlanService.listPlans({ ids: planIds }, em)).map(
458
+ async (plan) => ({
459
+ ...plan,
460
+ stripeFields: plans.data.find(
461
+ (stripePlan) => stripePlan.id === plan.externalId
462
+ )
463
+ })
464
+ )
531
465
  );
532
466
  }
533
467
  };
534
468
 
535
469
  // services/subscription.service.ts
536
470
  var import_services5 = require('@forklaunch/implementation-billing-base/services');
537
- var import_internal5 = require('@forklaunch/internal');
538
471
  var StripeSubscriptionService = class {
539
472
  constructor(
540
- stripe,
473
+ stripeClient,
541
474
  em,
542
475
  openTelemetryCollector,
543
476
  schemaValidator,
@@ -545,36 +478,27 @@ var StripeSubscriptionService = class {
545
478
  options
546
479
  ) {
547
480
  this.options = options;
548
- this.stripe = stripe;
481
+ this.stripeClient = stripeClient;
549
482
  this.em = em;
550
483
  this.openTelemetryCollector = openTelemetryCollector;
551
484
  this.schemaValidator = schemaValidator;
552
485
  this.mappers = mappers;
553
- this._mappers = (0, import_internal5.transformIntoInternalMapper)(
554
- mappers,
555
- schemaValidator
556
- );
557
486
  this.baseSubscriptionService = new import_services5.BaseSubscriptionService(
558
487
  em,
559
488
  openTelemetryCollector,
560
489
  schemaValidator,
561
- {
562
- SubscriptionMapper: import_internal5.IdentityResponseMapper,
563
- CreateSubscriptionMapper: import_internal5.IdentityRequestMapper,
564
- UpdateSubscriptionMapper: import_internal5.IdentityRequestMapper
565
- },
490
+ mappers,
566
491
  options
567
492
  );
568
493
  }
569
494
  baseSubscriptionService;
570
- _mappers;
571
- stripe;
495
+ stripeClient;
572
496
  em;
573
497
  openTelemetryCollector;
574
498
  schemaValidator;
575
499
  mappers;
576
500
  async createSubscription(subscriptionDto, em) {
577
- const subscription = await this.stripe.subscriptions.create({
501
+ const subscription = await this.stripeClient.subscriptions.create({
578
502
  ...subscriptionDto.stripeFields,
579
503
  customer: subscriptionDto.partyId,
580
504
  items: [
@@ -583,38 +507,33 @@ var StripeSubscriptionService = class {
583
507
  }
584
508
  ]
585
509
  });
586
- const subscriptionEntity =
587
- await this.baseSubscriptionService.createSubscription(
588
- await this._mappers.CreateSubscriptionMapper.deserializeDtoToEntity(
589
- {
590
- ...subscriptionDto,
591
- externalId: subscription.id,
592
- billingProvider: 'stripe'
593
- },
594
- em ?? this.em,
595
- subscription
596
- ),
597
- em
598
- );
599
- return this._mappers.SubscriptionMapper.serializeEntityToDto(
600
- subscriptionEntity
510
+ return await this.baseSubscriptionService.createSubscription(
511
+ {
512
+ ...subscriptionDto,
513
+ externalId: subscription.id,
514
+ billingProvider: 'stripe'
515
+ },
516
+ em ?? this.em,
517
+ subscription
601
518
  );
602
519
  }
603
520
  async getSubscription(idDto, em) {
604
- return {
605
- ...(await this._mappers.SubscriptionMapper.serializeEntityToDto(
606
- await this.baseSubscriptionService.getSubscription(idDto, em)
607
- )),
608
- stripeFields: await this.stripe.subscriptions.retrieve(idDto.id)
609
- };
521
+ const subscriptionEntity =
522
+ await this.baseSubscriptionService.getSubscription(idDto, em);
523
+ const stripeSubscription = await this.stripeClient.subscriptions.retrieve(
524
+ idDto.id
525
+ );
526
+ subscriptionEntity.stripeFields = stripeSubscription;
527
+ return subscriptionEntity;
610
528
  }
611
529
  async getUserSubscription(idDto, em) {
612
- return {
613
- ...(await this._mappers.SubscriptionMapper.serializeEntityToDto(
614
- await this.baseSubscriptionService.getUserSubscription(idDto, em)
615
- )),
616
- stripeFields: await this.stripe.subscriptions.retrieve(idDto.id)
617
- };
530
+ const subscriptionEntity =
531
+ await this.baseSubscriptionService.getUserSubscription(idDto, em);
532
+ const stripeSubscription = await this.stripeClient.subscriptions.retrieve(
533
+ idDto.id
534
+ );
535
+ subscriptionEntity.stripeFields = stripeSubscription;
536
+ return subscriptionEntity;
618
537
  }
619
538
  async getOrganizationSubscription(idDto, em) {
620
539
  const id = (
@@ -625,18 +544,19 @@ var StripeSubscriptionService = class {
625
544
  if (!id) {
626
545
  throw new Error('Subscription not found');
627
546
  }
628
- return {
629
- ...(await this._mappers.SubscriptionMapper.serializeEntityToDto(
630
- await this.baseSubscriptionService.getOrganizationSubscription(
631
- { id },
632
- em
633
- )
634
- )),
635
- stripeFields: await this.stripe.subscriptions.retrieve(idDto.id)
636
- };
547
+ const subscriptionEntity =
548
+ await this.baseSubscriptionService.getOrganizationSubscription(
549
+ { id },
550
+ em
551
+ );
552
+ const stripeSubscription = await this.stripeClient.subscriptions.retrieve(
553
+ idDto.id
554
+ );
555
+ subscriptionEntity.stripeFields = stripeSubscription;
556
+ return subscriptionEntity;
637
557
  }
638
558
  async updateSubscription(subscriptionDto, em) {
639
- const subscription = await this.stripe.subscriptions.update(
559
+ const subscription = await this.stripeClient.subscriptions.update(
640
560
  subscriptionDto.id,
641
561
  {
642
562
  ...subscriptionDto.stripeFields,
@@ -647,31 +567,24 @@ var StripeSubscriptionService = class {
647
567
  ]
648
568
  }
649
569
  );
650
- const subscriptionEntity =
651
- await this.baseSubscriptionService.updateSubscription(
652
- await this._mappers.UpdateSubscriptionMapper.deserializeDtoToEntity(
653
- {
654
- ...subscriptionDto,
655
- externalId: subscription.id,
656
- billingProvider: 'stripe',
657
- providerFields: subscription
658
- },
659
- em ?? this.em,
660
- subscription
661
- ),
662
- em
663
- );
664
- return this._mappers.SubscriptionMapper.serializeEntityToDto(
665
- subscriptionEntity
570
+ return await this.baseSubscriptionService.updateSubscription(
571
+ {
572
+ ...subscriptionDto,
573
+ externalId: subscription.id,
574
+ billingProvider: 'stripe',
575
+ providerFields: subscription
576
+ },
577
+ em ?? this.em,
578
+ subscription
666
579
  );
667
580
  }
668
581
  async deleteSubscription(idDto, em) {
669
- await this.stripe.subscriptions.cancel(idDto.id);
582
+ await this.stripeClient.subscriptions.cancel(idDto.id);
670
583
  await this.baseSubscriptionService.deleteSubscription(idDto, em);
671
584
  }
672
585
  async listSubscriptions(idsDto, em) {
673
586
  const subscriptions = (
674
- await this.stripe.subscriptions.list({
587
+ await this.stripeClient.subscriptions.list({
675
588
  status: 'active'
676
589
  })
677
590
  ).data.filter((s) => idsDto.ids?.includes(s.id));
@@ -686,24 +599,21 @@ var StripeSubscriptionService = class {
686
599
  return await Promise.all(
687
600
  (await this.baseSubscriptionService.listSubscriptions({ ids }, em)).map(
688
601
  async (subscription) => {
689
- return {
690
- ...(await this._mappers.SubscriptionMapper.serializeEntityToDto(
691
- subscription
692
- )),
693
- stripeFields: subscriptions.find(
694
- (s) => s.id === subscription.externalId
695
- )
696
- };
602
+ const stripeSubscription = subscriptions.find(
603
+ (s) => s.id === subscription.externalId
604
+ );
605
+ subscription.stripeFields = stripeSubscription;
606
+ return subscription;
697
607
  }
698
608
  )
699
609
  );
700
610
  }
701
611
  async cancelSubscription(idDto, em) {
702
- await this.stripe.subscriptions.cancel(idDto.id);
612
+ await this.stripeClient.subscriptions.cancel(idDto.id);
703
613
  await this.baseSubscriptionService.cancelSubscription(idDto, em);
704
614
  }
705
615
  async resumeSubscription(idDto, em) {
706
- await this.stripe.subscriptions.resume(idDto.id);
616
+ await this.stripeClient.subscriptions.resume(idDto.id);
707
617
  await this.baseSubscriptionService.resumeSubscription(idDto, em);
708
618
  }
709
619
  };
@@ -757,8 +667,7 @@ var StripeWebhookService = class {
757
667
  id: event.data.object.id,
758
668
  customerId: event.data.object.customer,
759
669
  expiresAt: new Date(event.data.object.created + 5 * 60 * 1e3),
760
- uri: event.data.object.url,
761
- providerFields: event.data.object
670
+ uri: event.data.object.url
762
671
  }
763
672
  );
764
673
  break;
@@ -786,8 +695,7 @@ var StripeWebhookService = class {
786
695
  ) ?? 0,
787
696
  paymentMethods: event.data.object.payment_method_types,
788
697
  status: 'CREATED',
789
- currency: event.data.object.currency,
790
- providerFields: event.data.object
698
+ currency: event.data.object.currency
791
699
  });
792
700
  }
793
701
  break;
@@ -801,8 +709,7 @@ var StripeWebhookService = class {
801
709
  ) ?? 0,
802
710
  paymentMethods: event.data.object.payment_method_types,
803
711
  status: 'UPDATED',
804
- currency: event.data.object.currency,
805
- providerFields: event.data.object
712
+ currency: event.data.object.currency
806
713
  });
807
714
  break;
808
715
  }
@@ -823,8 +730,7 @@ var StripeWebhookService = class {
823
730
  ? event.data.object.product
824
731
  : event.data.object.product?.id,
825
732
  price: event.data.object.amount,
826
- externalId: event.data.object.id,
827
- providerFields: event.data.object
733
+ externalId: event.data.object.id
828
734
  });
829
735
  } else {
830
736
  throw new Error('Invalid plan');
@@ -848,8 +754,7 @@ var StripeWebhookService = class {
848
754
  ? event.data.object.product
849
755
  : event.data.object.product?.id,
850
756
  price: event.data.object.amount,
851
- externalId: event.data.object.id,
852
- providerFields: event.data.object
757
+ externalId: event.data.object.id
853
758
  });
854
759
  } else {
855
760
  throw new Error('Invalid plan');
@@ -873,7 +778,6 @@ var StripeWebhookService = class {
873
778
  description: event.data.object.description ?? void 0,
874
779
  active: true,
875
780
  productId: event.data.object.items.data[0].plan.id,
876
- providerFields: event.data.object,
877
781
  externalId: event.data.object.id,
878
782
  billingProvider: BillingProviderEnum.STRIPE,
879
783
  startDate: new Date(event.data.object.created),
@@ -894,7 +798,6 @@ var StripeWebhookService = class {
894
798
  partyType: 'USER',
895
799
  description: event.data.object.description ?? void 0,
896
800
  active: true,
897
- providerFields: event.data.object,
898
801
  externalId: event.data.object.id,
899
802
  billingProvider: BillingProviderEnum.STRIPE,
900
803
  startDate: new Date(event.data.object.created),