@forklaunch/interfaces-billing 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 forklaunch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './interfaces/billingPortal.service.interface';
2
+ export * from './interfaces/checkoutSession.service.interface';
3
+ export * from './interfaces/paymentLink.service.interface';
4
+ export * from './interfaces/plan.service.interface';
5
+ export * from './interfaces/subscription.service.interface';
@@ -0,0 +1,36 @@
1
+ import { IdDto, RecordTimingDto } from '@forklaunch/common';
2
+
3
+ export type CreateBillingPortalDto = {
4
+ customerId: string;
5
+ uri: string;
6
+ expiresAt: Date;
7
+ extraFields?: unknown;
8
+ };
9
+ export type UpdateBillingPortalDto = IdDto & Partial<CreateBillingPortalDto>;
10
+ export type BillingPortalDto = IdDto &
11
+ CreateBillingPortalDto &
12
+ Partial<RecordTimingDto>;
13
+
14
+ export type BillingPortalServiceParameters = {
15
+ CreateBillingPortalDto: CreateBillingPortalDto;
16
+ UpdateBillingPortalDto: UpdateBillingPortalDto;
17
+ BillingPortalDto: BillingPortalDto;
18
+ IdDto: IdDto;
19
+ };
20
+
21
+ export interface BillingPortalService<
22
+ Params extends BillingPortalServiceParameters = BillingPortalServiceParameters
23
+ > {
24
+ // for generating external links
25
+ // store in cache, for permissions
26
+ createBillingPortalSession: (
27
+ billingPortalDto: Params['CreateBillingPortalDto']
28
+ ) => Promise<Params['BillingPortalDto']>;
29
+ getBillingPortalSession: (
30
+ idDto: Params['IdDto']
31
+ ) => Promise<Params['BillingPortalDto']>;
32
+ updateBillingPortalSession: (
33
+ billingPortalDto: Params['UpdateBillingPortalDto']
34
+ ) => Promise<Params['BillingPortalDto']>;
35
+ expireBillingPortalSession: (idDto: Params['IdDto']) => Promise<void>;
36
+ }
@@ -0,0 +1,40 @@
1
+ import { IdDto, RecordTimingDto } from '@forklaunch/common';
2
+
3
+ export type CreateCheckoutSessionDto<PaymentMethodEnum> = {
4
+ customerId: string;
5
+ paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
6
+ metadata?: unknown;
7
+ successRedirectUri: string;
8
+ cancelRedirectUri: string;
9
+ extraFields?: unknown;
10
+ };
11
+ export type UpdateCheckoutSessionDto<PaymentMethodEnum> = IdDto &
12
+ Partial<CreateCheckoutSessionDto<PaymentMethodEnum>>;
13
+ export type CheckoutSessionDto<PaymentMethodEnum> = IdDto &
14
+ CreateCheckoutSessionDto<PaymentMethodEnum> &
15
+ Partial<RecordTimingDto>;
16
+
17
+ export type CheckoutSessionServiceParameters<PaymentMethodEnum> = {
18
+ CreateCheckoutSessionDto: CreateCheckoutSessionDto<PaymentMethodEnum>;
19
+ CheckoutSessionDto: CheckoutSessionDto<PaymentMethodEnum>;
20
+ IdDto: IdDto;
21
+ };
22
+
23
+ export interface CheckoutSessionService<
24
+ PaymentMethodEnum,
25
+ Params extends
26
+ CheckoutSessionServiceParameters<PaymentMethodEnum> = CheckoutSessionServiceParameters<PaymentMethodEnum>
27
+ > {
28
+ // for generating external links
29
+ // store in cache, for permissions
30
+ createCheckoutSession: (
31
+ checkoutSessionDto: Params['CreateCheckoutSessionDto']
32
+ ) => Promise<Params['CheckoutSessionDto']>;
33
+ getCheckoutSession: (
34
+ idDto: Params['IdDto']
35
+ ) => Promise<Params['CheckoutSessionDto']>;
36
+ expireCheckoutSession: (idDto: Params['IdDto']) => Promise<void>;
37
+
38
+ handleCheckoutSuccess: (idDto: Params['IdDto']) => Promise<void>;
39
+ handleCheckoutFailure: (idDto: Params['IdDto']) => Promise<void>;
40
+ }
@@ -0,0 +1,49 @@
1
+ import { IdDto, IdsDto, RecordTimingDto } from '@forklaunch/common';
2
+
3
+ export type CreatePaymentLinkDto<CurrencyEnum> = {
4
+ amount: number;
5
+ currency: CurrencyEnum[keyof CurrencyEnum];
6
+ metadata?: unknown;
7
+ successRedirectUri: string;
8
+ cancelRedirectUri: string;
9
+ extraFields?: unknown;
10
+ };
11
+ export type UpdatePaymentLinkDto<CurrencyEnum> = IdDto &
12
+ Partial<CreatePaymentLinkDto<CurrencyEnum>>;
13
+ export type PaymentLinkDto<CurrencyEnum> = IdDto &
14
+ CreatePaymentLinkDto<CurrencyEnum> &
15
+ Partial<RecordTimingDto>;
16
+
17
+ export type PaymentLinkServiceParameters<CurrencyEnum> = {
18
+ CreatePaymentLinkDto: CreatePaymentLinkDto<CurrencyEnum>;
19
+ UpdatePaymentLinkDto: UpdatePaymentLinkDto<CurrencyEnum>;
20
+ PaymentLinkDto: PaymentLinkDto<CurrencyEnum>;
21
+ IdDto: IdDto;
22
+ IdsDto: IdsDto;
23
+ };
24
+
25
+ export interface PaymentLinkService<
26
+ CurrencyEnum,
27
+ Params extends
28
+ PaymentLinkServiceParameters<CurrencyEnum> = PaymentLinkServiceParameters<CurrencyEnum>
29
+ > {
30
+ // for one off products that are not part of a subscription
31
+ // think about how permissions work on payment links, but these should be ephemeral
32
+ // store in cache, for permissions
33
+ createPaymentLink: (
34
+ paymentLink: Params['CreatePaymentLinkDto']
35
+ ) => Promise<Params['PaymentLinkDto']>;
36
+ updatePaymentLink: (
37
+ paymentLink: Params['UpdatePaymentLinkDto']
38
+ ) => Promise<Params['PaymentLinkDto']>;
39
+ getPaymentLink: (idDto: Params['IdDto']) => Promise<Params['PaymentLinkDto']>;
40
+ expirePaymentLink: (idDto: Params['IdDto']) => Promise<void>;
41
+
42
+ handlePaymentSuccess: (idDto: Params['IdDto']) => Promise<void>;
43
+ handlePaymentFailure: (idDto: Params['IdDto']) => Promise<void>;
44
+
45
+ // admin API, make sure that permissions are correct here
46
+ listPaymentLinks: (
47
+ idsDto?: Params['IdsDto']
48
+ ) => Promise<Params['PaymentLinkDto'][]>;
49
+ }
@@ -0,0 +1,54 @@
1
+ import { IdDto, IdsDto, RecordTimingDto } from '@forklaunch/common';
2
+ import { EntityManager } from '@mikro-orm/core';
3
+
4
+ export type CreatePlanDto<PlanCadenceEnum, BillingProviderEnum> = {
5
+ active: boolean;
6
+ name: string;
7
+ description?: string;
8
+ price: number;
9
+ cadence: PlanCadenceEnum[keyof PlanCadenceEnum];
10
+ features?: string[];
11
+ extraFields?: unknown;
12
+ externalId: string;
13
+ billingProvider?: BillingProviderEnum[keyof BillingProviderEnum];
14
+ };
15
+ export type UpdatePlanDto<PlanCadenceEnum, BillingProviderEnum> = IdDto &
16
+ Partial<CreatePlanDto<PlanCadenceEnum, BillingProviderEnum>>;
17
+ export type PlanDto<PlanCadenceEnum, BillingProviderEnum> = IdDto &
18
+ CreatePlanDto<PlanCadenceEnum, BillingProviderEnum> &
19
+ Partial<RecordTimingDto>;
20
+
21
+ export type PlanServiceParameters<PlanCadenceEnum, BillingProviderEnum> = {
22
+ CreatePlanDto: CreatePlanDto<PlanCadenceEnum, BillingProviderEnum>;
23
+ UpdatePlanDto: UpdatePlanDto<PlanCadenceEnum, BillingProviderEnum>;
24
+ PlanDto: PlanDto<PlanCadenceEnum, BillingProviderEnum>;
25
+ IdDto: IdDto;
26
+ IdsDto: IdsDto;
27
+ };
28
+
29
+ export interface PlanService<
30
+ PlanCadenceEnum,
31
+ BillingProviderEnum,
32
+ Params extends PlanServiceParameters<
33
+ PlanCadenceEnum,
34
+ BillingProviderEnum
35
+ > = PlanServiceParameters<PlanCadenceEnum, BillingProviderEnum>
36
+ > {
37
+ createPlan: (
38
+ planDto: Params['CreatePlanDto'],
39
+ em?: EntityManager
40
+ ) => Promise<Params['PlanDto']>;
41
+ getPlan: (
42
+ idDto: Params['IdDto'],
43
+ em?: EntityManager
44
+ ) => Promise<Params['PlanDto']>;
45
+ updatePlan: (
46
+ planDto: Params['UpdatePlanDto'],
47
+ em?: EntityManager
48
+ ) => Promise<Params['PlanDto']>;
49
+ deletePlan: (idDto: Params['IdDto'], em?: EntityManager) => Promise<void>;
50
+ listPlans: (
51
+ idsDto?: Params['IdsDto'],
52
+ em?: EntityManager
53
+ ) => Promise<Params['PlanDto'][]>;
54
+ }
@@ -0,0 +1,76 @@
1
+ import { IdDto, IdsDto, RecordTimingDto } from '@forklaunch/common';
2
+ import { EntityManager } from '@mikro-orm/core';
3
+
4
+ export type CreateSubscriptionDto<PartyType, BillingProviderType> = {
5
+ partyId: string;
6
+ partyType: PartyType[keyof PartyType];
7
+ description?: string;
8
+ active: boolean;
9
+ productId: string;
10
+ extraFields?: unknown;
11
+ externalId: string;
12
+ billingProvider?: BillingProviderType[keyof BillingProviderType];
13
+ startDate: Date;
14
+ endDate: Date;
15
+ status: string;
16
+ };
17
+ export type UpdateSubscriptionDto<PartyType, BillingProviderType> = IdDto &
18
+ Partial<CreateSubscriptionDto<PartyType, BillingProviderType>>;
19
+ export type SubscriptionDto<PartyType, BillingProviderType> = IdDto &
20
+ CreateSubscriptionDto<PartyType, BillingProviderType> &
21
+ Partial<RecordTimingDto>;
22
+
23
+ export type SubscriptionServiceParameters<PartyType, BillingProviderType> = {
24
+ CreateSubscriptionDto: CreateSubscriptionDto<PartyType, BillingProviderType>;
25
+ UpdateSubscriptionDto: UpdateSubscriptionDto<PartyType, BillingProviderType>;
26
+ SubscriptionDto: SubscriptionDto<PartyType, BillingProviderType>;
27
+ IdDto: IdDto;
28
+ IdsDto: IdsDto;
29
+ };
30
+
31
+ export interface SubscriptionService<
32
+ PartyType,
33
+ BillingProviderType,
34
+ Params extends SubscriptionServiceParameters<
35
+ PartyType,
36
+ BillingProviderType
37
+ > = SubscriptionServiceParameters<PartyType, BillingProviderType>
38
+ > {
39
+ // store this in a table
40
+ createSubscription: (
41
+ subscriptionDto: Params['CreateSubscriptionDto'],
42
+ em?: EntityManager
43
+ ) => Promise<Params['SubscriptionDto']>;
44
+ getSubscription: (
45
+ idDto: Params['IdDto'],
46
+ em?: EntityManager
47
+ ) => Promise<Params['SubscriptionDto']>;
48
+ getUserSubscription: (
49
+ idDto: Params['IdDto'],
50
+ em?: EntityManager
51
+ ) => Promise<Params['SubscriptionDto']>;
52
+ getOrganizationSubscription: (
53
+ idDto: Params['IdDto'],
54
+ em?: EntityManager
55
+ ) => Promise<Params['SubscriptionDto']>;
56
+ updateSubscription: (
57
+ subscriptionDto: Params['UpdateSubscriptionDto'],
58
+ em?: EntityManager
59
+ ) => Promise<Params['SubscriptionDto']>;
60
+ deleteSubscription: (
61
+ id: Params['IdDto'],
62
+ em?: EntityManager
63
+ ) => Promise<void>;
64
+ listSubscriptions: (
65
+ idsDto: Params['IdsDto'],
66
+ em?: EntityManager
67
+ ) => Promise<Params['SubscriptionDto'][]>;
68
+ cancelSubscription: (
69
+ idDto: Params['IdDto'],
70
+ em?: EntityManager
71
+ ) => Promise<void>;
72
+ resumeSubscription: (
73
+ idDto: Params['IdDto'],
74
+ em?: EntityManager
75
+ ) => Promise<void>;
76
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@forklaunch/interfaces-billing",
3
+ "version": "0.1.0",
4
+ "description": "Billing interfaces for forklaunch",
5
+ "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/forklaunch/forklaunch-js/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/forklaunch/forklaunch-js.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Forklift Technologies, Inc.",
15
+ "main": "server.ts",
16
+ "dependencies": {
17
+ "@forklaunch/common": "^0.2.5",
18
+ "@mikro-orm/core": "^6.4.11"
19
+ },
20
+ "devDependencies": {
21
+ "depcheck": "^1.4.7",
22
+ "prettier": "^3.5.3",
23
+ "typedoc": "^0.28.1"
24
+ },
25
+ "mikro-orm": {
26
+ "configPaths": [
27
+ "./mikro-orm.config.ts",
28
+ "./dist/mikro-orm.config.js"
29
+ ]
30
+ },
31
+ "scripts": {
32
+ "build": "tsc",
33
+ "clean": "rm -rf dist pnpm.lock.yaml node_modules",
34
+ "docs": "typedoc --out docs *",
35
+ "format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.{ts,tsx,json}' --write",
36
+ "lint": "eslint . -c eslint.config.mjs",
37
+ "lint:fix": "eslint . -c eslint.config.mjs --fix",
38
+ "start": "ENV_FILE_PATH=.env.local NODE_OPTIONS='--import=tsx' node dist/server.js",
39
+ "start:bun": "bun run migrate:up && bun dist/server.js",
40
+ "test": "vitest --passWithNoTests"
41
+ }
42
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist"
5
+ },
6
+ "exclude": ["node_modules", "dist", "eslint.config.mjs"]
7
+ }