@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.
@@ -0,0 +1,31 @@
1
+ import { EntityManager } from '@mikro-orm/core';
2
+ import Stripe from 'stripe';
3
+ import { StripeBillingPortalDtos } from './stripe.dto.types';
4
+ import { StripeBillingPortalEntities } from './stripe.entity.types';
5
+
6
+ export type StripeBillingPortalMappers<
7
+ Entities extends StripeBillingPortalEntities,
8
+ Dto extends StripeBillingPortalDtos
9
+ > = {
10
+ BillingPortalMapper: {
11
+ toDto: (
12
+ entity: Entities['BillingPortalMapper']
13
+ ) => Promise<Dto['BillingPortalMapper']>;
14
+ };
15
+ CreateBillingPortalMapper: {
16
+ toEntity: (
17
+ dto: Dto['CreateBillingPortalMapper'],
18
+ em: EntityManager,
19
+ stripeSession: Stripe.BillingPortal.Session,
20
+ ...args: unknown[]
21
+ ) => Promise<Entities['CreateBillingPortalMapper']>;
22
+ };
23
+ UpdateBillingPortalMapper: {
24
+ toEntity: (
25
+ dto: Dto['UpdateBillingPortalMapper'],
26
+ em: EntityManager,
27
+ stripeSession: Stripe.BillingPortal.Session,
28
+ ...args: unknown[]
29
+ ) => Promise<Entities['UpdateBillingPortalMapper']>;
30
+ };
31
+ };
@@ -0,0 +1,32 @@
1
+ import { EntityManager } from '@mikro-orm/core';
2
+ import Stripe from 'stripe';
3
+ import { StripeCheckoutSessionDtos } from './stripe.dto.types';
4
+ import { StripeCheckoutSessionEntities } from './stripe.entity.types';
5
+
6
+ export type StripeCheckoutSessionMappers<
7
+ StatusEnum,
8
+ Entities extends StripeCheckoutSessionEntities<StatusEnum>,
9
+ Dto extends StripeCheckoutSessionDtos<StatusEnum>
10
+ > = {
11
+ CheckoutSessionMapper: {
12
+ toDto: (
13
+ entity: Entities['CheckoutSessionMapper']
14
+ ) => Promise<Dto['CheckoutSessionMapper']>;
15
+ };
16
+ CreateCheckoutSessionMapper: {
17
+ toEntity: (
18
+ dto: Dto['CreateCheckoutSessionMapper'],
19
+ em: EntityManager,
20
+ stripeSession: Stripe.Checkout.Session,
21
+ ...args: unknown[]
22
+ ) => Promise<Entities['CreateCheckoutSessionMapper']>;
23
+ };
24
+ UpdateCheckoutSessionMapper: {
25
+ toEntity: (
26
+ dto: Dto['UpdateCheckoutSessionMapper'],
27
+ em: EntityManager,
28
+ stripeSession: Stripe.Checkout.Session,
29
+ ...args: unknown[]
30
+ ) => Promise<Entities['UpdateCheckoutSessionMapper']>;
31
+ };
32
+ };
@@ -1,2 +1,7 @@
1
+ export * from './billingPortal.mapper.types';
2
+ export * from './checkoutSession.mapper.types';
3
+ export * from './paymentLink.mapper.types';
4
+ export * from './plan.mapper.types';
1
5
  export * from './stripe.dto.types';
2
6
  export type * from './stripe.entity.types';
