@forklaunch/implementation-billing-base 0.5.8 → 0.6.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.
- package/lib/domain/types/index.d.mts +326 -0
- package/lib/domain/types/index.d.ts +326 -0
- package/lib/domain/types/index.js +22 -0
- package/lib/domain/types/index.mjs +0 -0
- package/lib/eject/domain/types/billingPortal.mapper.types.ts +28 -0
- package/lib/eject/domain/types/checkoutSession.mapper.types.ts +39 -0
- package/lib/eject/domain/types/index.ts +7 -0
- package/lib/eject/domain/types/paymentLink.mapper.types.ts +39 -0
- package/lib/eject/domain/types/plan.mapper.types.ts +39 -0
- package/lib/eject/domain/types/subscription.mapper.types.ts +33 -0
- package/lib/eject/services/billingPortal.service.ts +33 -87
- package/lib/eject/services/checkoutSession.service.ts +40 -78
- package/lib/eject/services/paymentLink.service.ts +69 -97
- package/lib/eject/services/plan.service.ts +49 -86
- package/lib/eject/services/subscription.service.ts +36 -83
- package/lib/services/index.d.mts +168 -495
- package/lib/services/index.d.ts +168 -495
- package/lib/services/index.js +94 -139
- package/lib/services/index.mjs +94 -124
- package/package.json +9 -9
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
2
|
+
import { BaseCheckoutSessionDtos } from './baseBillingDto.types';
|
|
3
|
+
import { BaseCheckoutSessionEntities } from './baseBillingEntity.types';
|
|
4
|
+
|
|
5
|
+
export type CheckoutSessionMappers<
|
|
6
|
+
PaymentMethodEnum,
|
|
7
|
+
CurrencyEnum,
|
|
8
|
+
StatusEnum,
|
|
9
|
+
MapperEntities extends BaseCheckoutSessionEntities<
|
|
10
|
+
PaymentMethodEnum,
|
|
11
|
+
CurrencyEnum,
|
|
12
|
+
StatusEnum
|
|
13
|
+
>,
|
|
14
|
+
MapperDomains extends BaseCheckoutSessionDtos<
|
|
15
|
+
PaymentMethodEnum,
|
|
16
|
+
CurrencyEnum,
|
|
17
|
+
StatusEnum
|
|
18
|
+
>
|
|
19
|
+
> = {
|
|
20
|
+
CheckoutSessionMapper: {
|
|
21
|
+
toDto: (
|
|
22
|
+
entity: MapperEntities['CheckoutSessionMapper']
|
|
23
|
+
) => Promise<MapperDomains['CheckoutSessionMapper']>;
|
|
24
|
+
};
|
|
25
|
+
CreateCheckoutSessionMapper: {
|
|
26
|
+
toEntity: (
|
|
27
|
+
dto: MapperDomains['CreateCheckoutSessionMapper'],
|
|
28
|
+
em: EntityManager,
|
|
29
|
+
...args: unknown[]
|
|
30
|
+
) => Promise<MapperEntities['CreateCheckoutSessionMapper']>;
|
|
31
|
+
};
|
|
32
|
+
UpdateCheckoutSessionMapper: {
|
|
33
|
+
toEntity: (
|
|
34
|
+
dto: MapperDomains['UpdateCheckoutSessionMapper'],
|
|
35
|
+
em: EntityManager,
|
|
36
|
+
...args: unknown[]
|
|
37
|
+
) => Promise<MapperEntities['UpdateCheckoutSessionMapper']>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './baseBillingDto.types';
|
|
2
|
+
export * from './baseBillingEntity.types';
|
|
3
|
+
export * from './billingPortal.mapper.types';
|
|
4
|
+
export * from './checkoutSession.mapper.types';
|
|
5
|
+
export * from './paymentLink.mapper.types';
|
|
6
|
+
export * from './plan.mapper.types';
|
|
7
|
+
export * from './subscription.mapper.types';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
2
|
+
import { BasePaymentLinkDtos } from './baseBillingDto.types';
|
|
3
|
+
import { BasePaymentLinkEntities } from './baseBillingEntity.types';
|
|
4
|
+
|
|
5
|
+
export type PaymentLinkMappers<
|
|
6
|
+
PaymentMethodEnum,
|
|
7
|
+
CurrencyEnum,
|
|
8
|
+
StatusEnum,
|
|
9
|
+
MapperEntities extends BasePaymentLinkEntities<
|
|
10
|
+
PaymentMethodEnum,
|
|
11
|
+
CurrencyEnum,
|
|
12
|
+
StatusEnum
|
|
13
|
+
>,
|
|
14
|
+
MapperDomains extends BasePaymentLinkDtos<
|
|
15
|
+
PaymentMethodEnum,
|
|
16
|
+
CurrencyEnum,
|
|
17
|
+
StatusEnum
|
|
18
|
+
>
|
|
19
|
+
> = {
|
|
20
|
+
PaymentLinkMapper: {
|
|
21
|
+
toDto: (
|
|
22
|
+
entity: MapperEntities['PaymentLinkMapper']
|
|
23
|
+
) => Promise<MapperDomains['PaymentLinkMapper']>;
|
|
24
|
+
};
|
|
25
|
+
CreatePaymentLinkMapper: {
|
|
26
|
+
toEntity: (
|
|
27
|
+
dto: MapperDomains['CreatePaymentLinkMapper'],
|
|
28
|
+
em: EntityManager,
|
|
29
|
+
...args: unknown[]
|
|
30
|
+
) => Promise<MapperEntities['CreatePaymentLinkMapper']>;
|
|
31
|
+
};
|
|
32
|
+
UpdatePaymentLinkMapper: {
|
|
33
|
+
toEntity: (
|
|
34
|
+
dto: MapperDomains['UpdatePaymentLinkMapper'],
|
|
35
|
+
em: EntityManager,
|
|
36
|
+
...args: unknown[]
|
|
37
|
+
) => Promise<MapperEntities['UpdatePaymentLinkMapper']>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
2
|
+
import { BasePlanDtos } from './baseBillingDto.types';
|
|
3
|
+
import { BasePlanEntities } from './baseBillingEntity.types';
|
|
4
|
+
|
|
5
|
+
export type PlanMappers<
|
|
6
|
+
PlanCadenceEnum,
|
|
7
|
+
CurrencyEnum,
|
|
8
|
+
BillingProviderEnum,
|
|
9
|
+
MapperEntities extends BasePlanEntities<
|
|
10
|
+
PlanCadenceEnum,
|
|
11
|
+
CurrencyEnum,
|
|
12
|
+
BillingProviderEnum
|
|
13
|
+
>,
|
|
14
|
+
MapperDomains extends BasePlanDtos<
|
|
15
|
+
PlanCadenceEnum,
|
|
16
|
+
CurrencyEnum,
|
|
17
|
+
BillingProviderEnum
|
|
18
|
+
>
|
|
19
|
+
> = {
|
|
20
|
+
PlanMapper: {
|
|
21
|
+
toDto: (
|
|
22
|
+
entity: MapperEntities['PlanMapper']
|
|
23
|
+
) => Promise<MapperDomains['PlanMapper']>;
|
|
24
|
+
};
|
|
25
|
+
CreatePlanMapper: {
|
|
26
|
+
toEntity: (
|
|
27
|
+
dto: MapperDomains['CreatePlanMapper'],
|
|
28
|
+
em: EntityManager,
|
|
29
|
+
...args: unknown[]
|
|
30
|
+
) => Promise<MapperEntities['CreatePlanMapper']>;
|
|
31
|
+
};
|
|
32
|
+
UpdatePlanMapper: {
|
|
33
|
+
toEntity: (
|
|
34
|
+
dto: MapperDomains['UpdatePlanMapper'],
|
|
35
|
+
em: EntityManager,
|
|
36
|
+
...args: unknown[]
|
|
37
|
+
) => Promise<MapperEntities['UpdatePlanMapper']>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
2
|
+
import { BaseSubscriptionDtos } from './baseBillingDto.types';
|
|
3
|
+
import { BaseSubscriptionEntities } from './baseBillingEntity.types';
|
|
4
|
+
|
|
5
|
+
export type SubscriptionMappers<
|
|
6
|
+
PartyType,
|
|
7
|
+
BillingProviderType,
|
|
8
|
+
MapperEntities extends BaseSubscriptionEntities<
|
|
9
|
+
PartyType,
|
|
10
|
+
BillingProviderType
|
|
11
|
+
>,
|
|
12
|
+
MapperDomains extends BaseSubscriptionDtos<PartyType, BillingProviderType>
|
|
13
|
+
> = {
|
|
14
|
+
SubscriptionMapper: {
|
|
15
|
+
toDto: (
|
|
16
|
+
entity: MapperEntities['SubscriptionMapper']
|
|
17
|
+
) => Promise<MapperDomains['SubscriptionMapper']>;
|
|
18
|
+
};
|
|
19
|
+
CreateSubscriptionMapper: {
|
|
20
|
+
toEntity: (
|
|
21
|
+
dto: MapperDomains['CreateSubscriptionMapper'],
|
|
22
|
+
em: EntityManager,
|
|
23
|
+
...args: unknown[]
|
|
24
|
+
) => Promise<MapperEntities['CreateSubscriptionMapper']>;
|
|
25
|
+
};
|
|
26
|
+
UpdateSubscriptionMapper: {
|
|
27
|
+
toEntity: (
|
|
28
|
+
dto: MapperDomains['UpdateSubscriptionMapper'],
|
|
29
|
+
em: EntityManager,
|
|
30
|
+
...args: unknown[]
|
|
31
|
+
) => Promise<MapperEntities['UpdateSubscriptionMapper']>;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IdDto
|
|
1
|
+
import { IdDto } from '@forklaunch/common';
|
|
2
2
|
import { createCacheKey, TtlCache } from '@forklaunch/core/cache';
|
|
3
3
|
import {
|
|
4
4
|
evaluateTelemetryOptions,
|
|
@@ -7,92 +7,41 @@ import {
|
|
|
7
7
|
TelemetryOptions
|
|
8
8
|
} from '@forklaunch/core/http';
|
|
9
9
|
import { BillingPortalService } from '@forklaunch/interfaces-billing/interfaces';
|
|
10
|
-
import { UpdateBillingPortalDto } from '@forklaunch/interfaces-billing/types';
|
|
11
10
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
transformIntoInternalMapper
|
|
16
|
-
} from '@forklaunch/internal';
|
|
11
|
+
CreateBillingPortalDto,
|
|
12
|
+
UpdateBillingPortalDto
|
|
13
|
+
} from '@forklaunch/interfaces-billing/types';
|
|
17
14
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
18
15
|
import { EntityManager } from '@mikro-orm/core';
|
|
19
16
|
import { BaseBillingDtos } from '../domain/types/baseBillingDto.types';
|
|
20
17
|
import { BaseBillingEntities } from '../domain/types/baseBillingEntity.types';
|
|
18
|
+
import { BillingPortalMappers } from '../domain/types/billingPortal.mapper.types';
|
|
21
19
|
|
|
22
20
|
export class BaseBillingPortalService<
|
|
23
21
|
SchemaValidator extends AnySchemaValidator,
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
MapperEntities extends BaseBillingEntities,
|
|
23
|
+
MapperDomains extends BaseBillingDtos = BaseBillingDtos
|
|
26
24
|
> implements BillingPortalService
|
|
27
25
|
{
|
|
28
|
-
|
|
29
|
-
protected evaluatedTelemetryOptions: {
|
|
26
|
+
private evaluatedTelemetryOptions: {
|
|
30
27
|
logging?: boolean;
|
|
31
28
|
metrics?: boolean;
|
|
32
29
|
tracing?: boolean;
|
|
33
30
|
};
|
|
34
31
|
protected enableDatabaseBackup: boolean;
|
|
35
|
-
|
|
32
|
+
public em: EntityManager;
|
|
36
33
|
protected cache: TtlCache;
|
|
37
34
|
protected openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
|
|
38
35
|
protected schemaValidator: SchemaValidator;
|
|
39
|
-
protected mappers:
|
|
40
|
-
BillingPortalMapper: ResponseMapperConstructor<
|
|
41
|
-
SchemaValidator,
|
|
42
|
-
Dto['BillingPortalMapper'],
|
|
43
|
-
Entities['BillingPortalMapper']
|
|
44
|
-
>;
|
|
45
|
-
CreateBillingPortalMapper: RequestMapperConstructor<
|
|
46
|
-
SchemaValidator,
|
|
47
|
-
Dto['CreateBillingPortalMapper'],
|
|
48
|
-
Entities['CreateBillingPortalMapper'],
|
|
49
|
-
(
|
|
50
|
-
dto: Dto['CreateBillingPortalMapper'],
|
|
51
|
-
em: EntityManager
|
|
52
|
-
) => Promise<Entities['CreateBillingPortalMapper']>
|
|
53
|
-
>;
|
|
54
|
-
UpdateBillingPortalMapper: RequestMapperConstructor<
|
|
55
|
-
SchemaValidator,
|
|
56
|
-
Dto['UpdateBillingPortalMapper'],
|
|
57
|
-
Entities['UpdateBillingPortalMapper'],
|
|
58
|
-
(
|
|
59
|
-
dto: Dto['UpdateBillingPortalMapper'],
|
|
60
|
-
em: EntityManager
|
|
61
|
-
) => Promise<Entities['UpdateBillingPortalMapper']>
|
|
62
|
-
>;
|
|
63
|
-
};
|
|
36
|
+
protected mappers: BillingPortalMappers<MapperEntities, MapperDomains>;
|
|
64
37
|
|
|
65
38
|
constructor(
|
|
66
39
|
em: EntityManager,
|
|
67
40
|
cache: TtlCache,
|
|
68
41
|
openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
|
|
69
42
|
schemaValidator: SchemaValidator,
|
|
70
|
-
mappers:
|
|
71
|
-
|
|
72
|
-
SchemaValidator,
|
|
73
|
-
Dto['BillingPortalMapper'],
|
|
74
|
-
Entities['BillingPortalMapper']
|
|
75
|
-
>;
|
|
76
|
-
CreateBillingPortalMapper: RequestMapperConstructor<
|
|
77
|
-
SchemaValidator,
|
|
78
|
-
Dto['CreateBillingPortalMapper'],
|
|
79
|
-
Entities['CreateBillingPortalMapper'],
|
|
80
|
-
(
|
|
81
|
-
dto: Dto['CreateBillingPortalMapper'],
|
|
82
|
-
em: EntityManager
|
|
83
|
-
) => Promise<Entities['CreateBillingPortalMapper']>
|
|
84
|
-
>;
|
|
85
|
-
UpdateBillingPortalMapper: RequestMapperConstructor<
|
|
86
|
-
SchemaValidator,
|
|
87
|
-
Dto['UpdateBillingPortalMapper'],
|
|
88
|
-
Entities['UpdateBillingPortalMapper'],
|
|
89
|
-
(
|
|
90
|
-
dto: Dto['UpdateBillingPortalMapper'],
|
|
91
|
-
em: EntityManager
|
|
92
|
-
) => Promise<Entities['UpdateBillingPortalMapper']>
|
|
93
|
-
>;
|
|
94
|
-
},
|
|
95
|
-
readonly options?: {
|
|
43
|
+
mappers: BillingPortalMappers<MapperEntities, MapperDomains>,
|
|
44
|
+
options?: {
|
|
96
45
|
telemetry?: TelemetryOptions;
|
|
97
46
|
enableDatabaseBackup?: boolean;
|
|
98
47
|
}
|
|
@@ -102,7 +51,6 @@ export class BaseBillingPortalService<
|
|
|
102
51
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
103
52
|
this.schemaValidator = schemaValidator;
|
|
104
53
|
this.mappers = mappers;
|
|
105
|
-
this._mappers = transformIntoInternalMapper(mappers, schemaValidator);
|
|
106
54
|
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
107
55
|
this.evaluatedTelemetryOptions = options?.telemetry
|
|
108
56
|
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
@@ -116,8 +64,9 @@ export class BaseBillingPortalService<
|
|
|
116
64
|
protected createCacheKey = createCacheKey('billing_portal_session');
|
|
117
65
|
|
|
118
66
|
async createBillingPortalSession(
|
|
119
|
-
billingPortalDto:
|
|
120
|
-
|
|
67
|
+
billingPortalDto: CreateBillingPortalDto,
|
|
68
|
+
...args: unknown[]
|
|
69
|
+
): Promise<MapperDomains['BillingPortalMapper']> {
|
|
121
70
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
122
71
|
this.openTelemetryCollector.info(
|
|
123
72
|
'Creating billing portal session',
|
|
@@ -125,20 +74,18 @@ export class BaseBillingPortalService<
|
|
|
125
74
|
);
|
|
126
75
|
}
|
|
127
76
|
|
|
128
|
-
const billingPortal =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
77
|
+
const billingPortal = await this.mappers.CreateBillingPortalMapper.toEntity(
|
|
78
|
+
billingPortalDto,
|
|
79
|
+
this.em,
|
|
80
|
+
...args
|
|
81
|
+
);
|
|
133
82
|
|
|
134
83
|
if (this.enableDatabaseBackup) {
|
|
135
84
|
await this.em.persistAndFlush(billingPortal);
|
|
136
85
|
}
|
|
137
86
|
|
|
138
87
|
const createdBillingPortalDto =
|
|
139
|
-
await this.
|
|
140
|
-
billingPortal
|
|
141
|
-
);
|
|
88
|
+
await this.mappers.BillingPortalMapper.toDto(billingPortal);
|
|
142
89
|
|
|
143
90
|
await this.cache.putRecord({
|
|
144
91
|
key: this.createCacheKey(createdBillingPortalDto.id),
|
|
@@ -151,13 +98,13 @@ export class BaseBillingPortalService<
|
|
|
151
98
|
|
|
152
99
|
async getBillingPortalSession(
|
|
153
100
|
idDto: IdDto
|
|
154
|
-
): Promise<
|
|
101
|
+
): Promise<MapperDomains['BillingPortalMapper']> {
|
|
155
102
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
156
103
|
this.openTelemetryCollector.info('Getting billing portal session', idDto);
|
|
157
104
|
}
|
|
158
105
|
|
|
159
106
|
const billingPortalDetails = await this.cache.readRecord<
|
|
160
|
-
|
|
107
|
+
MapperEntities['BillingPortalMapper']
|
|
161
108
|
>(this.createCacheKey(idDto.id));
|
|
162
109
|
|
|
163
110
|
if (!billingPortalDetails) {
|
|
@@ -168,8 +115,9 @@ export class BaseBillingPortalService<
|
|
|
168
115
|
}
|
|
169
116
|
|
|
170
117
|
async updateBillingPortalSession(
|
|
171
|
-
billingPortalDto: UpdateBillingPortalDto
|
|
172
|
-
|
|
118
|
+
billingPortalDto: UpdateBillingPortalDto,
|
|
119
|
+
...args: unknown[]
|
|
120
|
+
): Promise<MapperDomains['BillingPortalMapper']> {
|
|
173
121
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
174
122
|
this.openTelemetryCollector.info(
|
|
175
123
|
'Updating billing portal session',
|
|
@@ -178,7 +126,7 @@ export class BaseBillingPortalService<
|
|
|
178
126
|
}
|
|
179
127
|
|
|
180
128
|
const existingBillingPortal = (
|
|
181
|
-
await this.cache.readRecord<
|
|
129
|
+
await this.cache.readRecord<MapperEntities['BillingPortalMapper']>(
|
|
182
130
|
this.createCacheKey(billingPortalDto.id)
|
|
183
131
|
)
|
|
184
132
|
)?.value;
|
|
@@ -187,11 +135,11 @@ export class BaseBillingPortalService<
|
|
|
187
135
|
throw new Error('Session not found');
|
|
188
136
|
}
|
|
189
137
|
|
|
190
|
-
const billingPortal =
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
138
|
+
const billingPortal = await this.mappers.UpdateBillingPortalMapper.toEntity(
|
|
139
|
+
billingPortalDto,
|
|
140
|
+
this.em,
|
|
141
|
+
...args
|
|
142
|
+
);
|
|
195
143
|
|
|
196
144
|
if (this.enableDatabaseBackup) {
|
|
197
145
|
await this.em.persistAndFlush({
|
|
@@ -201,9 +149,7 @@ export class BaseBillingPortalService<
|
|
|
201
149
|
|
|
202
150
|
const updatedBillingPortalDto = {
|
|
203
151
|
...existingBillingPortal,
|
|
204
|
-
...(await this.
|
|
205
|
-
billingPortal
|
|
206
|
-
))
|
|
152
|
+
...(await this.mappers.BillingPortalMapper.toDto(billingPortal))
|
|
207
153
|
};
|
|
208
154
|
|
|
209
155
|
await this.cache.putRecord({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IdDto
|
|
1
|
+
import { IdDto } from '@forklaunch/common';
|
|
2
2
|
import { createCacheKey, TtlCache } from '@forklaunch/core/cache';
|
|
3
3
|
import {
|
|
4
4
|
evaluateTelemetryOptions,
|
|
@@ -7,104 +7,63 @@ import {
|
|
|
7
7
|
TelemetryOptions
|
|
8
8
|
} from '@forklaunch/core/http';
|
|
9
9
|
import { CheckoutSessionService } from '@forklaunch/interfaces-billing/interfaces';
|
|
10
|
-
import {
|
|
11
|
-
InternalMapper,
|
|
12
|
-
RequestMapperConstructor,
|
|
13
|
-
ResponseMapperConstructor,
|
|
14
|
-
transformIntoInternalMapper
|
|
15
|
-
} from '@forklaunch/internal';
|
|
10
|
+
import { CreateCheckoutSessionDto } from '@forklaunch/interfaces-billing/types';
|
|
16
11
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
17
12
|
import { EntityManager } from '@mikro-orm/core';
|
|
18
13
|
import { BaseCheckoutSessionDtos } from '../domain/types/baseBillingDto.types';
|
|
19
14
|
import { BaseCheckoutSessionEntities } from '../domain/types/baseBillingEntity.types';
|
|
15
|
+
import { CheckoutSessionMappers } from '../domain/types/checkoutSession.mapper.types';
|
|
20
16
|
|
|
21
17
|
export class BaseCheckoutSessionService<
|
|
22
18
|
SchemaValidator extends AnySchemaValidator,
|
|
23
19
|
PaymentMethodEnum,
|
|
24
20
|
CurrencyEnum,
|
|
25
21
|
StatusEnum,
|
|
26
|
-
|
|
22
|
+
MapperEntities extends BaseCheckoutSessionEntities<
|
|
27
23
|
PaymentMethodEnum,
|
|
28
24
|
CurrencyEnum,
|
|
29
25
|
StatusEnum
|
|
30
26
|
>,
|
|
31
|
-
|
|
27
|
+
MapperDomains extends BaseCheckoutSessionDtos<
|
|
32
28
|
PaymentMethodEnum,
|
|
33
29
|
CurrencyEnum,
|
|
34
30
|
StatusEnum
|
|
35
31
|
> = BaseCheckoutSessionDtos<PaymentMethodEnum, CurrencyEnum, StatusEnum>
|
|
36
32
|
> implements CheckoutSessionService<PaymentMethodEnum, CurrencyEnum, StatusEnum>
|
|
37
33
|
{
|
|
38
|
-
|
|
39
|
-
protected evaluatedTelemetryOptions: {
|
|
34
|
+
private evaluatedTelemetryOptions: {
|
|
40
35
|
logging?: boolean;
|
|
41
36
|
metrics?: boolean;
|
|
42
37
|
tracing?: boolean;
|
|
43
38
|
};
|
|
44
39
|
protected enableDatabaseBackup: boolean;
|
|
45
|
-
|
|
46
|
-
protected
|
|
47
|
-
protected
|
|
48
|
-
protected
|
|
49
|
-
protected
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
SchemaValidator,
|
|
57
|
-
Dto['CreateCheckoutSessionMapper'],
|
|
58
|
-
Entities['CreateCheckoutSessionMapper'],
|
|
59
|
-
(
|
|
60
|
-
dto: Dto['CreateCheckoutSessionMapper'],
|
|
61
|
-
em: EntityManager
|
|
62
|
-
) => Promise<Entities['CreateCheckoutSessionMapper']>
|
|
63
|
-
>;
|
|
64
|
-
UpdateCheckoutSessionMapper: RequestMapperConstructor<
|
|
65
|
-
SchemaValidator,
|
|
66
|
-
Dto['UpdateCheckoutSessionMapper'],
|
|
67
|
-
Entities['UpdateCheckoutSessionMapper'],
|
|
68
|
-
(
|
|
69
|
-
dto: Dto['UpdateCheckoutSessionMapper'],
|
|
70
|
-
em: EntityManager
|
|
71
|
-
) => Promise<Entities['UpdateCheckoutSessionMapper']>
|
|
72
|
-
>;
|
|
73
|
-
};
|
|
40
|
+
public em: EntityManager;
|
|
41
|
+
protected cache: TtlCache;
|
|
42
|
+
protected openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
|
|
43
|
+
protected schemaValidator: SchemaValidator;
|
|
44
|
+
protected mappers: CheckoutSessionMappers<
|
|
45
|
+
PaymentMethodEnum,
|
|
46
|
+
CurrencyEnum,
|
|
47
|
+
StatusEnum,
|
|
48
|
+
MapperEntities,
|
|
49
|
+
MapperDomains
|
|
50
|
+
>;
|
|
74
51
|
|
|
75
52
|
constructor(
|
|
76
53
|
em: EntityManager,
|
|
77
54
|
cache: TtlCache,
|
|
78
55
|
openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
|
|
79
56
|
schemaValidator: SchemaValidator,
|
|
80
|
-
mappers:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
Dto['CreateCheckoutSessionMapper'],
|
|
89
|
-
Entities['CreateCheckoutSessionMapper'],
|
|
90
|
-
(
|
|
91
|
-
dto: Dto['CreateCheckoutSessionMapper'],
|
|
92
|
-
em: EntityManager
|
|
93
|
-
) => Promise<Entities['CreateCheckoutSessionMapper']>
|
|
94
|
-
>;
|
|
95
|
-
UpdateCheckoutSessionMapper: RequestMapperConstructor<
|
|
96
|
-
SchemaValidator,
|
|
97
|
-
Dto['UpdateCheckoutSessionMapper'],
|
|
98
|
-
Entities['UpdateCheckoutSessionMapper'],
|
|
99
|
-
(
|
|
100
|
-
dto: Dto['UpdateCheckoutSessionMapper'],
|
|
101
|
-
em: EntityManager
|
|
102
|
-
) => Promise<Entities['UpdateCheckoutSessionMapper']>
|
|
103
|
-
>;
|
|
104
|
-
},
|
|
105
|
-
readonly options?: {
|
|
106
|
-
enableDatabaseBackup?: boolean;
|
|
57
|
+
mappers: CheckoutSessionMappers<
|
|
58
|
+
PaymentMethodEnum,
|
|
59
|
+
CurrencyEnum,
|
|
60
|
+
StatusEnum,
|
|
61
|
+
MapperEntities,
|
|
62
|
+
MapperDomains
|
|
63
|
+
>,
|
|
64
|
+
options?: {
|
|
107
65
|
telemetry?: TelemetryOptions;
|
|
66
|
+
enableDatabaseBackup?: boolean;
|
|
108
67
|
}
|
|
109
68
|
) {
|
|
110
69
|
this.em = em;
|
|
@@ -112,7 +71,6 @@ export class BaseCheckoutSessionService<
|
|
|
112
71
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
113
72
|
this.schemaValidator = schemaValidator;
|
|
114
73
|
this.mappers = mappers;
|
|
115
|
-
this._mappers = transformIntoInternalMapper(mappers, schemaValidator);
|
|
116
74
|
this.enableDatabaseBackup = options?.enableDatabaseBackup ?? false;
|
|
117
75
|
this.evaluatedTelemetryOptions = options?.telemetry
|
|
118
76
|
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
@@ -126,8 +84,13 @@ export class BaseCheckoutSessionService<
|
|
|
126
84
|
protected createCacheKey = createCacheKey('checkout_session');
|
|
127
85
|
|
|
128
86
|
async createCheckoutSession(
|
|
129
|
-
checkoutSessionDto:
|
|
130
|
-
|
|
87
|
+
checkoutSessionDto: CreateCheckoutSessionDto<
|
|
88
|
+
PaymentMethodEnum,
|
|
89
|
+
CurrencyEnum,
|
|
90
|
+
StatusEnum
|
|
91
|
+
>,
|
|
92
|
+
...args: unknown[]
|
|
93
|
+
): Promise<MapperDomains['CheckoutSessionMapper']> {
|
|
131
94
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
132
95
|
this.openTelemetryCollector.info(
|
|
133
96
|
'Creating checkout session',
|
|
@@ -136,15 +99,14 @@ export class BaseCheckoutSessionService<
|
|
|
136
99
|
}
|
|
137
100
|
|
|
138
101
|
const checkoutSession =
|
|
139
|
-
await this.
|
|
102
|
+
await this.mappers.CreateCheckoutSessionMapper.toEntity(
|
|
140
103
|
checkoutSessionDto,
|
|
141
|
-
this.em
|
|
104
|
+
this.em,
|
|
105
|
+
...args
|
|
142
106
|
);
|
|
143
107
|
|
|
144
108
|
const createdCheckoutSessionDto =
|
|
145
|
-
await this.
|
|
146
|
-
checkoutSession
|
|
147
|
-
);
|
|
109
|
+
await this.mappers.CheckoutSessionMapper.toDto(checkoutSession);
|
|
148
110
|
|
|
149
111
|
if (this.enableDatabaseBackup) {
|
|
150
112
|
await this.em.persistAndFlush(checkoutSession);
|
|
@@ -161,15 +123,15 @@ export class BaseCheckoutSessionService<
|
|
|
161
123
|
|
|
162
124
|
async getCheckoutSession({
|
|
163
125
|
id
|
|
164
|
-
}: IdDto): Promise<
|
|
126
|
+
}: IdDto): Promise<MapperDomains['CheckoutSessionMapper']> {
|
|
165
127
|
const checkoutSessionDetails = await this.cache.readRecord<
|
|
166
|
-
|
|
128
|
+
MapperEntities['CheckoutSessionMapper']
|
|
167
129
|
>(this.createCacheKey(id));
|
|
168
130
|
if (!checkoutSessionDetails) {
|
|
169
131
|
throw new Error('Session not found');
|
|
170
132
|
}
|
|
171
133
|
|
|
172
|
-
return this.
|
|
134
|
+
return this.mappers.CheckoutSessionMapper.toDto(
|
|
173
135
|
checkoutSessionDetails.value
|
|
174
136
|
);
|
|
175
137
|
}
|