@forklaunch/implementation-billing-base 0.8.23 → 1.0.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/schemas/index.d.mts +8 -8
- package/lib/domain/schemas/index.d.ts +8 -8
- package/lib/domain/schemas/index.js +8 -8
- package/lib/domain/schemas/index.mjs +8 -8
- package/lib/domain/types/index.d.mts +459 -31
- package/lib/domain/types/index.d.ts +459 -31
- package/lib/eject/domain/schemas/plan.schema.ts +2 -2
- package/lib/eject/domain/schemas/subscription.schema.ts +2 -2
- package/lib/eject/domain/types/baseBillingEntity.types.ts +97 -46
- package/lib/eject/domain/types/billingPortal.mapper.types.ts +7 -4
- package/lib/eject/domain/types/checkoutSession.mapper.types.ts +7 -4
- package/lib/eject/domain/types/paymentLink.mapper.types.ts +7 -4
- package/lib/eject/domain/types/plan.mapper.types.ts +7 -4
- package/lib/eject/domain/types/subscription.mapper.types.ts +7 -4
- package/lib/eject/services/billingPortal.service.ts +3 -5
- package/lib/eject/services/checkoutSession.service.ts +19 -12
- package/lib/eject/services/paymentLink.service.ts +27 -17
- package/lib/eject/services/plan.service.ts +22 -8
- package/lib/eject/services/subscription.service.ts +55 -28
- package/lib/services/index.d.mts +4 -3
- package/lib/services/index.d.ts +4 -3
- package/lib/services/index.js +101 -57
- package/lib/services/index.mjs +101 -57
- package/package.json +9 -9
|
@@ -11,16 +11,20 @@ import {
|
|
|
11
11
|
UpdateSubscriptionDto
|
|
12
12
|
} from '@forklaunch/interfaces-billing/types';
|
|
13
13
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
14
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
14
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
15
15
|
import { BaseSubscriptionDtos } from '../domain/types/baseBillingDto.types';
|
|
16
16
|
import { BaseSubscriptionEntities } from '../domain/types/baseBillingEntity.types';
|
|
17
17
|
import { SubscriptionMappers } from '../domain/types/subscription.mapper.types';
|
|
18
|
+
import { Subscription } from '../persistence/entities';
|
|
18
19
|
|
|
19
20
|
export class BaseSubscriptionService<
|
|
20
21
|
SchemaValidator extends AnySchemaValidator,
|
|
21
22
|
PartyType,
|
|
22
23
|
BillingProviderType,
|
|
23
|
-
|
|
24
|
+
MapperEntities extends BaseSubscriptionEntities<
|
|
25
|
+
PartyType,
|
|
26
|
+
BillingProviderType
|
|
27
|
+
>,
|
|
24
28
|
Dto extends BaseSubscriptionDtos<
|
|
25
29
|
PartyType,
|
|
26
30
|
BillingProviderType
|
|
@@ -38,7 +42,7 @@ export class BaseSubscriptionService<
|
|
|
38
42
|
protected readonly mappers: SubscriptionMappers<
|
|
39
43
|
PartyType,
|
|
40
44
|
BillingProviderType,
|
|
41
|
-
|
|
45
|
+
MapperEntities,
|
|
42
46
|
Dto
|
|
43
47
|
>;
|
|
44
48
|
|
|
@@ -46,7 +50,12 @@ export class BaseSubscriptionService<
|
|
|
46
50
|
em: EntityManager,
|
|
47
51
|
openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
|
|
48
52
|
schemaValidator: SchemaValidator,
|
|
49
|
-
mappers: SubscriptionMappers<
|
|
53
|
+
mappers: SubscriptionMappers<
|
|
54
|
+
PartyType,
|
|
55
|
+
BillingProviderType,
|
|
56
|
+
MapperEntities,
|
|
57
|
+
Dto
|
|
58
|
+
>,
|
|
50
59
|
readonly options?: {
|
|
51
60
|
telemetry?: TelemetryOptions;
|
|
52
61
|
}
|
|
@@ -96,11 +105,11 @@ export class BaseSubscriptionService<
|
|
|
96
105
|
this.openTelemetryCollector.info('Getting subscription', idDto);
|
|
97
106
|
}
|
|
98
107
|
const subscription = await (em ?? this.em).findOneOrFail(
|
|
99
|
-
|
|
108
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
100
109
|
idDto
|
|
101
110
|
);
|
|
102
111
|
return this.mappers.SubscriptionMapper.toDto(
|
|
103
|
-
subscription as
|
|
112
|
+
subscription as InferEntity<MapperEntities['SubscriptionMapper']>
|
|
104
113
|
);
|
|
105
114
|
}
|
|
106
115
|
|
|
@@ -111,14 +120,17 @@ export class BaseSubscriptionService<
|
|
|
111
120
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
112
121
|
this.openTelemetryCollector.info('Getting user subscription', id);
|
|
113
122
|
}
|
|
114
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
const subscription = await (em ?? this.em).findOneOrFail(
|
|
124
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
125
|
+
{
|
|
126
|
+
partyId: id,
|
|
127
|
+
partyType: 'USER',
|
|
128
|
+
active: true
|
|
129
|
+
}
|
|
130
|
+
);
|
|
119
131
|
|
|
120
132
|
return this.mappers.SubscriptionMapper.toDto(
|
|
121
|
-
subscription as
|
|
133
|
+
subscription as InferEntity<MapperEntities['SubscriptionMapper']>
|
|
122
134
|
);
|
|
123
135
|
}
|
|
124
136
|
|
|
@@ -129,13 +141,16 @@ export class BaseSubscriptionService<
|
|
|
129
141
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
130
142
|
this.openTelemetryCollector.info('Getting organization subscription', id);
|
|
131
143
|
}
|
|
132
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
144
|
+
const subscription = await (em ?? this.em).findOneOrFail(
|
|
145
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
146
|
+
{
|
|
147
|
+
partyId: id,
|
|
148
|
+
partyType: 'ORGANIZATION',
|
|
149
|
+
active: true
|
|
150
|
+
}
|
|
151
|
+
);
|
|
137
152
|
return this.mappers.SubscriptionMapper.toDto(
|
|
138
|
-
subscription as
|
|
153
|
+
subscription as InferEntity<MapperEntities['SubscriptionMapper']>
|
|
139
154
|
);
|
|
140
155
|
}
|
|
141
156
|
|
|
@@ -172,11 +187,14 @@ export class BaseSubscriptionService<
|
|
|
172
187
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
173
188
|
this.openTelemetryCollector.info('Deleting subscription', idDto);
|
|
174
189
|
}
|
|
175
|
-
const subscription = await (em ?? this.em).findOne(
|
|
190
|
+
const subscription = await (em ?? this.em).findOne(
|
|
191
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
192
|
+
idDto
|
|
193
|
+
);
|
|
176
194
|
if (!subscription) {
|
|
177
195
|
throw new Error('Subscription not found');
|
|
178
196
|
}
|
|
179
|
-
await (em ?? this.em).
|
|
197
|
+
await (em ?? this.em).remove(subscription).flush();
|
|
180
198
|
}
|
|
181
199
|
|
|
182
200
|
async listSubscriptions(
|
|
@@ -188,12 +206,15 @@ export class BaseSubscriptionService<
|
|
|
188
206
|
}
|
|
189
207
|
return Promise.all(
|
|
190
208
|
(
|
|
191
|
-
await (em ?? this.em).findAll(
|
|
192
|
-
|
|
193
|
-
|
|
209
|
+
await (em ?? this.em).findAll(
|
|
210
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
211
|
+
{
|
|
212
|
+
where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : undefined
|
|
213
|
+
}
|
|
214
|
+
)
|
|
194
215
|
).map((subscription) =>
|
|
195
216
|
this.mappers.SubscriptionMapper.toDto(
|
|
196
|
-
subscription as
|
|
217
|
+
subscription as InferEntity<MapperEntities['SubscriptionMapper']>
|
|
197
218
|
)
|
|
198
219
|
)
|
|
199
220
|
);
|
|
@@ -203,11 +224,14 @@ export class BaseSubscriptionService<
|
|
|
203
224
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
204
225
|
this.openTelemetryCollector.info('Canceling subscription', idDto);
|
|
205
226
|
}
|
|
206
|
-
const subscription = await (em ?? this.em).findOne(
|
|
227
|
+
const subscription = await (em ?? this.em).findOne(
|
|
228
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
229
|
+
idDto
|
|
230
|
+
);
|
|
207
231
|
if (!subscription) {
|
|
208
232
|
throw new Error('Subscription not found');
|
|
209
233
|
}
|
|
210
|
-
|
|
234
|
+
subscription.active = false;
|
|
211
235
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
212
236
|
await innerEm.persist(subscription);
|
|
213
237
|
});
|
|
@@ -217,11 +241,14 @@ export class BaseSubscriptionService<
|
|
|
217
241
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
218
242
|
this.openTelemetryCollector.info('Resuming subscription', idDto);
|
|
219
243
|
}
|
|
220
|
-
const subscription = await (em ?? this.em).findOne(
|
|
244
|
+
const subscription = await (em ?? this.em).findOne(
|
|
245
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
246
|
+
idDto
|
|
247
|
+
);
|
|
221
248
|
if (!subscription) {
|
|
222
249
|
throw new Error('Subscription not found');
|
|
223
250
|
}
|
|
224
|
-
|
|
251
|
+
subscription.active = true;
|
|
225
252
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
226
253
|
await innerEm.persist(subscription);
|
|
227
254
|
});
|
package/lib/services/index.d.mts
CHANGED
|
@@ -8,6 +8,7 @@ export * from '@forklaunch/interfaces-billing/types';
|
|
|
8
8
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
9
9
|
import { EntityManager } from '@mikro-orm/core';
|
|
10
10
|
import { BaseBillingEntities, BaseBillingDtos, BillingPortalMappers, BaseCheckoutSessionEntities, BaseCheckoutSessionDtos, CheckoutSessionMappers, BasePaymentLinkEntities, BasePaymentLinkDtos, PaymentLinkMappers, BasePlanEntities, BasePlanDtos, PlanMappers, BaseSubscriptionEntities, BaseSubscriptionDtos, SubscriptionMappers } from '../domain/types/index.mjs';
|
|
11
|
+
import '@forklaunch/core/persistence';
|
|
11
12
|
|
|
12
13
|
declare class BaseBillingPortalService<SchemaValidator extends AnySchemaValidator, MapperEntities extends BaseBillingEntities, MapperDomains extends BaseBillingDtos = BaseBillingDtos> implements BillingPortalService {
|
|
13
14
|
private evaluatedTelemetryOptions;
|
|
@@ -89,7 +90,7 @@ declare class BasePlanService<SchemaValidator extends AnySchemaValidator, PlanCa
|
|
|
89
90
|
}, em?: EntityManager): Promise<void>;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator, PartyType, BillingProviderType,
|
|
93
|
+
declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator, PartyType, BillingProviderType, MapperEntities extends BaseSubscriptionEntities<PartyType, BillingProviderType>, Dto extends BaseSubscriptionDtos<PartyType, BillingProviderType> = BaseSubscriptionDtos<PartyType, BillingProviderType>> implements SubscriptionService<PartyType, BillingProviderType> {
|
|
93
94
|
readonly options?: {
|
|
94
95
|
telemetry?: TelemetryOptions;
|
|
95
96
|
} | undefined;
|
|
@@ -101,8 +102,8 @@ declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator
|
|
|
101
102
|
protected em: EntityManager;
|
|
102
103
|
protected readonly openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
|
|
103
104
|
protected readonly schemaValidator: SchemaValidator;
|
|
104
|
-
protected readonly mappers: SubscriptionMappers<PartyType, BillingProviderType,
|
|
105
|
-
constructor(em: EntityManager, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, schemaValidator: SchemaValidator, mappers: SubscriptionMappers<PartyType, BillingProviderType,
|
|
105
|
+
protected readonly mappers: SubscriptionMappers<PartyType, BillingProviderType, MapperEntities, Dto>;
|
|
106
|
+
constructor(em: EntityManager, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, schemaValidator: SchemaValidator, mappers: SubscriptionMappers<PartyType, BillingProviderType, MapperEntities, Dto>, options?: {
|
|
106
107
|
telemetry?: TelemetryOptions;
|
|
107
108
|
} | undefined);
|
|
108
109
|
createSubscription(subscriptionDto: CreateSubscriptionDto<PartyType, BillingProviderType>, em?: EntityManager, ...args: unknown[]): Promise<Dto['SubscriptionMapper']>;
|
package/lib/services/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from '@forklaunch/interfaces-billing/types';
|
|
|
8
8
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
9
9
|
import { EntityManager } from '@mikro-orm/core';
|
|
10
10
|
import { BaseBillingEntities, BaseBillingDtos, BillingPortalMappers, BaseCheckoutSessionEntities, BaseCheckoutSessionDtos, CheckoutSessionMappers, BasePaymentLinkEntities, BasePaymentLinkDtos, PaymentLinkMappers, BasePlanEntities, BasePlanDtos, PlanMappers, BaseSubscriptionEntities, BaseSubscriptionDtos, SubscriptionMappers } from '../domain/types/index.js';
|
|
11
|
+
import '@forklaunch/core/persistence';
|
|
11
12
|
|
|
12
13
|
declare class BaseBillingPortalService<SchemaValidator extends AnySchemaValidator, MapperEntities extends BaseBillingEntities, MapperDomains extends BaseBillingDtos = BaseBillingDtos> implements BillingPortalService {
|
|
13
14
|
private evaluatedTelemetryOptions;
|
|
@@ -89,7 +90,7 @@ declare class BasePlanService<SchemaValidator extends AnySchemaValidator, PlanCa
|
|
|
89
90
|
}, em?: EntityManager): Promise<void>;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator, PartyType, BillingProviderType,
|
|
93
|
+
declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator, PartyType, BillingProviderType, MapperEntities extends BaseSubscriptionEntities<PartyType, BillingProviderType>, Dto extends BaseSubscriptionDtos<PartyType, BillingProviderType> = BaseSubscriptionDtos<PartyType, BillingProviderType>> implements SubscriptionService<PartyType, BillingProviderType> {
|
|
93
94
|
readonly options?: {
|
|
94
95
|
telemetry?: TelemetryOptions;
|
|
95
96
|
} | undefined;
|
|
@@ -101,8 +102,8 @@ declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator
|
|
|
101
102
|
protected em: EntityManager;
|
|
102
103
|
protected readonly openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
|
|
103
104
|
protected readonly schemaValidator: SchemaValidator;
|
|
104
|
-
protected readonly mappers: SubscriptionMappers<PartyType, BillingProviderType,
|
|
105
|
-
constructor(em: EntityManager, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, schemaValidator: SchemaValidator, mappers: SubscriptionMappers<PartyType, BillingProviderType,
|
|
105
|
+
protected readonly mappers: SubscriptionMappers<PartyType, BillingProviderType, MapperEntities, Dto>;
|
|
106
|
+
constructor(em: EntityManager, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, schemaValidator: SchemaValidator, mappers: SubscriptionMappers<PartyType, BillingProviderType, MapperEntities, Dto>, options?: {
|
|
106
107
|
telemetry?: TelemetryOptions;
|
|
107
108
|
} | undefined);
|
|
108
109
|
createSubscription(subscriptionDto: CreateSubscriptionDto<PartyType, BillingProviderType>, em?: EntityManager, ...args: unknown[]): Promise<Dto['SubscriptionMapper']>;
|
package/lib/services/index.js
CHANGED
|
@@ -68,7 +68,7 @@ var BaseBillingPortalService = class {
|
|
|
68
68
|
...args[0] instanceof import_core.EntityManager ? args.slice(1) : args
|
|
69
69
|
);
|
|
70
70
|
if (this.enableDatabaseBackup) {
|
|
71
|
-
await this.em.
|
|
71
|
+
await this.em.persist(billingPortal).flush();
|
|
72
72
|
}
|
|
73
73
|
const createdBillingPortalDto = await this.mappers.BillingPortalMapper.toDto(billingPortal);
|
|
74
74
|
await this.cache.putRecord({
|
|
@@ -112,9 +112,7 @@ var BaseBillingPortalService = class {
|
|
|
112
112
|
...args[0] instanceof import_core.EntityManager ? args.slice(1) : args
|
|
113
113
|
);
|
|
114
114
|
if (this.enableDatabaseBackup) {
|
|
115
|
-
await this.em.
|
|
116
|
-
billingPortal
|
|
117
|
-
});
|
|
115
|
+
await this.em.persist(billingPortal).flush();
|
|
118
116
|
}
|
|
119
117
|
const updatedBillingPortalDto = {
|
|
120
118
|
...existingBillingPortal,
|
|
@@ -189,7 +187,7 @@ var BaseCheckoutSessionService = class {
|
|
|
189
187
|
);
|
|
190
188
|
const createdCheckoutSessionDto = await this.mappers.CheckoutSessionMapper.toDto(checkoutSession);
|
|
191
189
|
if (this.enableDatabaseBackup) {
|
|
192
|
-
await this.em.
|
|
190
|
+
await this.em.persist(checkoutSession).flush();
|
|
193
191
|
}
|
|
194
192
|
await this.cache.putRecord({
|
|
195
193
|
key: this.createCacheKey(createdCheckoutSessionDto.id),
|
|
@@ -226,11 +224,14 @@ var BaseCheckoutSessionService = class {
|
|
|
226
224
|
this.openTelemetryCollector.info("Checkout success", { id });
|
|
227
225
|
}
|
|
228
226
|
if (this.enableDatabaseBackup) {
|
|
229
|
-
const checkoutSession = await this.em.upsert(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
227
|
+
const checkoutSession = await this.em.upsert(
|
|
228
|
+
this.mappers.CheckoutSessionMapper.entity,
|
|
229
|
+
{
|
|
230
|
+
id,
|
|
231
|
+
status: "SUCCESS"
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
await this.em.persist(checkoutSession).flush();
|
|
234
235
|
}
|
|
235
236
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
236
237
|
}
|
|
@@ -239,11 +240,14 @@ var BaseCheckoutSessionService = class {
|
|
|
239
240
|
this.openTelemetryCollector.info("Checkout failure", { id });
|
|
240
241
|
}
|
|
241
242
|
if (this.enableDatabaseBackup) {
|
|
242
|
-
const checkoutSession = await this.em.upsert(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
const checkoutSession = await this.em.upsert(
|
|
244
|
+
this.mappers.CheckoutSessionMapper.entity,
|
|
245
|
+
{
|
|
246
|
+
id,
|
|
247
|
+
status: "FAILED"
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
await this.em.persist(checkoutSession).flush();
|
|
247
251
|
}
|
|
248
252
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
249
253
|
}
|
|
@@ -286,7 +290,7 @@ var BasePaymentLinkService = class {
|
|
|
286
290
|
...args[0] instanceof import_core3.EntityManager ? args.slice(1) : args
|
|
287
291
|
);
|
|
288
292
|
if (this.enableDatabaseBackup) {
|
|
289
|
-
await this.em.
|
|
293
|
+
await this.em.persist(paymentLink).flush();
|
|
290
294
|
}
|
|
291
295
|
const createdPaymentLinkDto = await this.mappers.PaymentLinkMapper.toDto(paymentLink);
|
|
292
296
|
await this.cache.putRecord({
|
|
@@ -311,7 +315,7 @@ var BasePaymentLinkService = class {
|
|
|
311
315
|
...args[0] instanceof import_core3.EntityManager ? args.slice(1) : args
|
|
312
316
|
);
|
|
313
317
|
if (this.enableDatabaseBackup) {
|
|
314
|
-
await this.em.
|
|
318
|
+
await this.em.persist(paymentLink).flush();
|
|
315
319
|
}
|
|
316
320
|
const updatedLinkDto = {
|
|
317
321
|
...existingLink,
|
|
@@ -340,33 +344,42 @@ var BasePaymentLinkService = class {
|
|
|
340
344
|
async expirePaymentLink({ id }) {
|
|
341
345
|
this.openTelemetryCollector.info("Payment link expired", { id });
|
|
342
346
|
if (this.enableDatabaseBackup) {
|
|
343
|
-
const paymentLink = await this.em.upsert(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
347
|
+
const paymentLink = await this.em.upsert(
|
|
348
|
+
this.mappers.PaymentLinkMapper.entity,
|
|
349
|
+
{
|
|
350
|
+
id,
|
|
351
|
+
status: "EXPIRED"
|
|
352
|
+
}
|
|
353
|
+
);
|
|
354
|
+
await this.em.remove(paymentLink).flush();
|
|
348
355
|
}
|
|
349
356
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
350
357
|
}
|
|
351
358
|
async handlePaymentSuccess({ id }) {
|
|
352
359
|
this.openTelemetryCollector.info("Payment link success", { id });
|
|
353
360
|
if (this.enableDatabaseBackup) {
|
|
354
|
-
const paymentLink = await this.em.upsert(
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
361
|
+
const paymentLink = await this.em.upsert(
|
|
362
|
+
this.mappers.PaymentLinkMapper.entity,
|
|
363
|
+
{
|
|
364
|
+
id,
|
|
365
|
+
status: "COMPLETED"
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
await this.em.remove(paymentLink).flush();
|
|
359
369
|
}
|
|
360
370
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
361
371
|
}
|
|
362
372
|
async handlePaymentFailure({ id }) {
|
|
363
373
|
this.openTelemetryCollector.info("Payment link failure", { id });
|
|
364
374
|
if (this.enableDatabaseBackup) {
|
|
365
|
-
const paymentLink = await this.em.upsert(
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
375
|
+
const paymentLink = await this.em.upsert(
|
|
376
|
+
this.mappers.PaymentLinkMapper.entity,
|
|
377
|
+
{
|
|
378
|
+
id,
|
|
379
|
+
status: "FAILED"
|
|
380
|
+
}
|
|
381
|
+
);
|
|
382
|
+
await this.em.remove(paymentLink).flush();
|
|
370
383
|
}
|
|
371
384
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
372
385
|
}
|
|
@@ -406,10 +419,15 @@ var BasePlanService = class {
|
|
|
406
419
|
this.openTelemetryCollector.info("Listing plans", idsDto);
|
|
407
420
|
}
|
|
408
421
|
return Promise.all(
|
|
409
|
-
(await (em ?? this.em).findAll(
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
422
|
+
(await (em ?? this.em).findAll(
|
|
423
|
+
this.mappers.PlanMapper.entity,
|
|
424
|
+
{
|
|
425
|
+
where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : void 0
|
|
426
|
+
}
|
|
427
|
+
)).map(
|
|
428
|
+
(plan) => this.mappers.PlanMapper.toDto(
|
|
429
|
+
plan
|
|
430
|
+
)
|
|
413
431
|
)
|
|
414
432
|
);
|
|
415
433
|
}
|
|
@@ -431,8 +449,13 @@ var BasePlanService = class {
|
|
|
431
449
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
432
450
|
this.openTelemetryCollector.info("Getting plan", idDto);
|
|
433
451
|
}
|
|
434
|
-
const plan = await (em ?? this.em).findOneOrFail(
|
|
435
|
-
|
|
452
|
+
const plan = await (em ?? this.em).findOneOrFail(
|
|
453
|
+
this.mappers.PlanMapper.entity,
|
|
454
|
+
idDto
|
|
455
|
+
);
|
|
456
|
+
return this.mappers.PlanMapper.toDto(
|
|
457
|
+
plan
|
|
458
|
+
);
|
|
436
459
|
}
|
|
437
460
|
async updatePlan(planDto, em, ...args) {
|
|
438
461
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -454,7 +477,10 @@ var BasePlanService = class {
|
|
|
454
477
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
455
478
|
this.openTelemetryCollector.info("Deleting plan", idDto);
|
|
456
479
|
}
|
|
457
|
-
await (em ?? this.em).nativeDelete(
|
|
480
|
+
await (em ?? this.em).nativeDelete(
|
|
481
|
+
this.mappers.PlanMapper.entity,
|
|
482
|
+
idDto
|
|
483
|
+
);
|
|
458
484
|
}
|
|
459
485
|
};
|
|
460
486
|
|
|
@@ -502,7 +528,7 @@ var BaseSubscriptionService = class {
|
|
|
502
528
|
this.openTelemetryCollector.info("Getting subscription", idDto);
|
|
503
529
|
}
|
|
504
530
|
const subscription = await (em ?? this.em).findOneOrFail(
|
|
505
|
-
|
|
531
|
+
this.mappers.SubscriptionMapper.entity,
|
|
506
532
|
idDto
|
|
507
533
|
);
|
|
508
534
|
return this.mappers.SubscriptionMapper.toDto(
|
|
@@ -513,11 +539,14 @@ var BaseSubscriptionService = class {
|
|
|
513
539
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
514
540
|
this.openTelemetryCollector.info("Getting user subscription", id);
|
|
515
541
|
}
|
|
516
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
542
|
+
const subscription = await (em ?? this.em).findOneOrFail(
|
|
543
|
+
this.mappers.SubscriptionMapper.entity,
|
|
544
|
+
{
|
|
545
|
+
partyId: id,
|
|
546
|
+
partyType: "USER",
|
|
547
|
+
active: true
|
|
548
|
+
}
|
|
549
|
+
);
|
|
521
550
|
return this.mappers.SubscriptionMapper.toDto(
|
|
522
551
|
subscription
|
|
523
552
|
);
|
|
@@ -526,11 +555,14 @@ var BaseSubscriptionService = class {
|
|
|
526
555
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
527
556
|
this.openTelemetryCollector.info("Getting organization subscription", id);
|
|
528
557
|
}
|
|
529
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
558
|
+
const subscription = await (em ?? this.em).findOneOrFail(
|
|
559
|
+
this.mappers.SubscriptionMapper.entity,
|
|
560
|
+
{
|
|
561
|
+
partyId: id,
|
|
562
|
+
partyType: "ORGANIZATION",
|
|
563
|
+
active: true
|
|
564
|
+
}
|
|
565
|
+
);
|
|
534
566
|
return this.mappers.SubscriptionMapper.toDto(
|
|
535
567
|
subscription
|
|
536
568
|
);
|
|
@@ -558,20 +590,26 @@ var BaseSubscriptionService = class {
|
|
|
558
590
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
559
591
|
this.openTelemetryCollector.info("Deleting subscription", idDto);
|
|
560
592
|
}
|
|
561
|
-
const subscription = await (em ?? this.em).findOne(
|
|
593
|
+
const subscription = await (em ?? this.em).findOne(
|
|
594
|
+
this.mappers.SubscriptionMapper.entity,
|
|
595
|
+
idDto
|
|
596
|
+
);
|
|
562
597
|
if (!subscription) {
|
|
563
598
|
throw new Error("Subscription not found");
|
|
564
599
|
}
|
|
565
|
-
await (em ?? this.em).
|
|
600
|
+
await (em ?? this.em).remove(subscription).flush();
|
|
566
601
|
}
|
|
567
602
|
async listSubscriptions(idsDto, em) {
|
|
568
603
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
569
604
|
this.openTelemetryCollector.info("Listing subscriptions", idsDto);
|
|
570
605
|
}
|
|
571
606
|
return Promise.all(
|
|
572
|
-
(await (em ?? this.em).findAll(
|
|
573
|
-
|
|
574
|
-
|
|
607
|
+
(await (em ?? this.em).findAll(
|
|
608
|
+
this.mappers.SubscriptionMapper.entity,
|
|
609
|
+
{
|
|
610
|
+
where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : void 0
|
|
611
|
+
}
|
|
612
|
+
)).map(
|
|
575
613
|
(subscription) => this.mappers.SubscriptionMapper.toDto(
|
|
576
614
|
subscription
|
|
577
615
|
)
|
|
@@ -582,7 +620,10 @@ var BaseSubscriptionService = class {
|
|
|
582
620
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
583
621
|
this.openTelemetryCollector.info("Canceling subscription", idDto);
|
|
584
622
|
}
|
|
585
|
-
const subscription = await (em ?? this.em).findOne(
|
|
623
|
+
const subscription = await (em ?? this.em).findOne(
|
|
624
|
+
this.mappers.SubscriptionMapper.entity,
|
|
625
|
+
idDto
|
|
626
|
+
);
|
|
586
627
|
if (!subscription) {
|
|
587
628
|
throw new Error("Subscription not found");
|
|
588
629
|
}
|
|
@@ -595,7 +636,10 @@ var BaseSubscriptionService = class {
|
|
|
595
636
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
596
637
|
this.openTelemetryCollector.info("Resuming subscription", idDto);
|
|
597
638
|
}
|
|
598
|
-
const subscription = await (em ?? this.em).findOne(
|
|
639
|
+
const subscription = await (em ?? this.em).findOne(
|
|
640
|
+
this.mappers.SubscriptionMapper.entity,
|
|
641
|
+
idDto
|
|
642
|
+
);
|
|
599
643
|
if (!subscription) {
|
|
600
644
|
throw new Error("Subscription not found");
|
|
601
645
|
}
|