7
+ export * from './subscription.mapper.types';
@@ -0,0 +1,32 @@
1
+ import { EntityManager } from '@mikro-orm/core';
2
+ import Stripe from 'stripe';
3
+ import { StripePaymentLinkDtos } from './stripe.dto.types';
4
+ import { StripePaymentLinkEntities } from './stripe.entity.types';
5
+
6
+ export type StripePaymentLinkMappers<
7
+ StatusEnum,
8
+ Entities extends StripePaymentLinkEntities<StatusEnum>,
9
+ Dto extends StripePaymentLinkDtos<StatusEnum>
10
+ > = {
11
+ PaymentLinkMapper: {
12
+ toDto: (
13
+ entity: Entities['PaymentLinkMapper']
14
+ ) => Promise<Dto['PaymentLinkMapper']>;
15
+ };
16
+ CreatePaymentLinkMapper: {
17
+ toEntity: (
18
+ dto: Dto['CreatePaymentLinkMapper'],
19
+ em: EntityManager,
20
+ stripePaymentLink: Stripe.PaymentLink,
21
+ ...args: unknown[]
22
+ ) => Promise<Entities['CreatePaymentLinkMapper']>;
23
+ };
24
+ UpdatePaymentLinkMapper: {
25
+ toEntity: (
26
+ dto: Dto['UpdatePaymentLinkMapper'],
27
+ em: EntityManager,
28
+ stripePaymentLink: Stripe.PaymentLink,
29
+ ...args: unknown[]
30
+ ) => Promise<Entities['UpdatePaymentLinkMapper']>;
31
+ };
32
+ };
@@ -0,0 +1,29 @@
1
+ import { EntityManager } from '@mikro-orm/core';
2
+ import Stripe from 'stripe';
3
+ import { StripePlanDtos } from './stripe.dto.types';
4
+ import { StripePlanEntities } from './stripe.entity.types';
5
+
6
+ export type StripePlanMappers<
7
+ Entities extends StripePlanEntities,
8
+ Dto extends StripePlanDtos
9
+ > = {
10
+ PlanMapper: {
11
+ toDto: (entity: Entities['PlanMapper']) => Promise<Dto['PlanMapper']>;
12
+ };
13
+ CreatePlanMapper: {
14
+ toEntity: (
15
+ dto: Dto['CreatePlanMapper'],
16
+ em: EntityManager,
17
+ stripePlan: Stripe.Plan,
18
+ ...args: unknown[]
19
+ ) => Promise<Entities['CreatePlanMapper']>;
20
+ };
21
+ UpdatePlanMapper: {
22
+ toEntity: (
23
+ dto: Dto['UpdatePlanMapper'],
24
+ em: EntityManager,
25
+ stripePlan: Stripe.Plan,
26
+ ...args: unknown[]
27
+ ) => Promise<Entities['UpdatePlanMapper']>;
28
+ };
29
+ };
@@ -0,0 +1,32 @@
1
+ import { EntityManager } from '@mikro-orm/core';
2
+ import Stripe from 'stripe';
3
+ import { StripeSubscriptionDtos } from './stripe.dto.types';
4
+ import { StripeSubscriptionEntities } from './stripe.entity.types';
5
+
6
+ export type StripeSubscriptionMappers<
7
+ PartyType,
8
+ Entities extends StripeSubscriptionEntities<PartyType>,
9
+ Dto extends StripeSubscriptionDtos<PartyType>
10
+ > = {
11
+ SubscriptionMapper: {
12
+ toDto: (
13
+ entity: Entities['SubscriptionMapper']
14
+ ) => Promise<Dto['SubscriptionMapper']>;
15
+ };
16
+ CreateSubscriptionMapper: {
17
+ toEntity: (
18
+ dto: Dto['CreateSubscriptionMapper'],
19
+ em: EntityManager,
20
+ stripeSubscription: Stripe.Subscription,
21
+ ...args: unknown[]
22
+ ) => Promise<Entities['CreateSubscriptionMapper']>;
23
+ };
24
+ UpdateSubscriptionMapper: {
25
+ toEntity: (
26
+ dto: Dto['UpdateSubscriptionMapper'],
27
+ em: EntityManager,
28
+ stripeSubscription: Stripe.Subscription,
29
+ ...args: unknown[]
30
+ ) => Promise<Entities['UpdateSubscriptionMapper']>;
31
+ };
32
+ };
@@ -1,4 +1,4 @@
1
- import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
1
+ import { IdDto } from '@forklaunch/common';
2
2
  import { TtlCache } from '@forklaunch/core/cache';
