payment-kit 1.16.8 → 1.16.9

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.
@@ -20,7 +20,7 @@ import {
20
20
  } from '../../../store/models';
21
21
  import { getPaymentAmountForCycleSubscription, type PaymentDetail } from '../../payment';
22
22
  import { getMainProductName } from '../../product';
23
- import { getCustomerSubscriptionPageUrl } from '../../subscription';
23
+ import { getCustomerSubscriptionPageUrl, getSubscriptionPaymentAddress } from '../../subscription';
24
24
  import { formatTime, getPrettyMsI18nLocale, getSimplifyDuration } from '../../time';
25
25
  import { getCustomerRechargeLink, getSubscriptionNotificationCustomActions } from '../../util';
26
26
  import type { BaseEmailTemplate, BaseEmailTemplateType } from './base';
@@ -101,8 +101,8 @@ export class SubscriptionWillRenewEmailTemplate
101
101
  if (!paymentMethod) {
102
102
  throw new Error(`Payment method not found: ${paymentCurrency.payment_method_id}`);
103
103
  }
104
- // @ts-ignore
105
- const paymentAddress = subscription.payment_details?.[paymentMethod.type]?.payer ?? undefined;
104
+
105
+ const paymentAddress = getSubscriptionPaymentAddress(subscription, paymentMethod.type);
106
106
  const balance = await getTokenByAddress(paymentAddress, paymentMethod, paymentCurrency);
107
107
  paymentDetail.balanceFormatted = fromUnitToToken(balance, paymentCurrency.decimal);
108
108
  paymentDetail.balance = +paymentDetail.balanceFormatted;
@@ -1024,3 +1024,12 @@ export async function checkUsageReportEmpty(
1024
1024
  );
1025
1025
  return usageReportEmpty.every(Boolean);
1026
1026
  }
