payment-kit 1.15.8 → 1.15.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.
- package/api/src/libs/notification/template/subscription-will-renew.ts +9 -5
- package/api/src/libs/payment.ts +1 -0
- package/api/src/routes/invoices.ts +8 -7
- package/api/src/routes/prices.ts +1 -1
- package/blocklet.yml +1 -1
- package/package.json +4 -4
- package/src/pages/customer/index.tsx +1 -1
- package/src/pages/customer/invoice/past-due.tsx +1 -1
- package/src/pages/customer/subscription/embed.tsx +15 -10
|
@@ -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
|
-
|
|
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 =
|
|
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.
|
|
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.
|
|
350
|
+
text: `${paymentDetail.balanceFormatted} ${paymentDetail.symbol}`,
|
|
347
351
|
},
|
|
348
352
|
},
|
|
349
353
|
]
|
package/api/src/libs/payment.ts
CHANGED
|
@@ -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
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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(
|
|
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(
|
|
182
|
+
...pick(firstInvoice, [
|
|
182
183
|
'number',
|
|
183
184
|
'paid',
|
|
184
185
|
'auto_advance',
|
package/api/src/routes/prices.ts
CHANGED
|
@@ -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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.9",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@arcblock/validator": "^1.18.135",
|
|
53
53
|
"@blocklet/js-sdk": "^1.16.31",
|
|
54
54
|
"@blocklet/logger": "^1.16.31",
|
|
55
|
-
"@blocklet/payment-react": "1.15.
|
|
55
|
+
"@blocklet/payment-react": "1.15.9",
|
|
56
56
|
"@blocklet/sdk": "^1.16.31",
|
|
57
57
|
"@blocklet/ui-react": "^2.10.33",
|
|
58
58
|
"@blocklet/uploader": "^0.1.36",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"devDependencies": {
|
|
119
119
|
"@abtnode/types": "^1.16.31",
|
|
120
120
|
"@arcblock/eslint-config-ts": "^0.3.2",
|
|
121
|
-
"@blocklet/payment-types": "1.15.
|
|
121
|
+
"@blocklet/payment-types": "1.15.9",
|
|
122
122
|
"@types/cookie-parser": "^1.4.7",
|
|
123
123
|
"@types/cors": "^2.8.17",
|
|
124
124
|
"@types/debug": "^4.1.12",
|
|
@@ -160,5 +160,5 @@
|
|
|
160
160
|
"parser": "typescript"
|
|
161
161
|
}
|
|
162
162
|
},
|
|
163
|
-
"gitHead": "
|
|
163
|
+
"gitHead": "d2919fe52ba2b7aee1c6c1275c325f91b81027da"
|
|
164
164
|
}
|
|
@@ -30,7 +30,7 @@ export default function CustomerInvoicePastDue() {
|
|
|
30
30
|
const { loading, error, data, runAsync } = useRequest(fetchData);
|
|
31
31
|
|
|
32
32
|
useEffect(() => {
|
|
33
|
-
events.
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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(() => {
|