@forklaunch/implementation-billing-base 0.1.4 → 0.1.5
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/eject/schemas/billingPortal.schema.ts +1 -1
- package/lib/eject/schemas/checkoutSession.schema.ts +1 -1
- package/lib/eject/schemas/index.ts +5 -0
- package/lib/eject/schemas/paymentLink.schema.ts +1 -1
- package/lib/eject/schemas/plan.schema.ts +1 -1
- package/lib/eject/schemas/subscription.schema.ts +1 -1
- package/lib/eject/services/billingPortal.service.ts +6 -6
- package/lib/eject/services/checkoutSession.service.ts +6 -6
- package/lib/eject/services/index.ts +5 -0
- package/lib/eject/services/paymentLink.service.ts +6 -6
- package/lib/eject/services/plan.service.ts +6 -6
- package/lib/eject/services/subscription.service.ts +6 -6
- package/lib/schemas/index.d.ts +6 -0
- package/lib/schemas/index.d.ts.map +1 -0
- package/lib/schemas/index.js +5 -0
- package/lib/services/billingPortal.service.d.ts +2 -1
- package/lib/services/billingPortal.service.d.ts.map +1 -1
- package/lib/services/checkoutSession.service.d.ts +2 -1
- package/lib/services/checkoutSession.service.d.ts.map +1 -1
- package/lib/services/index.d.ts +6 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +5 -0
- package/lib/services/paymentLink.service.d.ts +2 -1
- package/lib/services/paymentLink.service.d.ts.map +1 -1
- package/lib/services/plan.service.d.ts +2 -1
- package/lib/services/plan.service.d.ts.map +1 -1
- package/lib/services/subscription.service.d.ts +2 -1
- package/lib/services/subscription.service.d.ts.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -8
- package/lib/eject/schemas/zod/billingPortal.schema.ts +0 -29
- package/lib/eject/schemas/zod/checkoutSession.schema.ts +0 -46
- package/lib/eject/schemas/zod/paymentLink.schema.ts +0 -52
- package/lib/eject/schemas/zod/plan.schema.ts +0 -74
- package/lib/eject/schemas/zod/subscription.schema.ts +0 -78
- package/lib/eject/services/services/billingPortal.service.ts +0 -148
- package/lib/eject/services/services/checkoutSession.service.ts +0 -135
- package/lib/eject/services/services/paymentLink.service.ts +0 -173
- package/lib/eject/services/services/plan.service.ts +0 -135
- package/lib/eject/services/services/subscription.service.ts +0 -239
- package/lib/index.d.ts +0 -11
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forklaunch/implementation-billing-base",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Billing basic implementation for forklaunch",
|
|
5
5
|
"homepage": "https://github.com/forklaunch/forklaunch-js#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -12,23 +12,33 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"author": "Forklift Technologies, Inc.",
|
|
15
|
+
"exports": {
|
|
16
|
+
"./schemas": {
|
|
17
|
+
"types": "./lib/schemas/index.d.ts",
|
|
18
|
+
"import": "./lib/schemas/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./services": {
|
|
21
|
+
"types": "./lib/services/index.d.ts",
|
|
22
|
+
"import": "./lib/services/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
15
25
|
"files": [
|
|
16
26
|
"lib/**"
|
|
17
27
|
],
|
|
18
28
|
"dependencies": {
|
|
19
|
-
"@forklaunch/common": "^0.2.
|
|
20
|
-
"@forklaunch/core": "^0.6.
|
|
21
|
-
"@forklaunch/validator": "^0.4.
|
|
22
|
-
"@mikro-orm/core": "^6.4.
|
|
29
|
+
"@forklaunch/common": "^0.2.6",
|
|
30
|
+
"@forklaunch/core": "^0.6.2",
|
|
31
|
+
"@forklaunch/validator": "^0.4.10",
|
|
32
|
+
"@mikro-orm/core": "^6.4.12",
|
|
23
33
|
"@sinclair/typebox": "^0.34.33",
|
|
24
34
|
"ajv": "^8.17.1",
|
|
25
35
|
"zod": "^3.24.2",
|
|
26
|
-
"@forklaunch/interfaces-billing": "0.1.
|
|
36
|
+
"@forklaunch/interfaces-billing": "0.1.5"
|
|
27
37
|
},
|
|
28
38
|
"devDependencies": {
|
|
29
39
|
"depcheck": "^1.4.7",
|
|
30
40
|
"prettier": "^3.5.3",
|
|
31
|
-
"typedoc": "^0.28.
|
|
41
|
+
"typedoc": "^0.28.2"
|
|
32
42
|
},
|
|
33
43
|
"scripts": {
|
|
34
44
|
"build": "tsc && pnpm package:eject",
|
|
@@ -37,7 +47,7 @@
|
|
|
37
47
|
"format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.{ts,tsx,json}' --write",
|
|
38
48
|
"lint": "eslint . -c eslint.config.mjs",
|
|
39
49
|
"lint:fix": "eslint . -c eslint.config.mjs --fix",
|
|
40
|
-
"package:eject": "mkdir -p lib/eject && cp -r schemas/zod lib/eject/schemas && cp -r services lib/eject/services",
|
|
50
|
+
"package:eject": "rm -rf lib/eject && mkdir -p lib/eject && cp -r schemas/zod lib/eject/schemas && cp schemas/index.ts lib/eject/schemas && cp -r services lib/eject/services && find lib/eject -type f -name '*.ts' -exec sed -i '' 's|@forklaunch/validator/zod|@{{app_name}}/core|g' {} +",
|
|
41
51
|
"test": "vitest --passWithNoTests"
|
|
42
52
|
}
|
|
43
53
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
date,
|
|
3
|
-
optional,
|
|
4
|
-
string,
|
|
5
|
-
unknown,
|
|
6
|
-
uuid
|
|
7
|
-
} from '@forklaunch/validator/zod';
|
|
8
|
-
|
|
9
|
-
export const CreateBillingPortalSchema = {
|
|
10
|
-
customerId: string,
|
|
11
|
-
uri: string,
|
|
12
|
-
expiresAt: date
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const UpdateBillingPortalSchema = (uuidId: boolean) => ({
|
|
16
|
-
id: uuidId ? uuid : string,
|
|
17
|
-
uri: optional(string),
|
|
18
|
-
expiresAt: optional(date)
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export const BillingPortalSchema = (uuidId: boolean) => ({
|
|
22
|
-
id: uuidId ? uuid : string,
|
|
23
|
-
customerId: string,
|
|
24
|
-
uri: string,
|
|
25
|
-
expiresAt: date,
|
|
26
|
-
extraFields: optional(unknown),
|
|
27
|
-
createdAt: optional(date),
|
|
28
|
-
updatedAt: optional(date)
|
|
29
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { LiteralSchema } from '@forklaunch/validator';
|
|
2
|
-
import {
|
|
3
|
-
array,
|
|
4
|
-
date,
|
|
5
|
-
enum_,
|
|
6
|
-
optional,
|
|
7
|
-
string,
|
|
8
|
-
unknown,
|
|
9
|
-
uuid
|
|
10
|
-
} from '@forklaunch/validator/zod';
|
|
11
|
-
|
|
12
|
-
export const CreateCheckoutSessionSchema = <
|
|
13
|
-
T extends Record<string, LiteralSchema>
|
|
14
|
-
>(
|
|
15
|
-
PaymentMethodEnum: T
|
|
16
|
-
) => ({
|
|
17
|
-
customerId: string,
|
|
18
|
-
paymentMethods: array(enum_(PaymentMethodEnum)),
|
|
19
|
-
successRedirectUri: string,
|
|
20
|
-
cancelRedirectUri: string,
|
|
21
|
-
extraFields: optional(unknown)
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
export const UpdateCheckoutSessionSchema =
|
|
25
|
-
(uuidId: boolean) =>
|
|
26
|
-
<T extends Record<string, LiteralSchema>>(PaymentMethodEnum: T) => ({
|
|
27
|
-
id: uuidId ? uuid : string,
|
|
28
|
-
customerId: optional(string),
|
|
29
|
-
paymentMethods: optional(array(enum_(PaymentMethodEnum))),
|
|
30
|
-
successRedirectUri: optional(string),
|
|
31
|
-
cancelRedirectUri: optional(string),
|
|
32
|
-
extraFields: optional(unknown)
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export const CheckoutSessionSchema =
|
|
36
|
-
(uuidId: boolean) =>
|
|
37
|
-
<T extends Record<string, LiteralSchema>>(PaymentMethodEnum: T) => ({
|
|
38
|
-
id: uuidId ? uuid : string,
|
|
39
|
-
customerId: string,
|
|
40
|
-
paymentMethods: array(enum_(PaymentMethodEnum)),
|
|
41
|
-
successRedirectUri: string,
|
|
42
|
-
cancelRedirectUri: string,
|
|
43
|
-
extraFields: optional(unknown),
|
|
44
|
-
createdAt: optional(date),
|
|
45
|
-
updatedAt: optional(date)
|
|
46
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { LiteralSchema } from '@forklaunch/validator';
|
|
2
|
-
import {
|
|
3
|
-
date,
|
|
4
|
-
enum_,
|
|
5
|
-
number,
|
|
6
|
-
optional,
|
|
7
|
-
string,
|
|
8
|
-
unknown,
|
|
9
|
-
uuid
|
|
10
|
-
} from '@forklaunch/validator/zod';
|
|
11
|
-
|
|
12
|
-
export const CreatePaymentLinkSchema = <
|
|
13
|
-
T extends Record<string, LiteralSchema>
|
|
14
|
-
>(
|
|
15
|
-
CurrencyEnum: T
|
|
16
|
-
) => ({
|
|
17
|
-
amount: number,
|
|
18
|
-
currency: enum_(CurrencyEnum),
|
|
19
|
-
description: optional(string),
|
|
20
|
-
metadata: optional(unknown),
|
|
21
|
-
successRedirectUri: string,
|
|
22
|
-
cancelRedirectUri: string,
|
|
23
|
-
extraFields: optional(unknown)
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export const UpdatePaymentLinkSchema =
|
|
27
|
-
(uuidId: boolean) =>
|
|
28
|
-
<T extends Record<string, LiteralSchema>>(CurrencyEnum: T) => ({
|
|
29
|
-
id: uuidId ? uuid : string,
|
|
30
|
-
amount: optional(number),
|
|
31
|
-
currency: optional(enum_(CurrencyEnum)),
|
|
32
|
-
description: optional(string),
|
|
33
|
-
metadata: optional(unknown),
|
|
34
|
-
successRedirectUri: optional(string),
|
|
35
|
-
cancelRedirectUri: optional(string),
|
|
36
|
-
extraFields: optional(unknown)
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
export const PaymentLinkSchema =
|
|
40
|
-
(uuidId: boolean) =>
|
|
41
|
-
<T extends Record<string, LiteralSchema>>(CurrencyEnum: T) => ({
|
|
42
|
-
id: uuidId ? uuid : string,
|
|
43
|
-
amount: number,
|
|
44
|
-
currency: enum_(CurrencyEnum),
|
|
45
|
-
description: optional(string),
|
|
46
|
-
metadata: optional(unknown),
|
|
47
|
-
successRedirectUri: string,
|
|
48
|
-
cancelRedirectUri: string,
|
|
49
|
-
extraFields: optional(unknown),
|
|
50
|
-
createdAt: optional(date),
|
|
51
|
-
updatedAt: optional(date)
|
|
52
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { LiteralSchema } from '@forklaunch/validator';
|
|
2
|
-
import {
|
|
3
|
-
array,
|
|
4
|
-
boolean,
|
|
5
|
-
date,
|
|
6
|
-
enum_,
|
|
7
|
-
number,
|
|
8
|
-
optional,
|
|
9
|
-
string,
|
|
10
|
-
unknown,
|
|
11
|
-
uuid
|
|
12
|
-
} from '@forklaunch/validator/zod';
|
|
13
|
-
|
|
14
|
-
export const CreatePlanSchema = <
|
|
15
|
-
T extends Record<string, LiteralSchema>,
|
|
16
|
-
U extends Record<string, LiteralSchema>
|
|
17
|
-
>(
|
|
18
|
-
PlanCadenceEnum: T,
|
|
19
|
-
BillingProviderEnum: U
|
|
20
|
-
) => ({
|
|
21
|
-
name: string,
|
|
22
|
-
description: optional(string),
|
|
23
|
-
price: number,
|
|
24
|
-
cadence: enum_(PlanCadenceEnum),
|
|
25
|
-
features: array(string),
|
|
26
|
-
extraFields: optional(unknown),
|
|
27
|
-
externalId: string,
|
|
28
|
-
billingProvider: optional(enum_(BillingProviderEnum)),
|
|
29
|
-
active: boolean
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export const UpdatePlanSchema =
|
|
33
|
-
(uuidId: boolean) =>
|
|
34
|
-
<
|
|
35
|
-
T extends Record<string, LiteralSchema>,
|
|
36
|
-
U extends Record<string, LiteralSchema>
|
|
37
|
-
>(
|
|
38
|
-
PlanCadenceEnum: T,
|
|
39
|
-
BillingProviderEnum: U
|
|
40
|
-
) => ({
|
|
41
|
-
id: uuidId ? uuid : string,
|
|
42
|
-
name: optional(string),
|
|
43
|
-
description: optional(string),
|
|
44
|
-
price: optional(number),
|
|
45
|
-
cadence: optional(enum_(PlanCadenceEnum)),
|
|
46
|
-
features: optional(array(string)),
|
|
47
|
-
extraFields: optional(unknown),
|
|
48
|
-
externalId: optional(string),
|
|
49
|
-
billingProvider: optional(enum_(BillingProviderEnum)),
|
|
50
|
-
active: optional(boolean)
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
export const PlanSchema =
|
|
54
|
-
(uuidId: boolean) =>
|
|
55
|
-
<
|
|
56
|
-
T extends Record<string, LiteralSchema>,
|
|
57
|
-
U extends Record<string, LiteralSchema>
|
|
58
|
-
>(
|
|
59
|
-
PlanCadenceEnum: T,
|
|
60
|
-
BillingProviderEnum: U
|
|
61
|
-
) => ({
|
|
62
|
-
id: uuidId ? uuid : string,
|
|
63
|
-
name: string,
|
|
64
|
-
description: optional(string),
|
|
65
|
-
price: number,
|
|
66
|
-
cadence: enum_(PlanCadenceEnum),
|
|
67
|
-
features: optional(array(string)),
|
|
68
|
-
extraFields: optional(unknown),
|
|
69
|
-
externalId: string,
|
|
70
|
-
billingProvider: optional(enum_(BillingProviderEnum)),
|
|
71
|
-
active: boolean,
|
|
72
|
-
createdAt: optional(date),
|
|
73
|
-
updatedAt: optional(date)
|
|
74
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { LiteralSchema } from '@forklaunch/validator';
|
|
2
|
-
import {
|
|
3
|
-
boolean,
|
|
4
|
-
date,
|
|
5
|
-
enum_,
|
|
6
|
-
optional,
|
|
7
|
-
string,
|
|
8
|
-
unknown,
|
|
9
|
-
uuid
|
|
10
|
-
} from '@forklaunch/validator/zod';
|
|
11
|
-
|
|
12
|
-
export const CreateSubscriptionSchema = <
|
|
13
|
-
T extends Record<string, LiteralSchema>,
|
|
14
|
-
U extends Record<string, LiteralSchema>
|
|
15
|
-
>(
|
|
16
|
-
PartyEnum: T,
|
|
17
|
-
BillingProviderEnum: U
|
|
18
|
-
) => ({
|
|
19
|
-
partyId: string,
|
|
20
|
-
partyType: enum_(PartyEnum),
|
|
21
|
-
productId: string,
|
|
22
|
-
description: optional(string),
|
|
23
|
-
active: boolean,
|
|
24
|
-
externalId: string,
|
|
25
|
-
startDate: date,
|
|
26
|
-
endDate: date,
|
|
27
|
-
status: string,
|
|
28
|
-
billingProvider: optional(enum_(BillingProviderEnum)),
|
|
29
|
-
extraFields: optional(unknown)
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export const UpdateSubscriptionSchema =
|
|
33
|
-
(uuidId: boolean) =>
|
|
34
|
-
<
|
|
35
|
-
T extends Record<string, LiteralSchema>,
|
|
36
|
-
U extends Record<string, LiteralSchema>
|
|
37
|
-
>(
|
|
38
|
-
PartyEnum: T,
|
|
39
|
-
BillingProviderEnum: U
|
|
40
|
-
) => ({
|
|
41
|
-
id: uuidId ? uuid : string,
|
|
42
|
-
partyId: optional(string),
|
|
43
|
-
partyType: optional(enum_(PartyEnum)),
|
|
44
|
-
productId: optional(string),
|
|
45
|
-
description: optional(string),
|
|
46
|
-
active: optional(boolean),
|
|
47
|
-
externalId: optional(string),
|
|
48
|
-
startDate: optional(date),
|
|
49
|
-
endDate: optional(date),
|
|
50
|
-
status: optional(string),
|
|
51
|
-
billingProvider: optional(enum_(BillingProviderEnum)),
|
|
52
|
-
extraFields: optional(unknown)
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
export const SubscriptionSchema =
|
|
56
|
-
(uuidId: boolean) =>
|
|
57
|
-
<
|
|
58
|
-
T extends Record<string, LiteralSchema>,
|
|
59
|
-
U extends Record<string, LiteralSchema>
|
|
60
|
-
>(
|
|
61
|
-
PartyEnum: T,
|
|
62
|
-
BillingProviderEnum: U
|
|
63
|
-
) => ({
|
|
64
|
-
id: uuidId ? uuid : string,
|
|
65
|
-
partyId: string,
|
|
66
|
-
partyType: enum_(PartyEnum),
|
|
67
|
-
productId: string,
|
|
68
|
-
description: optional(string),
|
|
69
|
-
active: boolean,
|
|
70
|
-
externalId: string,
|
|
71
|
-
startDate: date,
|
|
72
|
-
endDate: date,
|
|
73
|
-
status: string,
|
|
74
|
-
billingProvider: optional(enum_(BillingProviderEnum)),
|
|
75
|
-
extraFields: optional(unknown),
|
|
76
|
-
createdAt: optional(date),
|
|
77
|
-
updatedAt: optional(date)
|
|
78
|
-
});
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BillingPortalDto,
|
|
3
|
-
BillingPortalService,
|
|
4
|
-
CreateBillingPortalDto,
|
|
5
|
-
UpdateBillingPortalDto
|
|
6
|
-
} from '@forklaunch/interfaces-billing';
|
|
7
|
-
import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
8
|
-
import { createCacheKey, TtlCache } from '@forklaunch/core/cache';
|
|
9
|
-
import {
|
|
10
|
-
InternalDtoMapper,
|
|
11
|
-
RequestDtoMapperConstructor,
|
|
12
|
-
ResponseDtoMapperConstructor,
|
|
13
|
-
transformIntoInternalDtoMapper
|
|
14
|
-
} from '@forklaunch/core/dtoMapper';
|
|
15
|
-
import {
|
|
16
|
-
MetricsDefinition,
|
|
17
|
-
OpenTelemetryCollector
|
|
18
|
-
} from '@forklaunch/core/http';
|
|
19
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
20
|
-
|
|
21
|
-
export class BaseBillingPortalService<
|
|
22
|
-
SchemaValidator extends AnySchemaValidator,
|
|
23
|
-
Metrics extends MetricsDefinition = MetricsDefinition,
|
|
24
|
-
Dto extends {
|
|
25
|
-
BillingPortalDtoMapper: BillingPortalDto;
|
|
26
|
-
CreateBillingPortalDtoMapper: CreateBillingPortalDto;
|
|
27
|
-
UpdateBillingPortalDtoMapper: UpdateBillingPortalDto;
|
|
28
|
-
} = {
|
|
29
|
-
BillingPortalDtoMapper: BillingPortalDto;
|
|
30
|
-
CreateBillingPortalDtoMapper: CreateBillingPortalDto;
|
|
31
|
-
UpdateBillingPortalDtoMapper: UpdateBillingPortalDto;
|
|
32
|
-
},
|
|
33
|
-
Entities extends {
|
|
34
|
-
BillingPortalDtoMapper: BillingPortalDto;
|
|
35
|
-
CreateBillingPortalDtoMapper: BillingPortalDto;
|
|
36
|
-
UpdateBillingPortalDtoMapper: BillingPortalDto;
|
|
37
|
-
} = {
|
|
38
|
-
BillingPortalDtoMapper: BillingPortalDto;
|
|
39
|
-
CreateBillingPortalDtoMapper: BillingPortalDto;
|
|
40
|
-
UpdateBillingPortalDtoMapper: BillingPortalDto;
|
|
41
|
-
}
|
|
42
|
-
> implements BillingPortalService
|
|
43
|
-
{
|
|
44
|
-
#dtoMappers: InternalDtoMapper<
|
|
45
|
-
InstanceTypeRecord<typeof this.dtoMappers>,
|
|
46
|
-
Entities,
|
|
47
|
-
Dto
|
|
48
|
-
>;
|
|
49
|
-
|
|
50
|
-
constructor(
|
|
51
|
-
protected cache: TtlCache,
|
|
52
|
-
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
53
|
-
protected schemaValidator: SchemaValidator,
|
|
54
|
-
protected dtoMappers: {
|
|
55
|
-
BillingPortalDtoMapper: ResponseDtoMapperConstructor<
|
|
56
|
-
SchemaValidator,
|
|
57
|
-
Dto['BillingPortalDtoMapper'],
|
|
58
|
-
Entities['BillingPortalDtoMapper']
|
|
59
|
-
>;
|
|
60
|
-
CreateBillingPortalDtoMapper: RequestDtoMapperConstructor<
|
|
61
|
-
SchemaValidator,
|
|
62
|
-
Dto['CreateBillingPortalDtoMapper'],
|
|
63
|
-
Entities['CreateBillingPortalDtoMapper']
|
|
64
|
-
>;
|
|
65
|
-
UpdateBillingPortalDtoMapper: RequestDtoMapperConstructor<
|
|
66
|
-
SchemaValidator,
|
|
67
|
-
Dto['UpdateBillingPortalDtoMapper'],
|
|
68
|
-
Entities['UpdateBillingPortalDtoMapper']
|
|
69
|
-
>;
|
|
70
|
-
}
|
|
71
|
-
) {
|
|
72
|
-
this.#dtoMappers = transformIntoInternalDtoMapper(
|
|
73
|
-
dtoMappers,
|
|
74
|
-
schemaValidator
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
protected createCacheKey = createCacheKey('billing_portal_session');
|
|
79
|
-
|
|
80
|
-
async createBillingPortalSession(
|
|
81
|
-
billingPortalDto: Dto['CreateBillingPortalDtoMapper']
|
|
82
|
-
): Promise<Dto['BillingPortalDtoMapper']> {
|
|
83
|
-
const billingPortalSession =
|
|
84
|
-
this.#dtoMappers.CreateBillingPortalDtoMapper.deserializeDtoToEntity(
|
|
85
|
-
billingPortalDto
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
this.openTelemetryCollector.debug(
|
|
89
|
-
'Create billing portal session',
|
|
90
|
-
billingPortalSession
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
await this.cache.putRecord({
|
|
94
|
-
key: this.createCacheKey(billingPortalSession.id),
|
|
95
|
-
value: billingPortalSession,
|
|
96
|
-
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
return this.#dtoMappers.BillingPortalDtoMapper.serializeEntityToDto(
|
|
100
|
-
billingPortalSession
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async getBillingPortalSession(
|
|
105
|
-
idDto: IdDto
|
|
106
|
-
): Promise<Dto['BillingPortalDtoMapper']> {
|
|
107
|
-
const billingPortalSessionDetails = await this.cache.readRecord<
|
|
108
|
-
Entities['BillingPortalDtoMapper']
|
|
109
|
-
>(this.createCacheKey(idDto.id));
|
|
110
|
-
if (!billingPortalSessionDetails) {
|
|
111
|
-
throw new Error('Session not found');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return this.#dtoMappers.BillingPortalDtoMapper.serializeEntityToDto(
|
|
115
|
-
billingPortalSessionDetails.value
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async updateBillingPortalSession(
|
|
120
|
-
billingPortalDto: UpdateBillingPortalDto
|
|
121
|
-
): Promise<Dto['BillingPortalDtoMapper']> {
|
|
122
|
-
const billingPortalSession =
|
|
123
|
-
this.#dtoMappers.UpdateBillingPortalDtoMapper.deserializeDtoToEntity(
|
|
124
|
-
billingPortalDto
|
|
125
|
-
);
|
|
126
|
-
// Save the updated session to your database or external service
|
|
127
|
-
await this.cache.putRecord({
|
|
128
|
-
key: this.createCacheKey(billingPortalSession.id),
|
|
129
|
-
value: billingPortalSession,
|
|
130
|
-
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
return this.#dtoMappers.BillingPortalDtoMapper.serializeEntityToDto(
|
|
134
|
-
billingPortalSession
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async expireBillingPortalSession(idDto: IdDto): Promise<void> {
|
|
139
|
-
const sessionExists = await this.cache.readRecord(
|
|
140
|
-
this.createCacheKey(idDto.id)
|
|
141
|
-
);
|
|
142
|
-
if (!sessionExists) {
|
|
143
|
-
throw new Error('Session not found');
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
await this.cache.deleteRecord(this.createCacheKey(idDto.id));
|
|
147
|
-
}
|
|
148
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CheckoutSessionDto,
|
|
3
|
-
CheckoutSessionService,
|
|
4
|
-
CreateCheckoutSessionDto,
|
|
5
|
-
UpdateCheckoutSessionDto
|
|
6
|
-
} from '@forklaunch/interfaces-billing';
|
|
7
|
-
import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
8
|
-
import { createCacheKey, TtlCache } from '@forklaunch/core/cache';
|
|
9
|
-
import {
|
|
10
|
-
InternalDtoMapper,
|
|
11
|
-
RequestDtoMapperConstructor,
|
|
12
|
-
ResponseDtoMapperConstructor,
|
|
13
|
-
transformIntoInternalDtoMapper
|
|
14
|
-
} from '@forklaunch/core/dtoMapper';
|
|
15
|
-
import {
|
|
16
|
-
MetricsDefinition,
|
|
17
|
-
OpenTelemetryCollector
|
|
18
|
-
} from '@forklaunch/core/http';
|
|
19
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
20
|
-
|
|
21
|
-
export class BaseCheckoutSessionService<
|
|
22
|
-
SchemaValidator extends AnySchemaValidator,
|
|
23
|
-
PaymentMethodEnum,
|
|
24
|
-
Metrics extends MetricsDefinition = MetricsDefinition,
|
|
25
|
-
Dto extends {
|
|
26
|
-
CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
|
|
27
|
-
CreateCheckoutSessionDtoMapper: CreateCheckoutSessionDto<PaymentMethodEnum>;
|
|
28
|
-
UpdateCheckoutSessionDtoMapper: UpdateCheckoutSessionDto<PaymentMethodEnum>;
|
|
29
|
-
} = {
|
|
30
|
-
CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
|
|
31
|
-
CreateCheckoutSessionDtoMapper: CreateCheckoutSessionDto<PaymentMethodEnum>;
|
|
32
|
-
UpdateCheckoutSessionDtoMapper: UpdateCheckoutSessionDto<PaymentMethodEnum>;
|
|
33
|
-
},
|
|
34
|
-
Entities extends {
|
|
35
|
-
CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
|
|
36
|
-
CreateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
|
|
37
|
-
UpdateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
|
|
38
|
-
} = {
|
|
39
|
-
CheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
|
|
40
|
-
CreateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
|
|
41
|
-
UpdateCheckoutSessionDtoMapper: CheckoutSessionDto<PaymentMethodEnum>;
|
|
42
|
-
}
|
|
43
|
-
> implements CheckoutSessionService<PaymentMethodEnum>
|
|
44
|
-
{
|
|
45
|
-
#dtoMappers: InternalDtoMapper<
|
|
46
|
-
InstanceTypeRecord<typeof this.dtoMappers>,
|
|
47
|
-
Entities,
|
|
48
|
-
Dto
|
|
49
|
-
>;
|
|
50
|
-
|
|
51
|
-
constructor(
|
|
52
|
-
protected readonly cache: TtlCache,
|
|
53
|
-
protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
54
|
-
protected readonly schemaValidator: SchemaValidator,
|
|
55
|
-
protected readonly dtoMappers: {
|
|
56
|
-
CheckoutSessionDtoMapper: ResponseDtoMapperConstructor<
|
|
57
|
-
SchemaValidator,
|
|
58
|
-
Dto['CheckoutSessionDtoMapper'],
|
|
59
|
-
Entities['CheckoutSessionDtoMapper']
|
|
60
|
-
>;
|
|
61
|
-
CreateCheckoutSessionDtoMapper: RequestDtoMapperConstructor<
|
|
62
|
-
SchemaValidator,
|
|
63
|
-
Dto['CreateCheckoutSessionDtoMapper'],
|
|
64
|
-
Entities['CreateCheckoutSessionDtoMapper']
|
|
65
|
-
>;
|
|
66
|
-
UpdateCheckoutSessionDtoMapper: RequestDtoMapperConstructor<
|
|
67
|
-
SchemaValidator,
|
|
68
|
-
Dto['UpdateCheckoutSessionDtoMapper'],
|
|
69
|
-
Entities['UpdateCheckoutSessionDtoMapper']
|
|
70
|
-
>;
|
|
71
|
-
}
|
|
72
|
-
) {
|
|
73
|
-
this.#dtoMappers = transformIntoInternalDtoMapper(
|
|
74
|
-
dtoMappers,
|
|
75
|
-
schemaValidator
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
protected createCacheKey = createCacheKey('checkout_session');
|
|
80
|
-
|
|
81
|
-
async createCheckoutSession(
|
|
82
|
-
checkoutSessionDto: Dto['CreateCheckoutSessionDtoMapper']
|
|
83
|
-
): Promise<Dto['CheckoutSessionDtoMapper']> {
|
|
84
|
-
const checkoutSession =
|
|
85
|
-
this.#dtoMappers.CreateCheckoutSessionDtoMapper.deserializeDtoToEntity(
|
|
86
|
-
checkoutSessionDto
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
// Store the checkoutSession details in the cache
|
|
90
|
-
await this.cache.putRecord({
|
|
91
|
-
key: this.createCacheKey(checkoutSession.id),
|
|
92
|
-
value: checkoutSession,
|
|
93
|
-
ttlMilliseconds: this.cache.getTtlMilliseconds()
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
return this.#dtoMappers.CheckoutSessionDtoMapper.serializeEntityToDto(
|
|
97
|
-
checkoutSession
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async getCheckoutSession({
|
|
102
|
-
id
|
|
103
|
-
}: IdDto): Promise<Dto['CheckoutSessionDtoMapper']> {
|
|
104
|
-
const checkoutSessionDetails = await this.cache.readRecord<
|
|
105
|
-
Entities['CheckoutSessionDtoMapper']
|
|
106
|
-
>(this.createCacheKey(id));
|
|
107
|
-
if (!checkoutSessionDetails) {
|
|
108
|
-
throw new Error('Session not found');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return this.#dtoMappers.CheckoutSessionDtoMapper.serializeEntityToDto(
|
|
112
|
-
checkoutSessionDetails.value
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async expireCheckoutSession({ id }: IdDto): Promise<void> {
|
|
117
|
-
const checkoutSessionDetails = await this.cache.readRecord(
|
|
118
|
-
this.createCacheKey(id)
|
|
119
|
-
);
|
|
120
|
-
if (!checkoutSessionDetails) {
|
|
121
|
-
throw new Error('Session not found');
|
|
122
|
-
}
|
|
123
|
-
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async handleCheckoutSuccess({ id }: IdDto): Promise<void> {
|
|
127
|
-
this.openTelemetryCollector.info('Checkout success', { id });
|
|
128
|
-
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async handleCheckoutFailure({ id }: IdDto): Promise<void> {
|
|
132
|
-
this.openTelemetryCollector.info('Checkout failure', { id });
|
|
133
|
-
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
134
|
-
}
|
|
135
|
-
}
|