payment-kit 1.13.20 → 1.13.22
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/integrations/stripe.ts +2 -2
- package/blocklet.yml +1 -1
- package/package.json +3 -3
- package/src/components/checkout/form/index.tsx +2 -2
- package/src/components/checkout/form/phone.tsx +4 -3
- package/src/components/checkout/pay.tsx +2 -2
- package/src/components/customer/edit.tsx +8 -6
- package/src/components/customer/form.tsx +21 -7
- package/src/components/metadata/editor.tsx +6 -4
- package/src/components/metadata/form.tsx +14 -8
- package/src/components/payment-link/rename.tsx +7 -4
- package/src/components/product/add-price.tsx +6 -4
- package/src/components/product/create.tsx +6 -4
- package/src/components/product/edit-price.tsx +6 -4
- package/src/components/product/edit.tsx +6 -4
- package/src/libs/util.ts +5 -0
|
@@ -43,14 +43,14 @@ const handleEvent = async (req: Request, res: Response) => {
|
|
|
43
43
|
|
|
44
44
|
if (STRIPE_EVENTS.includes(stripeEvent.type) === false) {
|
|
45
45
|
logger.debug('webhook event not interested', { id: stripeEvent.id, type: stripeEvent.type });
|
|
46
|
-
return res.
|
|
46
|
+
return res.json({ skipped: true });
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// only events from this app should be processed
|
|
50
50
|
const appPid = get(stripeEvent, 'data.object.metadata.appPid');
|
|
51
51
|
if (appPid && appPid !== env.appPid) {
|
|
52
52
|
logger.debug('webhook event for other app', { id: stripeEvent.id, type: stripeEvent.type });
|
|
53
|
-
return res.json({
|
|
53
|
+
return res.json({ skipped: true });
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
logger.debug('webhook received event', { id: stripeEvent.id, type: stripeEvent.type });
|
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.22",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@arcblock/eslint-config": "^0.2.4",
|
|
102
102
|
"@arcblock/eslint-config-ts": "^0.2.4",
|
|
103
|
-
"@did-pay/types": "1.13.
|
|
103
|
+
"@did-pay/types": "1.13.22",
|
|
104
104
|
"@types/cookie-parser": "^1.4.4",
|
|
105
105
|
"@types/cors": "^2.8.14",
|
|
106
106
|
"@types/dotenv-flow": "^3.3.1",
|
|
@@ -137,5 +137,5 @@
|
|
|
137
137
|
"parser": "typescript"
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
|
-
"gitHead": "
|
|
140
|
+
"gitHead": "c8b53669ddb7118a2e43596548f031547b2d3da3"
|
|
141
141
|
}
|
|
@@ -215,9 +215,9 @@ export default function PaymentForm({
|
|
|
215
215
|
}
|
|
216
216
|
};
|
|
217
217
|
|
|
218
|
-
const onAction =
|
|
218
|
+
const onAction = () => {
|
|
219
219
|
if (session.user) {
|
|
220
|
-
|
|
220
|
+
handleSubmit(onSubmit)();
|
|
221
221
|
} else {
|
|
222
222
|
session.login({
|
|
223
223
|
onSuccess: onUserLoggedIn,
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
/* eslint-disable react/prop-types */
|
|
2
2
|
import { InputAdornment, MenuItem, Select, Typography } from '@mui/material';
|
|
3
|
+
import omit from 'lodash/omit';
|
|
3
4
|
import { useEffect } from 'react';
|
|
4
5
|
import { useFormContext, useWatch } from 'react-hook-form';
|
|
5
6
|
import { CountryIso2, FlagEmoji, defaultCountries, parseCountry, usePhoneInput } from 'react-international-phone';
|
|
6
7
|
|
|
8
|
+
import { isValidCountry } from '../../../libs/util';
|
|
7
9
|
import FormInput from '../../input';
|
|
8
10
|
|
|
9
|
-
const isValidCountry = (code: string) => defaultCountries.some((x) => x[1] === code);
|
|
10
|
-
|
|
11
11
|
export default function PhoneInput({ ...props }) {
|
|
12
12
|
const countryFieldName = props.countryFieldName || 'billing_address.country';
|
|
13
13
|
|
|
14
14
|
const { control, getValues, setValue } = useFormContext();
|
|
15
15
|
const values = getValues();
|
|
16
|
+
|
|
16
17
|
const { phone, handlePhoneValueChange, inputRef, country, setCountry } = usePhoneInput({
|
|
17
18
|
defaultCountry: isValidCountry(values[countryFieldName]) ? values[countryFieldName] : 'us',
|
|
18
19
|
value: values[props.name] || '',
|
|
@@ -96,7 +97,7 @@ export default function PhoneInput({ ...props }) {
|
|
|
96
97
|
</InputAdornment>
|
|
97
98
|
),
|
|
98
99
|
}}
|
|
99
|
-
{...props}
|
|
100
|
+
{...omit(props, ['countryFieldName'])}
|
|
100
101
|
/>
|
|
101
102
|
);
|
|
102
103
|
}
|
|
@@ -14,7 +14,7 @@ import { FormProvider, useForm } from 'react-hook-form';
|
|
|
14
14
|
|
|
15
15
|
import { useSessionContext } from '../../contexts/session';
|
|
16
16
|
import { useSettingsContext } from '../../contexts/settings';
|
|
17
|
-
import { findCurrency, formatError, getStatementDescriptor } from '../../libs/util';
|
|
17
|
+
import { findCurrency, formatError, getStatementDescriptor, isValidCountry } from '../../libs/util';
|
|
18
18
|
import PaymentError from './error';
|
|
19
19
|
import CheckoutFooter from './footer';
|
|
20
20
|
import PaymentForm from './form';
|
|
@@ -175,7 +175,7 @@ export function CheckoutPayMain({
|
|
|
175
175
|
postal_code: '',
|
|
176
176
|
},
|
|
177
177
|
customer?.address || {},
|
|
178
|
-
{ country: customer?.address?.country || 'us' }
|
|
178
|
+
{ country: isValidCountry(customer?.address?.country || '') ? customer?.address?.country : 'us' }
|
|
179
179
|
),
|
|
180
180
|
},
|
|
181
181
|
});
|
|
@@ -5,6 +5,7 @@ import { Button, CircularProgress, Stack } from '@mui/material';
|
|
|
5
5
|
import type { EventHandler } from 'react';
|
|
6
6
|
import { FormProvider, useForm } from 'react-hook-form';
|
|
7
7
|
|
|
8
|
+
import { isValidCountry } from '../../libs/util';
|
|
8
9
|
import CustomerForm from './form';
|
|
9
10
|
|
|
10
11
|
export default function EditCustomer({
|
|
@@ -34,16 +35,17 @@ export default function EditCustomer({
|
|
|
34
35
|
postal_code: '',
|
|
35
36
|
},
|
|
36
37
|
data.address || {},
|
|
37
|
-
{ country: data.address?.country || 'us' }
|
|
38
|
+
{ country: isValidCountry(data.address?.country || '') ? data.address?.country : 'us' }
|
|
38
39
|
),
|
|
39
40
|
},
|
|
40
41
|
});
|
|
41
42
|
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
const onSubmit = () => {
|
|
44
|
+
methods.handleSubmit(async (formData: any) => {
|
|
45
|
+
await onSave(formData);
|
|
46
|
+
methods.reset();
|
|
47
|
+
onCancel(null);
|
|
48
|
+
})();
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
return (
|
|
@@ -3,6 +3,8 @@ import 'react-international-phone/style.css';
|
|
|
3
3
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
4
4
|
import { InputAdornment, Stack, Typography } from '@mui/material';
|
|
5
5
|
import { PhoneNumberUtil } from 'google-libphonenumber';
|
|
6
|
+
import { Controller, useFormContext } from 'react-hook-form';
|
|
7
|
+
import { CountrySelector } from 'react-international-phone';
|
|
6
8
|
import isEmail from 'validator/es/lib/isEmail';
|
|
7
9
|
|
|
8
10
|
import PhoneInput from '../checkout/form/phone';
|
|
@@ -12,9 +14,10 @@ const phoneUtil = PhoneNumberUtil.getInstance();
|
|
|
12
14
|
|
|
13
15
|
export default function CustomerForm() {
|
|
14
16
|
const { t } = useLocaleContext();
|
|
17
|
+
const { control, setValue } = useFormContext();
|
|
15
18
|
|
|
16
19
|
return (
|
|
17
|
-
<Stack direction="column" spacing={
|
|
20
|
+
<Stack direction="column" spacing={1}>
|
|
18
21
|
<Typography component="h6" sx={{ mb: 1, color: 'text.primary', fontWeight: 600 }}>
|
|
19
22
|
{t('checkout.contact')}
|
|
20
23
|
</Typography>
|
|
@@ -64,39 +67,50 @@ export default function CustomerForm() {
|
|
|
64
67
|
<Typography component="h6" sx={{ mb: 1, color: 'text.primary', fontWeight: 600 }}>
|
|
65
68
|
{t('checkout.billing.required')}
|
|
66
69
|
</Typography>
|
|
70
|
+
<Controller
|
|
71
|
+
name="address.country"
|
|
72
|
+
control={control}
|
|
73
|
+
render={({ field }) => (
|
|
74
|
+
<CountrySelector
|
|
75
|
+
selectedCountry={field.value}
|
|
76
|
+
onSelect={({ iso2 }) => setValue(field.name, iso2)}
|
|
77
|
+
buttonStyle={{}}
|
|
78
|
+
/>
|
|
79
|
+
)}
|
|
80
|
+
/>
|
|
67
81
|
<FormInput
|
|
68
82
|
name="address.state"
|
|
69
|
-
rules={{}}
|
|
70
83
|
variant="outlined"
|
|
71
84
|
errorPosition="right"
|
|
85
|
+
label={t('checkout.billing.state')}
|
|
72
86
|
placeholder={t('checkout.billing.state')}
|
|
73
87
|
/>
|
|
74
88
|
<FormInput
|
|
75
89
|
name="address.city"
|
|
76
|
-
rules={{}}
|
|
77
90
|
variant="outlined"
|
|
78
91
|
errorPosition="right"
|
|
92
|
+
label={t('checkout.billing.city')}
|
|
79
93
|
placeholder={t('checkout.billing.city')}
|
|
80
94
|
/>
|
|
81
95
|
<FormInput
|
|
82
96
|
name="address.line1"
|
|
83
|
-
rules={{}}
|
|
84
97
|
variant="outlined"
|
|
85
98
|
errorPosition="right"
|
|
99
|
+
label={t('checkout.billing.line1')}
|
|
86
100
|
placeholder={t('checkout.billing.line1')}
|
|
87
101
|
/>
|
|
88
102
|
<FormInput
|
|
89
103
|
name="address.line2"
|
|
90
|
-
rules={{}}
|
|
91
104
|
variant="outlined"
|
|
92
105
|
errorPosition="right"
|
|
106
|
+
label={t('checkout.billing.line2')}
|
|
93
107
|
placeholder={t('checkout.billing.line2')}
|
|
94
108
|
/>
|
|
95
109
|
<FormInput
|
|
96
110
|
name="address.postal_code"
|
|
97
|
-
errorPosition="right"
|
|
98
|
-
rules={{ required: t('checkout.required') }}
|
|
99
111
|
variant="outlined"
|
|
112
|
+
errorPosition="right"
|
|
113
|
+
label={t('checkout.billing.postal_code')}
|
|
100
114
|
placeholder={t('checkout.billing.postal_code')}
|
|
101
115
|
/>
|
|
102
116
|
</Stack>
|
|
@@ -31,10 +31,12 @@ export default function MetadataEditor({
|
|
|
31
31
|
reset();
|
|
32
32
|
onCancel(e);
|
|
33
33
|
};
|
|
34
|
-
const onSubmit =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const onSubmit = () => {
|
|
35
|
+
handleSubmit(async (formData: any) => {
|
|
36
|
+
await onSave(formData);
|
|
37
|
+
reset();
|
|
38
|
+
onCancel(null);
|
|
39
|
+
})();
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
return (
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
2
|
import { AddOutlined, DeleteOutlineOutlined } from '@mui/icons-material';
|
|
3
|
-
import { Box, Button, IconButton, Stack,
|
|
4
|
-
import {
|
|
3
|
+
import { Box, Button, IconButton, Stack, Typography } from '@mui/material';
|
|
4
|
+
import { useFieldArray, useFormContext } from 'react-hook-form';
|
|
5
|
+
|
|
6
|
+
import FormInput from '../input';
|
|
5
7
|
|
|
6
8
|
export default function MetadataForm({ title, actions }: { title?: string; actions?: React.ReactNode }) {
|
|
7
9
|
const { t } = useLocaleContext();
|
|
@@ -13,15 +15,19 @@ export default function MetadataForm({ title, actions }: { title?: string; actio
|
|
|
13
15
|
{metadata.fields.map((meta, index) => (
|
|
14
16
|
<Stack key={meta.id} mt={2} spacing={2} direction="row" alignItems="center">
|
|
15
17
|
<Stack direction="row" spacing={2}>
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
+
<FormInput
|
|
19
|
+
sx={{ flex: 1 }}
|
|
20
|
+
size="small"
|
|
18
21
|
name={`metadata.${index}.key`}
|
|
19
|
-
|
|
22
|
+
rules={{ required: t('checkout.required') }}
|
|
23
|
+
placeholder="Key"
|
|
20
24
|
/>
|
|
21
|
-
<
|
|
22
|
-
|
|
25
|
+
<FormInput
|
|
26
|
+
sx={{ flex: 2 }}
|
|
27
|
+
size="small"
|
|
23
28
|
name={`metadata.${index}.value`}
|
|
24
|
-
|
|
29
|
+
placeholder="Value"
|
|
30
|
+
rules={{ required: t('checkout.required') }}
|
|
25
31
|
/>
|
|
26
32
|
</Stack>
|
|
27
33
|
<IconButton size="small" onClick={() => metadata.remove(index)}>
|
|
@@ -26,10 +26,12 @@ export default function RenamePaymentLink({
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
const { handleSubmit, reset } = methods;
|
|
29
|
-
const onSubmit =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const onSubmit = () => {
|
|
30
|
+
handleSubmit(async (formData: any) => {
|
|
31
|
+
await onSave(formData);
|
|
32
|
+
reset();
|
|
33
|
+
onCancel(null);
|
|
34
|
+
})();
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
return (
|
|
@@ -54,6 +56,7 @@ export default function RenamePaymentLink({
|
|
|
54
56
|
<FormProvider {...methods}>
|
|
55
57
|
<TextInput
|
|
56
58
|
name="name"
|
|
59
|
+
rules={{ required: true }}
|
|
57
60
|
label={t('admin.paymentLink.name.label')}
|
|
58
61
|
placeholder={t('admin.paymentLink.name.placeholder')}
|
|
59
62
|
autoFocus
|
|
@@ -26,10 +26,12 @@ export default function AddPrice({
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
const { handleSubmit, reset } = methods;
|
|
29
|
-
const onSubmit =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const onSubmit = () => {
|
|
30
|
+
handleSubmit(async (formData: any) => {
|
|
31
|
+
await onSave(formData);
|
|
32
|
+
reset();
|
|
33
|
+
onCancel(null);
|
|
34
|
+
})();
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
return (
|
|
@@ -57,10 +57,12 @@ export default function CreateProduct({
|
|
|
57
57
|
});
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
const onSubmit =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
const onSubmit = () => {
|
|
61
|
+
handleSubmit(async (formData: any) => {
|
|
62
|
+
await onCreate(formData);
|
|
63
|
+
await reset();
|
|
64
|
+
await onSave(null);
|
|
65
|
+
})();
|
|
64
66
|
};
|
|
65
67
|
|
|
66
68
|
return (
|
|
@@ -46,10 +46,12 @@ export default function EditPrice({
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
const { handleSubmit, reset } = methods;
|
|
49
|
-
const onSubmit =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
const onSubmit = () => {
|
|
50
|
+
handleSubmit(async (formData: any) => {
|
|
51
|
+
await onSave(formData);
|
|
52
|
+
reset();
|
|
53
|
+
onCancel(null);
|
|
54
|
+
})();
|
|
53
55
|
};
|
|
54
56
|
|
|
55
57
|
return (
|
|
@@ -34,10 +34,12 @@ export default function EditProduct({
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
const { handleSubmit, reset } = methods;
|
|
37
|
-
const onSubmit =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const onSubmit = () => {
|
|
38
|
+
handleSubmit(async (formData: any) => {
|
|
39
|
+
await onSave(formData);
|
|
40
|
+
reset();
|
|
41
|
+
onCancel(null);
|
|
42
|
+
})();
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
return (
|
package/src/libs/util.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
import { BN, fromUnitToToken } from '@ocap/util';
|
|
16
16
|
import cloneDeep from 'lodash/cloneDeep';
|
|
17
17
|
import isEqual from 'lodash/isEqual';
|
|
18
|
+
import { defaultCountries } from 'react-international-phone';
|
|
18
19
|
|
|
19
20
|
import dayjs from './dayjs';
|
|
20
21
|
|
|
@@ -567,3 +568,7 @@ export function getSupportedPaymentCurrencies(items: TLineItemExpanded[]) {
|
|
|
567
568
|
}, []);
|
|
568
569
|
return Array.from(new Set(currencies));
|
|
569
570
|
}
|
|
571
|
+
|
|
572
|
+
export function isValidCountry(code: string) {
|
|
573
|
+
return defaultCountries.some((x) => x[1] === code);
|
|
574
|
+
}
|