@forklaunch/implementation-billing-stripe 0.5.20 → 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/schemas/index.d.mts +39 -39
- package/lib/domain/schemas/index.d.ts +39 -39
- package/lib/domain/schemas/index.js +8 -8
- package/lib/domain/schemas/index.mjs +8 -8
- package/lib/domain/types/index.d.mts +294 -65
- package/lib/domain/types/index.d.ts +294 -65
- 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/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 +9 -4
- package/lib/eject/domain/types/stripe.entity.types.ts +103 -63
- package/lib/eject/domain/types/stripeWebhookEvent.types.ts +16 -0
- package/lib/eject/domain/types/subscription.mapper.types.ts +10 -7
- package/lib/eject/services/checkoutSession.service.ts +17 -19
- package/lib/eject/services/paymentLink.service.ts +28 -28
- package/lib/eject/services/webhook.service.ts +11 -10
- package/lib/services/index.d.mts +17 -17
- package/lib/services/index.d.ts +17 -17
- package/lib/services/index.js +65970 -533
- package/lib/services/index.mjs +66070 -507
- package/package.json +9 -9
|
@@ -29,7 +29,7 @@ export const CreateSubscriptionSchema = <
|
|
|
29
29
|
startDate: date,
|
|
30
30
|
endDate: optional(date),
|
|
31
31
|
status: string,
|
|
32
|
-
billingProvider:
|
|
32
|
+
billingProvider: enum_(BillingProviderEnum),
|
|
33
33
|
stripeFields: type<StripeCreateSubscriptionDto<T>['stripeFields']>()
|
|
34
34
|
});
|
|
35
35
|
|
|
@@ -65,7 +65,7 @@ export const SubscriptionSchema = <T extends Record<string, LiteralSchema>>(
|
|
|
65
65
|
startDate: date,
|
|
66
66
|
endDate: optional(date),
|
|
67
67
|
status: string,
|
|
68
|
-
billingProvider:
|
|
68
|
+
billingProvider: enum_(BillingProviderEnum),
|
|
69
69
|
stripeFields: type<StripeSubscriptionDto<T>['stripeFields']>(),
|
|
70
70
|
createdAt: optional(date),
|
|
71
71
|
updatedAt: optional(date)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
1
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
2
2
|
import Stripe from 'stripe';
|
|
3
3
|
import { StripeBillingPortalDtos } from './stripe.dto.types';
|
|
4
4
|
import { StripeBillingPortalEntities } from './stripe.entity.types';
|
|
@@ -8,24 +8,27 @@ export type StripeBillingPortalMappers<
|
|
|
8
8
|
Dto extends StripeBillingPortalDtos
|
|
9
9
|
> = {
|
|
10
10
|
BillingPortalMapper: {
|
|
11
|
+
entity: Entities['BillingPortalMapper'];
|
|
11
12
|
toDto: (
|
|
12
|
-
entity: Entities['BillingPortalMapper']
|
|
13
|
+
entity: InferEntity<Entities['BillingPortalMapper']>
|
|
13
14
|
) => Promise<Dto['BillingPortalMapper']>;
|
|
14
15
|
};
|
|
15
16
|
CreateBillingPortalMapper: {
|
|
17
|
+
entity: Entities['CreateBillingPortalMapper'];
|
|
16
18
|
toEntity: (
|
|
17
19
|
dto: Dto['CreateBillingPortalMapper'],
|
|
18
20
|
em: EntityManager,
|
|
19
21
|
stripeSession: Stripe.BillingPortal.Session,
|
|
20
22
|
...args: unknown[]
|
|
21
|
-
) => Promise<Entities['CreateBillingPortalMapper']
|
|
23
|
+
) => Promise<InferEntity<Entities['CreateBillingPortalMapper']>>;
|
|
22
24
|
};
|
|
23
25
|
UpdateBillingPortalMapper: {
|
|
26
|
+
entity: Entities['UpdateBillingPortalMapper'];
|
|
24
27
|
toEntity: (
|
|
25
28
|
dto: Dto['UpdateBillingPortalMapper'],
|
|
26
29
|
em: EntityManager,
|
|
27
30
|
stripeSession: Stripe.BillingPortal.Session,
|
|
28
31
|
...args: unknown[]
|
|
29
|
-
) => Promise<Entities['UpdateBillingPortalMapper']
|
|
32
|
+
) => Promise<InferEntity<Entities['UpdateBillingPortalMapper']>>;
|
|
30
33
|
};
|
|
31
34
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
1
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
2
2
|
import Stripe from 'stripe';
|
|
3
3
|
import { StripeCheckoutSessionDtos } from './stripe.dto.types';
|
|
4
4
|
import { StripeCheckoutSessionEntities } from './stripe.entity.types';
|
|
@@ -9,24 +9,27 @@ export type StripeCheckoutSessionMappers<
|
|
|
9
9
|
Dto extends StripeCheckoutSessionDtos<StatusEnum>
|
|
10
10
|
> = {
|
|
11
11
|
CheckoutSessionMapper: {
|
|
12
|
+
entity: Entities['CheckoutSessionMapper'];
|
|
12
13
|
toDto: (
|
|
13
|
-
entity: Entities['CheckoutSessionMapper']
|
|
14
|
+
entity: InferEntity<Entities['CheckoutSessionMapper']>
|
|
14
15
|
) => Promise<Dto['CheckoutSessionMapper']>;
|
|
15
16
|
};
|
|
16
17
|
CreateCheckoutSessionMapper: {
|
|
18
|
+
entity: Entities['CreateCheckoutSessionMapper'];
|
|
17
19
|
toEntity: (
|
|
18
20
|
dto: Dto['CreateCheckoutSessionMapper'],
|
|
19
21
|
em: EntityManager,
|
|
20
22
|
stripeSession: Stripe.Checkout.Session,
|
|
21
23
|
...args: unknown[]
|
|
22
|
-
) => Promise<Entities['CreateCheckoutSessionMapper']
|
|
24
|
+
) => Promise<InferEntity<Entities['CreateCheckoutSessionMapper']>>;
|
|
23
25
|
};
|
|
24
26
|
UpdateCheckoutSessionMapper: {
|
|
27
|
+
entity: Entities['UpdateCheckoutSessionMapper'];
|
|
25
28
|
toEntity: (
|
|
26
29
|
dto: Dto['UpdateCheckoutSessionMapper'],
|
|
27
30
|
em: EntityManager,
|
|
28
31
|
stripeSession: Stripe.Checkout.Session,
|
|
29
32
|
...args: unknown[]
|
|
30
|
-
) => Promise<Entities['UpdateCheckoutSessionMapper']
|
|
33
|
+
) => Promise<InferEntity<Entities['UpdateCheckoutSessionMapper']>>;
|
|
31
34
|
};
|
|
32
35
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
1
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
2
2
|
import Stripe from 'stripe';
|
|
3
3
|
import { StripePaymentLinkDtos } from './stripe.dto.types';
|
|
4
4
|
import { StripePaymentLinkEntities } from './stripe.entity.types';
|
|
@@ -9,24 +9,27 @@ export type StripePaymentLinkMappers<
|
|
|
9
9
|
Dto extends StripePaymentLinkDtos<StatusEnum>
|
|
10
10
|
> = {
|
|
11
11
|
PaymentLinkMapper: {
|
|
12
|
+
entity: Entities['PaymentLinkMapper'];
|
|
12
13
|
toDto: (
|
|
13
|
-
entity: Entities['PaymentLinkMapper']
|
|
14
|
+
entity: InferEntity<Entities['PaymentLinkMapper']>
|
|
14
15
|
) => Promise<Dto['PaymentLinkMapper']>;
|
|
15
16
|
};
|
|
16
17
|
CreatePaymentLinkMapper: {
|
|
18
|
+
entity: Entities['CreatePaymentLinkMapper'];
|
|
17
19
|
toEntity: (
|
|
18
20
|
dto: Dto['CreatePaymentLinkMapper'],
|
|
19
21
|
em: EntityManager,
|
|
20
22
|
stripePaymentLink: Stripe.PaymentLink,
|
|
21
23
|
...args: unknown[]
|
|
22
|
-
) => Promise<Entities['CreatePaymentLinkMapper']
|
|
24
|
+
) => Promise<InferEntity<Entities['CreatePaymentLinkMapper']>>;
|
|
23
25
|
};
|
|
24
26
|
UpdatePaymentLinkMapper: {
|
|
27
|
+
entity: Entities['UpdatePaymentLinkMapper'];
|
|
25
28
|
toEntity: (
|
|
26
29
|
dto: Dto['UpdatePaymentLinkMapper'],
|
|
27
30
|
em: EntityManager,
|
|
28
31
|
stripePaymentLink: Stripe.PaymentLink,
|
|
29
32
|
...args: unknown[]
|
|
30
|
-
) => Promise<Entities['UpdatePaymentLinkMapper']
|
|
33
|
+
) => Promise<InferEntity<Entities['UpdatePaymentLinkMapper']>>;
|
|
31
34
|
};
|
|
32
35
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
1
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
2
2
|
import Stripe from 'stripe';
|
|
3
3
|
import { StripePlanDtos } from './stripe.dto.types';
|
|
4
4
|
import { StripePlanEntities } from './stripe.entity.types';
|
|
@@ -8,22 +8,27 @@ export type StripePlanMappers<
|
|
|
8
8
|
Dto extends StripePlanDtos
|
|
9
9
|
> = {
|
|
10
10
|
PlanMapper: {
|
|
11
|
-
|
|
11
|
+
entity: Entities['PlanMapper'];
|
|
12
|
+
toDto: (
|
|
13
|
+
entity: InferEntity<Entities['PlanMapper']>
|
|
14
|
+
) => Promise<Dto['PlanMapper']>;
|
|
12
15
|
};
|
|
13
16
|
CreatePlanMapper: {
|
|
17
|
+
entity: Entities['CreatePlanMapper'];
|
|
14
18
|
toEntity: (
|
|
15
19
|
dto: Dto['CreatePlanMapper'],
|
|
16
20
|
em: EntityManager,
|
|
17
21
|
stripePlan: Stripe.Product,
|
|
18
22
|
...args: unknown[]
|
|
19
|
-
) => Promise<Entities['CreatePlanMapper']
|
|
23
|
+
) => Promise<InferEntity<Entities['CreatePlanMapper']>>;
|
|
20
24
|
};
|
|
21
25
|
UpdatePlanMapper: {
|
|
26
|
+
entity: Entities['UpdatePlanMapper'];
|
|
22
27
|
toEntity: (
|
|
23
28
|
dto: Dto['UpdatePlanMapper'],
|
|
24
29
|
em: EntityManager,
|
|
25
30
|
stripePlan: Stripe.Product,
|
|
26
31
|
...args: unknown[]
|
|
27
|
-
) => Promise<Entities['UpdatePlanMapper']
|
|
32
|
+
) => Promise<InferEntity<Entities['UpdatePlanMapper']>>;
|
|
28
33
|
};
|
|
29
34
|
};
|
|
@@ -1,83 +1,123 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
BillingPortal,
|
|
3
|
+
CheckoutSession,
|
|
4
|
+
PaymentLink,
|
|
5
|
+
Plan,
|
|
6
|
+
Subscription
|
|
7
|
+
} from '../../persistence/entities';
|
|
8
|
+
import {
|
|
9
|
+
BillingProviderEnum,
|
|
10
|
+
CurrencyEnum,
|
|
11
|
+
PaymentMethodEnum,
|
|
12
|
+
PlanCadenceEnum
|
|
13
|
+
} from '../enum';
|
|
13
14
|
|
|
14
15
|
// Billing Portal Types
|
|
15
|
-
export type StripeBillingPortalEntity = BillingPortalDto & {
|
|
16
|
-
providerFields: Stripe.BillingPortal.Session;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
16
|
export type StripeBillingPortalEntities = {
|
|
20
|
-
BillingPortalMapper:
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
BillingPortalMapper: {
|
|
18
|
+
'~entity': (typeof BillingPortal)['~entity'];
|
|
19
|
+
};
|
|
20
|
+
CreateBillingPortalMapper: {
|
|
21
|
+
'~entity': (typeof BillingPortal)['~entity'];
|
|
22
|
+
};
|
|
23
|
+
UpdateBillingPortalMapper: {
|
|
24
|
+
'~entity': (typeof BillingPortal)['~entity'];
|
|
25
|
+
};
|
|
23
26
|
};
|
|
24
27
|
|
|
25
28
|
// Checkout Session Types
|
|
26
|
-
|
|
27
|
-
export type StripeCheckoutSessionEntity<StatusEnum> = CheckoutSessionDto<
|
|
28
|
-
typeof PaymentMethodEnum,
|
|
29
|
-
typeof CurrencyEnum,
|
|
30
|
-
StatusEnum
|
|
31
|
-
> & {
|
|
32
|
-
providerFields: Stripe.Checkout.Session;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
29
|
export type StripeCheckoutSessionEntities<StatusEnum> = {
|
|
36
|
-
CheckoutSessionMapper:
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
CheckoutSessionMapper: {
|
|
31
|
+
'~entity': (typeof CheckoutSession)['~entity'] & {
|
|
32
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
33
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
34
|
+
status: StatusEnum[keyof StatusEnum];
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
CreateCheckoutSessionMapper: {
|
|
38
|
+
'~entity': (typeof CheckoutSession)['~entity'] & {
|
|
39
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
40
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
41
|
+
status: StatusEnum[keyof StatusEnum];
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
UpdateCheckoutSessionMapper: {
|
|
45
|
+
'~entity': (typeof CheckoutSession)['~entity'] & {
|
|
46
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
47
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
48
|
+
status: StatusEnum[keyof StatusEnum];
|
|
49
|
+
};
|
|
50
|
+
};
|
|
39
51
|
};
|
|
40
52
|
|
|
41
53
|
// Payment Link Types
|
|
42
|
-
export type StripePaymentLinkEntity<StatusEnum> = PaymentLinkDto<
|
|
43
|
-
typeof PaymentMethodEnum,
|
|
44
|
-
typeof CurrencyEnum,
|
|
45
|
-
StatusEnum
|
|
46
|
-
> & {
|
|
47
|
-
providerFields: Stripe.PaymentLink;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
54
|
export type StripePaymentLinkEntities<StatusEnum> = {
|
|
51
|
-
PaymentLinkMapper:
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
PaymentLinkMapper: {
|
|
56
|
+
'~entity': (typeof PaymentLink)['~entity'] & {
|
|
57
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
58
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
59
|
+
status: StatusEnum[keyof StatusEnum];
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
CreatePaymentLinkMapper: {
|
|
63
|
+
'~entity': (typeof PaymentLink)['~entity'] & {
|
|
64
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
65
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
66
|
+
status: StatusEnum[keyof StatusEnum];
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
UpdatePaymentLinkMapper: {
|
|
70
|
+
'~entity': (typeof PaymentLink)['~entity'] & {
|
|
71
|
+
paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
|
|
72
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
73
|
+
status: StatusEnum[keyof StatusEnum];
|
|
74
|
+
};
|
|
75
|
+
};
|
|
54
76
|
};
|
|
55
77
|
|
|
56
78
|
// Plan Types
|
|
57
|
-
export type StripePlanEntity = PlanDto<
|
|
58
|
-
typeof PlanCadenceEnum,
|
|
59
|
-
typeof CurrencyEnum,
|
|
60
|
-
typeof BillingProviderEnum
|
|
61
|
-
> & {
|
|
62
|
-
providerFields: Stripe.Product;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
79
|
export type StripePlanEntities = {
|
|
66
|
-
PlanMapper:
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
PlanMapper: {
|
|
81
|
+
'~entity': (typeof Plan)['~entity'] & {
|
|
82
|
+
cadence: PlanCadenceEnum[keyof PlanCadenceEnum];
|
|
83
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
84
|
+
billingProvider: BillingProviderEnum[keyof BillingProviderEnum] | null;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
CreatePlanMapper: {
|
|
88
|
+
'~entity': (typeof Plan)['~entity'] & {
|
|
89
|
+
cadence: PlanCadenceEnum[keyof PlanCadenceEnum];
|
|
90
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
91
|
+
billingProvider: BillingProviderEnum[keyof BillingProviderEnum] | null;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
UpdatePlanMapper: {
|
|
95
|
+
'~entity': (typeof Plan)['~entity'] & {
|
|
96
|
+
cadence: PlanCadenceEnum[keyof PlanCadenceEnum];
|
|
97
|
+
currency: CurrencyEnum[keyof CurrencyEnum];
|
|
98
|
+
billingProvider: BillingProviderEnum[keyof BillingProviderEnum] | null;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
69
101
|
};
|
|
70
102
|
|
|
71
103
|
// Subscription Types
|
|
72
|
-
export type
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
104
|
+
export type StripeSubscriptionEntities<PartyTypeEnum> = {
|
|
105
|
+
SubscriptionMapper: {
|
|
106
|
+
'~entity': (typeof Subscription)['~entity'] & {
|
|
107
|
+
partyType: PartyTypeEnum[keyof PartyTypeEnum];
|
|
108
|
+
billingProvider: BillingProviderEnum[keyof BillingProviderEnum] | null;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
CreateSubscriptionMapper: {
|
|
112
|
+
'~entity': (typeof Subscription)['~entity'] & {
|
|
113
|
+
partyType: PartyTypeEnum[keyof PartyTypeEnum];
|
|
114
|
+
billingProvider: BillingProviderEnum[keyof BillingProviderEnum] | null;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
UpdateSubscriptionMapper: {
|
|
118
|
+
'~entity': (typeof Subscription)['~entity'] & {
|
|
119
|
+
partyType: PartyTypeEnum[keyof PartyTypeEnum];
|
|
120
|
+
billingProvider: BillingProviderEnum[keyof BillingProviderEnum] | null;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
83
123
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineEntity, p, type InferEntity } from '@mikro-orm/core';
|
|
2
|
+
|
|
3
|
+
export const StripeWebhookEventEntity = defineEntity({
|
|
4
|
+
name: 'StripeWebhookEvent',
|
|
5
|
+
properties: {
|
|
6
|
+
id: p.uuid().primary(),
|
|
7
|
+
createdAt: p.datetime(),
|
|
8
|
+
updatedAt: p.datetime(),
|
|
9
|
+
stripeId: p.string(),
|
|
10
|
+
idempotencyKey: p.string().nullable(),
|
|
11
|
+
eventType: p.string(),
|
|
12
|
+
eventData: p.json<unknown>()
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export type StripeWebhookEvent = InferEntity<typeof StripeWebhookEventEntity>;
|
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
1
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
2
2
|
import Stripe from 'stripe';
|
|
3
3
|
import { StripeSubscriptionDtos } from './stripe.dto.types';
|
|
4
4
|
import { StripeSubscriptionEntities } from './stripe.entity.types';
|
|
5
5
|
|
|
6
6
|
export type StripeSubscriptionMappers<
|
|
7
|
-
|
|
8
|
-
Entities extends StripeSubscriptionEntities<
|
|
9
|
-
Dto extends StripeSubscriptionDtos<
|
|
7
|
+
PartyTypeEnum,
|
|
8
|
+
Entities extends StripeSubscriptionEntities<PartyTypeEnum>,
|
|
9
|
+
Dto extends StripeSubscriptionDtos<PartyTypeEnum>
|
|
10
10
|
> = {
|
|
11
11
|
SubscriptionMapper: {
|
|
12
|
+
entity: Entities['SubscriptionMapper'];
|
|
12
13
|
toDto: (
|
|
13
|
-
entity: Entities['SubscriptionMapper']
|
|
14
|
+
entity: InferEntity<Entities['SubscriptionMapper']>
|
|
14
15
|
) => Promise<Dto['SubscriptionMapper']>;
|
|
15
16
|
};
|
|
16
17
|
CreateSubscriptionMapper: {
|
|
18
|
+
entity: Entities['CreateSubscriptionMapper'];
|
|
17
19
|
toEntity: (
|
|
18
20
|
dto: Dto['CreateSubscriptionMapper'],
|
|
19
21
|
em: EntityManager,
|
|
20
22
|
stripeSubscription: Stripe.Subscription,
|
|
21
23
|
...args: unknown[]
|
|
22
|
-
) => Promise<Entities['CreateSubscriptionMapper']
|
|
24
|
+
) => Promise<InferEntity<Entities['CreateSubscriptionMapper']>>;
|
|
23
25
|
};
|
|
24
26
|
UpdateSubscriptionMapper: {
|
|
27
|
+
entity: Entities['UpdateSubscriptionMapper'];
|
|
25
28
|
toEntity: (
|
|
26
29
|
dto: Dto['UpdateSubscriptionMapper'],
|
|
27
30
|
em: EntityManager,
|
|
28
31
|
stripeSubscription: Stripe.Subscription,
|
|
29
32
|
...args: unknown[]
|
|
30
|
-
) => Promise<Entities['UpdateSubscriptionMapper']
|
|
33
|
+
) => Promise<InferEntity<Entities['UpdateSubscriptionMapper']>>;
|
|
31
34
|
};
|
|
32
35
|
};
|
|
@@ -23,27 +23,25 @@ import { StripeCheckoutSessionEntities } from '../domain/types/stripe.entity.typ
|
|
|
23
23
|
export class StripeCheckoutSessionService<
|
|
24
24
|
SchemaValidator extends AnySchemaValidator,
|
|
25
25
|
StatusEnum,
|
|
26
|
-
|
|
27
|
-
Dto extends
|
|
28
|
-
StripeCheckoutSessionDtos<StatusEnum>
|
|
29
|
-
> implements
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
>
|
|
40
|
-
{
|
|
26
|
+
MapperEntities extends StripeCheckoutSessionEntities<StatusEnum>,
|
|
27
|
+
Dto extends StripeCheckoutSessionDtos<StatusEnum> =
|
|
28
|
+
StripeCheckoutSessionDtos<StatusEnum>
|
|
29
|
+
> implements CheckoutSessionService<
|
|
30
|
+
typeof PaymentMethodEnum,
|
|
31
|
+
typeof CurrencyEnum,
|
|
32
|
+
StatusEnum,
|
|
33
|
+
{
|
|
34
|
+
CreateCheckoutSessionDto: Dto['CreateCheckoutSessionMapper'];
|
|
35
|
+
CheckoutSessionDto: Dto['CheckoutSessionMapper'];
|
|
36
|
+
IdDto: IdDto;
|
|
37
|
+
}
|
|
38
|
+
> {
|
|
41
39
|
baseCheckoutSessionService: BaseCheckoutSessionService<
|
|
42
40
|
SchemaValidator,
|
|
43
41
|
PaymentMethodEnum,
|
|
44
42
|
CurrencyEnum,
|
|
45
43
|
StatusEnum,
|
|
46
|
-
|
|
44
|
+
MapperEntities,
|
|
47
45
|
Dto
|
|
48
46
|
>;
|
|
49
47
|
protected readonly stripeClient: Stripe;
|
|
@@ -53,7 +51,7 @@ export class StripeCheckoutSessionService<
|
|
|
53
51
|
protected readonly schemaValidator: SchemaValidator;
|
|
54
52
|
protected readonly mappers: StripeCheckoutSessionMappers<
|
|
55
53
|
StatusEnum,
|
|
56
|
-
|
|
54
|
+
MapperEntities,
|
|
57
55
|
Dto
|
|
58
56
|
>;
|
|
59
57
|
|
|
@@ -63,7 +61,7 @@ export class StripeCheckoutSessionService<
|
|
|
63
61
|
cache: TtlCache,
|
|
64
62
|
openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
|
|
65
63
|
schemaValidator: SchemaValidator,
|
|
66
|
-
mappers: StripeCheckoutSessionMappers<StatusEnum,
|
|
64
|
+
mappers: StripeCheckoutSessionMappers<StatusEnum, MapperEntities, Dto>,
|
|
67
65
|
readonly options?: {
|
|
68
66
|
enableDatabaseBackup?: boolean;
|
|
69
67
|
telemetry?: TelemetryOptions;
|
|
@@ -84,7 +82,7 @@ export class StripeCheckoutSessionService<
|
|
|
84
82
|
PaymentMethodEnum,
|
|
85
83
|
CurrencyEnum,
|
|
86
84
|
StatusEnum,
|
|
87
|
-
|
|
85
|
+
MapperEntities,
|
|
88
86
|
Dto
|
|
89
87
|
>,
|
|
90
88
|
options
|
|
@@ -25,22 +25,20 @@ export class StripePaymentLinkService<
|
|
|
25
25
|
SchemaValidator extends AnySchemaValidator,
|
|
26
26
|
StatusEnum,
|
|
27
27
|
Entities extends StripePaymentLinkEntities<StatusEnum>,
|
|
28
|
-
Dto extends
|
|
29
|
-
StripePaymentLinkDtos<StatusEnum>
|
|
30
|
-
> implements
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
>
|
|
43
|
-
{
|
|
28
|
+
Dto extends StripePaymentLinkDtos<StatusEnum> =
|
|
29
|
+
StripePaymentLinkDtos<StatusEnum>
|
|
30
|
+
> implements PaymentLinkService<
|
|
31
|
+
PaymentMethodEnum,
|
|
32
|
+
typeof CurrencyEnum,
|
|
33
|
+
StatusEnum,
|
|
34
|
+
{
|
|
35
|
+
CreatePaymentLinkDto: StripeCreatePaymentLinkDto<StatusEnum>;
|
|
36
|
+
UpdatePaymentLinkDto: StripeUpdatePaymentLinkDto<StatusEnum>;
|
|
37
|
+
PaymentLinkDto: StripePaymentLinkDto<StatusEnum>;
|
|
38
|
+
IdDto: IdDto;
|
|
39
|
+
IdsDto: IdsDto;
|
|
40
|
+
}
|
|
41
|
+
> {
|
|
44
42
|
basePaymentLinkService: BasePaymentLinkService<
|
|
45
43
|
SchemaValidator,
|
|
46
44
|
PaymentMethodEnum,
|
|
@@ -138,18 +136,20 @@ export class StripePaymentLinkService<
|
|
|
138
136
|
);
|
|
139
137
|
|
|
140
138
|
const paymentLink = await this.basePaymentLinkService.updatePaymentLink(
|
|
141
|
-
await this.mappers.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
139
|
+
await this.mappers.PaymentLinkMapper.toDto(
|
|
140
|
+
await this.mappers.UpdatePaymentLinkMapper.toEntity(
|
|
141
|
+
{
|
|
142
|
+
...paymentLinkDto,
|
|
143
|
+
id: session.id,
|
|
144
|
+
amount:
|
|
145
|
+
session.line_items?.data.reduce<number>(
|
|
146
|
+
(total, item) => total + item.amount_total,
|
|
147
|
+
0
|
|
148
|
+
) ?? 0
|
|
149
|
+
},
|
|
150
|
+
this.em,
|
|
151
|
+
session
|
|
152
|
+
)
|
|
153
153
|
),
|
|
154
154
|
...args
|
|
155
155
|
);
|
|
@@ -6,6 +6,7 @@ import { AnySchemaValidator } from '@forklaunch/validator';
|
|
|
6
6
|
import { EntityManager } from '@mikro-orm/core';
|
|
7
7
|
import Stripe from 'stripe';
|
|
8
8
|
import { PartyEnum } from '../../../../billing-base/domain/enum/party.enum';
|
|
9
|
+
import { StripeWebhookEvent } from '../../../../billing-stripe/persistence/entities/stripeWebhookEvent.entity';
|
|
9
10
|
import { BillingProviderEnum } from '../domain/enum/billingProvider.enum';
|
|
10
11
|
import { CurrencyEnum } from '../domain/enum/currency.enum';
|
|
11
12
|
import { PaymentMethodEnum } from '../domain/enum/paymentMethod.enum';
|
|
@@ -27,15 +28,15 @@ export class StripeWebhookService<
|
|
|
27
28
|
SchemaValidator extends AnySchemaValidator,
|
|
28
29
|
StatusEnum,
|
|
29
30
|
PartyEnum,
|
|
30
|
-
BillingPortalEntities extends
|
|
31
|
-
StripeBillingPortalEntities
|
|
32
|
-
CheckoutSessionEntities extends
|
|
33
|
-
StripeCheckoutSessionEntities<StatusEnum
|
|
34
|
-
PaymentLinkEntities extends
|
|
35
|
-
StripePaymentLinkEntities<StatusEnum
|
|
31
|
+
BillingPortalEntities extends StripeBillingPortalEntities =
|
|
32
|
+
StripeBillingPortalEntities,
|
|
33
|
+
CheckoutSessionEntities extends StripeCheckoutSessionEntities<StatusEnum> =
|
|
34
|
+
StripeCheckoutSessionEntities<StatusEnum>,
|
|
35
|
+
PaymentLinkEntities extends StripePaymentLinkEntities<StatusEnum> =
|
|
36
|
+
StripePaymentLinkEntities<StatusEnum>,
|
|
36
37
|
PlanEntities extends StripePlanEntities = StripePlanEntities,
|
|
37
|
-
SubscriptionEntities extends
|
|
38
|
-
StripeSubscriptionEntities<PartyEnum>
|
|
38
|
+
SubscriptionEntities extends StripeSubscriptionEntities<PartyEnum> =
|
|
39
|
+
StripeSubscriptionEntities<PartyEnum>
|
|
39
40
|
> {
|
|
40
41
|
protected readonly stripeClient: Stripe;
|
|
41
42
|
protected readonly em: EntityManager;
|
|
@@ -136,7 +137,7 @@ export class StripeWebhookService<
|
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
if (
|
|
139
|
-
await this.em.findOne(
|
|
140
|
+
await this.em.findOne(StripeWebhookEvent, {
|
|
140
141
|
idempotencyKey: event.request?.idempotency_key
|
|
141
142
|
})
|
|
142
143
|
) {
|
|
@@ -454,7 +455,7 @@ export class StripeWebhookService<
|
|
|
454
455
|
break;
|
|
455
456
|
}
|
|
456
457
|
|
|
457
|
-
await this.em.insert(
|
|
458
|
+
await this.em.insert(StripeWebhookEvent, {
|
|
458
459
|
stripeId: event.id,
|
|
459
460
|
idempotencyKey: event.request?.idempotency_key,
|
|
460
461
|
eventType: event.type,
|