payment-kit 1.15.8 → 1.15.10

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.
@@ -100,11 +100,14 @@ export class SubscriptionWillRenewEmailTemplate
100
100
  // paymentDetail.price = +amount;
101
101
 
102
102
  const paymentAmount = await getPaymentAmountForCycleSubscription(subscription, paymentCurrency);
103
- const paymentDetail = { price: paymentAmount, balance: 0, symbol: paymentCurrency.symbol };
103
+ const paymentDetail = { price: paymentAmount, balance: 0, symbol: paymentCurrency.symbol, balanceFormatted: '0' };
104
104
 
105
105
  const token = await getTokenSummaryByDid(userDid, customer.livemode);
106
106
 
107
- paymentDetail.balance = +fromUnitToToken(token?.[paymentCurrency.id] || '0', paymentCurrency.decimal);
107
+ const balance = fromUnitToToken(token?.[paymentCurrency.id] || '0', paymentCurrency.decimal);
108
+ paymentDetail.balanceFormatted = balance;
109
+ paymentDetail.balance = +balance;
110
+
108
111
  const { isPrePaid, interval } = await this.getPaymentCategory({
109
112
  subscriptionId: subscription.id,
110
113
  });
@@ -173,9 +176,10 @@ export class SubscriptionWillRenewEmailTemplate
173
176
 
174
177
  const lineItemExpanded = await Price.expand(subscriptionItems);
175
178
  const metered = lineItemExpanded.find((lineItem) => lineItem.price.recurring?.usage_type === 'metered');
179
+ const recurringItems = lineItemExpanded.filter((lineItem) => lineItem.price.type === 'recurring');
176
180
 
177
181
  const isPrePaid = !metered;
178
- const interval = metered?.price.recurring?.interval;
182
+ const interval = recurringItems?.[0]?.price.recurring?.interval;
179
183
 
180
184
  return {
181
185
  isPrePaid,
@@ -269,7 +273,7 @@ export class SubscriptionWillRenewEmailTemplate
269
273
  at,
270
274
  productName,
271
275
  willRenewDuration,
272
- balance: `${paymentDetail.balance} ${paymentDetail.symbol}`,
276
+ balance: `${paymentDetail.balanceFormatted} ${paymentDetail.symbol}`,
273
277
  })}`
274
278
  : `${translate('notification.subscriptionWillRenew.unableToPayBody', locale, {
275
279
  at,
@@ -343,7 +347,7 @@ export class SubscriptionWillRenewEmailTemplate
343
347
  ...(!canPay && {
344
348
  color: '#FF0000',
345
349
  }),
346
- text: `${paymentDetail.balance} ${paymentDetail.symbol}`,
350
+ text: `${paymentDetail.balanceFormatted} ${paymentDetail.symbol}`,
347
351
  },
348
352
  },
349
353
  ]
@@ -185,6 +185,7 @@ export interface PaymentDetail {
185
185
  balance: number;
186
186
  price: number;
187
187
  symbol: LiteralUnion<'ABT' | 'USD', string>;
188
+ balanceFormatted?: string;
188
189
  }
