payment-kit 1.18.11 → 1.18.12
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/routes/connect/change-payment.ts +1 -0
- package/api/src/routes/connect/change-plan.ts +1 -0
- package/api/src/routes/connect/setup.ts +1 -0
- package/api/src/routes/connect/shared.ts +39 -33
- package/api/src/routes/connect/subscribe.ts +14 -8
- package/blocklet.yml +2 -2
- package/package.json +15 -15
|
@@ -17,6 +17,7 @@ import logger from '../../libs/logger';
|
|
|
17
17
|
export default {
|
|
18
18
|
action: 'change-payment',
|
|
19
19
|
authPrincipal: false,
|
|
20
|
+
persistentDynamicClaims: true,
|
|
20
21
|
claims: {
|
|
21
22
|
authPrincipal: async ({ extraParams }: CallbackArgs) => {
|
|
22
23
|
const { paymentMethod } = await ensureChangePaymentContext(extraParams.subscriptionId);
|
|
@@ -21,6 +21,7 @@ import logger from '../../libs/logger';
|
|
|
21
21
|
export default {
|
|
22
22
|
action: 'change-plan',
|
|
23
23
|
authPrincipal: false,
|
|
24
|
+
persistentDynamicClaims: true,
|
|
24
25
|
claims: {
|
|
25
26
|
authPrincipal: async ({ extraParams }: CallbackArgs) => {
|
|
26
27
|
const { paymentMethod } = await ensureSubscription(extraParams.subscriptionId);
|
|
@@ -22,6 +22,7 @@ import { EVM_CHAIN_TYPES } from '../../libs/constants';
|
|
|
22
22
|
export default {
|
|
23
23
|
action: 'setup',
|
|
24
24
|
authPrincipal: false,
|
|
25
|
+
persistentDynamicClaims: true,
|
|
25
26
|
claims: {
|
|
26
27
|
authPrincipal: async ({ extraParams }: CallbackArgs) => {
|
|
27
28
|
const { paymentMethod } = await ensureSetupIntent(extraParams.checkoutSessionId);
|
|
@@ -1011,6 +1011,7 @@ export async function executeOcapTransactions(
|
|
|
1011
1011
|
nonce?: string
|
|
1012
1012
|
) {
|
|
1013
1013
|
const client = paymentMethod.getOcapClient();
|
|
1014
|
+
logger.info('start executeOcapTransactions', claims);
|
|
1014
1015
|
const delegation = claims.find((x) => x.type === 'signature' && x.meta?.purpose === 'delegation');
|
|
1015
1016
|
const staking = claims.find((x) => x.type === 'prepareTx' && x.meta?.purpose === 'staking');
|
|
1016
1017
|
const transactions = [
|
|
@@ -1021,40 +1022,45 @@ export async function executeOcapTransactions(
|
|
|
1021
1022
|
const stakingAmount =
|
|
1022
1023
|
staking?.requirement?.tokens?.find((x: any) => x.address === paymentCurrencyContract)?.value || '0';
|
|
1023
1024
|
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1025
|
+
try {
|
|
1026
|
+
const [delegationTxHash, stakingTxHash] = await Promise.all(
|
|
1027
|
+
transactions.map(async ([claim, type]) => {
|
|
1028
|
+
if (!claim) {
|
|
1029
|
+
return '';
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
const tx: Partial<Transaction> = client.decodeTx(claim.finalTx || claim.origin);
|
|
1033
|
+
if (claim.sig) {
|
|
1034
|
+
tx.signature = claim.sig;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// @ts-ignore
|
|
1038
|
+
const { buffer } = await client[`encode${type}Tx`]({ tx });
|
|
1039
|
+
// @ts-ignore
|
|
1040
|
+
const txHash = await client[`send${type}Tx`](
|
|
1041
|
+
// @ts-ignore
|
|
1042
|
+
{ tx, wallet: fromPublicKey(userPk, toTypeInfo(userDid)) },
|
|
1043
|
+
getGasPayerExtra(buffer, client.pickGasPayerHeaders(request))
|
|
1044
|
+
);
|
|
1045
|
+
|
|
1046
|
+
return txHash;
|
|
1047
|
+
})
|
|
1042
1048
|
);
|
|
1043
|
-
|
|
1044
|
-
return
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1049
|
+
|
|
1050
|
+
return {
|
|
1051
|
+
tx_hash: delegationTxHash,
|
|
1052
|
+
payer: userDid,
|
|
1053
|
+
type: 'delegate',
|
|
1054
|
+
staking: {
|
|
1055
|
+
tx_hash: stakingTxHash,
|
|
1056
|
+
address: await getCustomerStakeAddress(userDid, nonce || subscriptionId || ''),
|
|
1057
|
+
},
|
|
1058
|
+
stakingAmount,
|
|
1059
|
+
};
|
|
1060
|
+
} catch (err) {
|
|
1061
|
+
logger.error('executeOcapTransactions failed', err);
|
|
1062
|
+
throw err;
|
|
1063
|
+
}
|
|
1058
1064
|
}
|
|
1059
1065
|
|
|
1060
1066
|
|
|
@@ -23,6 +23,7 @@ import { EVM_CHAIN_TYPES } from '../../libs/constants';
|
|
|
23
23
|
export default {
|
|
24
24
|
action: 'subscription',
|
|
25
25
|
authPrincipal: false,
|
|
26
|
+
persistentDynamicClaims: true,
|
|
26
27
|
claims: {
|
|
27
28
|
authPrincipal: async ({ extraParams }: CallbackArgs) => {
|
|
28
29
|
const { paymentMethod } = await ensurePaymentIntent(extraParams.checkoutSessionId);
|
|
@@ -151,15 +152,15 @@ export default {
|
|
|
151
152
|
if (!subscription) {
|
|
152
153
|
throw new Error('Subscription for checkoutSession not found');
|
|
153
154
|
}
|
|
154
|
-
|
|
155
|
+
const paymentSettings = {
|
|
156
|
+
payment_method_types: [paymentMethod.type],
|
|
157
|
+
payment_method_options: {
|
|
158
|
+
[paymentMethod.type]: { payer: userDid },
|
|
159
|
+
},
|
|
160
|
+
};
|
|
155
161
|
const prepareTxExecution = async () => {
|
|
156
162
|
await subscription.update({
|
|
157
|
-
payment_settings:
|
|
158
|
-
payment_method_types: [paymentMethod.type],
|
|
159
|
-
payment_method_options: {
|
|
160
|
-
[paymentMethod.type]: { payer: userDid },
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
+
payment_settings: paymentSettings,
|
|
163
164
|
});
|
|
164
165
|
};
|
|
165
166
|
|
|
@@ -179,7 +180,9 @@ export default {
|
|
|
179
180
|
if (paymentMethod.type === 'arcblock') {
|
|
180
181
|
await prepareTxExecution();
|
|
181
182
|
const { invoice } = await ensureInvoiceForCheckout({ checkoutSession, customer, subscription });
|
|
182
|
-
|
|
183
|
+
if (invoice) {
|
|
184
|
+
await invoice.update({ payment_settings: paymentSettings });
|
|
185
|
+
}
|
|
183
186
|
const { stakingAmount, ...paymentDetails } = await executeOcapTransactions(
|
|
184
187
|
userDid,
|
|
185
188
|
userPk,
|
|
@@ -217,6 +220,9 @@ export default {
|
|
|
217
220
|
if (EVM_CHAIN_TYPES.includes(paymentMethod.type)) {
|
|
218
221
|
await prepareTxExecution();
|
|
219
222
|
const { invoice } = await ensureInvoiceForCheckout({ checkoutSession, customer, subscription });
|
|
223
|
+
if (invoice) {
|
|
224
|
+
await invoice.update({ payment_settings: paymentSettings });
|
|
225
|
+
}
|
|
220
226
|
broadcastEvmTransaction(checkoutSessionId, 'pending', claimsList);
|
|
221
227
|
|
|
222
228
|
const paymentDetails = await executeEvmTransaction('approve', userDid, claimsList, paymentMethod);
|
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.12
|
|
18
18
|
logo: logo.png
|
|
19
19
|
files:
|
|
20
20
|
- dist
|
|
@@ -165,4 +165,4 @@ events:
|
|
|
165
165
|
- type: invoice.paid
|
|
166
166
|
description: Invoice has been fully paid and settled
|
|
167
167
|
- type: refund.succeeded
|
|
168
|
-
description: Refund has been successfully processed and completed
|
|
168
|
+
description: Refund has been successfully processed and completed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.12",
|
|
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.39",
|
|
47
|
-
"@arcblock/did": "^1.19.
|
|
47
|
+
"@arcblock/did": "^1.19.14",
|
|
48
48
|
"@arcblock/did-auth-storage-nedb": "^1.7.1",
|
|
49
49
|
"@arcblock/did-connect": "^2.11.48",
|
|
50
|
-
"@arcblock/did-util": "^1.19.
|
|
51
|
-
"@arcblock/jwt": "^1.19.
|
|
50
|
+
"@arcblock/did-util": "^1.19.14",
|
|
51
|
+
"@arcblock/jwt": "^1.19.14",
|
|
52
52
|
"@arcblock/ux": "^2.11.48",
|
|
53
|
-
"@arcblock/validator": "^1.19.
|
|
53
|
+
"@arcblock/validator": "^1.19.14",
|
|
54
54
|
"@blocklet/js-sdk": "^1.16.39",
|
|
55
55
|
"@blocklet/logger": "^1.16.39",
|
|
56
|
-
"@blocklet/payment-react": "1.18.
|
|
56
|
+
"@blocklet/payment-react": "1.18.12",
|
|
57
57
|
"@blocklet/sdk": "^1.16.39",
|
|
58
58
|
"@blocklet/ui-react": "^2.11.48",
|
|
59
|
-
"@blocklet/uploader": "^0.1.
|
|
60
|
-
"@blocklet/xss": "^0.1.
|
|
59
|
+
"@blocklet/uploader": "^0.1.71",
|
|
60
|
+
"@blocklet/xss": "^0.1.27",
|
|
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.14",
|
|
66
|
+
"@ocap/client": "^1.19.14",
|
|
67
|
+
"@ocap/mcrypto": "^1.19.14",
|
|
68
|
+
"@ocap/util": "^1.19.14",
|
|
69
|
+
"@ocap/wallet": "^1.19.14",
|
|
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.39",
|
|
123
123
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
124
|
-
"@blocklet/payment-types": "1.18.
|
|
124
|
+
"@blocklet/payment-types": "1.18.12",
|
|
125
125
|
"@types/cookie-parser": "^1.4.7",
|
|
126
126
|
"@types/cors": "^2.8.17",
|
|
127
127
|
"@types/debug": "^4.1.12",
|
|
@@ -167,5 +167,5 @@
|
|
|
167
167
|
"parser": "typescript"
|
|
168
168
|
}
|
|
169
169
|
},
|
|
170
|
-
"gitHead": "
|
|
170
|
+
"gitHead": "7efd2af5c272e4928da6864edfcbd3f9054c722b"
|
|
171
171
|
}
|