@owlmeans/payment 0.1.1 → 0.1.3
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 +1 -1
- package/README.md +51 -491
- package/build/consts.d.ts +22 -2
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +20 -0
- package/build/consts.js.map +1 -1
- package/build/model/checkout.d.ts +5 -0
- package/build/model/checkout.d.ts.map +1 -0
- package/build/model/checkout.js +24 -0
- package/build/model/checkout.js.map +1 -0
- package/build/model/index.d.ts +1 -0
- package/build/model/index.d.ts.map +1 -1
- package/build/model/index.js +1 -0
- package/build/model/index.js.map +1 -1
- package/build/model/product.d.ts.map +1 -1
- package/build/model/product.js +1 -0
- package/build/model/product.js.map +1 -1
- package/build/model/subscription.d.ts +6 -2
- package/build/model/subscription.d.ts.map +1 -1
- package/build/model/subscription.js +13 -0
- package/build/model/subscription.js.map +1 -1
- package/build/modules.d.ts +2 -1
- package/build/modules.d.ts.map +1 -1
- package/build/modules.js +13 -4
- package/build/modules.js.map +1 -1
- package/build/service.d.ts.map +1 -1
- package/build/service.js +29 -6
- package/build/service.js.map +1 -1
- package/build/types.d.ts +22 -2
- package/build/types.d.ts.map +1 -1
- package/package.json +13 -11
- package/src/consts.ts +23 -2
- package/src/model/checkout.ts +27 -0
- package/src/model/index.ts +1 -0
- package/src/model/product.ts +1 -0
- package/src/model/subscription.ts +16 -2
- package/src/modules.ts +33 -5
- package/src/service.ts +45 -9
- package/src/types.ts +28 -2
- package/tsconfig.json +5 -10
package/src/service.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { createService
|
|
1
|
+
import { createService } from '@owlmeans/context'
|
|
2
2
|
import type { ConfigRecord } from '@owlmeans/context'
|
|
3
|
-
import { DEFAULT_ALIAS, PaymentEntityType } from './consts.js'
|
|
3
|
+
import { DEFAULT_ALIAS, PaymentEntityType, PLAN_RECORD_PREFIX, PRODUCT_RECORD_TYPE } from './consts.js'
|
|
4
4
|
import type { Localization, PaymentService } from './types.js'
|
|
5
5
|
import type { Config, Context } from './utils/types.js'
|
|
6
6
|
import { PLAN_RECORD_TYPE, PRODUCT_RECORD_PREFIX } from './consts.js'
|
|
7
|
-
import { PaymentIdentificationError, UnknownProduct } from './errors.js'
|
|
7
|
+
import { PaymentIdentificationError, UnknownPlan, UnknownProduct } from './errors.js'
|
|
8
8
|
import type { Product, ProductPlan } from './types.js'
|
|
9
9
|
import { fromConfigRecord } from '@owlmeans/config'
|
|
10
10
|
import type { ResourceRecord } from '@owlmeans/resource'
|
|
@@ -16,11 +16,12 @@ import type { AuthCredentials } from '@owlmeans/auth'
|
|
|
16
16
|
export const makePaymentService = (alias: string = DEFAULT_ALIAS): PaymentService => {
|
|
17
17
|
const service: PaymentService = createService<PaymentService>(alias, {
|
|
18
18
|
product: async sku => {
|
|
19
|
-
const context =
|
|
20
|
-
|
|
19
|
+
const context = service.assertCtx() as Context
|
|
21
20
|
const configRes = context.getConfigResource()
|
|
22
21
|
|
|
23
|
-
const result = fromConfigRecord<ConfigRecord, Product & ResourceRecord>(
|
|
22
|
+
const result = fromConfigRecord<ConfigRecord, Product & ResourceRecord>(
|
|
23
|
+
await configRes.get(`${PRODUCT_RECORD_PREFIX}:${sku}`)
|
|
24
|
+
)
|
|
24
25
|
|
|
25
26
|
if (result == null) {
|
|
26
27
|
throw new UnknownProduct(sku)
|
|
@@ -29,8 +30,17 @@ export const makePaymentService = (alias: string = DEFAULT_ALIAS): PaymentServic
|
|
|
29
30
|
return result as Product
|
|
30
31
|
},
|
|
31
32
|
|
|
33
|
+
products: async () => {
|
|
34
|
+
const context = service.assertCtx() as Context
|
|
35
|
+
const configRes = context.getConfigResource()
|
|
36
|
+
|
|
37
|
+
const { items } = await configRes.list({ recordType: PRODUCT_RECORD_TYPE })
|
|
38
|
+
|
|
39
|
+
return items.map(i => fromConfigRecord<ConfigRecord, Product & ResourceRecord>(i))
|
|
40
|
+
},
|
|
41
|
+
|
|
32
42
|
plans: async (productSku, duration) => {
|
|
33
|
-
const context =
|
|
43
|
+
const context = service.assertCtx() as Context
|
|
34
44
|
const configRes = context.getConfigResource()
|
|
35
45
|
|
|
36
46
|
const result = await configRes.list({
|
|
@@ -39,11 +49,37 @@ export const makePaymentService = (alias: string = DEFAULT_ALIAS): PaymentServic
|
|
|
39
49
|
|
|
40
50
|
return result.items.map(
|
|
41
51
|
item => fromConfigRecord<ConfigRecord, ProductPlan & ResourceRecord>(item)
|
|
42
|
-
)
|
|
52
|
+
)
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
plan: async planSku => {
|
|
56
|
+
const context = service.assertCtx() as Context
|
|
57
|
+
const configRes = context.getConfigResource()
|
|
58
|
+
|
|
59
|
+
const result = await configRes.get(`${PLAN_RECORD_PREFIX}:${planSku}`)
|
|
60
|
+
|
|
61
|
+
if (result == null) {
|
|
62
|
+
throw new UnknownPlan(planSku)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return fromConfigRecord<ConfigRecord, ProductPlan & ResourceRecord>(result)
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
allPlans: async productSku => {
|
|
69
|
+
const context = service.assertCtx() as Context
|
|
70
|
+
const configRes = context.getConfigResource()
|
|
71
|
+
|
|
72
|
+
const { items } = await configRes.list({
|
|
73
|
+
productSku, recordType: PLAN_RECORD_TYPE
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
return items.map(
|
|
77
|
+
item => fromConfigRecord<ConfigRecord, ProductPlan & ResourceRecord>(item)
|
|
78
|
+
)
|
|
43
79
|
},
|
|
44
80
|
|
|
45
81
|
localize: async (lng, entity) => {
|
|
46
|
-
const context =
|
|
82
|
+
const context = service.assertCtx() as Context
|
|
47
83
|
const configRes = context.getConfigResource()
|
|
48
84
|
|
|
49
85
|
const idsToCheck: string[] = []
|
package/src/types.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface Product {
|
|
|
15
15
|
* software services.
|
|
16
16
|
*/
|
|
17
17
|
services?: string[]
|
|
18
|
+
gateways?: string[]
|
|
18
19
|
capabilities?: PermissionSet[]
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -32,7 +33,7 @@ export interface ProductPlan {
|
|
|
32
33
|
sku: string
|
|
33
34
|
status: PlanStatus
|
|
34
35
|
payagateAliases?: {
|
|
35
|
-
[paygate: string]: string
|
|
36
|
+
[paygate: string]: string | null
|
|
36
37
|
}
|
|
37
38
|
duration: PlanDuration
|
|
38
39
|
trial?: number
|
|
@@ -87,11 +88,30 @@ export interface PlanSubscription {
|
|
|
87
88
|
consumptions?: { [key: string]: CapabilityUsage }
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
export interface
|
|
91
|
+
export interface CreateCheckoutBody {
|
|
92
|
+
productSku: string
|
|
93
|
+
sku?: string
|
|
94
|
+
entityId: string
|
|
95
|
+
service: string
|
|
96
|
+
subscriptionId?: string
|
|
97
|
+
successUrl?: string
|
|
98
|
+
cancelUrl?: string
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface CreateCheckoutResponse {
|
|
102
|
+
url: string
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface SubscriptionPropagateBody extends PlanSubscription {
|
|
91
106
|
service: string
|
|
92
107
|
externalId: string
|
|
93
108
|
}
|
|
94
109
|
|
|
110
|
+
/**
|
|
111
|
+
* @deprecated Use SubscriptionPropagateBody instead
|
|
112
|
+
*/
|
|
113
|
+
export type SubscriptionPropogateBody = SubscriptionPropagateBody
|
|
114
|
+
|
|
95
115
|
export interface LimitConfig {
|
|
96
116
|
interval: PlanDuration
|
|
97
117
|
limit: number
|
|
@@ -111,8 +131,14 @@ type PaymentEntity = Product | ProductPlan | PermissionSet
|
|
|
111
131
|
export interface PaymentService extends InitializedService {
|
|
112
132
|
product: (sku: string) => Promise<Product>
|
|
113
133
|
|
|
134
|
+
products: () => Promise<Product[]>
|
|
135
|
+
|
|
114
136
|
plans: (productSku: string, duration: PlanDuration) => Promise<ProductPlan[]>
|
|
115
137
|
|
|
138
|
+
plan: (planSku: string) => Promise<ProductPlan>
|
|
139
|
+
|
|
140
|
+
allPlans: (productSku: string) => Promise<ProductPlan[]>
|
|
141
|
+
|
|
116
142
|
localize: (lng: string, entity: PaymentEntity) => Promise<Localization | null>
|
|
117
143
|
|
|
118
144
|
shallowAuthentication: (token: string | null) => Promise<string>
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": [
|
|
3
|
-
"
|
|
3
|
+
"@owlmeans/dep-config/tsconfig.base.json"
|
|
4
4
|
],
|
|
5
5
|
"compilerOptions": {
|
|
6
|
-
"rootDir": "./src/",
|
|
7
|
-
"outDir": "./build/"
|
|
8
|
-
"moduleResolution": "Bundler"
|
|
6
|
+
"rootDir": "./src/",
|
|
7
|
+
"outDir": "./build/"
|
|
9
8
|
},
|
|
10
|
-
"exclude": [
|
|
11
|
-
|
|
12
|
-
"./build/**/*",
|
|
13
|
-
"./*.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
9
|
+
"exclude": ["./dist/**/*", "./build/**/*", "./*.ts"]
|
|
10
|
+
}
|