1027
+
1028
+ export function getSubscriptionPaymentAddress(subscription: Subscription, paymentMethodType: string) {
1029
+ return (
1030
+ // @ts-ignore
1031
+ subscription.payment_details?.[paymentMethodType]?.payer ||
1032
+ // @ts-ignore
1033
+ subscription.payment_settings?.payment_method_options?.[paymentMethodType]?.payer
1034
+ );
1035
+ }
@@ -16,6 +16,7 @@ import {
16
16
  checkUsageReportEmpty,
17
17
  getSubscriptionCycleAmount,
18
18
  getSubscriptionCycleSetup,
19
+ getSubscriptionPaymentAddress,
19
20
  getSubscriptionRefundSetup,
20
21
  getSubscriptionStakeAddress,
21
22
  getSubscriptionStakeReturnSetup,
@@ -456,7 +457,7 @@ const handleStakeSlashAfterCancel = async (subscription: Subscription) => {
456
457
  payment_details: {
457
458
  arcblock: {
458
459
  tx_hash: txHash,
459
- payer: subscription.payment_details?.arcblock?.payer as string,
460
+ payer: getSubscriptionPaymentAddress(subscription, 'arcblock'),
460
461
  type: 'slash',
461
462
  },
462
463
  },
@@ -19,6 +19,7 @@ import {
19
19
  expandSubscriptionItems,
20
20
  getSubscriptionCreateSetup,
21
21
  getSubscriptionItemPrice,
22
+ getSubscriptionPaymentAddress,
22
23
  getSubscriptionStakeSetup,
23
24
  } from '../../libs/subscription';
24
25
  import { getCustomerStakeAddress, OCAP_PAYMENT_TX_TYPE } from '../../libs/util';
@@ -620,7 +621,7 @@ export async function ensureSubscriptionRecharge(subscriptionId: string) {
620
621
  throw new Error(`Payment method ${paymentCurrency.payment_method_id} not found`);
621
622
  }
622
623
  // @ts-ignore
623
- const receiverAddress = subscription?.payment_details?.[paymentMethod.type]?.payer;
624
+ const receiverAddress = getSubscriptionPaymentAddress(subscription, paymentMethod.type);
624
625
  if (!receiverAddress) {
625
626
  throw new Error(`Receiver address not found for subscription ${subscriptionId}`);
626
627
  }
@@ -25,6 +25,7 @@ import {
25
25
  createProration,
26
26
  finalizeSubscriptionUpdate,
27
27
  getSubscriptionCreateSetup,
28
+ getSubscriptionPaymentAddress,
28
29
  getSubscriptionRefundSetup,
29
30
  getSubscriptionStakeReturnSetup,
30
31
  getSubscriptionStakeSlashSetup,
@@ -1809,7 +1810,7 @@ router.get('/:id/payer-token', authMine, async (req, res) => {
1809
1810
  }
1810
1811
 
1811
1812
  // @ts-ignore
1812
- const paymentAddress = subscription.payment_details?.[paymentMethod.type]?.payer ?? undefined;
1813
+ const paymentAddress = getSubscriptionPaymentAddress(subscription, paymentMethod.type);
1813
1814
  if (!paymentAddress && ['ethereum', 'arcblock'].includes(paymentMethod.type)) {
1814
1815
  return res.status(400).json({ error: `Payer not found on subscription payment detail: ${subscription.id}` });
1815
1816
  }
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.16.8
17
+ version: 1.16.9
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.16.8",
3
+ "version": "1.16.9",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "eject": "vite eject",
@@ -53,7 +53,7 @@
53
53
  "@arcblock/validator": "^1.18.150",
54
54
  "@blocklet/js-sdk": "1.16.33-beta-20241031-073543-49b1ff9b",
55
55
  "@blocklet/logger": "1.16.33-beta-20241031-073543-49b1ff9b",
56
- "@blocklet/payment-react": "1.16.8",
56
+ "@blocklet/payment-react": "1.16.9",
57
57
  "@blocklet/sdk": "1.16.33-beta-20241031-073543-49b1ff9b",
58
58
  "@blocklet/ui-react": "^2.10.74",
59
59
  "@blocklet/uploader": "^0.1.53",
@@ -120,7 +120,7 @@
120
120
  "devDependencies": {
121
121
  "@abtnode/types": "1.16.33-beta-20241031-073543-49b1ff9b",
122
122
  "@arcblock/eslint-config-ts": "^0.3.3",
123
- "@blocklet/payment-types": "1.16.8",
123
+ "@blocklet/payment-types": "1.16.9",
124
124
  "@types/cookie-parser": "^1.4.7",
125
125
  "@types/cors": "^2.8.17",
126
126
  "@types/debug": "^4.1.12",
@@ -166,5 +166,5 @@
166
166
  "parser": "typescript"
167
167
  }
168
168
  },
169
- "gitHead": "ad6dca32db4f5074471e000b714ff5046e06608f"
169
+ "gitHead": "4860066cb778dec9d1a28c47434e638218d4ac9d"
170
170
  }
@@ -77,16 +77,21 @@ export default function RechargePage() {
77
77
  const {
78
78
  paymentCurrency,
79
79
  payment_details: paymentDetails,
80
+ payment_settings: paymentSettings,
80
81
  paymentMethod,
81
82
  } = subscription || {
82
83
  customer: null,
83
84
  paymentCurrency: null,
84
85
  payment_details: null,
85
86
  paymentMethod: null,
87
+ payment_settings: null,
86
88
  };
87
89
 
88
- // @ts-ignore
89
- const receiveAddress = paymentDetails?.[paymentMethod?.type]?.payer;
90
+ const receiveAddress =
91
+ // @ts-ignore
92
+ paymentDetails?.[paymentMethod?.type]?.payer ||
93
+ // @ts-ignore
94
+ paymentSettings?.payment_method_options?.[paymentMethod?.type]?.payer;
90
95
  const fetchData = async () => {
91
96
  try {
92
97
  setLoading(true);
@@ -114,7 +119,7 @@ export default function RechargePage() {
114
119
  { amount: getCycleAmount(10), cycles: 10 },
115
120
  ]);
116
121
  } catch (err) {
117
- setError(err instanceof Error ? err.message : t('common.fetchError'));
122
+ setError(formatError(err) || t('common.fetchError'));
118
123
  console.error(err);
119
124
  } finally {
120
125
  setLoading(false);