3
3
  import {
4
4
  MetricsDefinition,
@@ -6,20 +6,13 @@ import {
6
6
  TelemetryOptions
7
7
  } from '@forklaunch/core/http';
8
8
  import { BaseBillingPortalService } from '@forklaunch/implementation-billing-base/services';
9
+ import { BillingPortalMappers } from '@forklaunch/implementation-billing-base/types';
9
10
  import { BillingPortalService } from '@forklaunch/interfaces-billing/interfaces';
10
- import {
11
- IdentityRequestMapper,
12
- IdentityResponseMapper,
13
- InternalMapper,
14
- RequestMapperConstructor,
15
- ResponseMapperConstructor,
16
- transformIntoInternalMapper
17
- } from '@forklaunch/internal';
18
11
  import { AnySchemaValidator } from '@forklaunch/validator';
19
12
  import { EntityManager } from '@mikro-orm/core';
20
13
  import Stripe from 'stripe';
14
+ import { StripeBillingPortalMappers } from '../domain/types/billingPortal.mapper.types';
21
15
  import {
22
- StripeBillingPortalDto,
23
16
  StripeBillingPortalDtos,
24
17
  StripeCreateBillingPortalDto,
25
18
  StripeUpdateBillingPortalDto
@@ -32,52 +25,24 @@ export class StripeBillingPortalService<
32
25
  Dto extends StripeBillingPortalDtos = StripeBillingPortalDtos
33
26
  > implements
34
27
  BillingPortalService<{
35
- CreateBillingPortalDto: StripeCreateBillingPortalDto;
36
- UpdateBillingPortalDto: StripeUpdateBillingPortalDto;
37
- BillingPortalDto: StripeBillingPortalDto;
28
+ CreateBillingPortalDto: Dto['CreateBillingPortalMapper'];
29
+ UpdateBillingPortalDto: Dto['UpdateBillingPortalMapper'];
30
+ BillingPortalDto: Dto['BillingPortalMapper'];
38
31
  IdDto: IdDto;
39
32
  }>
40
33
  {
41
- private readonly billingPortalSessionExpiryDurationMs = 5 * 60 * 1000;
42
-
43
34
  baseBillingPortalService: BaseBillingPortalService<
44
35
  SchemaValidator,
45
36
  Entities,
46
- Entities
37
+ Dto
47
38
  >;
48
- protected _mappers: InternalMapper<InstanceTypeRecord<typeof this.mappers>>;
49
- protected stripeClient: Stripe;
50
- protected em: EntityManager;
51
- protected cache: TtlCache;
52
- protected openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
53
- protected schemaValidator: SchemaValidator;
54
- protected mappers: {
55
- BillingPortalMapper: ResponseMapperConstructor<
56
- SchemaValidator,
57
- Dto['BillingPortalMapper'],
58
- Entities['BillingPortalMapper']
59
- >;
60
- CreateBillingPortalMapper: RequestMapperConstructor<
61
- SchemaValidator,
62
- Dto['CreateBillingPortalMapper'],
63
- Entities['CreateBillingPortalMapper'],
64
- (
65
- dto: Dto['CreateBillingPortalMapper'],
66
- em: EntityManager,
67
- session: Stripe.BillingPortal.Session
68
- ) => Promise<Entities['CreateBillingPortalMapper']>
69
- >;
70
- UpdateBillingPortalMapper: RequestMapperConstructor<
71
- SchemaValidator,
72
- Dto['UpdateBillingPortalMapper'],
73
- Entities['UpdateBillingPortalMapper'],
74
- (
75
- dto: Dto['UpdateBillingPortalMapper'],
76
- em: EntityManager,
77
- session: Stripe.BillingPortal.Session
78
- ) => Promise<Entities['UpdateBillingPortalMapper']>
79
- >;
80
- };
39
+ protected readonly stripeClient: Stripe;
40
+ protected readonly em: EntityManager;
41
+ protected readonly cache: TtlCache;
42
+ protected readonly openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
43
+ protected readonly schemaValidator: SchemaValidator;
44
+ private readonly billingPortalSessionExpiryDurationMs = 5 * 60 * 1000;
45
+ protected readonly mappers: StripeBillingPortalMappers<Entities, Dto>;
81
46
 
82
47
  constructor(
83
48
  stripeClient: Stripe,
@@ -85,36 +50,10 @@ export class StripeBillingPortalService<
85
50
  cache: TtlCache,
86
51
  openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
87
52
  schemaValidator: SchemaValidator,
88
- mappers: {
89
- BillingPortalMapper: ResponseMapperConstructor<
90
- SchemaValidator,
91
- Dto['BillingPortalMapper'],
92
- Entities['BillingPortalMapper']
93
- >;
94
- CreateBillingPortalMapper: RequestMapperConstructor<
95
- SchemaValidator,
96
- Dto['CreateBillingPortalMapper'],
97
- Entities['CreateBillingPortalMapper'],
98
- (
99
- dto: Dto['CreateBillingPortalMapper'],
100
- em: EntityManager,
101
- session: Stripe.BillingPortal.Session
102
- ) => Promise<Entities['CreateBillingPortalMapper']>
103
- >;
104
- UpdateBillingPortalMapper: RequestMapperConstructor<
105
- SchemaValidator,
106
- Dto['UpdateBillingPortalMapper'],
107
- Entities['UpdateBillingPortalMapper'],
108
- (
109
- dto: Dto['UpdateBillingPortalMapper'],
110
- em: EntityManager,
111
- session: Stripe.BillingPortal.Session
112
- ) => Promise<Entities['UpdateBillingPortalMapper']>
113
- >;
114
- },
53
+ mappers: StripeBillingPortalMappers<Entities, Dto>,
115
54
  readonly options?: {
116
- telemetry?: TelemetryOptions;
117
55
  enableDatabaseBackup?: boolean;
56
+ telemetry?: TelemetryOptions;
118
57
  }
119
58
  ) {
120
59
  this.stripeClient = stripeClient;
@@ -123,65 +62,48 @@ export class StripeBillingPortalService<
123
62
  this.openTelemetryCollector = openTelemetryCollector;
124
63
  this.schemaValidator = schemaValidator;
125
64
  this.mappers = mappers;
126
- this._mappers = transformIntoInternalMapper(mappers, schemaValidator);
127
- this.baseBillingPortalService = new BaseBillingPortalService(
65
+ this.baseBillingPortalService = new BaseBillingPortalService<
66
+ SchemaValidator,
67
+ Entities,
68
+ Dto
69
+ >(
128
70
  em,
129
71
  cache,
130
72
  openTelemetryCollector,
131
73
  schemaValidator,
132
- {
133
- BillingPortalMapper: IdentityResponseMapper<
134
- Entities['BillingPortalMapper']
135
- >,
136
- CreateBillingPortalMapper: IdentityRequestMapper<
137
- Entities['CreateBillingPortalMapper']
138
- >,
139
- UpdateBillingPortalMapper: IdentityRequestMapper<
140
- Entities['UpdateBillingPortalMapper']
141
- >
142
- },
74
+ mappers as BillingPortalMappers<Entities, Dto>,
143
75
  options
144
76
  );
145
77
  }
146
78
 
147
79
  async createBillingPortalSession(
148
- billingPortalDto: Dto['CreateBillingPortalMapper']
80
+ billingPortalDto: StripeCreateBillingPortalDto,
81
+ ...args: unknown[]
149
82
  ): Promise<Dto['BillingPortalMapper']> {
150
83
  const session = await this.stripeClient.billingPortal.sessions.create({
151
84
  ...billingPortalDto.stripeFields,
152
85
  customer: billingPortalDto.customerId
153
86
  });
154
87
 
155
- const billingPortalEntity =
156
- await this.baseBillingPortalService.createBillingPortalSession(
157
- await this._mappers.CreateBillingPortalMapper.deserializeDtoToEntity(
158
- {
159
- ...billingPortalDto,
160
- id: session.id,
161
- uri: session.url,
162
- expiresAt: new Date(
163
- Date.now() + this.billingPortalSessionExpiryDurationMs
164
- )
165
- },
166
- this.em,
167
- session
88
+ return await this.baseBillingPortalService.createBillingPortalSession(
89
+ {
90
+ ...billingPortalDto,
91
+ id: session.id,
92
+ uri: session.url,
93
+ expiresAt: new Date(
94
+ Date.now() + this.billingPortalSessionExpiryDurationMs
168
95
  )
169
- );
170
-
171
- return this._mappers.BillingPortalMapper.serializeEntityToDto(
172
- billingPortalEntity
96
+ },
97
+ this.em,
98
+ session,
99
+ ...args
173
100
  );
174
101
  }
175
102
 
176
103
  async getBillingPortalSession(
177
104
  idDto: IdDto
178
105
  ): Promise<Dto['BillingPortalMapper']> {
179
- const billingPortalEntity =
180
- await this.baseBillingPortalService.getBillingPortalSession(idDto);
181
-
182
- return this._mappers.BillingPortalMapper.serializeEntityToDto(
183
- billingPortalEntity
184
- );
106
+ return await this.baseBillingPortalService.getBillingPortalSession(idDto);
185
107
  }
186
108
 
187
109
  async expireBillingPortalSession(idDto: IdDto): Promise<void> {
@@ -189,7 +111,8 @@ export class StripeBillingPortalService<
189
111
  }
190
112
 
191
113
  async updateBillingPortalSession(
192
- billingPortalDto: Dto['UpdateBillingPortalMapper']
114
+ billingPortalDto: StripeUpdateBillingPortalDto,
115
+ ...args: unknown[]
193
116
  ): Promise<Dto['BillingPortalMapper']> {
194
117
  const existingSession =
195
118
  await this.baseBillingPortalService.getBillingPortalSession({
@@ -200,24 +123,18 @@ export class StripeBillingPortalService<
200
123
  customer: existingSession.customerId
201
124
  });
202
125
 
203
- const baseBillingPortalDto =
204
- await this.baseBillingPortalService.updateBillingPortalSession(
205
- await this._mappers.UpdateBillingPortalMapper.deserializeDtoToEntity(
206
- {
207
- ...billingPortalDto,
208
- id: session.id,
209
- uri: session.url,
210
- expiresAt: new Date(
211
- Date.now() + this.billingPortalSessionExpiryDurationMs
212
- )
213
- },
214
- this.em,
215
- session
126
+ return await this.baseBillingPortalService.updateBillingPortalSession(
127
+ {
128
+ ...billingPortalDto,
129
+ id: session.id,
130
+ uri: session.url,
131
+ expiresAt: new Date(
132
+ Date.now() + this.billingPortalSessionExpiryDurationMs
216
133
  )
217
- );
218
-
219
- return this._mappers.BillingPortalMapper.serializeEntityToDto(
220
- baseBillingPortalDto
134
+ },
135
+ this.em,
136
+ session,
137
+ ...args
221
138
  );
222
139
  }
223
140
  }
@@ -1,4 +1,4 @@
1
- import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
1
+ import { IdDto } from '@forklaunch/common';
2
2
  import { TtlCache } from '@forklaunch/core/cache';
3
3
  import {
4
4
  MetricsDefinition,
@@ -6,21 +6,18 @@ import {
6
6
  TelemetryOptions
7
7
  } from '@forklaunch/core/http';
8
8
  import { BaseCheckoutSessionService } from '@forklaunch/implementation-billing-base/services';
9
+ import { CheckoutSessionMappers } from '@forklaunch/implementation-billing-base/types';
9
10
  import { CheckoutSessionService } from '@forklaunch/interfaces-billing/interfaces';
10
- import {
11
- IdentityRequestMapper,
12
- IdentityResponseMapper,
13
- InternalMapper,
14
- RequestMapperConstructor,
15
- ResponseMapperConstructor,
16
- transformIntoInternalMapper
17
- } from '@forklaunch/internal';
18
11
  import { AnySchemaValidator } from '@forklaunch/validator';
19
12
  import { EntityManager } from '@mikro-orm/core';
20
13
  import Stripe from 'stripe';
21
14
  import { CurrencyEnum } from '../domain/enum/currency.enum';
22
15
  import { PaymentMethodEnum } from '../domain/enum/paymentMethod.enum';
23
- import { StripeCheckoutSessionDtos } from '../domain/types/stripe.dto.types';
16
+ import { StripeCheckoutSessionMappers } from '../domain/types/checkoutSession.mapper.types';
17
+ import {
18
+ StripeCheckoutSessionDtos,
19
+ StripeCreateCheckoutSessionDto
20
+ } from '../domain/types/stripe.dto.types';
24
21
  import { StripeCheckoutSessionEntities } from '../domain/types/stripe.entity.types';
25
22
 
26
23
  export class StripeCheckoutSessionService<
@@ -43,45 +40,22 @@ export class StripeCheckoutSessionService<
43
40
  {
44
41
  baseCheckoutSessionService: BaseCheckoutSessionService<
45
42
  SchemaValidator,
46
- typeof PaymentMethodEnum,
47
- typeof CurrencyEnum,
43
+ PaymentMethodEnum,
44
+ CurrencyEnum,
48
45
  StatusEnum,
49
46
  Entities,
50
- Entities
47
+ Dto
51
48
  >;
52
- protected _mappers: InternalMapper<InstanceTypeRecord<typeof this.mappers>>;
53
49
  protected readonly stripeClient: Stripe;
54
50
  protected readonly em: EntityManager;
55
51
  protected readonly cache: TtlCache;
56
52
  protected readonly openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
57
53
  protected readonly schemaValidator: SchemaValidator;
58
- protected readonly mappers: {
59
- CheckoutSessionMapper: ResponseMapperConstructor<
60
- SchemaValidator,
61
- Dto['CheckoutSessionMapper'],
62
- Entities['CheckoutSessionMapper']
63
- >;
64
- CreateCheckoutSessionMapper: RequestMapperConstructor<
65
- SchemaValidator,
66
- Dto['CreateCheckoutSessionMapper'],
67
- Entities['CreateCheckoutSessionMapper'],
68
- (
69
- dto: Dto['CreateCheckoutSessionMapper'],
70
- em: EntityManager,
71
- session: Stripe.Checkout.Session
72
- ) => Promise<Entities['CreateCheckoutSessionMapper']>
73
- >;
74
- UpdateCheckoutSessionMapper: RequestMapperConstructor<
75
- SchemaValidator,
76
- Dto['UpdateCheckoutSessionMapper'],
77
- Entities['UpdateCheckoutSessionMapper'],
78
- (
79
- dto: Dto['UpdateCheckoutSessionMapper'],
80
- em: EntityManager,
81
- session: Stripe.Checkout.Session
82
- ) => Promise<Entities['UpdateCheckoutSessionMapper']>
83
- >;
84
- };
54
+ protected readonly mappers: StripeCheckoutSessionMappers<
55
+ StatusEnum,
56
+ Entities,
57
+ Dto
58
+ >;
85
59
 
86
60
  constructor(
87
61
  stripeClient: Stripe,
@@ -89,33 +63,7 @@ export class StripeCheckoutSessionService<
89
63
  cache: TtlCache,
90
64
  openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
91
65
  schemaValidator: SchemaValidator,
92
- mappers: {
93
- CheckoutSessionMapper: ResponseMapperConstructor<
94
- SchemaValidator,
95
- Dto['CheckoutSessionMapper'],
96
- Entities['CheckoutSessionMapper']
97
- >;
98
- CreateCheckoutSessionMapper: RequestMapperConstructor<
99
- SchemaValidator,
100
- Dto['CreateCheckoutSessionMapper'],
101
- Entities['CreateCheckoutSessionMapper'],
102
- (
103
- dto: Dto['CreateCheckoutSessionMapper'],
104
- em: EntityManager,
105
- session: Stripe.Checkout.Session
106
- ) => Promise<Entities['CreateCheckoutSessionMapper']>
107
- >;
108
- UpdateCheckoutSessionMapper: RequestMapperConstructor<
109
- SchemaValidator,
110
- Dto['UpdateCheckoutSessionMapper'],
111
- Entities['UpdateCheckoutSessionMapper'],
112
- (
113
- dto: Dto['UpdateCheckoutSessionMapper'],
114
- em: EntityManager,
115
- session: Stripe.Checkout.Session
116
- ) => Promise<Entities['UpdateCheckoutSessionMapper']>
117
- >;
118
- },
66
+ mappers: StripeCheckoutSessionMappers<StatusEnum, Entities, Dto>,
119
67
  readonly options?: {
120
68
  enableDatabaseBackup?: boolean;
121
69
  telemetry?: TelemetryOptions;
@@ -127,29 +75,25 @@ export class StripeCheckoutSessionService<
127
75
  this.openTelemetryCollector = openTelemetryCollector;
128
76
  this.schemaValidator = schemaValidator;
129
77
  this.mappers = mappers;
130
- this._mappers = transformIntoInternalMapper(mappers, schemaValidator);
131
78
  this.baseCheckoutSessionService = new BaseCheckoutSessionService(
132
79
  em,
133
80
  cache,
134
81
  openTelemetryCollector,
135
82
  schemaValidator,
136
- {
137
- CheckoutSessionMapper: IdentityResponseMapper<
138
- Entities['CheckoutSessionMapper']
139
- >,
140
- CreateCheckoutSessionMapper: IdentityRequestMapper<
141
- Entities['CreateCheckoutSessionMapper']
142
- >,
143
- UpdateCheckoutSessionMapper: IdentityRequestMapper<
144
- Entities['UpdateCheckoutSessionMapper']
145
- >
146
- },
83
+ mappers as CheckoutSessionMappers<
84
+ PaymentMethodEnum,
85
+ CurrencyEnum,
86
+ StatusEnum,
87
+ Entities,
88
+ Dto
89
+ >,
147
90
  options
148
91
  );
149
92
  }
150
93
 
151
94
  async createCheckoutSession(
152
- checkoutSessionDto: Dto['CreateCheckoutSessionMapper']
95
+ checkoutSessionDto: StripeCreateCheckoutSessionDto<StatusEnum>,
96
+ ...args: unknown[]
153
97
  ): Promise<Dto['CheckoutSessionMapper']> {
154
98
  const session = await this.stripeClient.checkout.sessions.create({
155
99
  ...checkoutSessionDto.stripeFields,
@@ -159,37 +103,32 @@ export class StripeCheckoutSessionService<
159
103
  cancel_url: checkoutSessionDto.cancelRedirectUri
160
104
  });
161
105
 
162
- const checkoutSessionEntity =
163
- await this.baseCheckoutSessionService.createCheckoutSession(
164
- await this._mappers.CreateCheckoutSessionMapper.deserializeDtoToEntity(
165
- {
166
- ...checkoutSessionDto,
167
- id: session.id,
168
- uri: session.url,
169
- expiresAt: new Date(Date.now() + 5 * 60 * 1000),
170
- providerFields: session
171
- },
172
- this.em,
173
- session
174
- )
175
- );
176
-
177
- return this._mappers.CheckoutSessionMapper.serializeEntityToDto(
178
- checkoutSessionEntity
106
+ return await this.baseCheckoutSessionService.createCheckoutSession(
107
+ {
108
+ ...checkoutSessionDto,
109
+ id: session.id,
110
+ uri: session.url ?? undefined,
111
+ expiresAt: new Date(Date.now() + 5 * 60 * 1000),
112
+ providerFields: session
113
+ },
114
+ this.em,
115
+ session,
116
+ ...args
179
117
  );
180
118
  }
181
119
 
182
- async getCheckoutSession({
183
- id
184
- }: IdDto): Promise<Dto['CheckoutSessionMapper']> {
120
+ async getCheckoutSession(
121
+ idDto: IdDto
122
+ ): Promise<Dto['CheckoutSessionMapper']> {
123
+ const session = await this.stripeClient.checkout.sessions.retrieve(
124
+ idDto.id
125
+ );
185
126
  const databaseCheckoutSession =
186
- await this.baseCheckoutSessionService.getCheckoutSession({ id });
187
- return {
188
- ...this._mappers.CheckoutSessionMapper.serializeEntityToDto(
189
- databaseCheckoutSession
190
- ),
191
- stripeFields: await this.stripeClient.checkout.sessions.retrieve(id)
192
- };
127
+ await this.baseCheckoutSessionService.getCheckoutSession(idDto);
128
+
129
+ databaseCheckoutSession.stripeFields = session;
130
+
131
+ return databaseCheckoutSession;
193
132
  }
194
133
 
195
134
  async expireCheckoutSession({ id }: IdDto): Promise<void> {