payment-kit 1.16.6 → 1.16.8
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/routes/customers.ts +7 -6
- package/api/src/routes/payment-methods.ts +25 -1
- package/blocklet.yml +1 -1
- package/package.json +4 -4
- package/src/components/price/currency-select.tsx +15 -4
- package/src/components/price/form.tsx +2 -0
- package/src/pages/admin/settings/payment-methods/index.tsx +92 -2
- package/src/pages/customer/index.tsx +16 -9
- package/src/pages/customer/subscription/embed.tsx +7 -3
|
@@ -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
|
|
|
@@ -4,7 +4,8 @@ import { ethers } from 'ethers';
|
|
|
4
4
|
import { Router } from 'express';
|
|
5
5
|
import pick from 'lodash/pick';
|
|
6
6
|
import { InferAttributes, Op, WhereOptions } from 'sequelize';
|
|
7
|
-
|
|
7
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
8
|
+
import merge from 'lodash/merge';
|
|
8
9
|
import { ensureWebhookRegistered } from '../integrations/stripe/setup';
|
|
9
10
|
import logger from '../libs/logger';
|
|
10
11
|
import { authenticate } from '../libs/security';
|
|
@@ -215,4 +216,27 @@ router.get('/:id', auth, async (req, res) => {
|
|
|
215
216
|
}
|
|
216
217
|
});
|
|
217
218
|
|
|
219
|
+
router.put('/:id/settings', auth, async (req, res) => {
|
|
220
|
+
const { id } = req.params;
|
|
221
|
+
const settings = req.body;
|
|
222
|
+
try {
|
|
223
|
+
const paymentMethod = await PaymentMethod.findOne({ where: { id } });
|
|
224
|
+
if (!paymentMethod) {
|
|
225
|
+
return res.status(400).json({ error: 'payment method not found' });
|
|
226
|
+
}
|
|
227
|
+
if (paymentMethod.type !== 'arcblock') {
|
|
228
|
+
return res
|
|
229
|
+
.status(400)
|
|
230
|
+
.json({ error: `Updating settings is not supported for the ${paymentMethod.type} payment method` });
|
|
231
|
+
}
|
|
232
|
+
const updateSettings = merge(cloneDeep(paymentMethod.settings), settings);
|
|
233
|
+
const doc = await paymentMethod.update({
|
|
234
|
+
settings: updateSettings,
|
|
235
|
+
});
|
|
236
|
+
return res.json(doc);
|
|
237
|
+
} catch (err) {
|
|
238
|
+
return res.status(400).json({ error: err.message });
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
218
242
|
export default router;
|
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.8",
|
|
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.8",
|
|
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.8",
|
|
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": "ad6dca32db4f5074471e000b714ff5046e06608f"
|
|
170
170
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
2
|
import { usePaymentContext } from '@blocklet/payment-react';
|
|
3
|
-
import { AddOutlined } from '@mui/icons-material';
|
|
4
|
-
import { ListSubheader, MenuItem, Select, Stack, Typography } from '@mui/material';
|
|
3
|
+
import { AddOutlined, ArrowDropDown } from '@mui/icons-material';
|
|
4
|
+
import { ListSubheader, MenuItem, Select, Stack, SxProps, Typography } from '@mui/material';
|
|
5
5
|
import { useState } from 'react';
|
|
6
6
|
import type { LiteralUnion } from 'type-fest';
|
|
7
7
|
|
|
@@ -16,14 +16,24 @@ type Props = {
|
|
|
16
16
|
value: string;
|
|
17
17
|
width?: string;
|
|
18
18
|
disabled?: boolean;
|
|
19
|
+
selectSX?: SxProps;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
CurrencySelect.defaultProps = {
|
|
22
23
|
width: '100%',
|
|
23
24
|
disabled: false,
|
|
25
|
+
selectSX: {},
|
|
24
26
|
};
|
|
25
27
|
|
|
26
|
-
export default function CurrencySelect({
|
|
28
|
+
export default function CurrencySelect({
|
|
29
|
+
mode: initialMode,
|
|
30
|
+
hasSelected,
|
|
31
|
+
onSelect,
|
|
32
|
+
value,
|
|
33
|
+
width,
|
|
34
|
+
disabled,
|
|
35
|
+
selectSX,
|
|
36
|
+
}: Props) {
|
|
27
37
|
const { t } = useLocaleContext();
|
|
28
38
|
const { settings } = usePaymentContext();
|
|
29
39
|
const [mode, setMode] = useState(initialMode);
|
|
@@ -57,6 +67,7 @@ export default function CurrencySelect({ mode: initialMode, hasSelected, onSelec
|
|
|
57
67
|
}}
|
|
58
68
|
sx={{ cursor: canSelect ? 'pointer' : 'default', display: 'inline-flex' }}>
|
|
59
69
|
{selectedCurrency?.symbol} ({selectedPaymentMethod?.name})
|
|
70
|
+
{canSelect && <ArrowDropDown sx={{ color: 'rgba(0, 0, 0, 0.54)', fontSize: 21 }} />}
|
|
60
71
|
</Typography>
|
|
61
72
|
);
|
|
62
73
|
}
|
|
@@ -77,7 +88,7 @@ export default function CurrencySelect({ mode: initialMode, hasSelected, onSelec
|
|
|
77
88
|
)}
|
|
78
89
|
onChange={handleSelect}
|
|
79
90
|
open
|
|
80
|
-
sx={{ width }}
|
|
91
|
+
sx={{ width, ...selectSX }}
|
|
81
92
|
disabled={disabled}
|
|
82
93
|
onClose={() => setMode(initialMode)}>
|
|
83
94
|
{extraCurrencies.map((method) => [
|
|
@@ -238,6 +238,7 @@ export default function PriceForm({ prefix, simple }: PriceFormProps) {
|
|
|
238
238
|
}}
|
|
239
239
|
value={defaultCurrencyId}
|
|
240
240
|
disabled={isLocked}
|
|
241
|
+
selectSX={{ '.MuiOutlinedInput-notchedOutline': { border: 'none' } }}
|
|
241
242
|
/>
|
|
242
243
|
</InputAdornment>
|
|
243
244
|
),
|
|
@@ -331,6 +332,7 @@ export default function PriceForm({ prefix, simple }: PriceFormProps) {
|
|
|
331
332
|
}}
|
|
332
333
|
value={currency?.id!}
|
|
333
334
|
disabled={isLocked}
|
|
335
|
+
selectSX={{ '.MuiOutlinedInput-notchedOutline': { border: 'none' } }}
|
|
334
336
|
/>
|
|
335
337
|
</InputAdornment>
|
|
336
338
|
),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
|
-
import { Switch, api } from '@blocklet/payment-react';
|
|
2
|
+
import { Switch, api, formatError } from '@blocklet/payment-react';
|
|
3
3
|
import type { TPaymentMethodExpanded } from '@blocklet/payment-types';
|
|
4
|
-
import { AddOutlined, DeleteOutlined } from '@mui/icons-material';
|
|
4
|
+
import { AddOutlined, Check, Close, DeleteOutlined, EditOutlined } from '@mui/icons-material';
|
|
5
5
|
import {
|
|
6
6
|
Alert,
|
|
7
7
|
Avatar,
|
|
@@ -13,11 +13,15 @@ import {
|
|
|
13
13
|
ListItem,
|
|
14
14
|
ListItemAvatar,
|
|
15
15
|
ListItemText,
|
|
16
|
+
Stack,
|
|
17
|
+
TextField,
|
|
16
18
|
Typography,
|
|
17
19
|
} from '@mui/material';
|
|
18
20
|
import { useRequest, useSetState } from 'ahooks';
|
|
19
21
|
import useBus from 'use-bus';
|
|
20
22
|
|
|
23
|
+
import { useState } from 'react';
|
|
24
|
+
import Toast from '@arcblock/ux/lib/Toast';
|
|
21
25
|
import IconCollapse from '../../../../components/collapse';
|
|
22
26
|
import InfoCard from '../../../../components/info-card';
|
|
23
27
|
import InfoRow from '../../../../components/info-row';
|
|
@@ -31,6 +35,91 @@ const getMethods = (params: Record<string, any> = {}): Promise<TPaymentMethodExp
|
|
|
31
35
|
return api.get(`/api/payment-methods?${search.toString()}`).then((res) => res.data);
|
|
32
36
|
};
|
|
33
37
|
|
|
38
|
+
const updateApiHost = (id: string, apiHost: string) => {
|
|
39
|
+
return api.put(`/api/payment-methods/${id}/settings`, { arcblock: { api_host: apiHost } }).then((res) => res.data);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function EditApiHost({ method }: { method: TPaymentMethodExpanded }) {
|
|
43
|
+
const [edit, setEdit] = useState(false);
|
|
44
|
+
const { t } = useLocaleContext();
|
|
45
|
+
const [value, setValue] = useState(method.settings?.arcblock?.api_host || '');
|
|
46
|
+
const [tempValue, setTempValue] = useState(value);
|
|
47
|
+
const [error, setError] = useState('');
|
|
48
|
+
|
|
49
|
+
const handleSave = async () => {
|
|
50
|
+
if (!tempValue.trim()) {
|
|
51
|
+
setError(t('common.required'));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
await updateApiHost(method.id, tempValue);
|
|
56
|
+
Toast.success(t('common.saved'));
|
|
57
|
+
setValue(tempValue);
|
|
58
|
+
setEdit(false);
|
|
59
|
+
setError('');
|
|
60
|
+
} catch (err) {
|
|
61
|
+
Toast.error(formatError(err));
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const handleCancel = () => {
|
|
66
|
+
setTempValue(value);
|
|
67
|
+
setEdit(false);
|
|
68
|
+
setError('');
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<InfoRow
|
|
73
|
+
label={t('admin.paymentMethod.arcblock.api_host.label')}
|
|
74
|
+
value={
|
|
75
|
+
<Stack direction="row" alignItems="center" spacing={1} flexWrap="wrap">
|
|
76
|
+
{edit ? (
|
|
77
|
+
<>
|
|
78
|
+
<TextField
|
|
79
|
+
value={tempValue}
|
|
80
|
+
onChange={(e) => {
|
|
81
|
+
const val = e.target.value;
|
|
82
|
+
if (!val) {
|
|
83
|
+
setError(t('common.required'));
|
|
84
|
+
} else {
|
|
85
|
+
setError('');
|
|
86
|
+
}
|
|
87
|
+
setTempValue(val);
|
|
88
|
+
}}
|
|
89
|
+
variant="outlined"
|
|
90
|
+
size="small"
|
|
91
|
+
sx={{ flex: 1 }}
|
|
92
|
+
placeholder={t('admin.paymentMethod.arcblock.api_host.tip')}
|
|
93
|
+
error={!!error}
|
|
94
|
+
InputProps={{
|
|
95
|
+
endAdornment: error ? (
|
|
96
|
+
<Typography color="error" sx={{ whiteSpace: 'nowrap' }}>
|
|
97
|
+
{error}
|
|
98
|
+
</Typography>
|
|
99
|
+
) : undefined,
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
<IconButton onClick={handleSave} size="small">
|
|
103
|
+
<Check />
|
|
104
|
+
</IconButton>
|
|
105
|
+
<IconButton onClick={handleCancel} size="small">
|
|
106
|
+
<Close />
|
|
107
|
+
</IconButton>
|
|
108
|
+
</>
|
|
109
|
+
) : (
|
|
110
|
+
<>
|
|
111
|
+
<Typography variant="body2">{value}</Typography>
|
|
112
|
+
<IconButton onClick={() => setEdit(true)} size="small">
|
|
113
|
+
<EditOutlined fontSize="small" />
|
|
114
|
+
</IconButton>
|
|
115
|
+
</>
|
|
116
|
+
)}
|
|
117
|
+
</Stack>
|
|
118
|
+
}
|
|
119
|
+
/>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
34
123
|
const groupByType = (methods: TPaymentMethodExpanded[]) => {
|
|
35
124
|
const groups: Record<string, TPaymentMethodExpanded[]> = {};
|
|
36
125
|
methods.forEach((x) => {
|
|
@@ -80,6 +169,7 @@ export default function PaymentMethods() {
|
|
|
80
169
|
<Grid container spacing={2} mt={0}>
|
|
81
170
|
<Grid item xs={12} md={6}>
|
|
82
171
|
<InfoRow label={t('admin.paymentMethod.props.type')} value={method.type} />
|
|
172
|
+
{method.type === 'arcblock' && <EditApiHost method={method} />}
|
|
83
173
|
<InfoRow label={t('admin.paymentMethod.props.confirmation')} value={method.confirmation.type} />
|
|
84
174
|
<InfoRow
|
|
85
175
|
label={t('admin.paymentMethod.props.recurring')}
|
|
@@ -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
|
}
|
|
@@ -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)}
|