@blocklet/payment-react 1.21.13 → 1.21.15
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/.aigne/doc-smith/config.yaml +2 -2
- package/es/components/country-select.d.ts +6 -2
- package/es/components/country-select.js +170 -30
- package/es/components/source-data-viewer.js +25 -14
- package/es/history/credit/transactions-list.js +11 -1
- package/es/index.d.ts +1 -0
- package/es/libs/validator.d.ts +161 -0
- package/es/libs/validator.js +172 -61
- package/es/locales/en.js +1 -0
- package/es/locales/zh.js +1 -0
- package/es/payment/form/address.d.ts +1 -2
- package/es/payment/form/address.js +52 -41
- package/es/payment/form/index.js +133 -13
- package/lib/components/country-select.d.ts +6 -2
- package/lib/components/country-select.js +173 -40
- package/lib/components/source-data-viewer.js +5 -3
- package/lib/history/credit/transactions-list.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/libs/validator.d.ts +161 -0
- package/lib/libs/validator.js +173 -6
- package/lib/locales/en.js +1 -0
- package/lib/locales/zh.js +1 -0
- package/lib/payment/form/address.d.ts +1 -2
- package/lib/payment/form/address.js +63 -55
- package/lib/payment/form/index.js +171 -12
- package/package.json +3 -3
- package/src/components/country-select.tsx +176 -25
- package/src/components/source-data-viewer.tsx +9 -3
- package/src/history/credit/transactions-list.tsx +6 -1
- package/src/index.ts +2 -0
- package/src/libs/validator.ts +173 -61
- package/src/locales/en.tsx +1 -0
- package/src/locales/zh.tsx +1 -0
- package/src/payment/form/address.tsx +56 -50
- package/src/payment/form/index.tsx +160 -12
package/es/libs/validator.js
CHANGED
|
@@ -1,68 +1,179 @@
|
|
|
1
|
-
import isPostalCode from "validator/lib/isPostalCode";
|
|
2
1
|
import { t } from "../locales/index.js";
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
2
|
+
const threeDigit = /^\d{3}$/;
|
|
3
|
+
const fourDigit = /^\d{4}$/;
|
|
4
|
+
const fiveDigit = /^\d{5}$/;
|
|
5
|
+
const sixDigit = /^\d{6}$/;
|
|
6
|
+
export const postalCodePatterns = {
|
|
7
|
+
GB: /^GIR[ ]?0AA|((AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GY|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|JE|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}))|BFPO[ ]?\d{1,4}$/i,
|
|
8
|
+
JE: /^JE\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}$/i,
|
|
9
|
+
GG: /^GY\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}$/i,
|
|
10
|
+
IM: /^IM\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}$/i,
|
|
11
|
+
US: /^\d{5}([ -]\d{4})?$/,
|
|
12
|
+
CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ ]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
|
|
13
|
+
DE: /^\d{5}$/,
|
|
14
|
+
JP: /^\d{3}-?\d{4}$/,
|
|
15
|
+
FR: /^\d{2}[ ]?\d{3}$/,
|
|
16
|
+
AU: fourDigit,
|
|
17
|
+
IT: /^\d{5}$/,
|
|
18
|
+
CH: fourDigit,
|
|
19
|
+
AT: fourDigit,
|
|
20
|
+
ES: /^\d{5}$/,
|
|
21
|
+
NL: /^\d{4}[ ]?[A-Z]{2}$/i,
|
|
22
|
+
BE: fourDigit,
|
|
23
|
+
DK: fourDigit,
|
|
24
|
+
SE: /^\d{3}[ ]?\d{2}$/,
|
|
25
|
+
NO: fourDigit,
|
|
26
|
+
BR: /^\d{5}-?\d{3}$/,
|
|
27
|
+
PT: /^\d{4}(-\d{3})?$/,
|
|
28
|
+
FI: fiveDigit,
|
|
29
|
+
AX: /^22\d{3}$/,
|
|
30
|
+
KR: /^\d{5}$/,
|
|
31
|
+
// 2015年起使用5位数字邮编
|
|
32
|
+
CN: /^\d{6}$/,
|
|
33
|
+
TW: /^\d{3}(\d{2})?$/,
|
|
34
|
+
SG: sixDigit,
|
|
35
|
+
DZ: fiveDigit,
|
|
36
|
+
AD: /^AD\d{3}$/,
|
|
37
|
+
AR: /^([A-HJ-NP-Z])?\d{4}([A-Z]{3})?$/i,
|
|
38
|
+
AM: /^(37)?\d{4}$/,
|
|
39
|
+
AZ: /^\d{4}$/,
|
|
40
|
+
BH: /^((1[0-2]|[2-9])\d{2})?$/,
|
|
41
|
+
BD: fourDigit,
|
|
42
|
+
BB: /^(BB\d{5})?$/i,
|
|
43
|
+
BY: sixDigit,
|
|
44
|
+
BM: /^[A-Z]{2}[ ]?[A-Z0-9]{2}$/i,
|
|
45
|
+
BA: /^\d{5}$/,
|
|
46
|
+
IO: /^BBND 1ZZ$/i,
|
|
47
|
+
BN: /^[A-Z]{2}[ ]?\d{4}$/i,
|
|
48
|
+
BG: fourDigit,
|
|
49
|
+
KH: fiveDigit,
|
|
50
|
+
CV: fourDigit,
|
|
51
|
+
CL: /^\d{7}$/,
|
|
52
|
+
CR: /^\d{4,5}|\d{3}-\d{4}$/,
|
|
53
|
+
HR: /^\d{5}$/,
|
|
54
|
+
CY: fourDigit,
|
|
55
|
+
CZ: /^\d{3}[ ]?\d{2}$/,
|
|
56
|
+
DO: fiveDigit,
|
|
57
|
+
EC: /^([A-Z]\d{4}[A-Z]|(?:[A-Z]{2})?\d{6})?$/i,
|
|
58
|
+
EG: fiveDigit,
|
|
59
|
+
EE: fiveDigit,
|
|
60
|
+
FO: threeDigit,
|
|
61
|
+
GE: fourDigit,
|
|
62
|
+
GR: /^\d{3}[ ]?\d{2}$/,
|
|
63
|
+
GL: /^39\d{2}$/,
|
|
64
|
+
GT: fiveDigit,
|
|
65
|
+
HT: /^\d{4}$/,
|
|
66
|
+
HN: /^(?:\d{5})?$/,
|
|
67
|
+
HU: fourDigit,
|
|
68
|
+
IS: threeDigit,
|
|
69
|
+
IN: /^[1-9]\d{5}$/,
|
|
70
|
+
ID: fiveDigit,
|
|
71
|
+
IL: fiveDigit,
|
|
72
|
+
JO: fiveDigit,
|
|
73
|
+
KZ: sixDigit,
|
|
74
|
+
KE: fiveDigit,
|
|
75
|
+
KW: fiveDigit,
|
|
76
|
+
LA: fiveDigit,
|
|
77
|
+
LV: fourDigit,
|
|
78
|
+
LB: /^(\d{4}([ ]?\d{4})?)?$/,
|
|
79
|
+
LI: /^(948[5-9])|(949[0-7])$/,
|
|
80
|
+
LT: fiveDigit,
|
|
81
|
+
LU: fourDigit,
|
|
82
|
+
MK: fourDigit,
|
|
83
|
+
MY: fiveDigit,
|
|
84
|
+
MV: fiveDigit,
|
|
85
|
+
MT: /^[A-Z]{3}[ ]?\d{2,4}$/i,
|
|
86
|
+
MU: /^(\d{3}[A-Z]{2}\d{3})?$/i,
|
|
87
|
+
MX: fiveDigit,
|
|
88
|
+
MD: fourDigit,
|
|
89
|
+
MC: /^980\d{2}$/,
|
|
90
|
+
MA: fiveDigit,
|
|
91
|
+
NP: fiveDigit,
|
|
92
|
+
NZ: fourDigit,
|
|
93
|
+
NI: /^((\d{4}-)?\d{3}-\d{3}(-\d{1})?)?$/,
|
|
94
|
+
NG: /^(\d{6})?$/,
|
|
95
|
+
OM: /^(PC )?\d{3}$/i,
|
|
96
|
+
PK: fiveDigit,
|
|
97
|
+
PY: fourDigit,
|
|
98
|
+
PH: fourDigit,
|
|
99
|
+
PL: /^\d{2}-\d{3}$/,
|
|
100
|
+
PR: /^00[679]\d{2}([ -]\d{4})?$/,
|
|
101
|
+
RO: sixDigit,
|
|
102
|
+
RU: sixDigit,
|
|
103
|
+
SM: /^4789\d$/,
|
|
104
|
+
SA: fiveDigit,
|
|
105
|
+
SN: fiveDigit,
|
|
106
|
+
SK: /^\d{3}[ ]?\d{2}$/,
|
|
107
|
+
SI: fourDigit,
|
|
108
|
+
ZA: fourDigit,
|
|
109
|
+
LK: fiveDigit,
|
|
110
|
+
TJ: sixDigit,
|
|
111
|
+
TH: fiveDigit,
|
|
112
|
+
TN: fourDigit,
|
|
113
|
+
TR: fiveDigit,
|
|
114
|
+
TM: sixDigit,
|
|
115
|
+
UA: fiveDigit,
|
|
116
|
+
UY: fiveDigit,
|
|
117
|
+
UZ: sixDigit,
|
|
118
|
+
VA: /^00120$/,
|
|
119
|
+
VE: fourDigit,
|
|
120
|
+
ZM: fiveDigit,
|
|
121
|
+
// Territories & special regions
|
|
122
|
+
AS: /^96799$/,
|
|
123
|
+
CC: /^6799$/,
|
|
124
|
+
CK: fourDigit,
|
|
125
|
+
RS: sixDigit,
|
|
126
|
+
ME: /^8\d{4}$/,
|
|
127
|
+
CS: /^\d{5}$/,
|
|
128
|
+
// historical
|
|
129
|
+
YU: /^\d{5}$/,
|
|
130
|
+
// historical
|
|
131
|
+
CX: /^6798$/,
|
|
132
|
+
ET: fourDigit,
|
|
133
|
+
FK: /^FIQQ 1ZZ$/i,
|
|
134
|
+
NF: /^2899$/,
|
|
135
|
+
FM: /^(9694[1-4])([ -]\d{4})?$/,
|
|
136
|
+
GF: /^9[78]3\d{2}$/,
|
|
137
|
+
GN: threeDigit,
|
|
138
|
+
GP: /^9[78][01]\d{2}$/,
|
|
139
|
+
GS: /^SIQQ 1ZZ$/i,
|
|
140
|
+
GU: /^969[123]\d([ -]\d{4})?$/,
|
|
141
|
+
GW: fourDigit,
|
|
142
|
+
HM: fourDigit,
|
|
143
|
+
IQ: fiveDigit,
|
|
144
|
+
KG: sixDigit,
|
|
145
|
+
LR: fourDigit,
|
|
146
|
+
LS: threeDigit,
|
|
147
|
+
MG: threeDigit,
|
|
148
|
+
MH: /^969[67]\d([ -]\d{4})?$/,
|
|
149
|
+
MN: sixDigit,
|
|
150
|
+
MP: /^9695[012]([ -]\d{4})?$/,
|
|
151
|
+
MQ: /^9[78]2\d{2}$/,
|
|
152
|
+
NC: /^988\d{2}$/,
|
|
153
|
+
NE: fourDigit,
|
|
154
|
+
VI: /^008(([0-4]\d)|(5[01]))([ -]\d{4})?$/,
|
|
155
|
+
VN: sixDigit,
|
|
156
|
+
PF: /^987\d{2}$/,
|
|
157
|
+
PG: threeDigit,
|
|
158
|
+
PM: /^9[78]5\d{2}$/,
|
|
159
|
+
PN: /^PCRN 1ZZ$/i,
|
|
160
|
+
PW: /^96940$/,
|
|
161
|
+
RE: /^9[78]4\d{2}$/,
|
|
162
|
+
SH: /^(ASCN|STHL) 1ZZ$/i,
|
|
163
|
+
SJ: fourDigit,
|
|
164
|
+
SO: fiveDigit,
|
|
165
|
+
SZ: /^[HLMS]\d{3}$/i,
|
|
166
|
+
TC: /^TKCA 1ZZ$/i,
|
|
167
|
+
WF: /^986\d{2}$/,
|
|
168
|
+
XK: fiveDigit,
|
|
169
|
+
YT: /^976\d{2}$/
|
|
170
|
+
};
|
|
60
171
|
export function validatePostalCode(postalCode, country) {
|
|
61
172
|
if (!postalCode) return true;
|
|
62
|
-
const countryUpper = country?.toUpperCase();
|
|
63
|
-
const isSupported = country && POSTAL_CODE_SUPPORTED_COUNTRIES.includes(countryUpper);
|
|
64
173
|
try {
|
|
65
|
-
|
|
174
|
+
const countryUpper = country?.toUpperCase();
|
|
175
|
+
if (!countryUpper) return false;
|
|
176
|
+
return !postalCodePatterns[countryUpper] || postalCodePatterns[countryUpper].test(postalCode);
|
|
66
177
|
} catch (error) {
|
|
67
178
|
console.error(error);
|
|
68
179
|
return false;
|
package/es/locales/en.js
CHANGED
|
@@ -221,6 +221,7 @@ export default flat({
|
|
|
221
221
|
phonePlaceholder: "Phone number",
|
|
222
222
|
phoneTip: "In case we need to contact you about your order"
|
|
223
223
|
},
|
|
224
|
+
customerInfo: "Customer Information",
|
|
224
225
|
upsell: {
|
|
225
226
|
save: "Save with {recurring} billing",
|
|
226
227
|
revert: "Switch to {recurring} billing",
|
package/es/locales/zh.js
CHANGED
|
@@ -221,6 +221,7 @@ export default flat({
|
|
|
221
221
|
phonePlaceholder: "\u7535\u8BDD\u53F7\u7801",
|
|
222
222
|
phoneTip: "\u4EE5\u9632\u9700\u8981\u4E0E\u60A8\u8054\u7CFB\u6709\u5173\u60A8\u7684\u8BA2\u5355"
|
|
223
223
|
},
|
|
224
|
+
customerInfo: "\u5BA2\u6237\u4FE1\u606F",
|
|
224
225
|
upsell: {
|
|
225
226
|
save: "\u4F7F\u7528{recurring}\u8BA1\u8D39\u65B9\u5F0F",
|
|
226
227
|
revert: "\u5207\u6362\u5230{recurring}\u8BA1\u8D39\u65B9\u5F0F",
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { SxProps } from '@mui/material';
|
|
2
2
|
type Props = {
|
|
3
3
|
mode: string;
|
|
4
|
-
stripe: boolean;
|
|
5
4
|
sx?: SxProps;
|
|
6
5
|
fieldValidation?: Record<string, any>;
|
|
7
6
|
errorPosition?: 'right' | 'bottom';
|
|
8
7
|
};
|
|
9
|
-
export default function AddressForm({ mode,
|
|
8
|
+
export default function AddressForm({ mode, sx, fieldValidation, errorPosition }: Props): import("react").JSX.Element;
|
|
10
9
|
export {};
|
|
@@ -6,7 +6,7 @@ import FormInput from "../../components/input.js";
|
|
|
6
6
|
import FormLabel from "../../components/label.js";
|
|
7
7
|
import CountrySelect from "../../components/country-select.js";
|
|
8
8
|
import { getFieldValidation, validatePostalCode } from "../../libs/validator.js";
|
|
9
|
-
export default function AddressForm({ mode,
|
|
9
|
+
export default function AddressForm({ mode, sx = {}, fieldValidation = {}, errorPosition = "right" }) {
|
|
10
10
|
const { t, locale } = useLocaleContext();
|
|
11
11
|
const { control } = useFormContext();
|
|
12
12
|
const country = useWatch({ control, name: "billing_address.country" });
|
|
@@ -95,48 +95,59 @@ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation = {
|
|
|
95
95
|
)
|
|
96
96
|
] }) }) });
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
98
|
+
return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsx(Stack, { className: "cko-payment-address cko-payment-form", sx, children: /* @__PURE__ */ jsxs(Stack, { direction: "column", className: "cko-payment-form", spacing: 0, children: [
|
|
99
|
+
/* @__PURE__ */ jsx(FormLabel, { className: "base-label", children: t("payment.checkout.billing.state") }),
|
|
100
|
+
/* @__PURE__ */ jsx(
|
|
101
|
+
FormInput,
|
|
102
|
+
{
|
|
103
|
+
name: "billing_address.state",
|
|
104
|
+
rules: {
|
|
105
|
+
required: t("payment.checkout.required"),
|
|
106
|
+
...getFieldValidation("billing_address.state", fieldValidation, locale)
|
|
107
|
+
},
|
|
108
|
+
errorPosition,
|
|
109
|
+
variant: "outlined",
|
|
110
|
+
placeholder: t("payment.checkout.billing.state")
|
|
111
|
+
}
|
|
112
|
+
),
|
|
113
|
+
/* @__PURE__ */ jsx(FormLabel, { className: "base-label", children: t("payment.checkout.billing.postal_code") }),
|
|
114
|
+
/* @__PURE__ */ jsx(Stack, { direction: "row", spacing: 0, children: /* @__PURE__ */ jsx(
|
|
115
|
+
FormInput,
|
|
116
|
+
{
|
|
117
|
+
name: "billing_address.postal_code",
|
|
118
|
+
rules: {
|
|
119
|
+
required: t("payment.checkout.required"),
|
|
120
|
+
validate: (x) => {
|
|
121
|
+
const isValid = validatePostalCode(x, country);
|
|
122
|
+
return isValid ? true : t("payment.checkout.invalid");
|
|
112
123
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
...getFieldValidation("billing_address.postal_code", fieldValidation, locale)
|
|
125
|
+
},
|
|
126
|
+
errorPosition,
|
|
127
|
+
variant: "outlined",
|
|
128
|
+
placeholder: t("payment.checkout.billing.postal_code"),
|
|
129
|
+
InputProps: {
|
|
130
|
+
startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", style: { marginRight: "2px", marginLeft: "-8px" }, children: /* @__PURE__ */ jsx(
|
|
131
|
+
Controller,
|
|
132
|
+
{
|
|
133
|
+
name: "billing_address.country",
|
|
134
|
+
control,
|
|
135
|
+
render: ({ field }) => /* @__PURE__ */ jsx(
|
|
136
|
+
CountrySelect,
|
|
137
|
+
{
|
|
138
|
+
...field,
|
|
139
|
+
ref: field.ref,
|
|
140
|
+
sx: {
|
|
141
|
+
".MuiOutlinedInput-notchedOutline": {
|
|
142
|
+
borderColor: "transparent !important"
|
|
131
143
|
}
|
|
132
144
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
) })
|
|
137
149
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
return null;
|
|
150
|
+
}
|
|
151
|
+
) })
|
|
152
|
+
] }) }) });
|
|
142
153
|
}
|
package/es/payment/form/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import "react-international-phone/style.css";
|
|
3
3
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
4
|
+
import { FlagEmoji } from "react-international-phone";
|
|
4
5
|
import Toast from "@arcblock/ux/lib/Toast";
|
|
5
6
|
import { Box, Button, CircularProgress, Divider, Fade, Stack, Tooltip, Typography } from "@mui/material";
|
|
6
7
|
import { useMemoizedFn, useSetState } from "ahooks";
|
|
@@ -40,7 +41,7 @@ import LoadingButton from "../../components/loading-button.js";
|
|
|
40
41
|
import OverdueInvoicePayment from "../../components/over-due-invoice-payment.js";
|
|
41
42
|
import { saveCurrencyPreference } from "../../libs/currency.js";
|
|
42
43
|
import ConfirmDialog from "../../components/confirm.js";
|
|
43
|
-
import { getFieldValidation } from "../../libs/validator.js";
|
|
44
|
+
import { getFieldValidation, validatePostalCode } from "../../libs/validator.js";
|
|
44
45
|
export const waitForCheckoutComplete = async (sessionId) => {
|
|
45
46
|
let result;
|
|
46
47
|
await pWaitFor(
|
|
@@ -136,7 +137,8 @@ export default function PaymentForm({
|
|
|
136
137
|
customerLimited: false,
|
|
137
138
|
stripePaying: false,
|
|
138
139
|
fastCheckoutInfo: null,
|
|
139
|
-
creditInsufficientInfo: null
|
|
140
|
+
creditInsufficientInfo: null,
|
|
141
|
+
showEditForm: false
|
|
140
142
|
});
|
|
141
143
|
const currencies = flattenPaymentMethods(paymentMethods);
|
|
142
144
|
const searchParams = getQueryParams(window.location.href);
|
|
@@ -244,25 +246,97 @@ export default function PaymentForm({
|
|
|
244
246
|
const paymentCurrency = currencies.find((x) => x.id === paymentCurrencyId);
|
|
245
247
|
const showStake = method.type === "arcblock" && !checkoutSession.subscription_data?.no_stake;
|
|
246
248
|
const isDonationMode = checkoutSession?.submit_type === "donate" && isDonation;
|
|
247
|
-
const
|
|
249
|
+
const validateUserInfo = () => {
|
|
248
250
|
if (!session?.user) {
|
|
249
251
|
return false;
|
|
250
252
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
+
const { fullName, name, email, phone, address } = session.user;
|
|
254
|
+
const fieldValidation = checkoutSession.metadata?.page_info?.field_validation;
|
|
255
|
+
const hasName = !!(fullName || name);
|
|
256
|
+
if (!hasName) {
|
|
257
|
+
return false;
|
|
253
258
|
}
|
|
254
|
-
|
|
255
|
-
|
|
259
|
+
const hasValidEmail = email && isEmail(email);
|
|
260
|
+
if (!hasValidEmail) {
|
|
261
|
+
return false;
|
|
256
262
|
}
|
|
257
|
-
const
|
|
258
|
-
if (
|
|
259
|
-
|
|
263
|
+
const nameValidation = getFieldValidation("customer_name", fieldValidation, locale);
|
|
264
|
+
if (nameValidation.pattern && fullName) {
|
|
265
|
+
const pattern = nameValidation.pattern.value;
|
|
266
|
+
if (!pattern.test(fullName)) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const emailValidation = getFieldValidation("customer_email", fieldValidation, locale);
|
|
271
|
+
if (emailValidation.pattern && email) {
|
|
272
|
+
const pattern = emailValidation.pattern.value;
|
|
273
|
+
if (!pattern.test(email)) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (!address || !address.postalCode || !validatePostalCode(address.postalCode, address.country)) {
|
|
278
|
+
return false;
|
|
260
279
|
}
|
|
261
|
-
|
|
280
|
+
const postalCodeValidation = getFieldValidation("billing_address.postal_code", fieldValidation, locale);
|
|
281
|
+
if (postalCodeValidation.pattern) {
|
|
282
|
+
const pattern = postalCodeValidation.pattern.value;
|
|
283
|
+
if (!pattern.test(address.postalCode)) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (!address.province) {
|
|
262
288
|
return false;
|
|
263
289
|
}
|
|
290
|
+
const stateValidation = getFieldValidation("billing_address.state", fieldValidation, locale);
|
|
291
|
+
if (stateValidation.pattern) {
|
|
292
|
+
const pattern = stateValidation.pattern.value;
|
|
293
|
+
if (!pattern.test(address.province)) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (checkoutSession.phone_number_collection?.enabled) {
|
|
298
|
+
if (!phone || phone.trim() === "") {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
const phoneValidation = getFieldValidation("customer_phone", fieldValidation, locale);
|
|
302
|
+
if (phoneValidation.pattern) {
|
|
303
|
+
const pattern = phoneValidation.pattern.value;
|
|
304
|
+
if (!pattern.test(phone)) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const addressMode = checkoutSession.billing_address_collection;
|
|
310
|
+
if (addressMode === "required") {
|
|
311
|
+
if (!address?.country || !address?.province || !address?.line1 || !address?.city || !address?.postalCode) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
const line1Validation = getFieldValidation("billing_address.line1", fieldValidation, locale);
|
|
315
|
+
if (line1Validation.pattern) {
|
|
316
|
+
const pattern = line1Validation.pattern.value;
|
|
317
|
+
if (!pattern.test(address.line1)) {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const cityValidation = getFieldValidation("billing_address.city", fieldValidation, locale);
|
|
322
|
+
if (cityValidation.pattern) {
|
|
323
|
+
const pattern = cityValidation.pattern.value;
|
|
324
|
+
if (!pattern.test(address.city)) {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
264
329
|
return true;
|
|
265
|
-
}
|
|
330
|
+
};
|
|
331
|
+
const showForm = useMemo(() => {
|
|
332
|
+
if (!session?.user) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
if (state.showEditForm) {
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
return !validateUserInfo();
|
|
339
|
+
}, [session?.user, method, state.showEditForm]);
|
|
266
340
|
const handleConnected = async () => {
|
|
267
341
|
if (processingRef.current) {
|
|
268
342
|
return;
|
|
@@ -755,6 +829,53 @@ export default function PaymentForm({
|
|
|
755
829
|
]
|
|
756
830
|
}
|
|
757
831
|
) }),
|
|
832
|
+
!showForm && session?.user && /* @__PURE__ */ jsxs(
|
|
833
|
+
Stack,
|
|
834
|
+
{
|
|
835
|
+
spacing: 1.25,
|
|
836
|
+
sx: {
|
|
837
|
+
mt: 2,
|
|
838
|
+
p: 2,
|
|
839
|
+
pt: 1,
|
|
840
|
+
backgroundColor: "background.paper",
|
|
841
|
+
borderRadius: 1,
|
|
842
|
+
border: "1px solid",
|
|
843
|
+
borderColor: "divider"
|
|
844
|
+
},
|
|
845
|
+
children: [
|
|
846
|
+
/* @__PURE__ */ jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", sx: { mb: 0.25 }, children: [
|
|
847
|
+
/* @__PURE__ */ jsx(Typography, { variant: "subtitle2", sx: { color: "text.primary", fontSize: "0.875rem" }, children: t("payment.checkout.customerInfo") }),
|
|
848
|
+
/* @__PURE__ */ jsx(
|
|
849
|
+
Button,
|
|
850
|
+
{
|
|
851
|
+
size: "small",
|
|
852
|
+
variant: "text",
|
|
853
|
+
onClick: () => setState({ showEditForm: true }),
|
|
854
|
+
sx: { minWidth: 0 },
|
|
855
|
+
children: t("common.edit")
|
|
856
|
+
}
|
|
857
|
+
)
|
|
858
|
+
] }),
|
|
859
|
+
/* @__PURE__ */ jsxs(Stack, { spacing: 0.5, children: [
|
|
860
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { color: "text.primary", fontWeight: 600, fontSize: "0.9375rem" }, children: session.user.fullName || session.user.name }),
|
|
861
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { color: "text.secondary", fontSize: "0.8125rem" }, children: session.user.email }),
|
|
862
|
+
checkoutSession.phone_number_collection?.enabled && session.user.phone && /* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { color: "text.secondary", fontSize: "0.8125rem" }, children: session.user.phone }),
|
|
863
|
+
session.user.address && /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 0.75, children: [
|
|
864
|
+
session.user.address.country && /* @__PURE__ */ jsx(FlagEmoji, { iso2: session.user.address.country.toLowerCase(), style: { width: 18, height: 14 } }),
|
|
865
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "body2", sx: { color: "text.secondary", fontSize: "0.8125rem" }, children: [
|
|
866
|
+
[
|
|
867
|
+
session.user.address.line1,
|
|
868
|
+
session.user.address.city,
|
|
869
|
+
session.user.address.province,
|
|
870
|
+
session.user.address.country?.toUpperCase()
|
|
871
|
+
].filter(Boolean).join(", "),
|
|
872
|
+
session.user.address.postalCode && ` [ ${t("payment.checkout.billing.postal_code")}: ${session.user.address.postalCode} ]`
|
|
873
|
+
] })
|
|
874
|
+
] })
|
|
875
|
+
] })
|
|
876
|
+
]
|
|
877
|
+
}
|
|
878
|
+
),
|
|
758
879
|
showForm && /* @__PURE__ */ jsxs(
|
|
759
880
|
Stack,
|
|
760
881
|
{
|
|
@@ -824,7 +945,6 @@ export default function PaymentForm({
|
|
|
824
945
|
AddressForm,
|
|
825
946
|
{
|
|
826
947
|
mode: checkoutSession.billing_address_collection,
|
|
827
|
-
stripe: method?.type === "stripe",
|
|
828
948
|
sx: { marginTop: "0 !important" },
|
|
829
949
|
fieldValidation: checkoutSession.metadata?.page_info?.field_validation,
|
|
830
950
|
errorPosition: formErrorPosition
|
|
@@ -3,10 +3,14 @@ import type { CountryIso2 } from 'react-international-phone';
|
|
|
3
3
|
export type CountrySelectProps = {
|
|
4
4
|
value: CountryIso2;
|
|
5
5
|
onChange: (value: CountryIso2) => void;
|
|
6
|
-
name
|
|
6
|
+
name?: string;
|
|
7
7
|
sx?: SxProps;
|
|
8
8
|
showDialCode?: boolean;
|
|
9
|
+
label?: string;
|
|
10
|
+
allowClear?: boolean;
|
|
11
|
+
bordered?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
9
13
|
};
|
|
10
|
-
export default function CountrySelect({ ref, value, onChange, name, sx, showDialCode, }: CountrySelectProps & {
|
|
14
|
+
export default function CountrySelect({ ref, value, onChange, name, sx, showDialCode, label, bordered, allowClear, disabled, }: CountrySelectProps & {
|
|
11
15
|
ref?: React.RefObject<HTMLDivElement | null>;
|
|
12
16
|
}): import("react").JSX.Element;
|