payment-kit 1.16.7 → 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.
- package/api/src/libs/notification/template/subscription-will-renew.ts +3 -3
- package/api/src/libs/subscription.ts +9 -0
- package/api/src/queues/subscription.ts +2 -1
- package/api/src/routes/connect/shared.ts +2 -1
- package/api/src/routes/customers.ts +7 -6
- package/api/src/routes/subscriptions.ts +2 -1
- package/blocklet.yml +1 -1
- package/package.json +4 -4
- package/src/pages/customer/index.tsx +16 -9
- package/src/pages/customer/recharge.tsx +8 -3
- package/src/pages/customer/subscription/embed.tsx +7 -3
|
@@ -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
|
-
|
|
105
|
-
const paymentAddress = subscription
|
|
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
|
|
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
|
|
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
|
}
|
|
@@ -86,24 +86,25 @@ router.get('/me', sessionMiddleware(), async (req, res) => {
|
|
|
86
86
|
|
|
87
87
|
try {
|
|
88
88
|
const doc = await Customer.findByPkOrDid(req.user.did as string);
|
|
89
|
+
const livemode = req.query.livemode ? !!req?.livemode : !!doc?.livemode;
|
|
89
90
|
if (!doc) {
|
|
90
91
|
if (req.query.fallback) {
|
|
91
92
|
const result = await blocklet.getUser(req.user.did);
|
|
92
|
-
res.json({ ...result.user, address: {} });
|
|
93
|
+
res.json({ ...result.user, address: {}, livemode });
|
|
93
94
|
} else {
|
|
94
95
|
res.json({ error: 'Customer not found' });
|
|
95
96
|
}
|
|
96
97
|
} else {
|
|
97
98
|
const [summary, stake, token] = await Promise.all([
|
|
98
99
|
doc.getSummary(),
|
|
99
|
-
getStakeSummaryByDid(doc.did,
|
|
100
|
-
getTokenSummaryByDid(doc.did,
|
|
100
|
+
getStakeSummaryByDid(doc.did, livemode),
|
|
101
|
+
getTokenSummaryByDid(doc.did, livemode),
|
|
101
102
|
]);
|
|
102
|
-
res.json({ ...doc.toJSON(), summary: { ...summary, stake, token } });
|
|
103
|
+
res.json({ ...doc.toJSON(), summary: { ...summary, stake, token }, livemode });
|
|
103
104
|
}
|
|
104
105
|
} catch (err) {
|
|
105
|
-
console.error(err);
|
|
106
|
-
res.json(
|
|
106
|
+
console.error('get customer failed', err);
|
|
107
|
+
res.status(500).json({ error: `Failed to get customer: ${err.message}` });
|
|
107
108
|
}
|
|
108
109
|
});
|
|
109
110
|
|
|
@@ -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
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.16.
|
|
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.
|
|
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.
|
|
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": "
|
|
169
|
+
"gitHead": "4860066cb778dec9d1a28c47434e638218d4ac9d"
|
|
170
170
|
}
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
} from '@mui/material';
|
|
29
29
|
import type { SelectChangeEvent } from '@mui/material/Select';
|
|
30
30
|
import { styled, SxProps } from '@mui/system';
|
|
31
|
-
import { useSetState } from 'ahooks';
|
|
31
|
+
import { useRequest, useSetState } from 'ahooks';
|
|
32
32
|
import { flatten, isEmpty } from 'lodash';
|
|
33
33
|
import { memo, useEffect, useMemo, useState } from 'react';
|
|
34
34
|
import { FlagEmoji, defaultCountries, parseCountry } from 'react-international-phone';
|
|
@@ -101,19 +101,14 @@ export default function CustomerHome() {
|
|
|
101
101
|
const navigate = useNavigate();
|
|
102
102
|
const { isMobile } = useMobile('lg');
|
|
103
103
|
const { isPending, startTransition } = useTransitionContext();
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
const { data, error, loading, runAsync } = useRequest(fetchData, {
|
|
105
|
+
manual: true,
|
|
106
|
+
});
|
|
106
107
|
const countryDetail = useMemo(() => {
|
|
107
108
|
const item = defaultCountries.find((v) => v[1] === data?.address?.country);
|
|
108
109
|
return item ? parseCountry(item) : { name: '' };
|
|
109
110
|
}, [data]);
|
|
110
111
|
|
|
111
|
-
const runAsync = () => {
|
|
112
|
-
fetchData().then((res) => {
|
|
113
|
-
setData(res);
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
|
|
117
112
|
useEffect(() => {
|
|
118
113
|
runAsync();
|
|
119
114
|
events.on('switch-did', () => {
|
|
@@ -127,6 +122,18 @@ export default function CustomerHome() {
|
|
|
127
122
|
}
|
|
128
123
|
}, [data]);
|
|
129
124
|
|
|
125
|
+
if (loading) {
|
|
126
|
+
return <ProgressBar pending />;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (error) {
|
|
130
|
+
return (
|
|
131
|
+
<Alert sx={{ mt: 3 }} severity="error">
|
|
132
|
+
{formatError(error)}
|
|
133
|
+
</Alert>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
130
137
|
if (!data) {
|
|
131
138
|
return null;
|
|
132
139
|
}
|
|
@@ -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
|
-
|
|
89
|
-
|
|
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
|
|
122
|
+
setError(formatError(err) || t('common.fetchError'));
|
|
118
123
|
console.error(err);
|
|
119
124
|
} finally {
|
|
120
125
|
setLoading(false);
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
getPrefix,
|
|
17
17
|
getSubscriptionStatusColor,
|
|
18
18
|
useDefaultPageSize,
|
|
19
|
+
useMobile,
|
|
19
20
|
} from '@blocklet/payment-react';
|
|
20
21
|
import type { Paginated, TInvoiceExpanded, TSubscriptionExpanded } from '@blocklet/payment-types';
|
|
21
22
|
import {
|
|
@@ -60,6 +61,7 @@ export default function SubscriptionEmbed() {
|
|
|
60
61
|
const subscriptionId = params.get('id') || '';
|
|
61
62
|
const authToken = params.get('authToken') || '';
|
|
62
63
|
const defaultPageSize = useDefaultPageSize(20);
|
|
64
|
+
const { isMobile } = useMobile();
|
|
63
65
|
const { data: subscription, error, loading } = useRequest(() => fetchSubscriptionData(subscriptionId, authToken));
|
|
64
66
|
const { data } = useRequest(
|
|
65
67
|
() =>
|
|
@@ -181,7 +183,7 @@ export default function SubscriptionEmbed() {
|
|
|
181
183
|
width: '100%',
|
|
182
184
|
height: '100%',
|
|
183
185
|
}}>
|
|
184
|
-
<Typography component="h3" sx={{ textAlign: 'center' }} variant="h5" gutterBottom>
|
|
186
|
+
<Typography component="h3" sx={{ textAlign: 'center', fontWeight: 500 }} variant="h5" gutterBottom>
|
|
185
187
|
{t('payment.customer.subscriptions.current')}
|
|
186
188
|
</Typography>
|
|
187
189
|
<Box sx={{ marginTop: '12px' }}>
|
|
@@ -212,8 +214,10 @@ export default function SubscriptionEmbed() {
|
|
|
212
214
|
return (
|
|
213
215
|
<ListItem key={item.id} disableGutters sx={{ display: 'flex', justifyContent: 'space-between' }}>
|
|
214
216
|
<Typography component="div" sx={{ flex: 3, gap: 1, display: 'flex', alignItems: 'center' }}>
|
|
215
|
-
{
|
|
216
|
-
|
|
217
|
+
<Typography component="span" sx={{ whiteSpace: 'nowrap' }}>
|
|
218
|
+
{formatToDate(item.created_at, locale, 'YYYY-MM-DD')}
|
|
219
|
+
</Typography>
|
|
220
|
+
{!isMobile && <Status label={getInvoiceDescriptionAndReason(item, locale)?.type} />}
|
|
217
221
|
</Typography>
|
|
218
222
|
<Typography component="span" sx={{ flex: 1, textAlign: 'right' }}>
|
|
219
223
|
{formatBNStr(item.total, item.paymentCurrency.decimal)}
|