@forklaunch/implementation-billing-base 0.8.23 → 0.9.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 +272 -31
- package/lib/domain/types/index.d.ts +272 -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 +8 -7
- package/lib/eject/services/checkoutSession.service.ts +24 -14
- package/lib/eject/services/paymentLink.service.ts +28 -19
- package/lib/eject/services/plan.service.ts +23 -10
- package/lib/eject/services/subscription.service.ts +56 -32
- package/lib/services/index.d.mts +3 -3
- package/lib/services/index.d.ts +3 -3
- package/lib/services/index.js +102 -56
- package/lib/services/index.mjs +102 -56
- package/package.json +8 -8
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
2
|
+
BillingPortal,
|
|
3
|
+
CheckoutSession,
|
|
4
|
+
PaymentLink,
|
|
5
|
+
Plan,
|
|
6
|
+
Subscription
|
|
7
|
+
} from '../../persistence/entities';
|
|
8
8
|
|
|
9
|
-
// billing entity types
|
|
9
|
+
// billing portal entity types
|
|
10
10
|
export type BaseBillingEntities = {
|
|
11
|
-
BillingPortalMapper:
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
BillingPortalMapper: {
|
|
12
|
+
'~entity': (typeof BillingPortal)['~entity'];
|
|
13
|
+
};
|
|
14
|
+
CreateBillingPortalMapper: {
|
|
15
|
+
'~entity': (typeof BillingPortal)['~entity'];
|
|
16
|
+
};
|
|
17
|
+
UpdateBillingPortalMapper: {
|
|
18
|
+
'~entity': (typeof BillingPortal)['~entity'];
|
|
19
|
+
};
|
|
14
20
|
};
|
|
15
21
|
|
|
16
22
|
// checkout session entity types
|
|
@@ -19,21 +25,27 @@ export type BaseCheckoutSessionEntities<
|
|
|
19
25
|
CurrencyEnum,
|
|
20
26
|
StatusEnum
|
|
21
27
|
> = {
|
|
22
|
-
CheckoutSessionMapper:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
CheckoutSessionMapper: {
|
|
29
|
+
'~entity': (typeof CheckoutSession)['~entity'] & {
|
|
30
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
31
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
32
|
+
status: StatusEnum[keyof StatusEnum];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
CreateCheckoutSessionMapper: {
|
|
36
|
+
'~entity': (typeof CheckoutSession)['~entity'] & {
|
|
37
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
38
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
39
|
+
status: StatusEnum[keyof StatusEnum];
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
UpdateCheckoutSessionMapper: {
|
|
43
|
+
'~entity': (typeof CheckoutSession)['~entity'] & {
|
|
44
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
45
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
46
|
+
status: StatusEnum[keyof StatusEnum];
|
|
47
|
+
};
|
|
48
|
+
};
|
|
37
49
|
};
|
|
38
50
|
|
|
39
51
|
// payment link entity types
|
|
@@ -42,21 +54,27 @@ export type BasePaymentLinkEntities<
|
|
|
42
54
|
CurrencyEnum,
|
|
43
55
|
StatusEnum
|
|
44
56
|
> = {
|
|
45
|
-
PaymentLinkMapper:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
PaymentLinkMapper: {
|
|
58
|
+
'~entity': (typeof PaymentLink)['~entity'] & {
|
|
59
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
60
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
61
|
+
status: StatusEnum[keyof StatusEnum];
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
CreatePaymentLinkMapper: {
|
|
65
|
+
'~entity': (typeof PaymentLink)['~entity'] & {
|
|
66
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
67
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
68
|
+
status: StatusEnum[keyof StatusEnum];
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
UpdatePaymentLinkMapper: {
|
|
72
|
+
'~entity': (typeof PaymentLink)['~entity'] & {
|
|
73
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
74
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
75
|
+
status: StatusEnum[keyof StatusEnum];
|
|
76
|
+
};
|
|
77
|
+
};
|
|
60
78
|
};
|
|
61
79
|
|
|
62
80
|
// plan entity types
|
|
@@ -65,14 +83,47 @@ export type BasePlanEntities<
|
|
|
65
83
|
CurrencyEnum,
|
|
66
84
|
BillingProviderEnum
|
|
67
85
|
> = {
|
|
68
|
-
PlanMapper:
|
|
69
|
-
|
|
70
|
-
|
|
86
|
+
PlanMapper: {
|
|
87
|
+
'~entity': (typeof Plan)['~entity'] & {
|
|
88
|
+
cadence: PlanCadenceEnum[keyof PlanCadenceEnum];
|
|
89
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
90
|
+
billingProvider: BillingProviderEnum[keyof BillingProviderEnum] | null;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
CreatePlanMapper: {
|
|
94
|
+
'~entity': (typeof Plan)['~entity'] & {
|
|
95
|
+
cadence: PlanCadenceEnum[keyof PlanCadenceEnum];
|
|
96
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
97
|
+
billingProvider: BillingProviderEnum[keyof BillingProviderEnum] | null;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
UpdatePlanMapper: {
|
|
101
|
+
'~entity': (typeof Plan)['~entity'] & {
|
|
102
|
+
cadence: PlanCadenceEnum[keyof PlanCadenceEnum];
|
|
103
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
104
|
+
billingProvider: BillingProviderEnum[keyof BillingProviderEnum] | null;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
71
107
|
};
|
|
72
108
|
|
|
73
109
|
// subscription entity types
|
|
74
110
|
export type BaseSubscriptionEntities<PartyType, BillingProviderType> = {
|
|
75
|
-
SubscriptionMapper:
|
|
76
|
-
|
|
77
|
-
|
|
111
|
+
SubscriptionMapper: {
|
|
112
|
+
'~entity': (typeof Subscription)['~entity'] & {
|
|
113
|
+
partyType: PartyType[keyof PartyType];
|
|
114
|
+
billingProvider: BillingProviderType[keyof BillingProviderType] | null;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
CreateSubscriptionMapper: {
|
|
118
|
+
'~entity': (typeof Subscription)['~entity'] & {
|
|
119
|
+
partyType: PartyType[keyof PartyType];
|
|
120
|
+
billingProvider: BillingProviderType[keyof BillingProviderType] | null;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
UpdateSubscriptionMapper: {
|
|
124
|
+
'~entity': (typeof Subscription)['~entity'] & {
|
|
125
|
+
partyType: PartyType[keyof PartyType];
|
|
126
|
+
billingProvider: BillingProviderType[keyof BillingProviderType] | null;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
78
129
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
1
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
2
2
|
import { BaseBillingDtos } from './baseBillingDto.types';
|
|
3
3
|
import { BaseBillingEntities } from './baseBillingEntity.types';
|
|
4
4
|
|
|
@@ -7,22 +7,25 @@ export type BillingPortalMappers<
|
|
|
7
7
|
MapperDomains extends BaseBillingDtos
|
|
8
8
|
> = {
|
|
9
9
|
BillingPortalMapper: {
|
|
10
|
+
entity: MapperEntities['BillingPortalMapper'];
|
|
10
11
|
toDto: (
|
|
11
|
-
entity: MapperEntities['BillingPortalMapper']
|
|
12
|
+
entity: InferEntity<MapperEntities['BillingPortalMapper']>
|
|
12
13
|
) => Promise<MapperDomains['BillingPortalMapper']>;
|
|
13
14
|
};
|
|
14
15
|
CreateBillingPortalMapper: {
|
|
16
|
+
entity: MapperEntities['CreateBillingPortalMapper'];
|
|
15
17
|
toEntity: (
|
|
16
18
|
dto: MapperDomains['CreateBillingPortalMapper'],
|
|
17
19
|
em: EntityManager,
|
|
18
20
|
...args: unknown[]
|
|
19
|
-
) => Promise<MapperEntities['CreateBillingPortalMapper']
|
|
21
|
+
) => Promise<InferEntity<MapperEntities['CreateBillingPortalMapper']>>;
|
|
20
22
|
};
|
|
21
23
|
UpdateBillingPortalMapper: {
|
|
24
|
+
entity: MapperEntities['UpdateBillingPortalMapper'];
|
|
22
25
|
toEntity: (
|
|
23
26
|
dto: MapperDomains['UpdateBillingPortalMapper'],
|
|
24
27
|
em: EntityManager,
|
|
25
28
|
...args: unknown[]
|
|
26
|
-
) => Promise<MapperEntities['UpdateBillingPortalMapper']
|
|
29
|
+
) => Promise<InferEntity<MapperEntities['UpdateBillingPortalMapper']>>;
|
|
27
30
|
};
|
|
28
31
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
1
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
2
2
|
import { BaseCheckoutSessionDtos } from './baseBillingDto.types';
|
|
3
3
|
import { BaseCheckoutSessionEntities } from './baseBillingEntity.types';
|
|
4
4
|
|
|
@@ -18,22 +18,25 @@ export type CheckoutSessionMappers<
|
|
|
18
18
|
>
|
|
19
19
|
> = {
|
|
20
20
|
CheckoutSessionMapper: {
|
|
21
|
+
entity: MapperEntities['CheckoutSessionMapper'];
|
|
21
22
|
toDto: (
|
|
22
|
-
entity: MapperEntities['CheckoutSessionMapper']
|
|
23
|
+
entity: InferEntity<MapperEntities['CheckoutSessionMapper']>
|
|
23
24
|
) => Promise<MapperDomains['CheckoutSessionMapper']>;
|
|
24
25
|
};
|
|
25
26
|
CreateCheckoutSessionMapper: {
|
|
27
|
+
entity: MapperEntities['CreateCheckoutSessionMapper'];
|
|
26
28
|
toEntity: (
|
|
27
29
|
dto: MapperDomains['CreateCheckoutSessionMapper'],
|
|
28
30
|
em: EntityManager,
|
|
29
31
|
...args: unknown[]
|
|
30
|
-
) => Promise<MapperEntities['CreateCheckoutSessionMapper']
|
|
32
|
+
) => Promise<InferEntity<MapperEntities['CreateCheckoutSessionMapper']>>;
|
|
31
33
|
};
|
|
32
34
|
UpdateCheckoutSessionMapper: {
|
|
35
|
+
entity: MapperEntities['UpdateCheckoutSessionMapper'];
|
|
33
36
|
toEntity: (
|
|
34
37
|
dto: MapperDomains['UpdateCheckoutSessionMapper'],
|
|
35
38
|
em: EntityManager,
|
|
36
39
|
...args: unknown[]
|
|
37
|
-
) => Promise<MapperEntities['UpdateCheckoutSessionMapper']
|
|
40
|
+
) => Promise<InferEntity<MapperEntities['UpdateCheckoutSessionMapper']>>;
|
|
38
41
|
};
|
|
39
42
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
1
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
2
2
|
import { BasePaymentLinkDtos } from './baseBillingDto.types';
|
|
3
3
|
import { BasePaymentLinkEntities } from './baseBillingEntity.types';
|
|
4
4
|
|
|
@@ -18,22 +18,25 @@ export type PaymentLinkMappers<
|
|
|
18
18
|
>
|
|
19
19
|
> = {
|
|
20
20
|
PaymentLinkMapper: {
|
|
21
|
+
entity: MapperEntities['PaymentLinkMapper'];
|
|
21
22
|
toDto: (
|
|
22
|
-
entity: MapperEntities['PaymentLinkMapper']
|
|
23
|
+
entity: InferEntity<MapperEntities['PaymentLinkMapper']>
|
|
23
24
|
) => Promise<MapperDomains['PaymentLinkMapper']>;
|
|
24
25
|
};
|
|
25
26
|
CreatePaymentLinkMapper: {
|
|
27
|
+
entity: MapperEntities['CreatePaymentLinkMapper'];
|
|
26
28
|
toEntity: (
|
|
27
29
|
dto: MapperDomains['CreatePaymentLinkMapper'],
|
|
28
30
|
em: EntityManager,
|
|
29
31
|
...args: unknown[]
|
|
30
|
-
) => Promise<MapperEntities['CreatePaymentLinkMapper']
|
|
32
|
+
) => Promise<InferEntity<MapperEntities['CreatePaymentLinkMapper']>>;
|
|
31
33
|
};
|
|
32
34
|
UpdatePaymentLinkMapper: {
|
|
35
|
+
entity: MapperEntities['UpdatePaymentLinkMapper'];
|
|
33
36
|
toEntity: (
|
|
34
37
|
dto: MapperDomains['UpdatePaymentLinkMapper'],
|
|
35
38
|
em: EntityManager,
|
|
36
39
|
...args: unknown[]
|
|
37
|
-
) => Promise<MapperEntities['UpdatePaymentLinkMapper']
|
|
40
|
+
) => Promise<InferEntity<MapperEntities['UpdatePaymentLinkMapper']>>;
|
|
38
41
|
};
|
|
39
42
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
1
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
2
2
|
import { BasePlanDtos } from './baseBillingDto.types';
|
|
3
3
|
import { BasePlanEntities } from './baseBillingEntity.types';
|
|
4
4
|
|
|
@@ -18,22 +18,25 @@ export type PlanMappers<
|
|
|
18
18
|
>
|
|
19
19
|
> = {
|
|
20
20
|
PlanMapper: {
|
|
21
|
+
entity: MapperEntities['PlanMapper'];
|
|
21
22
|
toDto: (
|
|
22
|
-
entity: MapperEntities['PlanMapper']
|
|
23
|
+
entity: InferEntity<MapperEntities['PlanMapper']>
|
|
23
24
|
) => Promise<MapperDomains['PlanMapper']>;
|
|
24
25
|
};
|
|
25
26
|
CreatePlanMapper: {
|
|
27
|
+
entity: MapperEntities['CreatePlanMapper'];
|
|
26
28
|
toEntity: (
|
|
27
29
|
dto: MapperDomains['CreatePlanMapper'],
|
|
28
30
|
em: EntityManager,
|
|
29
31
|
...args: unknown[]
|
|
30
|
-
) => Promise<MapperEntities['CreatePlanMapper']
|
|
32
|
+
) => Promise<InferEntity<MapperEntities['CreatePlanMapper']>>;
|
|
31
33
|
};
|
|
32
34
|
UpdatePlanMapper: {
|
|
35
|
+
entity: MapperEntities['UpdatePlanMapper'];
|
|
33
36
|
toEntity: (
|
|
34
37
|
dto: MapperDomains['UpdatePlanMapper'],
|
|
35
38
|
em: EntityManager,
|
|
36
39
|
...args: unknown[]
|
|
37
|
-
) => Promise<MapperEntities['UpdatePlanMapper']
|
|
40
|
+
) => Promise<InferEntity<MapperEntities['UpdatePlanMapper']>>;
|
|
38
41
|
};
|
|
39
42
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
1
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
2
2
|
import { BaseSubscriptionDtos } from './baseBillingDto.types';
|
|
3
3
|
import { BaseSubscriptionEntities } from './baseBillingEntity.types';
|
|
4
4
|
|
|
@@ -12,22 +12,25 @@ export type SubscriptionMappers<
|
|
|
12
12
|
MapperDomains extends BaseSubscriptionDtos<PartyType, BillingProviderType>
|
|
13
13
|
> = {
|
|
14
14
|
SubscriptionMapper: {
|
|
15
|
+
entity: MapperEntities['SubscriptionMapper'];
|
|
15
16
|
toDto: (
|
|
16
|
-
entity: MapperEntities['SubscriptionMapper']
|
|
17
|
+
entity: InferEntity<MapperEntities['SubscriptionMapper']>
|
|
17
18
|
) => Promise<MapperDomains['SubscriptionMapper']>;
|
|
18
19
|
};
|
|
19
20
|
CreateSubscriptionMapper: {
|
|
21
|
+
entity: MapperEntities['CreateSubscriptionMapper'];
|
|
20
22
|
toEntity: (
|
|
21
23
|
dto: MapperDomains['CreateSubscriptionMapper'],
|
|
22
24
|
em: EntityManager,
|
|
23
25
|
...args: unknown[]
|
|
24
|
-
) => Promise<MapperEntities['CreateSubscriptionMapper']
|
|
26
|
+
) => Promise<InferEntity<MapperEntities['CreateSubscriptionMapper']>>;
|
|
25
27
|
};
|
|
26
28
|
UpdateSubscriptionMapper: {
|
|
29
|
+
entity: MapperEntities['UpdateSubscriptionMapper'];
|
|
27
30
|
toEntity: (
|
|
28
31
|
dto: MapperDomains['UpdateSubscriptionMapper'],
|
|
29
32
|
em: EntityManager,
|
|
30
33
|
...args: unknown[]
|
|
31
|
-
) => Promise<MapperEntities['UpdateSubscriptionMapper']
|
|
34
|
+
) => Promise<InferEntity<MapperEntities['UpdateSubscriptionMapper']>>;
|
|
32
35
|
};
|
|
33
36
|
};
|
|
@@ -21,8 +21,7 @@ export class BaseBillingPortalService<
|
|
|
21
21
|
SchemaValidator extends AnySchemaValidator,
|
|
22
22
|
MapperEntities extends BaseBillingEntities,
|
|
23
23
|
MapperDomains extends BaseBillingDtos = BaseBillingDtos
|
|
24
|
-
> implements BillingPortalService
|
|
25
|
-
{
|
|
24
|
+
> implements BillingPortalService {
|
|
26
25
|
private evaluatedTelemetryOptions: {
|
|
27
26
|
logging?: boolean;
|
|
28
27
|
metrics?: boolean;
|
|
@@ -81,7 +80,7 @@ export class BaseBillingPortalService<
|
|
|
81
80
|
);
|
|
82
81
|
|
|
83
82
|
if (this.enableDatabaseBackup) {
|
|
84
|
-
await this.em.
|
|
83
|
+
await this.em.persist(billingPortal).flush();
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
const createdBillingPortalDto =
|
|
@@ -104,7 +103,7 @@ export class BaseBillingPortalService<
|
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
const billingPortalDetails = await this.cache.readRecord<
|
|
107
|
-
|
|
106
|
+
MapperDomains['BillingPortalMapper']
|
|
108
107
|
>(this.createCacheKey(idDto.id));
|
|
109
108
|
|
|
110
109
|
if (!billingPortalDetails) {
|
|
@@ -147,9 +146,11 @@ export class BaseBillingPortalService<
|
|
|
147
146
|
);
|
|
148
147
|
|
|
149
148
|
if (this.enableDatabaseBackup) {
|
|
150
|
-
await this.em
|
|
151
|
-
|
|
152
|
-
|
|
149
|
+
await this.em
|
|
150
|
+
.persist({
|
|
151
|
+
billingPortal
|
|
152
|
+
})
|
|
153
|
+
.flush();
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
const updatedBillingPortalDto = {
|
|
@@ -10,6 +10,7 @@ import { CheckoutSessionService } from '@forklaunch/interfaces-billing/interface
|
|
|
10
10
|
import { CreateCheckoutSessionDto } from '@forklaunch/interfaces-billing/types';
|
|
11
11
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
12
12
|
import { EntityManager } from '@mikro-orm/core';
|
|
13
|
+
import { CheckoutSession } from '../persistence/entities';
|
|
13
14
|
import { BaseCheckoutSessionDtos } from '../domain/types/baseBillingDto.types';
|
|
14
15
|
import { BaseCheckoutSessionEntities } from '../domain/types/baseBillingEntity.types';
|
|
15
16
|
import { CheckoutSessionMappers } from '../domain/types/checkoutSession.mapper.types';
|
|
@@ -29,8 +30,11 @@ export class BaseCheckoutSessionService<
|
|
|
29
30
|
CurrencyEnum,
|
|
30
31
|
StatusEnum
|
|
31
32
|
> = BaseCheckoutSessionDtos<PaymentMethodEnum, CurrencyEnum, StatusEnum>
|
|
32
|
-
> implements CheckoutSessionService<
|
|
33
|
-
|
|
33
|
+
> implements CheckoutSessionService<
|
|
34
|
+
PaymentMethodEnum,
|
|
35
|
+
CurrencyEnum,
|
|
36
|
+
StatusEnum
|
|
37
|
+
> {
|
|
34
38
|
private evaluatedTelemetryOptions: {
|
|
35
39
|
logging?: boolean;
|
|
36
40
|
metrics?: boolean;
|
|
@@ -109,7 +113,7 @@ export class BaseCheckoutSessionService<
|
|
|
109
113
|
await this.mappers.CheckoutSessionMapper.toDto(checkoutSession);
|
|
110
114
|
|
|
111
115
|
if (this.enableDatabaseBackup) {
|
|
112
|
-
await this.em.
|
|
116
|
+
await this.em.persist(checkoutSession).flush();
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
await this.cache.putRecord({
|
|
@@ -125,7 +129,7 @@ export class BaseCheckoutSessionService<
|
|
|
125
129
|
id
|
|
126
130
|
}: IdDto): Promise<MapperDomains['CheckoutSessionMapper']> {
|
|
127
131
|
const checkoutSessionDetails = await this.cache.readRecord<
|
|
128
|
-
|
|
132
|
+
MapperDomains['CheckoutSessionMapper']
|
|
129
133
|
>(this.createCacheKey(id));
|
|
130
134
|
if (!checkoutSessionDetails) {
|
|
131
135
|
throw new Error('Session not found');
|
|
@@ -155,11 +159,14 @@ export class BaseCheckoutSessionService<
|
|
|
155
159
|
}
|
|
156
160
|
|
|
157
161
|
if (this.enableDatabaseBackup) {
|
|
158
|
-
const checkoutSession = await this.em.upsert(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
162
|
+
const checkoutSession = await this.em.upsert(
|
|
163
|
+
this.mappers.CheckoutSessionMapper.entity as typeof CheckoutSession,
|
|
164
|
+
{
|
|
165
|
+
id,
|
|
166
|
+
status: 'SUCCESS'
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
await this.em.persist(checkoutSession).flush();
|
|
163
170
|
}
|
|
164
171
|
|
|
165
172
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
@@ -171,11 +178,14 @@ export class BaseCheckoutSessionService<
|
|
|
171
178
|
}
|
|
172
179
|
|
|
173
180
|
if (this.enableDatabaseBackup) {
|
|
174
|
-
const checkoutSession = await this.em.upsert(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
181
|
+
const checkoutSession = await this.em.upsert(
|
|
182
|
+
this.mappers.CheckoutSessionMapper.entity as typeof CheckoutSession,
|
|
183
|
+
{
|
|
184
|
+
id,
|
|
185
|
+
status: 'FAILED'
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
await this.em.persist(checkoutSession).flush();
|
|
179
189
|
}
|
|
180
190
|
|
|
181
191
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from '@forklaunch/interfaces-billing/types';
|
|
14
14
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
15
15
|
import { EntityManager } from '@mikro-orm/core';
|
|
16
|
+
import { PaymentLink } from '../persistence/entities';
|
|
16
17
|
import { BasePaymentLinkDtos } from '../domain/types/baseBillingDto.types';
|
|
17
18
|
import { BasePaymentLinkEntities } from '../domain/types/baseBillingEntity.types';
|
|
18
19
|
import { PaymentLinkMappers } from '../domain/types/paymentLink.mapper.types';
|
|
@@ -32,8 +33,7 @@ export class BasePaymentLinkService<
|
|
|
32
33
|
CurrencyEnum,
|
|
33
34
|
StatusEnum
|
|
34
35
|
> = BasePaymentLinkDtos<PaymentMethodEnum, CurrencyEnum, StatusEnum>
|
|
35
|
-
> implements PaymentLinkService<PaymentMethodEnum, CurrencyEnum, StatusEnum>
|
|
36
|
-
{
|
|
36
|
+
> implements PaymentLinkService<PaymentMethodEnum, CurrencyEnum, StatusEnum> {
|
|
37
37
|
private evaluatedTelemetryOptions: {
|
|
38
38
|
logging?: boolean;
|
|
39
39
|
metrics?: boolean;
|
|
@@ -106,7 +106,7 @@ export class BasePaymentLinkService<
|
|
|
106
106
|
);
|
|
107
107
|
|
|
108
108
|
if (this.enableDatabaseBackup) {
|
|
109
|
-
await this.em.
|
|
109
|
+
await this.em.persist(paymentLink).flush();
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
const createdPaymentLinkDto =
|
|
@@ -147,7 +147,7 @@ export class BasePaymentLinkService<
|
|
|
147
147
|
);
|
|
148
148
|
|
|
149
149
|
if (this.enableDatabaseBackup) {
|
|
150
|
-
await this.em.
|
|
150
|
+
await this.em.persist(paymentLink).flush();
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
const updatedLinkDto = {
|
|
@@ -185,11 +185,14 @@ export class BasePaymentLinkService<
|
|
|
185
185
|
this.openTelemetryCollector.info('Payment link expired', { id });
|
|
186
186
|
|
|
187
187
|
if (this.enableDatabaseBackup) {
|
|
188
|
-
const paymentLink = await this.em.upsert(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
188
|
+
const paymentLink = await this.em.upsert(
|
|
189
|
+
this.mappers.PaymentLinkMapper.entity as typeof PaymentLink,
|
|
190
|
+
{
|
|
191
|
+
id,
|
|
192
|
+
status: 'EXPIRED'
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
await this.em.remove(paymentLink).flush();
|
|
193
196
|
}
|
|
194
197
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
195
198
|
}
|
|
@@ -197,11 +200,14 @@ export class BasePaymentLinkService<
|
|
|
197
200
|
async handlePaymentSuccess({ id }: IdDto): Promise<void> {
|
|
198
201
|
this.openTelemetryCollector.info('Payment link success', { id });
|
|
199
202
|
if (this.enableDatabaseBackup) {
|
|
200
|
-
const paymentLink = await this.em.upsert(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
const paymentLink = await this.em.upsert(
|
|
204
|
+
this.mappers.PaymentLinkMapper.entity as typeof PaymentLink,
|
|
205
|
+
{
|
|
206
|
+
id,
|
|
207
|
+
status: 'COMPLETED'
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
await this.em.remove(paymentLink).flush();
|
|
205
211
|
}
|
|
206
212
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
207
213
|
}
|
|
@@ -209,11 +215,14 @@ export class BasePaymentLinkService<
|
|
|
209
215
|
async handlePaymentFailure({ id }: IdDto): Promise<void> {
|
|
210
216
|
this.openTelemetryCollector.info('Payment link failure', { id });
|
|
211
217
|
if (this.enableDatabaseBackup) {
|
|
212
|
-
const paymentLink = await this.em.upsert(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
218
|
+
const paymentLink = await this.em.upsert(
|
|
219
|
+
this.mappers.PaymentLinkMapper.entity as typeof PaymentLink,
|
|
220
|
+
{
|
|
221
|
+
id,
|
|
222
|
+
status: 'FAILED'
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
await this.em.remove(paymentLink).flush();
|
|
217
226
|
}
|
|
218
227
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
219
228
|
}
|
|
@@ -11,10 +11,11 @@ import {
|
|
|
11
11
|
UpdatePlanDto
|
|
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 { BasePlanDtos } from '../domain/types/baseBillingDto.types';
|
|
16
16
|
import { BasePlanEntities } from '../domain/types/baseBillingEntity.types';
|
|
17
17
|
import { PlanMappers } from '../domain/types/plan.mapper.types';
|
|
18
|
+
import { Plan } from '../persistence/entities';
|
|
18
19
|
|
|
19
20
|
export class BasePlanService<
|
|
20
21
|
SchemaValidator extends AnySchemaValidator,
|
|
@@ -31,8 +32,7 @@ export class BasePlanService<
|
|
|
31
32
|
CurrencyEnum,
|
|
32
33
|
BillingProviderEnum
|
|
33
34
|
> = BasePlanDtos<PlanCadenceEnum, CurrencyEnum, BillingProviderEnum>
|
|
34
|
-
> implements PlanService<PlanCadenceEnum, CurrencyEnum, BillingProviderEnum>
|
|
35
|
-
{
|
|
35
|
+
> implements PlanService<PlanCadenceEnum, CurrencyEnum, BillingProviderEnum> {
|
|
36
36
|
private evaluatedTelemetryOptions: {
|
|
37
37
|
logging?: boolean;
|
|
38
38
|
metrics?: boolean;
|
|
@@ -87,11 +87,16 @@ export class BasePlanService<
|
|
|
87
87
|
|
|
88
88
|
return Promise.all(
|
|
89
89
|
(
|
|
90
|
-
await (em ?? this.em).findAll(
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
await (em ?? this.em).findAll(
|
|
91
|
+
this.mappers.PlanMapper.entity as typeof Plan,
|
|
92
|
+
{
|
|
93
|
+
where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : undefined
|
|
94
|
+
}
|
|
95
|
+
)
|
|
93
96
|
).map((plan) =>
|
|
94
|
-
this.mappers.PlanMapper.toDto(
|
|
97
|
+
this.mappers.PlanMapper.toDto(
|
|
98
|
+
plan as InferEntity<MapperEntities['PlanMapper']>
|
|
99
|
+
)
|
|
95
100
|
)
|
|
96
101
|
);
|
|
97
102
|
}
|
|
@@ -122,8 +127,13 @@ export class BasePlanService<
|
|
|
122
127
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
123
128
|
this.openTelemetryCollector.info('Getting plan', idDto);
|
|
124
129
|
}
|
|
125
|
-
const plan = await (em ?? this.em).findOneOrFail(
|
|
126
|
-
|
|
130
|
+
const plan = await (em ?? this.em).findOneOrFail(
|
|
131
|
+
this.mappers.PlanMapper.entity as typeof Plan,
|
|
132
|
+
idDto
|
|
133
|
+
);
|
|
134
|
+
return this.mappers.PlanMapper.toDto(
|
|
135
|
+
plan as InferEntity<MapperEntities['PlanMapper']>
|
|
136
|
+
);
|
|
127
137
|
}
|
|
128
138
|
|
|
129
139
|
async updatePlan(
|
|
@@ -151,6 +161,9 @@ export class BasePlanService<
|
|
|
151
161
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
152
162
|
this.openTelemetryCollector.info('Deleting plan', idDto);
|
|
153
163
|
}
|
|
154
|
-
await (em ?? this.em).nativeDelete(
|
|
164
|
+
await (em ?? this.em).nativeDelete(
|
|
165
|
+
this.mappers.PlanMapper.entity as typeof Plan,
|
|
166
|
+
idDto
|
|
167
|
+
);
|
|
155
168
|
}
|
|
156
169
|
}
|