payment-kit 1.18.29 → 1.18.31
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/api/src/crons/index.ts +8 -0
- package/api/src/crons/metering-subscription-detection.ts +9 -0
- package/api/src/integrations/arcblock/nft.ts +1 -0
- package/api/src/integrations/blocklet/passport.ts +1 -1
- package/api/src/integrations/stripe/handlers/invoice.ts +2 -2
- package/api/src/integrations/stripe/handlers/setup-intent.ts +29 -1
- package/api/src/integrations/stripe/handlers/subscription.ts +19 -15
- package/api/src/integrations/stripe/resource.ts +81 -1
- package/api/src/libs/audit.ts +42 -0
- package/api/src/libs/constants.ts +2 -0
- package/api/src/libs/env.ts +2 -2
- package/api/src/libs/invoice.ts +54 -7
- package/api/src/libs/notification/index.ts +72 -4
- package/api/src/libs/notification/template/base.ts +2 -0
- package/api/src/libs/notification/template/subscription-renew-failed.ts +1 -5
- package/api/src/libs/notification/template/subscription-renewed.ts +1 -5
- package/api/src/libs/notification/template/subscription-succeeded.ts +8 -18
- package/api/src/libs/notification/template/subscription-trial-start.ts +2 -10
- package/api/src/libs/notification/template/subscription-upgraded.ts +1 -5
- package/api/src/libs/payment.ts +48 -8
- package/api/src/libs/product.ts +1 -4
- package/api/src/libs/session.ts +600 -8
- package/api/src/libs/setting.ts +172 -0
- package/api/src/libs/subscription.ts +7 -69
- package/api/src/libs/ws.ts +5 -0
- package/api/src/queues/checkout-session.ts +42 -36
- package/api/src/queues/notification.ts +3 -2
- package/api/src/queues/payment.ts +56 -8
- package/api/src/queues/usage-record.ts +2 -10
- package/api/src/routes/checkout-sessions.ts +324 -187
- package/api/src/routes/connect/shared.ts +160 -38
- package/api/src/routes/connect/subscribe.ts +123 -64
- package/api/src/routes/payment-currencies.ts +11 -0
- package/api/src/routes/payment-links.ts +11 -1
- package/api/src/routes/payment-stats.ts +2 -2
- package/api/src/routes/payouts.ts +2 -1
- package/api/src/routes/settings.ts +45 -0
- package/api/src/routes/subscriptions.ts +1 -2
- package/api/src/store/migrations/20250408-subscription-grouping.ts +39 -0
- package/api/src/store/migrations/20250419-subscription-grouping.ts +69 -0
- package/api/src/store/models/checkout-session.ts +52 -0
- package/api/src/store/models/index.ts +1 -0
- package/api/src/store/models/payment-link.ts +6 -0
- package/api/src/store/models/subscription.ts +8 -6
- package/api/src/store/models/types.ts +32 -1
- package/api/tests/libs/session.spec.ts +423 -0
- package/api/tests/libs/subscription.spec.ts +0 -110
- package/blocklet.yml +3 -1
- package/package.json +25 -24
- package/scripts/sdk.js +486 -155
- package/src/locales/en.tsx +4 -0
- package/src/locales/zh.tsx +3 -0
- package/src/pages/admin/settings/vault-config/edit-form.tsx +58 -3
- package/src/pages/admin/settings/vault-config/index.tsx +35 -1
- package/src/pages/customer/subscription/change-payment.tsx +8 -3
- package/src/pages/integrations/overview.tsx +1 -1
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
getDueUnit,
|
|
6
6
|
getMaxRetryCount,
|
|
7
7
|
getMinRetryMail,
|
|
8
|
-
getSubscriptionCreateSetup,
|
|
9
8
|
getSubscriptionStakeSetup,
|
|
10
9
|
getSubscriptionTrialSetup,
|
|
11
10
|
shouldCancelSubscription,
|
|
@@ -114,115 +113,6 @@ describe('getMinRetryMail', () => {
|
|
|
114
113
|
});
|
|
115
114
|
});
|
|
116
115
|
|
|
117
|
-
describe('getSubscriptionCreateSetup', () => {
|
|
118
|
-
const currencies = [
|
|
119
|
-
{
|
|
120
|
-
currency_id: 'usd',
|
|
121
|
-
unit_amount: '1',
|
|
122
|
-
},
|
|
123
|
-
];
|
|
124
|
-
|
|
125
|
-
it('should calculate setup for recurring licensed price type', () => {
|
|
126
|
-
const items = [
|
|
127
|
-
{
|
|
128
|
-
price: { type: 'one_time', currency_options: currencies },
|
|
129
|
-
quantity: 1,
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
price: {
|
|
133
|
-
type: 'recurring',
|
|
134
|
-
currency_options: currencies,
|
|
135
|
-
recurring: { interval: 'day', interval_count: '1', usage_type: 'licensed' },
|
|
136
|
-
},
|
|
137
|
-
quantity: 2,
|
|
138
|
-
},
|
|
139
|
-
];
|
|
140
|
-
const result = getSubscriptionCreateSetup(items as any, 'usd');
|
|
141
|
-
expect(result.amount.setup).toBe('3');
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('should not calculate setup for recurring metered price type', () => {
|
|
145
|
-
const items = [
|
|
146
|
-
{
|
|
147
|
-
price: { type: 'one_time', currency_options: currencies },
|
|
148
|
-
quantity: 1,
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
price: {
|
|
152
|
-
type: 'recurring',
|
|
153
|
-
currency_options: currencies,
|
|
154
|
-
recurring: { interval: 'day', interval_count: '1', usage_type: 'metered' },
|
|
155
|
-
},
|
|
156
|
-
quantity: 2,
|
|
157
|
-
},
|
|
158
|
-
];
|
|
159
|
-
const result = getSubscriptionCreateSetup(items as any, 'usd');
|
|
160
|
-
expect(result.amount.setup).toBe('1');
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('should calculate cycle duration for recurring price type', () => {
|
|
164
|
-
const items = [
|
|
165
|
-
{
|
|
166
|
-
price: { type: 'recurring', currency_options: currencies, recurring: { interval: 'day', interval_count: '1' } },
|
|
167
|
-
quantity: 2,
|
|
168
|
-
},
|
|
169
|
-
];
|
|
170
|
-
const result = getSubscriptionCreateSetup(items as any, 'usd');
|
|
171
|
-
expect(result.cycle.duration).toBe(24 * 60 * 60 * 1000);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('should calculate trial period when only trialInDays is provided', () => {
|
|
175
|
-
const items = [
|
|
176
|
-
{
|
|
177
|
-
price: { type: 'recurring', currency_options: currencies, recurring: { interval: 'day', interval_count: '1' } },
|
|
178
|
-
quantity: 2,
|
|
179
|
-
},
|
|
180
|
-
];
|
|
181
|
-
const result = getSubscriptionCreateSetup(items as any, 'usd', 7);
|
|
182
|
-
const now = dayjs().unix();
|
|
183
|
-
expect(result.trial.start).toBe(now);
|
|
184
|
-
expect(result.trial.end).toBe(
|
|
185
|
-
dayjs()
|
|
186
|
-
.add(7 * 24 * 60 * 60 * 1000, 'millisecond')
|
|
187
|
-
.unix()
|
|
188
|
-
);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('should trialEnd overwrite trialInDays', () => {
|
|
192
|
-
const items = [
|
|
193
|
-
{
|
|
194
|
-
price: { type: 'recurring', currency_options: currencies, recurring: { interval: 'day', interval_count: '1' } },
|
|
195
|
-
quantity: 2,
|
|
196
|
-
},
|
|
197
|
-
];
|
|
198
|
-
const result = getSubscriptionCreateSetup(items as any, 'usd', 1, dayjs().add(7, 'day').unix());
|
|
199
|
-
const now = dayjs().unix();
|
|
200
|
-
expect(result.trial.start).toBe(now);
|
|
201
|
-
expect(result.trial.end).toBe(
|
|
202
|
-
dayjs()
|
|
203
|
-
.add(7 * 24 * 60 * 60 * 1000, 'millisecond')
|
|
204
|
-
.unix()
|
|
205
|
-
);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('should calculate trial period when only trialEnd is provided', () => {
|
|
209
|
-
const items = [
|
|
210
|
-
{
|
|
211
|
-
price: { type: 'recurring', currency_options: currencies, recurring: { interval: 'day', interval_count: '1' } },
|
|
212
|
-
quantity: 2,
|
|
213
|
-
},
|
|
214
|
-
];
|
|
215
|
-
const result = getSubscriptionCreateSetup(items as any, 'usd', 0, dayjs().add(7, 'day').unix());
|
|
216
|
-
const now = dayjs().unix();
|
|
217
|
-
expect(result.trial.start).toBe(now);
|
|
218
|
-
expect(result.trial.end).toBe(
|
|
219
|
-
dayjs()
|
|
220
|
-
.add(7 * 24 * 60 * 60 * 1000, 'millisecond')
|
|
221
|
-
.unix()
|
|
222
|
-
);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
116
|
describe('getDaysUntilCancel', () => {
|
|
227
117
|
it('should return the number of days from the query when days_until_cancel is present', () => {
|
|
228
118
|
const query = { days_until_cancel: '5' };
|
package/blocklet.yml
CHANGED
|
@@ -14,7 +14,7 @@ repository:
|
|
|
14
14
|
type: git
|
|
15
15
|
url: git+https://github.com/blocklet/payment-kit.git
|
|
16
16
|
specVersion: 1.2.8
|
|
17
|
-
version: 1.18.
|
|
17
|
+
version: 1.18.31
|
|
18
18
|
logo: logo.png
|
|
19
19
|
files:
|
|
20
20
|
- dist
|
|
@@ -167,3 +167,5 @@ events:
|
|
|
167
167
|
description: Invoice has been fully paid and settled
|
|
168
168
|
- type: refund.succeeded
|
|
169
169
|
description: Refund has been successfully processed and completed
|
|
170
|
+
- type: manual.notification
|
|
171
|
+
description: Application will send notification to user manually
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.31",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"types": "rm -rf types && tsc -p tsconfig.types.json && rm -f ../../packages/types/lib/*.d.ts && cp -f types/store/models/*.d.ts ../../packages/types/lib",
|
|
20
20
|
"deploy": "pnpm run bundle && blocklet deploy .blocklet/bundle",
|
|
21
21
|
"upload": "pnpm run bundle && blocklet upload .blocklet/release/blocklet.json",
|
|
22
|
-
"bump-version": "zx --quiet scripts/bump-version.mjs"
|
|
22
|
+
"bump-version": "zx --quiet scripts/bump-version.mjs",
|
|
23
|
+
"sdk-test": "node scripts/sdk.js"
|
|
23
24
|
},
|
|
24
25
|
"lint-staged": {
|
|
25
26
|
"*.{mjs,js,jsx,ts,tsx}": [
|
|
@@ -43,30 +44,30 @@
|
|
|
43
44
|
]
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"@abtnode/cron": "^1.16.
|
|
47
|
-
"@arcblock/did": "^1.
|
|
47
|
+
"@abtnode/cron": "^1.16.42",
|
|
48
|
+
"@arcblock/did": "^1.20.1",
|
|
48
49
|
"@arcblock/did-auth-storage-nedb": "^1.7.1",
|
|
49
|
-
"@arcblock/did-connect": "^2.
|
|
50
|
-
"@arcblock/did-util": "^1.
|
|
51
|
-
"@arcblock/jwt": "^1.
|
|
52
|
-
"@arcblock/ux": "^2.
|
|
53
|
-
"@arcblock/validator": "^1.
|
|
54
|
-
"@blocklet/js-sdk": "^1.16.
|
|
55
|
-
"@blocklet/logger": "^1.16.
|
|
56
|
-
"@blocklet/payment-react": "1.18.
|
|
57
|
-
"@blocklet/sdk": "^1.16.
|
|
58
|
-
"@blocklet/ui-react": "^2.
|
|
59
|
-
"@blocklet/uploader": "^0.1.
|
|
60
|
-
"@blocklet/xss": "^0.1.
|
|
50
|
+
"@arcblock/did-connect": "^2.13.5",
|
|
51
|
+
"@arcblock/did-util": "^1.20.1",
|
|
52
|
+
"@arcblock/jwt": "^1.20.1",
|
|
53
|
+
"@arcblock/ux": "^2.13.5",
|
|
54
|
+
"@arcblock/validator": "^1.20.1",
|
|
55
|
+
"@blocklet/js-sdk": "^1.16.42",
|
|
56
|
+
"@blocklet/logger": "^1.16.42",
|
|
57
|
+
"@blocklet/payment-react": "1.18.31",
|
|
58
|
+
"@blocklet/sdk": "^1.16.42",
|
|
59
|
+
"@blocklet/ui-react": "^2.13.5",
|
|
60
|
+
"@blocklet/uploader": "^0.1.83",
|
|
61
|
+
"@blocklet/xss": "^0.1.32",
|
|
61
62
|
"@mui/icons-material": "^5.16.6",
|
|
62
63
|
"@mui/lab": "^5.0.0-alpha.173",
|
|
63
64
|
"@mui/material": "^5.16.6",
|
|
64
65
|
"@mui/system": "^5.16.6",
|
|
65
|
-
"@ocap/asset": "^1.
|
|
66
|
-
"@ocap/client": "^1.
|
|
67
|
-
"@ocap/mcrypto": "^1.
|
|
68
|
-
"@ocap/util": "^1.
|
|
69
|
-
"@ocap/wallet": "^1.
|
|
66
|
+
"@ocap/asset": "^1.20.1",
|
|
67
|
+
"@ocap/client": "^1.20.1",
|
|
68
|
+
"@ocap/mcrypto": "^1.20.1",
|
|
69
|
+
"@ocap/util": "^1.20.1",
|
|
70
|
+
"@ocap/wallet": "^1.20.1",
|
|
70
71
|
"@stripe/react-stripe-js": "^2.7.3",
|
|
71
72
|
"@stripe/stripe-js": "^2.4.0",
|
|
72
73
|
"ahooks": "^3.8.0",
|
|
@@ -119,9 +120,9 @@
|
|
|
119
120
|
"web3": "^4.16.0"
|
|
120
121
|
},
|
|
121
122
|
"devDependencies": {
|
|
122
|
-
"@abtnode/types": "^1.16.
|
|
123
|
+
"@abtnode/types": "^1.16.42",
|
|
123
124
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
124
|
-
"@blocklet/payment-types": "1.18.
|
|
125
|
+
"@blocklet/payment-types": "1.18.31",
|
|
125
126
|
"@types/cookie-parser": "^1.4.7",
|
|
126
127
|
"@types/cors": "^2.8.17",
|
|
127
128
|
"@types/debug": "^4.1.12",
|
|
@@ -167,5 +168,5 @@
|
|
|
167
168
|
"parser": "typescript"
|
|
168
169
|
}
|
|
169
170
|
},
|
|
170
|
-
"gitHead": "
|
|
171
|
+
"gitHead": "c9b1eff248ecd07bc1f606df039464dafa786914"
|
|
171
172
|
}
|