189
190
  export async function getPaymentDetail(
190
191
  userDid: string,
@@ -134,13 +134,14 @@ router.get('/', authMine, async (req, res) => {
134
134
  const client = method.getOcapClient();
135
135
  const { address } = subscription.payment_details.arcblock.staking;
136
136
  const { state } = await client.getStakeState({ address });
137
- const last =
138
- list[list.length - 1] ||
139
- (await Invoice.findOne({ where: { subscription_id: subscription.id }, order: [['created_at', 'ASC']] }));
140
-
141
- if (state && last) {
137
+ const firstInvoice = await Invoice.findOne({
138
+ where: { subscription_id: subscription.id },
139
+ order: [['created_at', 'ASC']],
140
+ });
141
+ const last = query.o === 'asc' ? list?.[list.length - 1] : list?.[0];
142
+ if (state && firstInvoice) {
142
143
  const data = JSON.parse(state.data?.value || '{}');
143
- const customer = await Customer.findByPk(last.customer_id);
144
+ const customer = await Customer.findByPk(firstInvoice.customer_id);
144
145
  const currency = await PaymentCurrency.findOne({
145
146
  where: { payment_method_id: method.id, is_base_currency: true },
146
147
  });
@@ -178,7 +179,7 @@ router.get('/', authMine, async (req, res) => {
178
179
  amount_due: '0',
179
180
  amount_paid: stakeAmount,
180
181
  amount_remaining: '0',
181
- ...pick(last, [
182
+ ...pick(firstInvoice, [
182
183
  'number',
183
184
  'paid',
184
185
  'auto_advance',
@@ -305,7 +305,7 @@ router.put('/:id', auth, async (req, res) => {
305
305
  pick(
306
306
  req.body,
307
307
  locked
308
- ? ['nickname', 'description', 'metadata', 'currency_options', 'upsell', ...quantityKeys]
308
+ ? ['nickname', 'description', 'metadata', 'currency_options', 'upsell', 'lookup_key', ...quantityKeys]
309
309
  : ['type', 'model', 'active', 'livemode', 'nickname', 'recurring', 'description', 'tiers', 'unit_amount', 'transform_quantity', 'metadata', 'lookup_key', 'currency_options', 'upsell', ...quantityKeys] // prettier-ignore
310
310
  )
311
311
  );
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.15.8
17
+ version: 1.15.10
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.15.8",
3
+ "version": "1.15.10",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "eject": "vite eject",
@@ -42,20 +42,20 @@
42
42
  ]
43
43
  },
44
44
  "dependencies": {
45
- "@abtnode/cron": "^1.16.31",
45
+ "@abtnode/cron": "^1.16.32",
46
46
  "@arcblock/did": "^1.18.135",
47
47
  "@arcblock/did-auth-storage-nedb": "^1.7.1",
48
- "@arcblock/did-connect": "^2.10.33",
48
+ "@arcblock/did-connect": "^2.10.39",
49
49
  "@arcblock/did-util": "^1.18.135",
50
50
  "@arcblock/jwt": "^1.18.135",
51
- "@arcblock/ux": "^2.10.33",
51
+ "@arcblock/ux": "^2.10.39",
52
52
  "@arcblock/validator": "^1.18.135",
53
- "@blocklet/js-sdk": "^1.16.31",
54
- "@blocklet/logger": "^1.16.31",
55
- "@blocklet/payment-react": "1.15.8",
56
- "@blocklet/sdk": "^1.16.31",
57
- "@blocklet/ui-react": "^2.10.33",
58
- "@blocklet/uploader": "^0.1.36",
53
+ "@blocklet/js-sdk": "^1.16.32",
54
+ "@blocklet/logger": "^1.16.32",
55
+ "@blocklet/payment-react": "1.15.10",
56
+ "@blocklet/sdk": "^1.16.32",
57
+ "@blocklet/ui-react": "^2.10.39",
58
+ "@blocklet/uploader": "^0.1.40",
59
59
  "@blocklet/xss": "^0.1.7",
60
60
  "@mui/icons-material": "^5.16.6",
61
61
  "@mui/lab": "^5.0.0-alpha.173",
@@ -116,9 +116,9 @@
116
116
  "validator": "^13.12.0"
117
117
  },
118
118
  "devDependencies": {
119
- "@abtnode/types": "^1.16.31",
119
+ "@abtnode/types": "^1.16.32",
120
120
  "@arcblock/eslint-config-ts": "^0.3.2",
121
- "@blocklet/payment-types": "1.15.8",
121
+ "@blocklet/payment-types": "1.15.10",
122
122
  "@types/cookie-parser": "^1.4.7",
123
123
  "@types/cors": "^2.8.17",
124
124
  "@types/debug": "^4.1.12",
@@ -144,7 +144,7 @@
144
144
  "typescript": "^4.9.5",
145
145
  "vite": "^5.3.5",
146
146
  "vite-node": "^2.0.4",
147
- "vite-plugin-blocklet": "^0.9.4",
147
+ "vite-plugin-blocklet": "^0.9.8",
148
148
  "vite-plugin-node-polyfills": "^0.21.0",
149
149
  "vite-plugin-svgr": "^4.2.0",
150
150
  "vite-tsconfig-paths": "^4.3.2",
@@ -160,5 +160,5 @@
160
160
  "parser": "typescript"
161
161
  }
162
162
  },
163
- "gitHead": "d0e3c23bed5a41a9b16554fc3b7458e8dee4fd60"
163
+ "gitHead": "a146baddb1c4108e652546014220d37a0288722b"
164
164
  }
@@ -116,7 +116,7 @@ export default function CustomerHome() {
116
116
 
117
117
  useEffect(() => {
118
118
  runAsync();
119
- events.once('switch-did', () => {
119
+ events.on('switch-did', () => {
120
120
  runAsync();
121
121
  });
122
122
  }, []);
@@ -30,7 +30,7 @@ export default function CustomerInvoicePastDue() {
30
30
  const { loading, error, data, runAsync } = useRequest(fetchData);
31
31
 
32
32
  useEffect(() => {
33
- events.once('switch-did', () => {
33
+ events.on('switch-did', () => {
34
34
  runAsync().catch(console.error);
35
35
  });
36
36
  }, []);
@@ -60,16 +60,21 @@ export default function SubscriptionEmbed() {
60
60
  const authToken = params.get('authToken') || '';
61
61
  const defaultPageSize = useDefaultPageSize(20);
62
62
  const { data: subscription, error, loading } = useRequest(() => fetchSubscriptionData(subscriptionId, authToken));
63
- const { data } = useRequest(() =>
64
- fetchInvoiceData({
65
- page: 1,
66
- pageSize: defaultPageSize,
67
- status: 'open,paid,uncollectible',
68
- subscription_id: subscriptionId,
69
- authToken,
70
- ignore_zero: true,
71
- include_staking: true,
72
- })
63
+ const { data } = useRequest(
64
+ () =>
65
+ fetchInvoiceData({
66
+ page: 1,
67
+ pageSize: defaultPageSize,
68
+ status: 'open,paid,uncollectible',
69
+ subscription_id: subscriptionId,
70
+ authToken,
71
+ ignore_zero: true,
72
+ include_staking: true,
73
+ customer_id: subscription?.customer_id,
74
+ }),
75
+ {
76
+ refreshDeps: [subscriptionId, authToken, subscription?.customer_id],
77
+ }
73
78
  );
74
79
 
75
80
  const subscriptionPageUrl: string = useMemo(() => {