payment-kit 1.18.10 → 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/libs/util.ts +52 -2
- package/api/src/routes/checkout-sessions.ts +18 -1
- 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/api/tests/libs/util.spec.ts +279 -1
- package/blocklet.yml +1 -1
- package/package.json +15 -15
package/api/src/libs/util.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { joinURL, withQuery, withTrailingSlash } from 'ufo';
|
|
|
11
11
|
import axios from 'axios';
|
|
12
12
|
import dayjs from './dayjs';
|
|
13
13
|
import { blocklet, wallet } from './auth';
|
|
14
|
-
import type { Subscription } from '../store/models';
|
|
14
|
+
import type { PaymentMethod, Subscription } from '../store/models';
|
|
15
15
|
import logger from './logger';
|
|
16
16
|
|
|
17
17
|
export const OCAP_PAYMENT_TX_TYPE = 'fg:t:transfer_v2';
|
|
@@ -73,7 +73,7 @@ export const STRIPE_EVENTS: any[] = [
|
|
|
73
73
|
'refund.updated',
|
|
74
74
|
];
|
|
75
75
|
|
|
76
|
-
const api = axios.create({
|
|
76
|
+
export const api = axios.create({
|
|
77
77
|
timeout: 10 * 1000,
|
|
78
78
|
});
|
|
79
79
|
|
|
@@ -458,3 +458,53 @@ export function getAdminBillingSubscriptionUrl({
|
|
|
458
458
|
export function getCustomerIndexUrl({ locale, userDid }: { locale: string; userDid: string }) {
|
|
459
459
|
return getUrl(withQuery('customer', { locale, ...getConnectQueryParam({ userDid }) }));
|
|
460
460
|
}
|
|
461
|
+
|
|
462
|
+
// Check if user is in blocklist
|
|
463
|
+
export async function isUserInBlocklist(did: string, paymentMethod: PaymentMethod): Promise<boolean> {
|
|
464
|
+
try {
|
|
465
|
+
// Get API host from payment method settings
|
|
466
|
+
// @ts-ignore
|
|
467
|
+
const apiHost = paymentMethod?.settings?.[paymentMethod.type]?.api_host;
|
|
468
|
+
if (!apiHost) {
|
|
469
|
+
logger.warn('No API host found in payment method settings', { paymentMethodId: paymentMethod.id });
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// Get user information
|
|
474
|
+
const { user }: { user: any } = await blocklet.getUser(did);
|
|
475
|
+
if (!user) {
|
|
476
|
+
logger.error('User not found', { did });
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
// Get all wallet DIDs associated with the user
|
|
480
|
+
const connectedAccounts = user.connectedAccounts || user.extraConfigs?.connectedAccounts || [];
|
|
481
|
+
const walletDids = connectedAccounts
|
|
482
|
+
.filter((account: any) => account.provider === 'wallet')
|
|
483
|
+
.map((account: any) => account.did);
|
|
484
|
+
|
|
485
|
+
if (!walletDids.length) {
|
|
486
|
+
logger.info('No wallet DIDs found for user', { did });
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
const blockedUrl = joinURL(apiHost, '/blocked');
|
|
491
|
+
const blockedResponse = await api.get(blockedUrl);
|
|
492
|
+
const blockedDids = blockedResponse.data || [];
|
|
493
|
+
|
|
494
|
+
if (!Array.isArray(blockedDids) || blockedDids.length === 0) {
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// Check if any of the user's DIDs are in the blocklist
|
|
499
|
+
const isBlocked = walletDids.some((walletDid: string) => blockedDids.includes(walletDid));
|
|
500
|
+
|
|
501
|
+
if (isBlocked) {
|
|
502
|
+
logger.info('User is in blocklist', { did, walletDids, blockedDids });
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return isBlocked;
|
|
506
|
+
} catch (error) {
|
|
507
|
+
logger.error('Error checking blocklist', { error: error.message, did });
|
|
508
|
+
return false; // Default to allowing payment on error
|
|
509
|
+
}
|
|
510
|
+
}
|
|
@@ -48,7 +48,13 @@ import {
|
|
|
48
48
|
getSubscriptionCreateSetup,
|
|
49
49
|
getSubscriptionTrialSetup,
|
|
50
50
|
} from '../libs/subscription';
|
|
51
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
CHECKOUT_SESSION_TTL,
|
|
53
|
+
formatAmountPrecisionLimit,
|
|
54
|
+
formatMetadata,
|
|
55
|
+
getDataObjectFromQuery,
|
|
56
|
+
isUserInBlocklist,
|
|
57
|
+
} from '../libs/util';
|
|
52
58
|
import { invoiceQueue } from '../queues/invoice';
|
|
53
59
|
import { paymentQueue } from '../queues/payment';
|
|
54
60
|
import {
|
|
@@ -70,6 +76,7 @@ import { SetupIntent } from '../store/models/setup-intent';
|
|
|
70
76
|
import { Subscription } from '../store/models/subscription';
|
|
71
77
|
import { SubscriptionItem } from '../store/models/subscription-item';
|
|
72
78
|
import { ensureInvoiceForCheckout } from './connect/shared';
|
|
79
|
+
import { CHARGE_SUPPORTED_CHAIN_TYPES } from '../libs/constants';
|
|
73
80
|
|
|
74
81
|
const router = Router();
|
|
75
82
|
|
|
@@ -692,6 +699,16 @@ router.put('/:id/submit', user, ensureCheckoutSessionOpen, async (req, res) => {
|
|
|
692
699
|
});
|
|
693
700
|
}
|
|
694
701
|
|
|
702
|
+
// check if user in block list
|
|
703
|
+
if (CHARGE_SUPPORTED_CHAIN_TYPES.includes(paymentMethod.type)) {
|
|
704
|
+
const inBlock = await isUserInBlocklist(req.user.did, paymentMethod);
|
|
705
|
+
if (inBlock) {
|
|
706
|
+
return res
|
|
707
|
+
.status(403)
|
|
708
|
+
.json({ code: 'PAYMENT_RESTRICTED', error: 'Unable to process your purchase at this time' });
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
695
712
|
await checkoutSession.update({ customer_id: customer.id, customer_did: req.user.did });
|
|
696
713
|
|
|
697
714
|
// payment intent is only created when checkout session is in payment mode
|
|
@@ -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);
|
|
@@ -11,8 +11,13 @@ import {
|
|
|
11
11
|
getNextRetry,
|
|
12
12
|
tryWithTimeout,
|
|
13
13
|
getSubscriptionNotificationCustomActions,
|
|
14
|
+
isUserInBlocklist,
|
|
15
|
+
api,
|
|
14
16
|
} from '../../src/libs/util';
|
|
15
|
-
import type { Subscription } from '../../src/store/models';
|
|
17
|
+
import type { Subscription, PaymentMethod } from '../../src/store/models';
|
|
18
|
+
|
|
19
|
+
import { blocklet } from '../../src/libs/auth';
|
|
20
|
+
import logger from '../../src/libs/logger';
|
|
16
21
|
|
|
17
22
|
describe('createIdGenerator', () => {
|
|
18
23
|
it('should return a function that generates an ID with the specified prefix and size', () => {
|
|
@@ -375,3 +380,276 @@ describe('getSubscriptionNotificationCustomActions', () => {
|
|
|
375
380
|
});
|
|
376
381
|
});
|
|
377
382
|
});
|
|
383
|
+
|
|
384
|
+
describe('isUserInBlocklist', () => {
|
|
385
|
+
let mockAxios: any;
|
|
386
|
+
let mockBlocklet: any;
|
|
387
|
+
let mockLogger: any;
|
|
388
|
+
|
|
389
|
+
beforeEach(() => {
|
|
390
|
+
mockAxios = jest.spyOn(api, 'get').mockImplementation();
|
|
391
|
+
|
|
392
|
+
mockBlocklet = jest.spyOn(blocklet, 'getUser').mockImplementation();
|
|
393
|
+
|
|
394
|
+
mockLogger = {
|
|
395
|
+
warn: jest.spyOn(logger, 'warn').mockImplementation(),
|
|
396
|
+
info: jest.spyOn(logger, 'info').mockImplementation(),
|
|
397
|
+
error: jest.spyOn(logger, 'error').mockImplementation(),
|
|
398
|
+
};
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
afterEach(() => {
|
|
402
|
+
jest.clearAllMocks();
|
|
403
|
+
jest.resetAllMocks();
|
|
404
|
+
jest.restoreAllMocks();
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it('should return true when user DID is in blocklist', async () => {
|
|
408
|
+
// Setup mocks
|
|
409
|
+
const userDid = 'did:user:123';
|
|
410
|
+
const paymentMethod = {
|
|
411
|
+
id: 'pm_123',
|
|
412
|
+
type: 'arcblock',
|
|
413
|
+
settings: {
|
|
414
|
+
arcblock: {
|
|
415
|
+
api_host: 'https://api.example.com',
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
} as PaymentMethod;
|
|
419
|
+
|
|
420
|
+
mockAxios.mockResolvedValueOnce({ data: ['did:user:123', 'did:user:456'] });
|
|
421
|
+
mockBlocklet.mockResolvedValueOnce({
|
|
422
|
+
user: {
|
|
423
|
+
did: userDid,
|
|
424
|
+
connectedAccounts: [{ provider: 'wallet', did: userDid }],
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
// Execute
|
|
429
|
+
const result = await isUserInBlocklist(userDid, paymentMethod);
|
|
430
|
+
|
|
431
|
+
// Verify
|
|
432
|
+
expect(result).toBe(true);
|
|
433
|
+
expect(mockAxios).toHaveBeenCalledWith('https://api.example.com/blocked');
|
|
434
|
+
expect(mockBlocklet).toHaveBeenCalledWith(userDid);
|
|
435
|
+
expect(mockLogger.info).toHaveBeenCalled();
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it('should return true when user wallet DID is in blocklist', async () => {
|
|
439
|
+
// Setup mocks
|
|
440
|
+
const userDid = 'did:user:123';
|
|
441
|
+
const walletDid = 'did:wallet:456';
|
|
442
|
+
const paymentMethod = {
|
|
443
|
+
id: 'pm_123',
|
|
444
|
+
type: 'arcblock',
|
|
445
|
+
settings: {
|
|
446
|
+
arcblock: {
|
|
447
|
+
api_host: 'https://api.example.com',
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
} as PaymentMethod;
|
|
451
|
+
|
|
452
|
+
mockAxios.mockResolvedValueOnce({ data: ['did:wallet:456', 'did:user:789'] });
|
|
453
|
+
mockBlocklet.mockResolvedValueOnce({
|
|
454
|
+
user: {
|
|
455
|
+
did: userDid,
|
|
456
|
+
connectedAccounts: [{ provider: 'wallet', did: walletDid }],
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// Execute
|
|
461
|
+
const result = await isUserInBlocklist(userDid, paymentMethod);
|
|
462
|
+
|
|
463
|
+
// Verify
|
|
464
|
+
expect(result).toBe(true);
|
|
465
|
+
expect(mockAxios).toHaveBeenCalledWith('https://api.example.com/blocked');
|
|
466
|
+
expect(mockBlocklet).toHaveBeenCalledWith(userDid);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
it('should return false when user is not in blocklist', async () => {
|
|
470
|
+
// Setup mocks
|
|
471
|
+
const userDid = 'did:user:123';
|
|
472
|
+
const walletDid = 'did:wallet:456';
|
|
473
|
+
const paymentMethod = {
|
|
474
|
+
id: 'pm_123',
|
|
475
|
+
type: 'arcblock',
|
|
476
|
+
settings: {
|
|
477
|
+
arcblock: {
|
|
478
|
+
api_host: 'https://api.example.com',
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
} as PaymentMethod;
|
|
482
|
+
|
|
483
|
+
mockAxios.mockResolvedValueOnce({ data: ['did:user:789', 'did:wallet:789'] });
|
|
484
|
+
mockBlocklet.mockResolvedValueOnce({
|
|
485
|
+
user: {
|
|
486
|
+
did: userDid,
|
|
487
|
+
connectedAccounts: [{ provider: 'wallet', did: walletDid }],
|
|
488
|
+
},
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
// Execute
|
|
492
|
+
const result = await isUserInBlocklist(userDid, paymentMethod);
|
|
493
|
+
|
|
494
|
+
// Verify
|
|
495
|
+
expect(result).toBe(false);
|
|
496
|
+
expect(mockAxios).toHaveBeenCalledWith('https://api.example.com/blocked');
|
|
497
|
+
expect(mockBlocklet).toHaveBeenCalledWith(userDid);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it('should handle API host with trailing slash', async () => {
|
|
501
|
+
// Setup mocks
|
|
502
|
+
const userDid = 'did:user:123';
|
|
503
|
+
const paymentMethod = {
|
|
504
|
+
id: 'pm_123',
|
|
505
|
+
type: 'arcblock',
|
|
506
|
+
settings: {
|
|
507
|
+
arcblock: {
|
|
508
|
+
api_host: 'https://api.example.com/',
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
} as PaymentMethod;
|
|
512
|
+
|
|
513
|
+
mockAxios.mockResolvedValueOnce({ data: ['did:user:789'] });
|
|
514
|
+
mockBlocklet.mockResolvedValueOnce({
|
|
515
|
+
user: {
|
|
516
|
+
did: userDid,
|
|
517
|
+
connectedAccounts: [{ provider: 'wallet', did: userDid }],
|
|
518
|
+
},
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
// Execute
|
|
522
|
+
await isUserInBlocklist(userDid, paymentMethod);
|
|
523
|
+
|
|
524
|
+
// Verify - 确保调用了正确的 URL
|
|
525
|
+
expect(mockAxios).toHaveBeenCalledWith('https://api.example.com/blocked');
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
it('should return false when API host is not found', async () => {
|
|
529
|
+
// Setup mocks
|
|
530
|
+
const userDid = 'did:user:123';
|
|
531
|
+
const paymentMethod = {
|
|
532
|
+
id: 'pm_123',
|
|
533
|
+
type: 'arcblock',
|
|
534
|
+
settings: {},
|
|
535
|
+
} as PaymentMethod;
|
|
536
|
+
|
|
537
|
+
// Execute
|
|
538
|
+
const result = await isUserInBlocklist(userDid, paymentMethod);
|
|
539
|
+
|
|
540
|
+
// Verify
|
|
541
|
+
expect(result).toBe(false);
|
|
542
|
+
expect(mockLogger.warn).toHaveBeenCalled();
|
|
543
|
+
expect(mockAxios).not.toHaveBeenCalled();
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
it('should return false when blocklist is empty', async () => {
|
|
547
|
+
// Setup mocks
|
|
548
|
+
const userDid = 'did:user:123';
|
|
549
|
+
const paymentMethod = {
|
|
550
|
+
id: 'pm_123',
|
|
551
|
+
type: 'arcblock',
|
|
552
|
+
settings: {
|
|
553
|
+
arcblock: {
|
|
554
|
+
api_host: 'https://api.example.com',
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
} as PaymentMethod;
|
|
558
|
+
|
|
559
|
+
// 先模拟用户信息获取
|
|
560
|
+
mockBlocklet.mockResolvedValueOnce({
|
|
561
|
+
user: {
|
|
562
|
+
did: userDid,
|
|
563
|
+
connectedAccounts: [{ provider: 'wallet', did: userDid }],
|
|
564
|
+
},
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
// 再模拟空黑名单
|
|
568
|
+
mockAxios.mockResolvedValueOnce({ data: [] });
|
|
569
|
+
|
|
570
|
+
// Execute
|
|
571
|
+
const result = await isUserInBlocklist(userDid, paymentMethod);
|
|
572
|
+
|
|
573
|
+
// Verify
|
|
574
|
+
expect(result).toBe(false);
|
|
575
|
+
expect(mockBlocklet).toHaveBeenCalled(); // 现在应该调用了用户信息获取
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
it('should return false when user is not found', async () => {
|
|
579
|
+
// Setup mocks
|
|
580
|
+
const userDid = 'did:user:123';
|
|
581
|
+
const paymentMethod = {
|
|
582
|
+
id: 'pm_123',
|
|
583
|
+
type: 'arcblock',
|
|
584
|
+
settings: {
|
|
585
|
+
arcblock: {
|
|
586
|
+
api_host: 'https://api.example.com',
|
|
587
|
+
},
|
|
588
|
+
},
|
|
589
|
+
} as PaymentMethod;
|
|
590
|
+
|
|
591
|
+
mockAxios.mockResolvedValueOnce({ data: ['did:user:123'] });
|
|
592
|
+
mockBlocklet.mockResolvedValueOnce({ user: null });
|
|
593
|
+
|
|
594
|
+
// Execute
|
|
595
|
+
const result = await isUserInBlocklist(userDid, paymentMethod);
|
|
596
|
+
|
|
597
|
+
// Verify
|
|
598
|
+
expect(result).toBe(false);
|
|
599
|
+
expect(mockLogger.error).toHaveBeenCalled();
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
it('should return false when API request fails', async () => {
|
|
603
|
+
// Setup mocks
|
|
604
|
+
const userDid = 'did:user:123';
|
|
605
|
+
const paymentMethod = {
|
|
606
|
+
id: 'pm_123',
|
|
607
|
+
type: 'arcblock',
|
|
608
|
+
settings: {
|
|
609
|
+
arcblock: {
|
|
610
|
+
api_host: 'https://api.example.com',
|
|
611
|
+
},
|
|
612
|
+
},
|
|
613
|
+
} as PaymentMethod;
|
|
614
|
+
|
|
615
|
+
mockAxios.mockRejectedValueOnce(new Error('Network error'));
|
|
616
|
+
|
|
617
|
+
// Execute
|
|
618
|
+
const result = await isUserInBlocklist(userDid, paymentMethod);
|
|
619
|
+
|
|
620
|
+
// Verify
|
|
621
|
+
expect(result).toBe(false);
|
|
622
|
+
expect(mockLogger.error).toHaveBeenCalled();
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
it('should handle extraConfigs for connected accounts', async () => {
|
|
626
|
+
// Setup mocks
|
|
627
|
+
const userDid = 'did:user:123';
|
|
628
|
+
const walletDid = 'did:wallet:456';
|
|
629
|
+
const paymentMethod = {
|
|
630
|
+
id: 'pm_123',
|
|
631
|
+
type: 'arcblock',
|
|
632
|
+
settings: {
|
|
633
|
+
arcblock: {
|
|
634
|
+
api_host: 'https://api.example.com',
|
|
635
|
+
},
|
|
636
|
+
},
|
|
637
|
+
} as PaymentMethod;
|
|
638
|
+
|
|
639
|
+
mockAxios.mockResolvedValueOnce({ data: ['did:wallet:456'] });
|
|
640
|
+
mockBlocklet.mockResolvedValueOnce({
|
|
641
|
+
user: {
|
|
642
|
+
did: userDid,
|
|
643
|
+
extraConfigs: {
|
|
644
|
+
connectedAccounts: [{ provider: 'wallet', did: walletDid }],
|
|
645
|
+
},
|
|
646
|
+
},
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
// Execute
|
|
650
|
+
const result = await isUserInBlocklist(userDid, paymentMethod);
|
|
651
|
+
|
|
652
|
+
// Verify
|
|
653
|
+
expect(result).toBe(true);
|
|
654
|
+
});
|
|
655
|
+
});
|
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.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
|
}
|