payment-kit 1.16.5 → 1.16.7

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.
@@ -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
@@ -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.5
17
+ version: 1.16.7
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.5",
3
+ "version": "1.16.7",
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.5",
56
+ "@blocklet/payment-react": "1.16.7",
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.5",
123
+ "@blocklet/payment-types": "1.16.7",
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": "74e38987168230f01af52d1aff14bfa6a18c0578"
169
+ "gitHead": "ebd2f35810953ca0a6c0c008a4c95f2296cccb38"
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({ mode: initialMode, hasSelected, onSelect, value, width, disabled }: Props) {
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
  ),
package/src/libs/util.ts CHANGED
@@ -92,8 +92,9 @@ export function getWebhookStatusColor(status: string) {
92
92
 
93
93
  export function getDefaultPriceCurrencyIdsFromProduct(product: TProductExpanded): string[] {
94
94
  return (
95
- product.prices.find((price) => price.id === product.default_price_id)?.currency_options.map((x) => x.currency_id) ||
96
- []
95
+ product.prices
96
+ .find((price) => price.id === product.default_price_id)
97
+ ?.currency_options?.map((x) => x.currency_id) || []
97
98
  );
98
99
  }
99
100
 
@@ -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')}