@blocklet/payment-react 1.21.12 → 1.21.14
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 +38 -41
- package/es/payment/form/index.js +130 -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 +51 -55
- package/lib/payment/form/index.js +168 -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 +45 -50
- package/src/payment/form/index.tsx +157 -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,45 @@ 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
|
-
return isValid ? true : t("payment.checkout.invalid");
|
|
110
|
-
},
|
|
111
|
-
...getFieldValidation("billing_address.postal_code", fieldValidation, locale)
|
|
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.postal_code") }),
|
|
100
|
+
/* @__PURE__ */ jsx(Stack, { direction: "row", spacing: 0, children: /* @__PURE__ */ jsx(
|
|
101
|
+
FormInput,
|
|
102
|
+
{
|
|
103
|
+
name: "billing_address.postal_code",
|
|
104
|
+
rules: {
|
|
105
|
+
required: t("payment.checkout.required"),
|
|
106
|
+
validate: (x) => {
|
|
107
|
+
const isValid = validatePostalCode(x, country);
|
|
108
|
+
return isValid ? true : t("payment.checkout.invalid");
|
|
112
109
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
110
|
+
...getFieldValidation("billing_address.postal_code", fieldValidation, locale)
|
|
111
|
+
},
|
|
112
|
+
errorPosition,
|
|
113
|
+
variant: "outlined",
|
|
114
|
+
placeholder: t("payment.checkout.billing.postal_code"),
|
|
115
|
+
InputProps: {
|
|
116
|
+
startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", style: { marginRight: "2px", marginLeft: "-8px" }, children: /* @__PURE__ */ jsx(
|
|
117
|
+
Controller,
|
|
118
|
+
{
|
|
119
|
+
name: "billing_address.country",
|
|
120
|
+
control,
|
|
121
|
+
render: ({ field }) => /* @__PURE__ */ jsx(
|
|
122
|
+
CountrySelect,
|
|
123
|
+
{
|
|
124
|
+
...field,
|
|
125
|
+
ref: field.ref,
|
|
126
|
+
sx: {
|
|
127
|
+
".MuiOutlinedInput-notchedOutline": {
|
|
128
|
+
borderColor: "transparent !important"
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
) })
|
|
137
135
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
return null;
|
|
136
|
+
}
|
|
137
|
+
) })
|
|
138
|
+
] }) }) });
|
|
142
139
|
}
|
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,94 @@ 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
|
+
}
|
|
260
276
|
}
|
|
261
|
-
if (
|
|
277
|
+
if (!address || !address.postalCode || !validatePostalCode(address.postalCode, address.country)) {
|
|
262
278
|
return false;
|
|
263
279
|
}
|
|
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 (checkoutSession.phone_number_collection?.enabled) {
|
|
288
|
+
if (!phone || phone.trim() === "") {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
const phoneValidation = getFieldValidation("customer_phone", fieldValidation, locale);
|
|
292
|
+
if (phoneValidation.pattern) {
|
|
293
|
+
const pattern = phoneValidation.pattern.value;
|
|
294
|
+
if (!pattern.test(phone)) {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const addressMode = checkoutSession.billing_address_collection;
|
|
300
|
+
if (addressMode === "required") {
|
|
301
|
+
if (!address?.country || !address?.province || !address?.line1 || !address?.city || !address?.postalCode) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
const line1Validation = getFieldValidation("billing_address.line1", fieldValidation, locale);
|
|
305
|
+
if (line1Validation.pattern) {
|
|
306
|
+
const pattern = line1Validation.pattern.value;
|
|
307
|
+
if (!pattern.test(address.line1)) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const cityValidation = getFieldValidation("billing_address.city", fieldValidation, locale);
|
|
312
|
+
if (cityValidation.pattern) {
|
|
313
|
+
const pattern = cityValidation.pattern.value;
|
|
314
|
+
if (!pattern.test(address.city)) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const stateValidation = getFieldValidation("billing_address.state", fieldValidation, locale);
|
|
319
|
+
if (stateValidation.pattern) {
|
|
320
|
+
const pattern = stateValidation.pattern.value;
|
|
321
|
+
if (!pattern.test(address.province)) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
264
326
|
return true;
|
|
265
|
-
}
|
|
327
|
+
};
|
|
328
|
+
const showForm = useMemo(() => {
|
|
329
|
+
if (!session?.user) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
if (state.showEditForm) {
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
return !validateUserInfo();
|
|
336
|
+
}, [session?.user, method, state.showEditForm]);
|
|
266
337
|
const handleConnected = async () => {
|
|
267
338
|
if (processingRef.current) {
|
|
268
339
|
return;
|
|
@@ -755,6 +826,53 @@ export default function PaymentForm({
|
|
|
755
826
|
]
|
|
756
827
|
}
|
|
757
828
|
) }),
|
|
829
|
+
!showForm && session?.user && /* @__PURE__ */ jsxs(
|
|
830
|
+
Stack,
|
|
831
|
+
{
|
|
832
|
+
spacing: 1.25,
|
|
833
|
+
sx: {
|
|
834
|
+
mt: 2,
|
|
835
|
+
p: 2,
|
|
836
|
+
pt: 1,
|
|
837
|
+
backgroundColor: "background.paper",
|
|
838
|
+
borderRadius: 1,
|
|
839
|
+
border: "1px solid",
|
|
840
|
+
borderColor: "divider"
|
|
841
|
+
},
|
|
842
|
+
children: [
|
|
843
|
+
/* @__PURE__ */ jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", sx: { mb: 0.25 }, children: [
|
|
844
|
+
/* @__PURE__ */ jsx(Typography, { variant: "subtitle2", sx: { color: "text.primary", fontSize: "0.875rem" }, children: t("payment.checkout.customerInfo") }),
|
|
845
|
+
/* @__PURE__ */ jsx(
|
|
846
|
+
Button,
|
|
847
|
+
{
|
|
848
|
+
size: "small",
|
|
849
|
+
variant: "text",
|
|
850
|
+
onClick: () => setState({ showEditForm: true }),
|
|
851
|
+
sx: { minWidth: 0 },
|
|
852
|
+
children: t("common.edit")
|
|
853
|
+
}
|
|
854
|
+
)
|
|
855
|
+
] }),
|
|
856
|
+
/* @__PURE__ */ jsxs(Stack, { spacing: 0.5, children: [
|
|
857
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { color: "text.primary", fontWeight: 600, fontSize: "0.9375rem" }, children: session.user.fullName || session.user.name }),
|
|
858
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { color: "text.secondary", fontSize: "0.8125rem" }, children: session.user.email }),
|
|
859
|
+
checkoutSession.phone_number_collection?.enabled && session.user.phone && /* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { color: "text.secondary", fontSize: "0.8125rem" }, children: session.user.phone }),
|
|
860
|
+
session.user.address && /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 0.75, children: [
|
|
861
|
+
session.user.address.country && /* @__PURE__ */ jsx(FlagEmoji, { iso2: session.user.address.country.toLowerCase(), style: { width: 18, height: 14 } }),
|
|
862
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "body2", sx: { color: "text.secondary", fontSize: "0.8125rem" }, children: [
|
|
863
|
+
[
|
|
864
|
+
session.user.address.line1,
|
|
865
|
+
session.user.address.city,
|
|
866
|
+
session.user.address.province,
|
|
867
|
+
session.user.address.country?.toUpperCase()
|
|
868
|
+
].filter(Boolean).join(", "),
|
|
869
|
+
session.user.address.postalCode && ` [ ${t("payment.checkout.billing.postal_code")}: ${session.user.address.postalCode} ]`
|
|
870
|
+
] })
|
|
871
|
+
] })
|
|
872
|
+
] })
|
|
873
|
+
]
|
|
874
|
+
}
|
|
875
|
+
),
|
|
758
876
|
showForm && /* @__PURE__ */ jsxs(
|
|
759
877
|
Stack,
|
|
760
878
|
{
|
|
@@ -824,7 +942,6 @@ export default function PaymentForm({
|
|
|
824
942
|
AddressForm,
|
|
825
943
|
{
|
|
826
944
|
mode: checkoutSession.billing_address_collection,
|
|
827
|
-
stripe: method?.type === "stripe",
|
|
828
945
|
sx: { marginTop: "0 !important" },
|
|
829
946
|
fieldValidation: checkoutSession.metadata?.page_info?.field_validation,
|
|
830
947
|
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;
|