payment-kit 1.13.41 → 1.13.43

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.
@@ -1,9 +1,8 @@
1
- import { toBN } from '@ocap/util';
2
-
3
1
  import { wallet } from '../libs/auth';
4
2
  import dayjs from '../libs/dayjs';
5
3
  import CustomError from '../libs/error';
6
4
  import logger from '../libs/logger';
5
+ import { isDelegationSufficientForPayment } from '../libs/payment';
7
6
  import createQueue from '../libs/queue';
8
7
  import { MAX_RETRY_COUNT, getNextRetry } from '../libs/util';
9
8
  import { CheckoutSession } from '../store/models/checkout-session';
@@ -66,10 +65,14 @@ export const handlePayment = async (job: PaymentJob) => {
66
65
  const payer = paymentSettings?.payment_method_options.arcblock?.payer;
67
66
 
68
67
  // check balance before capture
69
- const result = await client.getAccountTokens({ address: payer, token: paymentCurrency.contract });
70
- const balance = result.tokens.find((x: any) => x.address === paymentCurrency.contract)?.balance;
71
- if (balance === undefined || toBN(balance).lt(toBN(paymentIntent.amount))) {
72
- throw new CustomError('INSUFFICIENT_BALANCE', 'payer balance not enough for this payment');
68
+ const result = await isDelegationSufficientForPayment({
69
+ paymentMethod,
70
+ paymentCurrency,
71
+ userDid: payer as string,
72
+ amount: paymentIntent.amount,
73
+ });
74
+ if (result.sufficient === false) {
75
+ throw new CustomError(result.reason, 'payer balance or delegation not sufficient for this payment');
73
76
  }
74
77
 
75
78
  // do the capture
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.13.41
17
+ version: 1.13.43
18
18
  logo: logo.png
19
19
  files:
20
20
  - dist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payment-kit",
3
- "version": "1.13.41",
3
+ "version": "1.13.43",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev",
6
6
  "eject": "vite eject",
@@ -103,7 +103,7 @@
103
103
  "@abtnode/types": "1.16.17",
104
104
  "@arcblock/eslint-config": "^0.2.4",
105
105
  "@arcblock/eslint-config-ts": "^0.2.4",
106
- "@did-pay/types": "1.13.41",
106
+ "@did-pay/types": "1.13.43",
107
107
  "@types/cookie-parser": "^1.4.5",
108
108
  "@types/cors": "^2.8.15",
109
109
  "@types/dotenv-flow": "^3.3.2",
@@ -140,5 +140,5 @@
140
140
  "parser": "typescript"
141
141
  }
142
142
  },
143
- "gitHead": "5f150269dbc497d19cc4d8422b03c67d29793cf2"
143
+ "gitHead": "45e2930980a56ef53f1994ca52748972740bd505"
144
144
  }