payment-kit 1.18.6 → 1.18.8
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/libs/auth.ts +1 -1
- package/api/src/routes/connect/change-payment.ts +47 -22
- package/api/src/routes/connect/change-plan.ts +45 -20
- package/api/src/routes/connect/setup.ts +46 -21
- package/api/src/routes/connect/subscribe.ts +40 -21
- package/api/src/routes/payment-links.ts +1 -1
- package/blocklet.yml +1 -1
- package/package.json +19 -19
- package/src/components/filter-toolbar.tsx +10 -10
- package/src/components/layout/admin.tsx +1 -0
- package/src/components/payment-link/product-select.tsx +1 -1
- package/src/components/price/currency-select.tsx +3 -1
- package/src/components/price/form.tsx +1 -1
- package/src/components/section/header.tsx +1 -1
- package/src/components/subscription/list.tsx +1 -0
- package/src/components/uploader.tsx +1 -0
- package/src/global.css +4 -4
- package/src/libs/util.ts +13 -0
- package/src/pages/admin/developers/webhooks/detail.tsx +1 -1
- package/src/pages/admin/overview.tsx +3 -3
- package/src/pages/admin/payments/intents/detail.tsx +1 -1
- package/src/pages/admin/payments/payouts/detail.tsx +1 -1
- package/src/pages/admin/payments/refunds/detail.tsx +1 -1
- package/src/pages/admin/products/products/detail.tsx +1 -1
- package/src/pages/customer/payout/detail.tsx +1 -1
- package/src/pages/customer/recharge.tsx +35 -6
- package/src/pages/customer/subscription/change-payment.tsx +8 -2
- package/src/pages/customer/subscription/change-plan.tsx +1 -1
- package/src/pages/integrations/donations/index.tsx +1 -1
- package/src/pages/integrations/donations/preview.tsx +73 -52
- package/src/pages/integrations/overview.tsx +63 -40
package/api/src/libs/auth.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from './shared';
|
|
13
13
|
import { ensureStakeInvoice } from '../../libs/invoice';
|
|
14
14
|
import { EVM_CHAIN_TYPES } from '../../libs/constants';
|
|
15
|
+
import logger from '../../libs/logger';
|
|
15
16
|
|
|
16
17
|
export default {
|
|
17
18
|
action: 'change-payment',
|
|
@@ -26,17 +27,15 @@ export default {
|
|
|
26
27
|
const { subscriptionId } = extraParams;
|
|
27
28
|
const { subscription, paymentMethod, paymentCurrency } = await ensureChangePaymentContext(subscriptionId);
|
|
28
29
|
|
|
29
|
-
const
|
|
30
|
-
|
|
30
|
+
const claimsList: any[] = [];
|
|
31
31
|
// @ts-ignore
|
|
32
32
|
const items = subscription!.items as TLineItemExpanded[];
|
|
33
33
|
const trialing = true;
|
|
34
34
|
const billingThreshold = Number(subscription.billing_thresholds?.amount_gte || 0);
|
|
35
35
|
|
|
36
36
|
if (paymentMethod.type === 'arcblock') {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
await getDelegationTxClaim({
|
|
37
|
+
claimsList.push({
|
|
38
|
+
signature: await getDelegationTxClaim({
|
|
40
39
|
mode: 'setup',
|
|
41
40
|
userDid,
|
|
42
41
|
userPk,
|
|
@@ -48,12 +47,10 @@ export default {
|
|
|
48
47
|
billingThreshold,
|
|
49
48
|
items,
|
|
50
49
|
}),
|
|
51
|
-
|
|
50
|
+
});
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
'prepareTx',
|
|
56
|
-
await getStakeTxClaim({
|
|
52
|
+
claimsList.push({
|
|
53
|
+
prepareTx: await getStakeTxClaim({
|
|
57
54
|
userDid,
|
|
58
55
|
userPk,
|
|
59
56
|
paymentCurrency,
|
|
@@ -61,9 +58,9 @@ export default {
|
|
|
61
58
|
items,
|
|
62
59
|
subscription,
|
|
63
60
|
}),
|
|
64
|
-
|
|
61
|
+
});
|
|
65
62
|
|
|
66
|
-
return
|
|
63
|
+
return claimsList;
|
|
67
64
|
}
|
|
68
65
|
|
|
69
66
|
if (EVM_CHAIN_TYPES.includes(paymentMethod.type)) {
|
|
@@ -71,9 +68,8 @@ export default {
|
|
|
71
68
|
throw new Error(`Payment currency ${paymentMethod.type}:${paymentCurrency.id} does not support subscription`);
|
|
72
69
|
}
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
await getDelegationTxClaim({
|
|
71
|
+
claimsList.push({
|
|
72
|
+
signature: await getDelegationTxClaim({
|
|
77
73
|
mode: 'subscription',
|
|
78
74
|
userDid,
|
|
79
75
|
userPk,
|
|
@@ -85,19 +81,48 @@ export default {
|
|
|
85
81
|
billingThreshold,
|
|
86
82
|
items,
|
|
87
83
|
}),
|
|
88
|
-
|
|
84
|
+
});
|
|
89
85
|
|
|
90
|
-
return
|
|
86
|
+
return claimsList;
|
|
91
87
|
}
|
|
92
88
|
|
|
93
|
-
throw new Error(`
|
|
89
|
+
throw new Error(`ChangePayment: Payment method ${paymentMethod.type} not supported`);
|
|
94
90
|
},
|
|
95
91
|
|
|
96
|
-
onAuth: async ({ request, userDid, userPk, claims, extraParams }: CallbackArgs) => {
|
|
92
|
+
onAuth: async ({ request, userDid, userPk, claims, extraParams, updateSession, step }: CallbackArgs) => {
|
|
97
93
|
const { subscriptionId } = extraParams;
|
|
98
|
-
const { subscription,
|
|
94
|
+
const { setupIntent, subscription, paymentMethod, paymentCurrency, customer } =
|
|
99
95
|
await ensureChangePaymentContext(subscriptionId);
|
|
100
96
|
|
|
97
|
+
const result = request?.context?.store?.result || [];
|
|
98
|
+
result.push({
|
|
99
|
+
step,
|
|
100
|
+
claim: claims?.[0],
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// 判断是否为最后一步
|
|
104
|
+
const staking = result.find((x: any) => x.claim?.type === 'prepareTx' && x.claim?.meta?.purpose === 'staking');
|
|
105
|
+
const isFinalStep = (paymentMethod.type === 'arcblock' && staking) || paymentMethod.type !== 'arcblock';
|
|
106
|
+
|
|
107
|
+
if (!isFinalStep) {
|
|
108
|
+
await updateSession({
|
|
109
|
+
result,
|
|
110
|
+
});
|
|
111
|
+
return { result };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 清理 session
|
|
115
|
+
try {
|
|
116
|
+
await updateSession({
|
|
117
|
+
result: [],
|
|
118
|
+
});
|
|
119
|
+
} catch (error) {
|
|
120
|
+
logger.error('updateSession', {
|
|
121
|
+
error,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const claimsList = result.map((x: any) => x.claim);
|
|
125
|
+
|
|
101
126
|
const prepareTxExecution = async () => {
|
|
102
127
|
await subscription?.update({
|
|
103
128
|
payment_settings: {
|
|
@@ -141,7 +166,7 @@ export default {
|
|
|
141
166
|
const { stakingAmount, ...paymentDetails } = await executeOcapTransactions(
|
|
142
167
|
userDid,
|
|
143
168
|
userPk,
|
|
144
|
-
|
|
169
|
+
claimsList,
|
|
145
170
|
paymentMethod,
|
|
146
171
|
request,
|
|
147
172
|
subscription?.id,
|
|
@@ -172,7 +197,7 @@ export default {
|
|
|
172
197
|
|
|
173
198
|
if (EVM_CHAIN_TYPES.includes(paymentMethod.type)) {
|
|
174
199
|
await prepareTxExecution();
|
|
175
|
-
const paymentDetails = await executeEvmTransaction('approve', userDid,
|
|
200
|
+
const paymentDetails = await executeEvmTransaction('approve', userDid, claimsList, paymentMethod);
|
|
176
201
|
waitForEvmTxConfirm(paymentMethod.getEvmClient(), +paymentDetails.block_height, paymentMethod.confirmation.block)
|
|
177
202
|
.then(async () => {
|
|
178
203
|
await afterTxExecution(paymentDetails);
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from './shared';
|
|
17
17
|
import { ensureStakeInvoice } from '../../libs/invoice';
|
|
18
18
|
import { EVM_CHAIN_TYPES } from '../../libs/constants';
|
|
19
|
+
import logger from '../../libs/logger';
|
|
19
20
|
|
|
20
21
|
export default {
|
|
21
22
|
action: 'change-plan',
|
|
@@ -30,7 +31,7 @@ export default {
|
|
|
30
31
|
const { subscriptionId } = extraParams;
|
|
31
32
|
const { paymentMethod, paymentCurrency, subscription, customer } = await ensureSubscription(subscriptionId);
|
|
32
33
|
|
|
33
|
-
const
|
|
34
|
+
const claimsList: any[] = [];
|
|
34
35
|
// @ts-ignore
|
|
35
36
|
const items = subscription!.items as TLineItemExpanded[];
|
|
36
37
|
const trialing = false;
|
|
@@ -45,11 +46,9 @@ export default {
|
|
|
45
46
|
amount: fastCheckoutAmount,
|
|
46
47
|
});
|
|
47
48
|
|
|
48
|
-
// if we can complete purchase without any wallet interaction
|
|
49
49
|
if (delegation.sufficient === false) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
await getDelegationTxClaim({
|
|
50
|
+
claimsList.push({
|
|
51
|
+
signature: await getDelegationTxClaim({
|
|
53
52
|
mode: 'subscription',
|
|
54
53
|
userDid,
|
|
55
54
|
userPk,
|
|
@@ -61,13 +60,11 @@ export default {
|
|
|
61
60
|
billingThreshold,
|
|
62
61
|
items,
|
|
63
62
|
}),
|
|
64
|
-
|
|
63
|
+
});
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
'prepareTx',
|
|
70
|
-
await getStakeTxClaim({
|
|
66
|
+
claimsList.push({
|
|
67
|
+
prepareTx: await getStakeTxClaim({
|
|
71
68
|
userDid,
|
|
72
69
|
userPk,
|
|
73
70
|
paymentCurrency,
|
|
@@ -75,9 +72,9 @@ export default {
|
|
|
75
72
|
items,
|
|
76
73
|
subscription: subscription!,
|
|
77
74
|
}),
|
|
78
|
-
|
|
75
|
+
});
|
|
79
76
|
|
|
80
|
-
return
|
|
77
|
+
return claimsList;
|
|
81
78
|
}
|
|
82
79
|
|
|
83
80
|
if (EVM_CHAIN_TYPES.includes(paymentMethod.type)) {
|
|
@@ -85,9 +82,8 @@ export default {
|
|
|
85
82
|
throw new Error(`Payment currency ${paymentMethod.type}:${paymentCurrency.id} does not support subscription`);
|
|
86
83
|
}
|
|
87
84
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
await getDelegationTxClaim({
|
|
85
|
+
claimsList.push({
|
|
86
|
+
signature: await getDelegationTxClaim({
|
|
91
87
|
mode: 'subscription',
|
|
92
88
|
userDid,
|
|
93
89
|
userPk,
|
|
@@ -99,19 +95,48 @@ export default {
|
|
|
99
95
|
billingThreshold,
|
|
100
96
|
items,
|
|
101
97
|
}),
|
|
102
|
-
|
|
98
|
+
});
|
|
103
99
|
|
|
104
|
-
return
|
|
100
|
+
return claimsList;
|
|
105
101
|
}
|
|
106
102
|
|
|
107
103
|
throw new Error(`ChangePlan: Payment method ${paymentMethod.type} not supported`);
|
|
108
104
|
},
|
|
109
105
|
|
|
110
|
-
onAuth: async ({ request, userDid, userPk, claims, extraParams }: CallbackArgs) => {
|
|
106
|
+
onAuth: async ({ request, userDid, userPk, claims, extraParams, updateSession, step }: CallbackArgs) => {
|
|
111
107
|
const { subscriptionId } = extraParams;
|
|
112
108
|
const { invoice, paymentMethod, subscription, paymentCurrency, customer } =
|
|
113
109
|
await ensureSubscription(subscriptionId);
|
|
114
110
|
|
|
111
|
+
const result = request?.context?.store?.result || [];
|
|
112
|
+
result.push({
|
|
113
|
+
step,
|
|
114
|
+
claim: claims?.[0],
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// 判断是否为最后一步
|
|
118
|
+
const staking = result.find((x: any) => x.claim?.type === 'prepareTx' && x.claim?.meta?.purpose === 'staking');
|
|
119
|
+
const isFinalStep = (paymentMethod.type === 'arcblock' && staking) || paymentMethod.type !== 'arcblock';
|
|
120
|
+
|
|
121
|
+
if (!isFinalStep) {
|
|
122
|
+
await updateSession({
|
|
123
|
+
result,
|
|
124
|
+
});
|
|
125
|
+
return { result };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 清理 session
|
|
129
|
+
try {
|
|
130
|
+
await updateSession({
|
|
131
|
+
result: [],
|
|
132
|
+
});
|
|
133
|
+
} catch (error) {
|
|
134
|
+
logger.error('updateSession', {
|
|
135
|
+
error,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const claimsList = result.map((x: any) => x.claim);
|
|
139
|
+
|
|
115
140
|
const prepareTxExecution = async () => {
|
|
116
141
|
await subscription?.update({
|
|
117
142
|
payment_settings: {
|
|
@@ -148,7 +173,7 @@ export default {
|
|
|
148
173
|
const { stakingAmount, ...paymentDetails } = await executeOcapTransactions(
|
|
149
174
|
userDid,
|
|
150
175
|
userPk,
|
|
151
|
-
|
|
176
|
+
claimsList,
|
|
152
177
|
paymentMethod,
|
|
153
178
|
request,
|
|
154
179
|
subscription?.id,
|
|
@@ -181,7 +206,7 @@ export default {
|
|
|
181
206
|
if (EVM_CHAIN_TYPES.includes(paymentMethod.type)) {
|
|
182
207
|
await prepareTxExecution();
|
|
183
208
|
|
|
184
|
-
const paymentDetails = await executeEvmTransaction('approve', userDid,
|
|
209
|
+
const paymentDetails = await executeEvmTransaction('approve', userDid, claimsList, paymentMethod);
|
|
185
210
|
waitForEvmTxConfirm(paymentMethod.getEvmClient(), +paymentDetails.block_height, paymentMethod.confirmation.block)
|
|
186
211
|
.then(async () => {
|
|
187
212
|
await afterTxExecution(paymentDetails);
|
|
@@ -39,10 +39,9 @@ export default {
|
|
|
39
39
|
throw new Error('Subscription for checkoutSession not found');
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
const
|
|
42
|
+
const claimsList: any[] = [];
|
|
43
43
|
const now = dayjs().unix();
|
|
44
44
|
const items = checkoutSession.line_items as TLineItemExpanded[];
|
|
45
|
-
|
|
46
45
|
const { trialEnd, trialInDays } = getSubscriptionTrialSetup(
|
|
47
46
|
checkoutSession.subscription_data as any,
|
|
48
47
|
paymentCurrency.id
|
|
@@ -62,9 +61,8 @@ export default {
|
|
|
62
61
|
});
|
|
63
62
|
// if we can complete purchase without any wallet interaction
|
|
64
63
|
if (delegation.sufficient === false) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
await getDelegationTxClaim({
|
|
64
|
+
claimsList.push({
|
|
65
|
+
signature: await getDelegationTxClaim({
|
|
68
66
|
mode: checkoutSession.mode,
|
|
69
67
|
userDid,
|
|
70
68
|
userPk,
|
|
@@ -76,13 +74,12 @@ export default {
|
|
|
76
74
|
billingThreshold: Math.max(minStakeAmount, billingThreshold),
|
|
77
75
|
items,
|
|
78
76
|
}),
|
|
79
|
-
|
|
77
|
+
});
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
// we always need to stake for the subscription
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
await getStakeTxClaim({
|
|
81
|
+
claimsList.push({
|
|
82
|
+
prepareTx: await getStakeTxClaim({
|
|
86
83
|
userDid,
|
|
87
84
|
userPk,
|
|
88
85
|
paymentCurrency,
|
|
@@ -90,9 +87,9 @@ export default {
|
|
|
90
87
|
items,
|
|
91
88
|
subscription,
|
|
92
89
|
}),
|
|
93
|
-
|
|
90
|
+
});
|
|
94
91
|
|
|
95
|
-
return
|
|
92
|
+
return claimsList;
|
|
96
93
|
}
|
|
97
94
|
|
|
98
95
|
if (EVM_CHAIN_TYPES.includes(paymentMethod.type)) {
|
|
@@ -100,9 +97,8 @@ export default {
|
|
|
100
97
|
throw new Error(`Payment currency ${paymentMethod.type}:${paymentCurrency.id} does not support setup`);
|
|
101
98
|
}
|
|
102
99
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
await getDelegationTxClaim({
|
|
100
|
+
claimsList.push({
|
|
101
|
+
signature: await getDelegationTxClaim({
|
|
106
102
|
mode: checkoutSession.mode,
|
|
107
103
|
userDid,
|
|
108
104
|
userPk,
|
|
@@ -114,15 +110,15 @@ export default {
|
|
|
114
110
|
billingThreshold,
|
|
115
111
|
items,
|
|
116
112
|
}),
|
|
117
|
-
|
|
113
|
+
});
|
|
118
114
|
|
|
119
|
-
return
|
|
115
|
+
return claimsList;
|
|
120
116
|
}
|
|
121
117
|
|
|
122
118
|
throw new Error(`Payment method ${paymentMethod.type} not supported`);
|
|
123
119
|
},
|
|
124
120
|
onAuth: async (args: CallbackArgs) => {
|
|
125
|
-
const { request, userDid, userPk, claims, extraParams } = args;
|
|
121
|
+
const { request, userDid, userPk, claims, extraParams, updateSession, step } = args;
|
|
126
122
|
const { checkoutSessionId, connectedDid, sessionUserDid } = extraParams;
|
|
127
123
|
const { setupIntent, checkoutSession, paymentMethod, subscription, invoice, paymentCurrency, customer } =
|
|
128
124
|
await ensureSetupIntent(checkoutSessionId, connectedDid || sessionUserDid || userDid);
|
|
@@ -131,6 +127,35 @@ export default {
|
|
|
131
127
|
throw new Error('Subscription for checkoutSession not found');
|
|
132
128
|
}
|
|
133
129
|
|
|
130
|
+
const result = request?.context?.store?.result || [];
|
|
131
|
+
result.push({
|
|
132
|
+
step,
|
|
133
|
+
claim: claims?.[0],
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// 判断是否为最后一步
|
|
137
|
+
const staking = result.find((x: any) => x.claim?.type === 'prepareTx' && x.claim?.meta?.purpose === 'staking');
|
|
138
|
+
const isFinalStep = (paymentMethod.type === 'arcblock' && staking) || paymentMethod.type !== 'arcblock';
|
|
139
|
+
|
|
140
|
+
if (!isFinalStep) {
|
|
141
|
+
await updateSession({
|
|
142
|
+
result,
|
|
143
|
+
});
|
|
144
|
+
return { result };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 清理 session
|
|
148
|
+
try {
|
|
149
|
+
await updateSession({
|
|
150
|
+
result: [],
|
|
151
|
+
});
|
|
152
|
+
} catch (error) {
|
|
153
|
+
logger.error('updateSession', {
|
|
154
|
+
error,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const claimsList = result.map((x: any) => x.claim);
|
|
158
|
+
|
|
134
159
|
const paymentSettings = {
|
|
135
160
|
payment_method_types: [paymentMethod.type],
|
|
136
161
|
payment_method_options: {
|
|
@@ -177,7 +202,7 @@ export default {
|
|
|
177
202
|
const { stakingAmount, ...paymentDetails } = await executeOcapTransactions(
|
|
178
203
|
userDid,
|
|
179
204
|
userPk,
|
|
180
|
-
|
|
205
|
+
claimsList,
|
|
181
206
|
paymentMethod,
|
|
182
207
|
request,
|
|
183
208
|
subscription?.id,
|
|
@@ -216,12 +241,12 @@ export default {
|
|
|
216
241
|
|
|
217
242
|
if (EVM_CHAIN_TYPES.includes(paymentMethod.type)) {
|
|
218
243
|
await prepareTxExecution();
|
|
219
|
-
broadcastEvmTransaction(checkoutSessionId, 'pending',
|
|
220
|
-
const paymentDetails = await executeEvmTransaction('approve', userDid,
|
|
244
|
+
broadcastEvmTransaction(checkoutSessionId, 'pending', claimsList);
|
|
245
|
+
const paymentDetails = await executeEvmTransaction('approve', userDid, claimsList, paymentMethod);
|
|
221
246
|
waitForEvmTxConfirm(paymentMethod.getEvmClient(), +paymentDetails.block_height, paymentMethod.confirmation.block)
|
|
222
247
|
.then(async () => {
|
|
223
248
|
await afterTxExecution(paymentDetails);
|
|
224
|
-
broadcastEvmTransaction(checkoutSessionId, 'confirmed',
|
|
249
|
+
broadcastEvmTransaction(checkoutSessionId, 'confirmed', claimsList);
|
|
225
250
|
})
|
|
226
251
|
.catch(console.error);
|
|
227
252
|
|
|
@@ -40,7 +40,6 @@ export default {
|
|
|
40
40
|
throw new Error('Subscription for checkoutSession not found');
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
const claims: { [type: string]: [string, object] } = {};
|
|
44
43
|
const now = dayjs().unix();
|
|
45
44
|
const items = checkoutSession.line_items as TLineItemExpanded[];
|
|
46
45
|
const { trialEnd, trialInDays } = getSubscriptionTrialSetup(
|
|
@@ -51,7 +50,7 @@ export default {
|
|
|
51
50
|
const billingThreshold = Number(checkoutSession.subscription_data?.billing_threshold_amount || 0);
|
|
52
51
|
const minStakeAmount = Number(checkoutSession.subscription_data?.min_stake_amount || 0);
|
|
53
52
|
const fastCheckoutAmount = getFastCheckoutAmount(items, checkoutSession.mode, paymentCurrency.id, trialing);
|
|
54
|
-
|
|
53
|
+
const claimsList: any[] = [];
|
|
55
54
|
if (paymentMethod.type === 'arcblock') {
|
|
56
55
|
const delegation = await isDelegationSufficientForPayment({
|
|
57
56
|
paymentMethod,
|
|
@@ -62,9 +61,8 @@ export default {
|
|
|
62
61
|
|
|
63
62
|
// if we can complete purchase without any wallet interaction
|
|
64
63
|
if (delegation.sufficient === false) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
await getDelegationTxClaim({
|
|
64
|
+
claimsList.push({
|
|
65
|
+
signature: await getDelegationTxClaim({
|
|
68
66
|
mode: checkoutSession.mode,
|
|
69
67
|
userDid,
|
|
70
68
|
userPk,
|
|
@@ -76,13 +74,12 @@ export default {
|
|
|
76
74
|
billingThreshold: Math.max(minStakeAmount, billingThreshold),
|
|
77
75
|
items,
|
|
78
76
|
}),
|
|
79
|
-
|
|
77
|
+
});
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
// we always need to stake for the subscription
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
await getStakeTxClaim({
|
|
81
|
+
claimsList.push({
|
|
82
|
+
prepareTx: await getStakeTxClaim({
|
|
86
83
|
userDid,
|
|
87
84
|
userPk,
|
|
88
85
|
paymentCurrency,
|
|
@@ -90,9 +87,9 @@ export default {
|
|
|
90
87
|
items,
|
|
91
88
|
subscription,
|
|
92
89
|
}),
|
|
93
|
-
|
|
90
|
+
});
|
|
94
91
|
|
|
95
|
-
return
|
|
92
|
+
return claimsList;
|
|
96
93
|
}
|
|
97
94
|
|
|
98
95
|
if (EVM_CHAIN_TYPES.includes(paymentMethod.type)) {
|
|
@@ -100,9 +97,8 @@ export default {
|
|
|
100
97
|
throw new Error(`Payment currency ${paymentMethod.type}:${paymentCurrency.id} does not support subscription`);
|
|
101
98
|
}
|
|
102
99
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
await getDelegationTxClaim({
|
|
100
|
+
claimsList.push({
|
|
101
|
+
signature: await getDelegationTxClaim({
|
|
106
102
|
mode: checkoutSession.mode,
|
|
107
103
|
userDid,
|
|
108
104
|
userPk,
|
|
@@ -114,20 +110,43 @@ export default {
|
|
|
114
110
|
billingThreshold,
|
|
115
111
|
items,
|
|
116
112
|
}),
|
|
117
|
-
|
|
113
|
+
});
|
|
118
114
|
|
|
119
|
-
return
|
|
115
|
+
return claimsList;
|
|
120
116
|
}
|
|
121
117
|
|
|
122
118
|
throw new Error(`subscription: Payment method ${paymentMethod.type} not supported`);
|
|
123
119
|
},
|
|
124
120
|
onAuth: async (args: CallbackArgs) => {
|
|
125
|
-
const { request, userDid, userPk, claims, extraParams } = args;
|
|
121
|
+
const { request, userDid, userPk, claims, extraParams, updateSession, step } = args;
|
|
126
122
|
const { checkoutSessionId, connectedDid, sessionUserDid } = extraParams;
|
|
127
123
|
const { checkoutSession, customer, paymentMethod, subscription, paymentCurrency } = await ensurePaymentIntent(
|
|
128
124
|
checkoutSessionId,
|
|
129
125
|
connectedDid || sessionUserDid || userDid
|
|
130
126
|
);
|
|
127
|
+
const result = request?.context?.store?.result || [];
|
|
128
|
+
result.push({
|
|
129
|
+
step,
|
|
130
|
+
claim: claims?.[0],
|
|
131
|
+
});
|
|
132
|
+
const staking = result.find((x: any) => x.claim?.type === 'prepareTx' && x.claim?.meta?.purpose === 'staking');
|
|
133
|
+
const isFinalStep = (paymentMethod.type === 'arcblock' && staking) || paymentMethod.type !== 'arcblock';
|
|
134
|
+
if (!isFinalStep) {
|
|
135
|
+
await updateSession({
|
|
136
|
+
result,
|
|
137
|
+
});
|
|
138
|
+
return { result };
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
await updateSession({
|
|
142
|
+
result: [],
|
|
143
|
+
});
|
|
144
|
+
} catch (error) {
|
|
145
|
+
logger.error('updateSession', {
|
|
146
|
+
error,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const claimsList = result.map((x: any) => x.claim);
|
|
131
150
|
|
|
132
151
|
if (!subscription) {
|
|
133
152
|
throw new Error('Subscription for checkoutSession not found');
|
|
@@ -164,7 +183,7 @@ export default {
|
|
|
164
183
|
const { stakingAmount, ...paymentDetails } = await executeOcapTransactions(
|
|
165
184
|
userDid,
|
|
166
185
|
userPk,
|
|
167
|
-
|
|
186
|
+
claimsList,
|
|
168
187
|
paymentMethod,
|
|
169
188
|
request,
|
|
170
189
|
subscription?.id,
|
|
@@ -198,9 +217,9 @@ export default {
|
|
|
198
217
|
if (EVM_CHAIN_TYPES.includes(paymentMethod.type)) {
|
|
199
218
|
await prepareTxExecution();
|
|
200
219
|
const { invoice } = await ensureInvoiceForCheckout({ checkoutSession, customer, subscription });
|
|
201
|
-
broadcastEvmTransaction(checkoutSessionId, 'pending',
|
|
220
|
+
broadcastEvmTransaction(checkoutSessionId, 'pending', claimsList);
|
|
202
221
|
|
|
203
|
-
const paymentDetails = await executeEvmTransaction('approve', userDid,
|
|
222
|
+
const paymentDetails = await executeEvmTransaction('approve', userDid, claimsList, paymentMethod);
|
|
204
223
|
waitForEvmTxConfirm(
|
|
205
224
|
paymentMethod.getEvmClient(),
|
|
206
225
|
Number(paymentDetails.block_height),
|
|
@@ -208,7 +227,7 @@ export default {
|
|
|
208
227
|
)
|
|
209
228
|
.then(async () => {
|
|
210
229
|
await afterTxExecution(invoice!, paymentDetails);
|
|
211
|
-
broadcastEvmTransaction(checkoutSessionId, 'confirmed',
|
|
230
|
+
broadcastEvmTransaction(checkoutSessionId, 'confirmed', claimsList);
|
|
212
231
|
})
|
|
213
232
|
.catch(console.error);
|
|
214
233
|
|
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.8",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -44,29 +44,29 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@abtnode/cron": "^1.16.38",
|
|
47
|
-
"@arcblock/did": "^1.19.
|
|
47
|
+
"@arcblock/did": "^1.19.10",
|
|
48
48
|
"@arcblock/did-auth-storage-nedb": "^1.7.1",
|
|
49
|
-
"@arcblock/did-connect": "^2.11.
|
|
50
|
-
"@arcblock/did-util": "^1.19.
|
|
51
|
-
"@arcblock/jwt": "^1.19.
|
|
52
|
-
"@arcblock/ux": "^2.11.
|
|
53
|
-
"@arcblock/validator": "^1.19.
|
|
49
|
+
"@arcblock/did-connect": "^2.11.44",
|
|
50
|
+
"@arcblock/did-util": "^1.19.10",
|
|
51
|
+
"@arcblock/jwt": "^1.19.10",
|
|
52
|
+
"@arcblock/ux": "^2.11.44",
|
|
53
|
+
"@arcblock/validator": "^1.19.10",
|
|
54
54
|
"@blocklet/js-sdk": "^1.16.38",
|
|
55
55
|
"@blocklet/logger": "^1.16.38",
|
|
56
|
-
"@blocklet/payment-react": "1.18.
|
|
56
|
+
"@blocklet/payment-react": "1.18.8",
|
|
57
57
|
"@blocklet/sdk": "^1.16.38",
|
|
58
|
-
"@blocklet/ui-react": "^2.11.
|
|
59
|
-
"@blocklet/uploader": "^0.1.
|
|
60
|
-
"@blocklet/xss": "^0.1.
|
|
58
|
+
"@blocklet/ui-react": "^2.11.44",
|
|
59
|
+
"@blocklet/uploader": "^0.1.70",
|
|
60
|
+
"@blocklet/xss": "^0.1.25",
|
|
61
61
|
"@mui/icons-material": "^5.16.6",
|
|
62
62
|
"@mui/lab": "^5.0.0-alpha.173",
|
|
63
63
|
"@mui/material": "^5.16.6",
|
|
64
64
|
"@mui/system": "^5.16.6",
|
|
65
|
-
"@ocap/asset": "^1.19.
|
|
66
|
-
"@ocap/client": "^1.19.
|
|
67
|
-
"@ocap/mcrypto": "^1.19.
|
|
68
|
-
"@ocap/util": "^1.19.
|
|
69
|
-
"@ocap/wallet": "^1.19.
|
|
65
|
+
"@ocap/asset": "^1.19.10",
|
|
66
|
+
"@ocap/client": "^1.19.10",
|
|
67
|
+
"@ocap/mcrypto": "^1.19.10",
|
|
68
|
+
"@ocap/util": "^1.19.10",
|
|
69
|
+
"@ocap/wallet": "^1.19.10",
|
|
70
70
|
"@stripe/react-stripe-js": "^2.7.3",
|
|
71
71
|
"@stripe/stripe-js": "^2.4.0",
|
|
72
72
|
"ahooks": "^3.8.0",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"devDependencies": {
|
|
122
122
|
"@abtnode/types": "^1.16.38",
|
|
123
123
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
124
|
-
"@blocklet/payment-types": "1.18.
|
|
124
|
+
"@blocklet/payment-types": "1.18.8",
|
|
125
125
|
"@types/cookie-parser": "^1.4.7",
|
|
126
126
|
"@types/cors": "^2.8.17",
|
|
127
127
|
"@types/debug": "^4.1.12",
|
|
@@ -151,7 +151,7 @@
|
|
|
151
151
|
"vite": "^5.3.5",
|
|
152
152
|
"vite-node": "^2.0.4",
|
|
153
153
|
"vite-plugin-babel-import": "^2.0.5",
|
|
154
|
-
"vite-plugin-blocklet": "^0.9.
|
|
154
|
+
"vite-plugin-blocklet": "^0.9.21",
|
|
155
155
|
"vite-plugin-node-polyfills": "^0.21.0",
|
|
156
156
|
"vite-plugin-svgr": "^4.2.0",
|
|
157
157
|
"vite-tsconfig-paths": "^4.3.2",
|
|
@@ -167,5 +167,5 @@
|
|
|
167
167
|
"parser": "typescript"
|
|
168
168
|
}
|
|
169
169
|
},
|
|
170
|
-
"gitHead": "
|
|
170
|
+
"gitHead": "0815493ffd53c977d2d14779703d85f2e0e34299"
|
|
171
171
|
}
|