@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/lib/libs/validator.js
CHANGED
|
@@ -4,17 +4,184 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getFieldValidation = getFieldValidation;
|
|
7
|
+
exports.postalCodePatterns = void 0;
|
|
7
8
|
exports.validatePostalCode = validatePostalCode;
|
|
8
|
-
var _isPostalCode = _interopRequireDefault(require("validator/lib/isPostalCode"));
|
|
9
9
|
var _locales = require("../locales");
|
|
10
|
-
|
|
11
|
-
const
|
|
10
|
+
const threeDigit = /^\d{3}$/;
|
|
11
|
+
const fourDigit = /^\d{4}$/;
|
|
12
|
+
const fiveDigit = /^\d{5}$/;
|
|
13
|
+
const sixDigit = /^\d{6}$/;
|
|
14
|
+
const postalCodePatterns = exports.postalCodePatterns = {
|
|
15
|
+
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,
|
|
16
|
+
JE: /^JE\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}$/i,
|
|
17
|
+
GG: /^GY\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}$/i,
|
|
18
|
+
IM: /^IM\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}$/i,
|
|
19
|
+
US: /^\d{5}([ -]\d{4})?$/,
|
|
20
|
+
CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ ]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
|
|
21
|
+
DE: /^\d{5}$/,
|
|
22
|
+
JP: /^\d{3}-?\d{4}$/,
|
|
23
|
+
FR: /^\d{2}[ ]?\d{3}$/,
|
|
24
|
+
AU: fourDigit,
|
|
25
|
+
IT: /^\d{5}$/,
|
|
26
|
+
CH: fourDigit,
|
|
27
|
+
AT: fourDigit,
|
|
28
|
+
ES: /^\d{5}$/,
|
|
29
|
+
NL: /^\d{4}[ ]?[A-Z]{2}$/i,
|
|
30
|
+
BE: fourDigit,
|
|
31
|
+
DK: fourDigit,
|
|
32
|
+
SE: /^\d{3}[ ]?\d{2}$/,
|
|
33
|
+
NO: fourDigit,
|
|
34
|
+
BR: /^\d{5}-?\d{3}$/,
|
|
35
|
+
PT: /^\d{4}(-\d{3})?$/,
|
|
36
|
+
FI: fiveDigit,
|
|
37
|
+
AX: /^22\d{3}$/,
|
|
38
|
+
KR: /^\d{5}$/,
|
|
39
|
+
// 2015年起使用5位数字邮编
|
|
40
|
+
CN: /^\d{6}$/,
|
|
41
|
+
TW: /^\d{3}(\d{2})?$/,
|
|
42
|
+
SG: sixDigit,
|
|
43
|
+
DZ: fiveDigit,
|
|
44
|
+
AD: /^AD\d{3}$/,
|
|
45
|
+
AR: /^([A-HJ-NP-Z])?\d{4}([A-Z]{3})?$/i,
|
|
46
|
+
AM: /^(37)?\d{4}$/,
|
|
47
|
+
AZ: /^\d{4}$/,
|
|
48
|
+
BH: /^((1[0-2]|[2-9])\d{2})?$/,
|
|
49
|
+
BD: fourDigit,
|
|
50
|
+
BB: /^(BB\d{5})?$/i,
|
|
51
|
+
BY: sixDigit,
|
|
52
|
+
BM: /^[A-Z]{2}[ ]?[A-Z0-9]{2}$/i,
|
|
53
|
+
BA: /^\d{5}$/,
|
|
54
|
+
IO: /^BBND 1ZZ$/i,
|
|
55
|
+
BN: /^[A-Z]{2}[ ]?\d{4}$/i,
|
|
56
|
+
BG: fourDigit,
|
|
57
|
+
KH: fiveDigit,
|
|
58
|
+
CV: fourDigit,
|
|
59
|
+
CL: /^\d{7}$/,
|
|
60
|
+
CR: /^\d{4,5}|\d{3}-\d{4}$/,
|
|
61
|
+
HR: /^\d{5}$/,
|
|
62
|
+
CY: fourDigit,
|
|
63
|
+
CZ: /^\d{3}[ ]?\d{2}$/,
|
|
64
|
+
DO: fiveDigit,
|
|
65
|
+
EC: /^([A-Z]\d{4}[A-Z]|(?:[A-Z]{2})?\d{6})?$/i,
|
|
66
|
+
EG: fiveDigit,
|
|
67
|
+
EE: fiveDigit,
|
|
68
|
+
FO: threeDigit,
|
|
69
|
+
GE: fourDigit,
|
|
70
|
+
GR: /^\d{3}[ ]?\d{2}$/,
|
|
71
|
+
GL: /^39\d{2}$/,
|
|
72
|
+
GT: fiveDigit,
|
|
73
|
+
HT: /^\d{4}$/,
|
|
74
|
+
HN: /^(?:\d{5})?$/,
|
|
75
|
+
HU: fourDigit,
|
|
76
|
+
IS: threeDigit,
|
|
77
|
+
IN: /^[1-9]\d{5}$/,
|
|
78
|
+
ID: fiveDigit,
|
|
79
|
+
IL: fiveDigit,
|
|
80
|
+
JO: fiveDigit,
|
|
81
|
+
KZ: sixDigit,
|
|
82
|
+
KE: fiveDigit,
|
|
83
|
+
KW: fiveDigit,
|
|
84
|
+
LA: fiveDigit,
|
|
85
|
+
LV: fourDigit,
|
|
86
|
+
LB: /^(\d{4}([ ]?\d{4})?)?$/,
|
|
87
|
+
LI: /^(948[5-9])|(949[0-7])$/,
|
|
88
|
+
LT: fiveDigit,
|
|
89
|
+
LU: fourDigit,
|
|
90
|
+
MK: fourDigit,
|
|
91
|
+
MY: fiveDigit,
|
|
92
|
+
MV: fiveDigit,
|
|
93
|
+
MT: /^[A-Z]{3}[ ]?\d{2,4}$/i,
|
|
94
|
+
MU: /^(\d{3}[A-Z]{2}\d{3})?$/i,
|
|
95
|
+
MX: fiveDigit,
|
|
96
|
+
MD: fourDigit,
|
|
97
|
+
MC: /^980\d{2}$/,
|
|
98
|
+
MA: fiveDigit,
|
|
99
|
+
NP: fiveDigit,
|
|
100
|
+
NZ: fourDigit,
|
|
101
|
+
NI: /^((\d{4}-)?\d{3}-\d{3}(-\d{1})?)?$/,
|
|
102
|
+
NG: /^(\d{6})?$/,
|
|
103
|
+
OM: /^(PC )?\d{3}$/i,
|
|
104
|
+
PK: fiveDigit,
|
|
105
|
+
PY: fourDigit,
|
|
106
|
+
PH: fourDigit,
|
|
107
|
+
PL: /^\d{2}-\d{3}$/,
|
|
108
|
+
PR: /^00[679]\d{2}([ -]\d{4})?$/,
|
|
109
|
+
RO: sixDigit,
|
|
110
|
+
RU: sixDigit,
|
|
111
|
+
SM: /^4789\d$/,
|
|
112
|
+
SA: fiveDigit,
|
|
113
|
+
SN: fiveDigit,
|
|
114
|
+
SK: /^\d{3}[ ]?\d{2}$/,
|
|
115
|
+
SI: fourDigit,
|
|
116
|
+
ZA: fourDigit,
|
|
117
|
+
LK: fiveDigit,
|
|
118
|
+
TJ: sixDigit,
|
|
119
|
+
TH: fiveDigit,
|
|
120
|
+
TN: fourDigit,
|
|
121
|
+
TR: fiveDigit,
|
|
122
|
+
TM: sixDigit,
|
|
123
|
+
UA: fiveDigit,
|
|
124
|
+
UY: fiveDigit,
|
|
125
|
+
UZ: sixDigit,
|
|
126
|
+
VA: /^00120$/,
|
|
127
|
+
VE: fourDigit,
|
|
128
|
+
ZM: fiveDigit,
|
|
129
|
+
// Territories & special regions
|
|
130
|
+
AS: /^96799$/,
|
|
131
|
+
CC: /^6799$/,
|
|
132
|
+
CK: fourDigit,
|
|
133
|
+
RS: sixDigit,
|
|
134
|
+
ME: /^8\d{4}$/,
|
|
135
|
+
CS: /^\d{5}$/,
|
|
136
|
+
// historical
|
|
137
|
+
YU: /^\d{5}$/,
|
|
138
|
+
// historical
|
|
139
|
+
CX: /^6798$/,
|
|
140
|
+
ET: fourDigit,
|
|
141
|
+
FK: /^FIQQ 1ZZ$/i,
|
|
142
|
+
NF: /^2899$/,
|
|
143
|
+
FM: /^(9694[1-4])([ -]\d{4})?$/,
|
|
144
|
+
GF: /^9[78]3\d{2}$/,
|
|
145
|
+
GN: threeDigit,
|
|
146
|
+
GP: /^9[78][01]\d{2}$/,
|
|
147
|
+
GS: /^SIQQ 1ZZ$/i,
|
|
148
|
+
GU: /^969[123]\d([ -]\d{4})?$/,
|
|
149
|
+
GW: fourDigit,
|
|
150
|
+
HM: fourDigit,
|
|
151
|
+
IQ: fiveDigit,
|
|
152
|
+
KG: sixDigit,
|
|
153
|
+
LR: fourDigit,
|
|
154
|
+
LS: threeDigit,
|
|
155
|
+
MG: threeDigit,
|
|
156
|
+
MH: /^969[67]\d([ -]\d{4})?$/,
|
|
157
|
+
MN: sixDigit,
|
|
158
|
+
MP: /^9695[012]([ -]\d{4})?$/,
|
|
159
|
+
MQ: /^9[78]2\d{2}$/,
|
|
160
|
+
NC: /^988\d{2}$/,
|
|
161
|
+
NE: fourDigit,
|
|
162
|
+
VI: /^008(([0-4]\d)|(5[01]))([ -]\d{4})?$/,
|
|
163
|
+
VN: sixDigit,
|
|
164
|
+
PF: /^987\d{2}$/,
|
|
165
|
+
PG: threeDigit,
|
|
166
|
+
PM: /^9[78]5\d{2}$/,
|
|
167
|
+
PN: /^PCRN 1ZZ$/i,
|
|
168
|
+
PW: /^96940$/,
|
|
169
|
+
RE: /^9[78]4\d{2}$/,
|
|
170
|
+
SH: /^(ASCN|STHL) 1ZZ$/i,
|
|
171
|
+
SJ: fourDigit,
|
|
172
|
+
SO: fiveDigit,
|
|
173
|
+
SZ: /^[HLMS]\d{3}$/i,
|
|
174
|
+
TC: /^TKCA 1ZZ$/i,
|
|
175
|
+
WF: /^986\d{2}$/,
|
|
176
|
+
XK: fiveDigit,
|
|
177
|
+
YT: /^976\d{2}$/
|
|
178
|
+
};
|
|
12
179
|
function validatePostalCode(postalCode, country) {
|
|
13
180
|
if (!postalCode) return true;
|
|
14
|
-
const countryUpper = country?.toUpperCase();
|
|
15
|
-
const isSupported = country && POSTAL_CODE_SUPPORTED_COUNTRIES.includes(countryUpper);
|
|
16
181
|
try {
|
|
17
|
-
|
|
182
|
+
const countryUpper = country?.toUpperCase();
|
|
183
|
+
if (!countryUpper) return false;
|
|
184
|
+
return !postalCodePatterns[countryUpper] || postalCodePatterns[countryUpper].test(postalCode);
|
|
18
185
|
} catch (error) {
|
|
19
186
|
console.error(error);
|
|
20
187
|
return false;
|
package/lib/locales/en.js
CHANGED
|
@@ -228,6 +228,7 @@ module.exports = (0, _flat.default)({
|
|
|
228
228
|
phonePlaceholder: "Phone number",
|
|
229
229
|
phoneTip: "In case we need to contact you about your order"
|
|
230
230
|
},
|
|
231
|
+
customerInfo: "Customer Information",
|
|
231
232
|
upsell: {
|
|
232
233
|
save: "Save with {recurring} billing",
|
|
233
234
|
revert: "Switch to {recurring} billing",
|
package/lib/locales/zh.js
CHANGED
|
@@ -228,6 +228,7 @@ module.exports = (0, _flat.default)({
|
|
|
228
228
|
phonePlaceholder: "\u7535\u8BDD\u53F7\u7801",
|
|
229
229
|
phoneTip: "\u4EE5\u9632\u9700\u8981\u4E0E\u60A8\u8054\u7CFB\u6709\u5173\u60A8\u7684\u8BA2\u5355"
|
|
230
230
|
},
|
|
231
|
+
customerInfo: "\u5BA2\u6237\u4FE1\u606F",
|
|
231
232
|
upsell: {
|
|
232
233
|
save: "\u4F7F\u7528{recurring}\u8BA1\u8D39\u65B9\u5F0F",
|
|
233
234
|
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 {};
|
|
@@ -15,7 +15,6 @@ var _validator = require("../../libs/validator");
|
|
|
15
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
16
|
function AddressForm({
|
|
17
17
|
mode,
|
|
18
|
-
stripe,
|
|
19
18
|
sx = {},
|
|
20
19
|
fieldValidation = {},
|
|
21
20
|
errorPosition = "right"
|
|
@@ -122,64 +121,73 @@ function AddressForm({
|
|
|
122
121
|
})
|
|
123
122
|
});
|
|
124
123
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
124
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Fade, {
|
|
125
|
+
in: true,
|
|
126
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
127
|
+
className: "cko-payment-address cko-payment-form",
|
|
128
|
+
sx,
|
|
129
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
130
|
+
direction: "column",
|
|
131
|
+
className: "cko-payment-form",
|
|
132
|
+
spacing: 0,
|
|
133
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_label.default, {
|
|
134
|
+
className: "base-label",
|
|
135
|
+
children: t("payment.checkout.billing.state")
|
|
136
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
137
|
+
name: "billing_address.state",
|
|
138
|
+
rules: {
|
|
139
|
+
required: t("payment.checkout.required"),
|
|
140
|
+
...(0, _validator.getFieldValidation)("billing_address.state", fieldValidation, locale)
|
|
141
|
+
},
|
|
142
|
+
errorPosition,
|
|
143
|
+
variant: "outlined",
|
|
144
|
+
placeholder: t("payment.checkout.billing.state")
|
|
145
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_label.default, {
|
|
146
|
+
className: "base-label",
|
|
147
|
+
children: t("payment.checkout.billing.postal_code")
|
|
148
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
149
|
+
direction: "row",
|
|
134
150
|
spacing: 0,
|
|
135
|
-
children:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
name: "billing_address.postal_code",
|
|
143
|
-
rules: {
|
|
144
|
-
required: t("payment.checkout.required"),
|
|
145
|
-
validate: x => {
|
|
146
|
-
const isValid = (0, _validator.validatePostalCode)(x, country);
|
|
147
|
-
return isValid ? true : t("payment.checkout.invalid");
|
|
148
|
-
},
|
|
149
|
-
...(0, _validator.getFieldValidation)("billing_address.postal_code", fieldValidation, locale)
|
|
151
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
152
|
+
name: "billing_address.postal_code",
|
|
153
|
+
rules: {
|
|
154
|
+
required: t("payment.checkout.required"),
|
|
155
|
+
validate: x => {
|
|
156
|
+
const isValid = (0, _validator.validatePostalCode)(x, country);
|
|
157
|
+
return isValid ? true : t("payment.checkout.invalid");
|
|
150
158
|
},
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
...(0, _validator.getFieldValidation)("billing_address.postal_code", fieldValidation, locale)
|
|
160
|
+
},
|
|
161
|
+
errorPosition,
|
|
162
|
+
variant: "outlined",
|
|
163
|
+
placeholder: t("payment.checkout.billing.postal_code"),
|
|
164
|
+
InputProps: {
|
|
165
|
+
startAdornment: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.InputAdornment, {
|
|
166
|
+
position: "start",
|
|
167
|
+
style: {
|
|
168
|
+
marginRight: "2px",
|
|
169
|
+
marginLeft: "-8px"
|
|
170
|
+
},
|
|
171
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
|
|
172
|
+
name: "billing_address.country",
|
|
173
|
+
control,
|
|
174
|
+
render: ({
|
|
175
|
+
field
|
|
176
|
+
}) => /* @__PURE__ */(0, _jsxRuntime.jsx)(_countrySelect.default, {
|
|
177
|
+
...field,
|
|
178
|
+
ref: field.ref,
|
|
179
|
+
sx: {
|
|
180
|
+
".MuiOutlinedInput-notchedOutline": {
|
|
181
|
+
borderColor: "transparent !important"
|
|
173
182
|
}
|
|
174
|
-
}
|
|
183
|
+
}
|
|
175
184
|
})
|
|
176
185
|
})
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
})
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
})]
|
|
181
190
|
})
|
|
182
|
-
})
|
|
183
|
-
}
|
|
184
|
-
return null;
|
|
191
|
+
})
|
|
192
|
+
});
|
|
185
193
|
}
|
|
@@ -8,6 +8,7 @@ exports.waitForCheckoutComplete = exports.hasDidWallet = void 0;
|
|
|
8
8
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
9
|
require("react-international-phone/style.css");
|
|
10
10
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
11
|
+
var _reactInternationalPhone = require("react-international-phone");
|
|
11
12
|
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
12
13
|
var _material = require("@mui/material");
|
|
13
14
|
var _ahooks = require("ahooks");
|
|
@@ -159,7 +160,8 @@ function PaymentForm({
|
|
|
159
160
|
customerLimited: false,
|
|
160
161
|
stripePaying: false,
|
|
161
162
|
fastCheckoutInfo: null,
|
|
162
|
-
creditInsufficientInfo: null
|
|
163
|
+
creditInsufficientInfo: null,
|
|
164
|
+
showEditForm: false
|
|
163
165
|
});
|
|
164
166
|
const currencies = (0, _util2.flattenPaymentMethods)(paymentMethods);
|
|
165
167
|
const searchParams = (0, _util2.getQueryParams)(window.location.href);
|
|
@@ -277,25 +279,103 @@ function PaymentForm({
|
|
|
277
279
|
const paymentCurrency = currencies.find(x => x.id === paymentCurrencyId);
|
|
278
280
|
const showStake = method.type === "arcblock" && !checkoutSession.subscription_data?.no_stake;
|
|
279
281
|
const isDonationMode = checkoutSession?.submit_type === "donate" && isDonation;
|
|
280
|
-
const
|
|
282
|
+
const validateUserInfo = () => {
|
|
281
283
|
if (!session?.user) {
|
|
282
284
|
return false;
|
|
283
285
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
+
const {
|
|
287
|
+
fullName,
|
|
288
|
+
name,
|
|
289
|
+
email,
|
|
290
|
+
phone,
|
|
291
|
+
address
|
|
292
|
+
} = session.user;
|
|
293
|
+
const fieldValidation = checkoutSession.metadata?.page_info?.field_validation;
|
|
294
|
+
const hasName = !!(fullName || name);
|
|
295
|
+
if (!hasName) {
|
|
296
|
+
return false;
|
|
286
297
|
}
|
|
287
|
-
|
|
288
|
-
|
|
298
|
+
const hasValidEmail = email && (0, _isEmail.default)(email);
|
|
299
|
+
if (!hasValidEmail) {
|
|
300
|
+
return false;
|
|
289
301
|
}
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
292
|
-
|
|
302
|
+
const nameValidation = (0, _validator.getFieldValidation)("customer_name", fieldValidation, locale);
|
|
303
|
+
if (nameValidation.pattern && fullName) {
|
|
304
|
+
const pattern = nameValidation.pattern.value;
|
|
305
|
+
if (!pattern.test(fullName)) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const emailValidation = (0, _validator.getFieldValidation)("customer_email", fieldValidation, locale);
|
|
310
|
+
if (emailValidation.pattern && email) {
|
|
311
|
+
const pattern = emailValidation.pattern.value;
|
|
312
|
+
if (!pattern.test(email)) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (!address || !address.postalCode || !(0, _validator.validatePostalCode)(address.postalCode, address.country)) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
const postalCodeValidation = (0, _validator.getFieldValidation)("billing_address.postal_code", fieldValidation, locale);
|
|
320
|
+
if (postalCodeValidation.pattern) {
|
|
321
|
+
const pattern = postalCodeValidation.pattern.value;
|
|
322
|
+
if (!pattern.test(address.postalCode)) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
293
325
|
}
|
|
294
|
-
if (
|
|
326
|
+
if (!address.province) {
|
|
295
327
|
return false;
|
|
296
328
|
}
|
|
329
|
+
const stateValidation = (0, _validator.getFieldValidation)("billing_address.state", fieldValidation, locale);
|
|
330
|
+
if (stateValidation.pattern) {
|
|
331
|
+
const pattern = stateValidation.pattern.value;
|
|
332
|
+
if (!pattern.test(address.province)) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (checkoutSession.phone_number_collection?.enabled) {
|
|
337
|
+
if (!phone || phone.trim() === "") {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
const phoneValidation = (0, _validator.getFieldValidation)("customer_phone", fieldValidation, locale);
|
|
341
|
+
if (phoneValidation.pattern) {
|
|
342
|
+
const pattern = phoneValidation.pattern.value;
|
|
343
|
+
if (!pattern.test(phone)) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const addressMode = checkoutSession.billing_address_collection;
|
|
349
|
+
if (addressMode === "required") {
|
|
350
|
+
if (!address?.country || !address?.province || !address?.line1 || !address?.city || !address?.postalCode) {
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
const line1Validation = (0, _validator.getFieldValidation)("billing_address.line1", fieldValidation, locale);
|
|
354
|
+
if (line1Validation.pattern) {
|
|
355
|
+
const pattern = line1Validation.pattern.value;
|
|
356
|
+
if (!pattern.test(address.line1)) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const cityValidation = (0, _validator.getFieldValidation)("billing_address.city", fieldValidation, locale);
|
|
361
|
+
if (cityValidation.pattern) {
|
|
362
|
+
const pattern = cityValidation.pattern.value;
|
|
363
|
+
if (!pattern.test(address.city)) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
297
368
|
return true;
|
|
298
|
-
}
|
|
369
|
+
};
|
|
370
|
+
const showForm = (0, _react.useMemo)(() => {
|
|
371
|
+
if (!session?.user) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
if (state.showEditForm) {
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
return !validateUserInfo();
|
|
378
|
+
}, [session?.user, method, state.showEditForm]);
|
|
299
379
|
const handleConnected = async () => {
|
|
300
380
|
if (processingRef.current) {
|
|
301
381
|
return;
|
|
@@ -822,6 +902,86 @@ function PaymentForm({
|
|
|
822
902
|
returnUrl: getRedirectUrl()
|
|
823
903
|
})]
|
|
824
904
|
})
|
|
905
|
+
}), !showForm && session?.user && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
906
|
+
spacing: 1.25,
|
|
907
|
+
sx: {
|
|
908
|
+
mt: 2,
|
|
909
|
+
p: 2,
|
|
910
|
+
pt: 1,
|
|
911
|
+
backgroundColor: "background.paper",
|
|
912
|
+
borderRadius: 1,
|
|
913
|
+
border: "1px solid",
|
|
914
|
+
borderColor: "divider"
|
|
915
|
+
},
|
|
916
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
917
|
+
direction: "row",
|
|
918
|
+
justifyContent: "space-between",
|
|
919
|
+
alignItems: "center",
|
|
920
|
+
sx: {
|
|
921
|
+
mb: 0.25
|
|
922
|
+
},
|
|
923
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
924
|
+
variant: "subtitle2",
|
|
925
|
+
sx: {
|
|
926
|
+
color: "text.primary",
|
|
927
|
+
fontSize: "0.875rem"
|
|
928
|
+
},
|
|
929
|
+
children: t("payment.checkout.customerInfo")
|
|
930
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
931
|
+
size: "small",
|
|
932
|
+
variant: "text",
|
|
933
|
+
onClick: () => setState({
|
|
934
|
+
showEditForm: true
|
|
935
|
+
}),
|
|
936
|
+
sx: {
|
|
937
|
+
minWidth: 0
|
|
938
|
+
},
|
|
939
|
+
children: t("common.edit")
|
|
940
|
+
})]
|
|
941
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
942
|
+
spacing: 0.5,
|
|
943
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
944
|
+
variant: "body2",
|
|
945
|
+
sx: {
|
|
946
|
+
color: "text.primary",
|
|
947
|
+
fontWeight: 600,
|
|
948
|
+
fontSize: "0.9375rem"
|
|
949
|
+
},
|
|
950
|
+
children: session.user.fullName || session.user.name
|
|
951
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
952
|
+
variant: "body2",
|
|
953
|
+
sx: {
|
|
954
|
+
color: "text.secondary",
|
|
955
|
+
fontSize: "0.8125rem"
|
|
956
|
+
},
|
|
957
|
+
children: session.user.email
|
|
958
|
+
}), checkoutSession.phone_number_collection?.enabled && session.user.phone && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
959
|
+
variant: "body2",
|
|
960
|
+
sx: {
|
|
961
|
+
color: "text.secondary",
|
|
962
|
+
fontSize: "0.8125rem"
|
|
963
|
+
},
|
|
964
|
+
children: session.user.phone
|
|
965
|
+
}), session.user.address && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
966
|
+
direction: "row",
|
|
967
|
+
alignItems: "center",
|
|
968
|
+
spacing: 0.75,
|
|
969
|
+
children: [session.user.address.country && /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactInternationalPhone.FlagEmoji, {
|
|
970
|
+
iso2: session.user.address.country.toLowerCase(),
|
|
971
|
+
style: {
|
|
972
|
+
width: 18,
|
|
973
|
+
height: 14
|
|
974
|
+
}
|
|
975
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
976
|
+
variant: "body2",
|
|
977
|
+
sx: {
|
|
978
|
+
color: "text.secondary",
|
|
979
|
+
fontSize: "0.8125rem"
|
|
980
|
+
},
|
|
981
|
+
children: [[session.user.address.line1, session.user.address.city, session.user.address.province, session.user.address.country?.toUpperCase()].filter(Boolean).join(", "), session.user.address.postalCode && ` [ ${t("payment.checkout.billing.postal_code")}: ${session.user.address.postalCode} ]`]
|
|
982
|
+
})]
|
|
983
|
+
})]
|
|
984
|
+
})]
|
|
825
985
|
}), showForm && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
826
986
|
direction: "column",
|
|
827
987
|
className: "cko-payment-form",
|
|
@@ -876,7 +1036,6 @@ function PaymentForm({
|
|
|
876
1036
|
})]
|
|
877
1037
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_address.default, {
|
|
878
1038
|
mode: checkoutSession.billing_address_collection,
|
|
879
|
-
stripe: method?.type === "stripe",
|
|
880
1039
|
sx: {
|
|
881
1040
|
marginTop: "0 !important"
|
|
882
1041
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.15",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"@babel/core": "^7.27.4",
|
|
95
95
|
"@babel/preset-env": "^7.27.2",
|
|
96
96
|
"@babel/preset-react": "^7.27.1",
|
|
97
|
-
"@blocklet/payment-types": "1.21.
|
|
97
|
+
"@blocklet/payment-types": "1.21.15",
|
|
98
98
|
"@storybook/addon-essentials": "^7.6.20",
|
|
99
99
|
"@storybook/addon-interactions": "^7.6.20",
|
|
100
100
|
"@storybook/addon-links": "^7.6.20",
|
|
@@ -125,5 +125,5 @@
|
|
|
125
125
|
"vite-plugin-babel": "^1.3.1",
|
|
126
126
|
"vite-plugin-node-polyfills": "^0.23.0"
|
|
127
127
|
},
|
|
128
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "fd48f9233f19514b537e30b013e09a7d9f7a9f48"
|
|
129
129
|
}
|