@blocklet/payment-react 1.18.33 → 1.18.35
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/es/components/over-due-invoice-payment.js +7 -1
- package/es/history/invoice/list.js +2 -1
- package/es/libs/util.d.ts +1 -0
- package/es/libs/util.js +13 -0
- package/es/libs/validator.d.ts +1 -0
- package/es/libs/validator.js +14 -0
- package/es/locales/en.js +32 -5
- package/es/locales/zh.js +32 -5
- package/es/payment/form/address.d.ts +5 -1
- package/es/payment/form/address.js +26 -13
- package/es/payment/form/index.js +173 -41
- package/lib/components/over-due-invoice-payment.js +8 -1
- package/lib/history/invoice/list.js +3 -1
- package/lib/libs/util.d.ts +1 -0
- package/lib/libs/util.js +16 -1
- package/lib/libs/validator.d.ts +1 -0
- package/lib/libs/validator.js +14 -0
- package/lib/locales/en.js +32 -5
- package/lib/locales/zh.js +32 -5
- package/lib/payment/form/address.d.ts +5 -1
- package/lib/payment/form/address.js +21 -12
- package/lib/payment/form/index.js +230 -59
- package/package.json +6 -6
- package/src/components/over-due-invoice-payment.tsx +7 -1
- package/src/history/invoice/list.tsx +2 -1
- package/src/libs/util.ts +15 -0
- package/src/libs/validator.ts +14 -0
- package/src/locales/en.tsx +31 -1
- package/src/locales/zh.tsx +29 -1
- package/src/payment/form/address.tsx +25 -10
- package/src/payment/form/index.tsx +197 -35
|
@@ -13,12 +13,16 @@ var _countrySelect = _interopRequireDefault(require("../../components/country-se
|
|
|
13
13
|
var _validator = require("../../libs/validator");
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
AddressForm.defaultProps = {
|
|
16
|
-
sx: {}
|
|
16
|
+
sx: {},
|
|
17
|
+
fieldValidation: {},
|
|
18
|
+
errorPosition: "right"
|
|
17
19
|
};
|
|
18
20
|
function AddressForm({
|
|
19
21
|
mode,
|
|
20
22
|
stripe,
|
|
21
|
-
sx = {}
|
|
23
|
+
sx = {},
|
|
24
|
+
fieldValidation,
|
|
25
|
+
errorPosition
|
|
22
26
|
}) {
|
|
23
27
|
const {
|
|
24
28
|
t
|
|
@@ -46,9 +50,10 @@ function AddressForm({
|
|
|
46
50
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
47
51
|
name: "billing_address.line1",
|
|
48
52
|
rules: {
|
|
49
|
-
required: t("payment.checkout.required")
|
|
53
|
+
required: t("payment.checkout.required"),
|
|
54
|
+
...(0, _validator.getFieldValidation)("billing_address.line1", fieldValidation)
|
|
50
55
|
},
|
|
51
|
-
errorPosition
|
|
56
|
+
errorPosition,
|
|
52
57
|
variant: "outlined",
|
|
53
58
|
placeholder: t("payment.checkout.billing.line1")
|
|
54
59
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.FormLabel, {
|
|
@@ -57,9 +62,10 @@ function AddressForm({
|
|
|
57
62
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
58
63
|
name: "billing_address.city",
|
|
59
64
|
rules: {
|
|
60
|
-
required: t("payment.checkout.required")
|
|
65
|
+
required: t("payment.checkout.required"),
|
|
66
|
+
...(0, _validator.getFieldValidation)("billing_address.city", fieldValidation)
|
|
61
67
|
},
|
|
62
|
-
errorPosition
|
|
68
|
+
errorPosition,
|
|
63
69
|
variant: "outlined",
|
|
64
70
|
placeholder: t("payment.checkout.billing.city")
|
|
65
71
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.FormLabel, {
|
|
@@ -68,9 +74,10 @@ function AddressForm({
|
|
|
68
74
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
69
75
|
name: "billing_address.state",
|
|
70
76
|
rules: {
|
|
71
|
-
required: t("payment.checkout.required")
|
|
77
|
+
required: t("payment.checkout.required"),
|
|
78
|
+
...(0, _validator.getFieldValidation)("billing_address.state", fieldValidation)
|
|
72
79
|
},
|
|
73
|
-
errorPosition
|
|
80
|
+
errorPosition,
|
|
74
81
|
variant: "outlined",
|
|
75
82
|
placeholder: t("payment.checkout.billing.state")
|
|
76
83
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.FormLabel, {
|
|
@@ -83,9 +90,10 @@ function AddressForm({
|
|
|
83
90
|
validate: x => {
|
|
84
91
|
const isValid = (0, _validator.validatePostalCode)(x, country);
|
|
85
92
|
return isValid ? true : t("payment.checkout.invalid");
|
|
86
|
-
}
|
|
93
|
+
},
|
|
94
|
+
...(0, _validator.getFieldValidation)("billing_address.postal_code", fieldValidation)
|
|
87
95
|
},
|
|
88
|
-
errorPosition
|
|
96
|
+
errorPosition,
|
|
89
97
|
variant: "outlined",
|
|
90
98
|
placeholder: t("payment.checkout.billing.postal_code"),
|
|
91
99
|
InputProps: {
|
|
@@ -139,9 +147,10 @@ function AddressForm({
|
|
|
139
147
|
validate: x => {
|
|
140
148
|
const isValid = (0, _validator.validatePostalCode)(x, country);
|
|
141
149
|
return isValid ? true : t("payment.checkout.invalid");
|
|
142
|
-
}
|
|
150
|
+
},
|
|
151
|
+
...(0, _validator.getFieldValidation)("billing_address.postal_code", fieldValidation)
|
|
143
152
|
},
|
|
144
|
-
errorPosition
|
|
153
|
+
errorPosition,
|
|
145
154
|
variant: "outlined",
|
|
146
155
|
placeholder: t("payment.checkout.billing.postal_code"),
|
|
147
156
|
wrapperStyle: {
|
|
@@ -17,12 +17,15 @@ var _reactHookForm = require("react-hook-form");
|
|
|
17
17
|
var _ufo = require("ufo");
|
|
18
18
|
var _useBus = require("use-bus");
|
|
19
19
|
var _isEmail = _interopRequireDefault(require("validator/es/lib/isEmail"));
|
|
20
|
+
var _util = require("@ocap/util");
|
|
21
|
+
var _DID = _interopRequireDefault(require("@arcblock/ux/lib/DID"));
|
|
20
22
|
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
23
|
+
var _iconsMaterial = require("@mui/icons-material");
|
|
21
24
|
var _input = _interopRequireDefault(require("../../components/input"));
|
|
22
25
|
var _payment = require("../../contexts/payment");
|
|
23
26
|
var _subscription = require("../../hooks/subscription");
|
|
24
27
|
var _api = _interopRequireDefault(require("../../libs/api"));
|
|
25
|
-
var
|
|
28
|
+
var _util2 = require("../../libs/util");
|
|
26
29
|
var _address = _interopRequireDefault(require("./address"));
|
|
27
30
|
var _currency = _interopRequireDefault(require("./currency"));
|
|
28
31
|
var _phone = _interopRequireDefault(require("./phone"));
|
|
@@ -32,6 +35,8 @@ var _phoneValidator = require("../../libs/phone-validator");
|
|
|
32
35
|
var _loadingButton = _interopRequireDefault(require("../../components/loading-button"));
|
|
33
36
|
var _overDueInvoicePayment = _interopRequireDefault(require("../../components/over-due-invoice-payment"));
|
|
34
37
|
var _currency2 = require("../../libs/currency");
|
|
38
|
+
var _confirm = _interopRequireDefault(require("../../components/confirm"));
|
|
39
|
+
var _validator = require("../../libs/validator");
|
|
35
40
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
36
41
|
const waitForCheckoutComplete = async sessionId => {
|
|
37
42
|
let result;
|
|
@@ -107,7 +112,8 @@ function PaymentForm({
|
|
|
107
112
|
isDonation = false
|
|
108
113
|
}) {
|
|
109
114
|
const {
|
|
110
|
-
t
|
|
115
|
+
t,
|
|
116
|
+
locale
|
|
111
117
|
} = (0, _context.useLocaleContext)();
|
|
112
118
|
const {
|
|
113
119
|
isMobile
|
|
@@ -118,6 +124,7 @@ function PaymentForm({
|
|
|
118
124
|
payable
|
|
119
125
|
} = (0, _payment.usePaymentContext)();
|
|
120
126
|
const subscription = (0, _subscription.useSubscription)("events");
|
|
127
|
+
const formErrorPosition = isMobile ? "bottom" : "right";
|
|
121
128
|
const {
|
|
122
129
|
control,
|
|
123
130
|
getValues,
|
|
@@ -131,7 +138,7 @@ function PaymentForm({
|
|
|
131
138
|
const quantityInventoryStatus = (0, _react.useMemo)(() => {
|
|
132
139
|
let status = true;
|
|
133
140
|
for (const item of checkoutSession.line_items) {
|
|
134
|
-
if ((0,
|
|
141
|
+
if ((0, _util2.formatQuantityInventory)(item.price, item.quantity)) {
|
|
135
142
|
status = false;
|
|
136
143
|
break;
|
|
137
144
|
}
|
|
@@ -146,9 +153,10 @@ function PaymentForm({
|
|
|
146
153
|
stripeContext: void 0,
|
|
147
154
|
customer,
|
|
148
155
|
customerLimited: false,
|
|
149
|
-
stripePaying: false
|
|
156
|
+
stripePaying: false,
|
|
157
|
+
fastCheckoutInfo: null
|
|
150
158
|
});
|
|
151
|
-
const currencies = (0,
|
|
159
|
+
const currencies = (0, _util2.flattenPaymentMethods)(paymentMethods);
|
|
152
160
|
const onCheckoutComplete = (0, _ahooks.useMemoizedFn)(async ({
|
|
153
161
|
response
|
|
154
162
|
}) => {
|
|
@@ -229,6 +237,10 @@ function PaymentForm({
|
|
|
229
237
|
control,
|
|
230
238
|
name: "payment_method"
|
|
231
239
|
});
|
|
240
|
+
const paymentCurrencyId = (0, _reactHookForm.useWatch)({
|
|
241
|
+
control,
|
|
242
|
+
name: "payment_currency"
|
|
243
|
+
});
|
|
232
244
|
const afterUserLoggedIn = (0, _ahooks.useMemoizedFn)(() => {
|
|
233
245
|
if (hasDidWallet(session.user) || skipBindWallet) {
|
|
234
246
|
handleSubmit(onFormSubmit, onFormError)();
|
|
@@ -240,7 +252,7 @@ function PaymentForm({
|
|
|
240
252
|
});
|
|
241
253
|
}
|
|
242
254
|
});
|
|
243
|
-
const payee = (0,
|
|
255
|
+
const payee = (0, _util2.getStatementDescriptor)(checkoutSession.line_items);
|
|
244
256
|
let buttonText = "";
|
|
245
257
|
if (paymentLink?.donation_settings) {
|
|
246
258
|
if (action) {
|
|
@@ -255,6 +267,8 @@ function PaymentForm({
|
|
|
255
267
|
action: buttonText
|
|
256
268
|
});
|
|
257
269
|
const method = paymentMethods.find(x => x.id === paymentMethod);
|
|
270
|
+
const paymentCurrency = currencies.find(x => x.id === paymentCurrencyId);
|
|
271
|
+
const showStake = method.type === "arcblock" && !checkoutSession.subscription_data?.no_stake;
|
|
258
272
|
const isDonationMode = checkoutSession?.submit_type === "donate" && isDonation;
|
|
259
273
|
const showForm = !!session?.user;
|
|
260
274
|
const skipBindWallet = method.type === "stripe";
|
|
@@ -272,7 +286,7 @@ function PaymentForm({
|
|
|
272
286
|
onPaid(result);
|
|
273
287
|
}
|
|
274
288
|
} catch (err) {
|
|
275
|
-
_Toast.default.error((0,
|
|
289
|
+
_Toast.default.error((0, _util2.formatError)(err));
|
|
276
290
|
} finally {
|
|
277
291
|
setState({
|
|
278
292
|
paying: false
|
|
@@ -299,6 +313,94 @@ function PaymentForm({
|
|
|
299
313
|
});
|
|
300
314
|
}
|
|
301
315
|
};
|
|
316
|
+
const handleFastCheckoutConfirm = async () => {
|
|
317
|
+
if (!state.fastCheckoutInfo) return;
|
|
318
|
+
setState({
|
|
319
|
+
fastCheckoutInfo: {
|
|
320
|
+
...state.fastCheckoutInfo,
|
|
321
|
+
loading: true
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
try {
|
|
325
|
+
const result = await _api.default.post(`/api/checkout-sessions/${checkoutSession.id}/fast-checkout-confirm`);
|
|
326
|
+
if (result.data.fastPaid) {
|
|
327
|
+
setState({
|
|
328
|
+
fastCheckoutInfo: null,
|
|
329
|
+
paying: true
|
|
330
|
+
});
|
|
331
|
+
await handleConnected();
|
|
332
|
+
} else {
|
|
333
|
+
_Toast.default.error(t("payment.checkout.fastPay.failed"));
|
|
334
|
+
setState({
|
|
335
|
+
fastCheckoutInfo: null,
|
|
336
|
+
paying: true
|
|
337
|
+
});
|
|
338
|
+
openConnect();
|
|
339
|
+
}
|
|
340
|
+
} catch (err) {
|
|
341
|
+
console.error(err);
|
|
342
|
+
_Toast.default.error((0, _util2.formatError)(err));
|
|
343
|
+
setState({
|
|
344
|
+
fastCheckoutInfo: null
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
const handleFastCheckoutCancel = () => {
|
|
349
|
+
setState({
|
|
350
|
+
fastCheckoutInfo: null
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
const openConnect = () => {
|
|
354
|
+
try {
|
|
355
|
+
if (!["arcblock", "ethereum", "base"].includes(method.type)) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
setState({
|
|
359
|
+
paying: true
|
|
360
|
+
});
|
|
361
|
+
connect.open({
|
|
362
|
+
locale,
|
|
363
|
+
containerEl: void 0,
|
|
364
|
+
action: checkoutSession.mode,
|
|
365
|
+
prefix: (0, _ufo.joinURL)((0, _util2.getPrefix)(), "/api/did"),
|
|
366
|
+
saveConnect: false,
|
|
367
|
+
useSocket: (0, _util2.isCrossOrigin)() === false,
|
|
368
|
+
extraParams: {
|
|
369
|
+
checkoutSessionId: checkoutSession.id,
|
|
370
|
+
sessionUserDid: session?.user?.did
|
|
371
|
+
},
|
|
372
|
+
onSuccess: async () => {
|
|
373
|
+
connect.close();
|
|
374
|
+
await handleConnected();
|
|
375
|
+
},
|
|
376
|
+
onClose: () => {
|
|
377
|
+
connect.close();
|
|
378
|
+
setState({
|
|
379
|
+
submitting: false,
|
|
380
|
+
paying: false
|
|
381
|
+
});
|
|
382
|
+
},
|
|
383
|
+
onError: err => {
|
|
384
|
+
console.error(err);
|
|
385
|
+
setState({
|
|
386
|
+
submitting: false,
|
|
387
|
+
paying: false
|
|
388
|
+
});
|
|
389
|
+
onError(err);
|
|
390
|
+
},
|
|
391
|
+
messages: {
|
|
392
|
+
title: t("payment.checkout.connectModal.title", {
|
|
393
|
+
action: buttonText
|
|
394
|
+
}),
|
|
395
|
+
scan: t("payment.checkout.connectModal.scan"),
|
|
396
|
+
confirm: t("payment.checkout.connectModal.confirm"),
|
|
397
|
+
cancel: t("payment.checkout.connectModal.cancel")
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
} catch (err) {
|
|
401
|
+
_Toast.default.error((0, _util2.formatError)(err));
|
|
402
|
+
}
|
|
403
|
+
};
|
|
302
404
|
const onFormSubmit = async data => {
|
|
303
405
|
setState({
|
|
304
406
|
submitting: true
|
|
@@ -318,47 +420,18 @@ function PaymentForm({
|
|
|
318
420
|
customerLimited: false
|
|
319
421
|
});
|
|
320
422
|
if (["arcblock", "ethereum", "base"].includes(method.type)) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
action: checkoutSession.mode,
|
|
330
|
-
prefix: (0, _ufo.joinURL)((0, _util.getPrefix)(), "/api/did"),
|
|
331
|
-
saveConnect: false,
|
|
332
|
-
useSocket: (0, _util.isCrossOrigin)() === false,
|
|
333
|
-
extraParams: {
|
|
334
|
-
checkoutSessionId: checkoutSession.id,
|
|
335
|
-
sessionUserDid: session?.user?.did
|
|
336
|
-
},
|
|
337
|
-
onSuccess: async () => {
|
|
338
|
-
connect.close();
|
|
339
|
-
await handleConnected();
|
|
340
|
-
},
|
|
341
|
-
onClose: () => {
|
|
342
|
-
connect.close();
|
|
343
|
-
setState({
|
|
344
|
-
submitting: false,
|
|
345
|
-
paying: false
|
|
346
|
-
});
|
|
347
|
-
},
|
|
348
|
-
onError: err => {
|
|
349
|
-
console.error(err);
|
|
350
|
-
setState({
|
|
351
|
-
submitting: false,
|
|
352
|
-
paying: false
|
|
353
|
-
});
|
|
354
|
-
onError(err);
|
|
355
|
-
},
|
|
356
|
-
messages: {
|
|
357
|
-
title: "DID Connect",
|
|
358
|
-
scan: "Use following methods to complete this payment",
|
|
359
|
-
confirm: "Confirm"
|
|
423
|
+
if ((result.data.balance?.sufficient || result.data.delegation?.sufficient) && !isDonationMode && result.data.fastPayInfo) {
|
|
424
|
+
setState({
|
|
425
|
+
fastCheckoutInfo: {
|
|
426
|
+
open: true,
|
|
427
|
+
loading: false,
|
|
428
|
+
sourceType: result.data.fastPayInfo.type,
|
|
429
|
+
amount: result.data.fastPayInfo.amount,
|
|
430
|
+
payer: result.data.fastPayInfo.payer
|
|
360
431
|
}
|
|
361
432
|
});
|
|
433
|
+
} else {
|
|
434
|
+
openConnect();
|
|
362
435
|
}
|
|
363
436
|
}
|
|
364
437
|
if (["stripe"].includes(method.type)) {
|
|
@@ -387,7 +460,7 @@ function PaymentForm({
|
|
|
387
460
|
}
|
|
388
461
|
}
|
|
389
462
|
if (shouldToast) {
|
|
390
|
-
_Toast.default.error((0,
|
|
463
|
+
_Toast.default.error((0, _util2.formatError)(err));
|
|
391
464
|
}
|
|
392
465
|
} finally {
|
|
393
466
|
setState({
|
|
@@ -464,6 +537,77 @@ function PaymentForm({
|
|
|
464
537
|
window.removeEventListener("keydown", handleKeyDown);
|
|
465
538
|
};
|
|
466
539
|
}, [state.submitting, state.paying, state.stripePaying, quantityInventoryStatus, payable]);
|
|
540
|
+
const balanceLink = (0, _util2.getTokenBalanceLink)(method, state.fastCheckoutInfo?.payer || "");
|
|
541
|
+
const FastCheckoutConfirmDialog = state.fastCheckoutInfo && /* @__PURE__ */(0, _jsxRuntime.jsx)(_confirm.default, {
|
|
542
|
+
onConfirm: handleFastCheckoutConfirm,
|
|
543
|
+
onCancel: handleFastCheckoutCancel,
|
|
544
|
+
title: t("payment.checkout.fastPay.title"),
|
|
545
|
+
message: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
546
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
547
|
+
children: t("payment.checkout.fastPay.autoPaymentReason")
|
|
548
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
549
|
+
children: t("payment.checkout.fastPay.confirmPrompt")
|
|
550
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Divider, {
|
|
551
|
+
sx: {
|
|
552
|
+
mt: 1.5,
|
|
553
|
+
mb: 1.5
|
|
554
|
+
}
|
|
555
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
556
|
+
spacing: 1,
|
|
557
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
558
|
+
flexDirection: "row",
|
|
559
|
+
alignItems: "center",
|
|
560
|
+
justifyContent: "space-between",
|
|
561
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
562
|
+
color: "text.primary",
|
|
563
|
+
sx: {
|
|
564
|
+
whiteSpace: "nowrap"
|
|
565
|
+
},
|
|
566
|
+
children: t("payment.checkout.fastPay.payer")
|
|
567
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
568
|
+
sx: {
|
|
569
|
+
display: "flex",
|
|
570
|
+
alignItems: "center",
|
|
571
|
+
gap: 0.5
|
|
572
|
+
},
|
|
573
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_DID.default, {
|
|
574
|
+
did: state.fastCheckoutInfo.payer || "",
|
|
575
|
+
compact: true,
|
|
576
|
+
responsive: false
|
|
577
|
+
}), balanceLink && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Tooltip, {
|
|
578
|
+
title: t("payment.checkout.fastPay.balanceLink"),
|
|
579
|
+
placement: "top",
|
|
580
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.OpenInNew, {
|
|
581
|
+
sx: {
|
|
582
|
+
color: "text.lighter",
|
|
583
|
+
fontSize: "0.85rem",
|
|
584
|
+
cursor: "pointer",
|
|
585
|
+
"&:hover": {
|
|
586
|
+
color: "text.primary"
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
onClick: () => {
|
|
590
|
+
window.open(balanceLink, "_blank");
|
|
591
|
+
}
|
|
592
|
+
})
|
|
593
|
+
})]
|
|
594
|
+
})]
|
|
595
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
596
|
+
flexDirection: "row",
|
|
597
|
+
alignItems: "center",
|
|
598
|
+
justifyContent: "space-between",
|
|
599
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
600
|
+
color: "text.primary",
|
|
601
|
+
children: t("payment.checkout.fastPay.amount")
|
|
602
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
603
|
+
children: [(0, _util.fromUnitToToken)(state.fastCheckoutInfo.amount, paymentCurrency?.decimal || 18).toString(), " ", paymentCurrency?.symbol]
|
|
604
|
+
})]
|
|
605
|
+
})]
|
|
606
|
+
})]
|
|
607
|
+
}),
|
|
608
|
+
loading: state.fastCheckoutInfo.loading,
|
|
609
|
+
color: "primary"
|
|
610
|
+
});
|
|
467
611
|
if (onlyShowBtn) {
|
|
468
612
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
469
613
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
@@ -504,7 +648,7 @@ function PaymentForm({
|
|
|
504
648
|
setState({
|
|
505
649
|
customerLimited: false
|
|
506
650
|
});
|
|
507
|
-
window.open((0, _ufo.joinURL)((0,
|
|
651
|
+
window.open((0, _ufo.joinURL)((0, _util2.getPrefix)(), `/customer/invoice/past-due?referer=${encodeURIComponent(window.location.href)}`), "_self");
|
|
508
652
|
}
|
|
509
653
|
},
|
|
510
654
|
dialogProps: {
|
|
@@ -514,7 +658,7 @@ function PaymentForm({
|
|
|
514
658
|
}),
|
|
515
659
|
title: t("payment.customer.pastDue.alert.title")
|
|
516
660
|
}
|
|
517
|
-
})]
|
|
661
|
+
}), FastCheckoutConfirmDialog]
|
|
518
662
|
});
|
|
519
663
|
}
|
|
520
664
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
@@ -589,9 +733,10 @@ function PaymentForm({
|
|
|
589
733
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
590
734
|
name: "customer_name",
|
|
591
735
|
variant: "outlined",
|
|
592
|
-
errorPosition:
|
|
736
|
+
errorPosition: formErrorPosition,
|
|
593
737
|
rules: {
|
|
594
|
-
required: t("payment.checkout.required")
|
|
738
|
+
required: t("payment.checkout.required"),
|
|
739
|
+
...(0, _validator.getFieldValidation)("customer_name", checkoutSession.metadata?.page_info?.field_validation, locale)
|
|
595
740
|
}
|
|
596
741
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.FormLabel, {
|
|
597
742
|
className: "base-label",
|
|
@@ -599,10 +744,11 @@ function PaymentForm({
|
|
|
599
744
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
600
745
|
name: "customer_email",
|
|
601
746
|
variant: "outlined",
|
|
602
|
-
errorPosition:
|
|
747
|
+
errorPosition: formErrorPosition,
|
|
603
748
|
rules: {
|
|
604
749
|
required: t("payment.checkout.required"),
|
|
605
|
-
validate: x => (0, _isEmail.default)(x) ? true : t("payment.checkout.invalid")
|
|
750
|
+
validate: x => (0, _isEmail.default)(x) ? true : t("payment.checkout.invalid"),
|
|
751
|
+
...(0, _validator.getFieldValidation)("customer_email", checkoutSession.metadata?.page_info?.field_validation, locale)
|
|
606
752
|
}
|
|
607
753
|
}), checkoutSession.phone_number_collection?.enabled && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
608
754
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.FormLabel, {
|
|
@@ -611,14 +757,15 @@ function PaymentForm({
|
|
|
611
757
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_phone.default, {
|
|
612
758
|
name: "customer_phone",
|
|
613
759
|
variant: "outlined",
|
|
614
|
-
errorPosition:
|
|
760
|
+
errorPosition: formErrorPosition,
|
|
615
761
|
placeholder: "Phone number",
|
|
616
762
|
rules: {
|
|
617
763
|
required: t("payment.checkout.required"),
|
|
618
764
|
validate: async x => {
|
|
619
765
|
const isValid = await (0, _phoneValidator.validatePhoneNumber)(x);
|
|
620
766
|
return isValid ? true : t("payment.checkout.invalid");
|
|
621
|
-
}
|
|
767
|
+
},
|
|
768
|
+
...(0, _validator.getFieldValidation)("customer_phone", checkoutSession.metadata?.page_info?.field_validation, locale)
|
|
622
769
|
}
|
|
623
770
|
})]
|
|
624
771
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_address.default, {
|
|
@@ -626,7 +773,9 @@ function PaymentForm({
|
|
|
626
773
|
stripe: method?.type === "stripe",
|
|
627
774
|
sx: {
|
|
628
775
|
marginTop: "0 !important"
|
|
629
|
-
}
|
|
776
|
+
},
|
|
777
|
+
fieldValidation: checkoutSession.metadata?.page_info?.field_validation,
|
|
778
|
+
errorPosition: formErrorPosition
|
|
630
779
|
})]
|
|
631
780
|
})]
|
|
632
781
|
})
|
|
@@ -661,9 +810,31 @@ function PaymentForm({
|
|
|
661
810
|
fontSize: "0.7875rem",
|
|
662
811
|
lineHeight: "0.9625rem"
|
|
663
812
|
},
|
|
664
|
-
children: t("payment.checkout.confirm", {
|
|
813
|
+
children: showStake ? t("payment.checkout.confirm.withStake", {
|
|
814
|
+
payee
|
|
815
|
+
}) : t("payment.checkout.confirm.withoutStake", {
|
|
665
816
|
payee
|
|
666
817
|
})
|
|
818
|
+
}), checkoutSession.metadata?.page_info?.form_purpose_description && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
819
|
+
sx: {
|
|
820
|
+
mt: 1,
|
|
821
|
+
display: "flex",
|
|
822
|
+
alignItems: "center",
|
|
823
|
+
gap: 0.5
|
|
824
|
+
},
|
|
825
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.HelpOutline, {
|
|
826
|
+
sx: {
|
|
827
|
+
color: "text.lighter",
|
|
828
|
+
fontSize: "0.75rem"
|
|
829
|
+
}
|
|
830
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
831
|
+
variant: "body2",
|
|
832
|
+
sx: {
|
|
833
|
+
fontSize: "0.75rem",
|
|
834
|
+
color: "text.lighter"
|
|
835
|
+
},
|
|
836
|
+
children: locale === "zh" ? checkoutSession.metadata.page_info.form_purpose_description.zh : checkoutSession.metadata.page_info.form_purpose_description.en
|
|
837
|
+
})]
|
|
667
838
|
})]
|
|
668
839
|
})
|
|
669
840
|
}), state.customerLimited && /* @__PURE__ */(0, _jsxRuntime.jsx)(_overDueInvoicePayment.default, {
|
|
@@ -681,7 +852,7 @@ function PaymentForm({
|
|
|
681
852
|
setState({
|
|
682
853
|
customerLimited: false
|
|
683
854
|
});
|
|
684
|
-
window.open((0, _ufo.joinURL)((0,
|
|
855
|
+
window.open((0, _ufo.joinURL)((0, _util2.getPrefix)(), `/customer/invoice/past-due?referer=${encodeURIComponent(window.location.href)}`), "_self");
|
|
685
856
|
}
|
|
686
857
|
},
|
|
687
858
|
dialogProps: {
|
|
@@ -691,6 +862,6 @@ function PaymentForm({
|
|
|
691
862
|
}),
|
|
692
863
|
title: t("payment.customer.pastDue.alert.title")
|
|
693
864
|
}
|
|
694
|
-
})]
|
|
865
|
+
}), FastCheckoutConfirmDialog]
|
|
695
866
|
});
|
|
696
867
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.35",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@arcblock/did-connect": "^2.13.
|
|
58
|
-
"@arcblock/ux": "^2.13.
|
|
57
|
+
"@arcblock/did-connect": "^2.13.12",
|
|
58
|
+
"@arcblock/ux": "^2.13.12",
|
|
59
59
|
"@arcblock/ws": "^1.20.2",
|
|
60
|
-
"@blocklet/ui-react": "^2.13.
|
|
60
|
+
"@blocklet/ui-react": "^2.13.12",
|
|
61
61
|
"@mui/icons-material": "^5.16.6",
|
|
62
62
|
"@mui/lab": "^5.0.0-alpha.173",
|
|
63
63
|
"@mui/material": "^5.16.6",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"@babel/core": "^7.25.2",
|
|
94
94
|
"@babel/preset-env": "^7.25.2",
|
|
95
95
|
"@babel/preset-react": "^7.24.7",
|
|
96
|
-
"@blocklet/payment-types": "1.18.
|
|
96
|
+
"@blocklet/payment-types": "1.18.35",
|
|
97
97
|
"@storybook/addon-essentials": "^7.6.20",
|
|
98
98
|
"@storybook/addon-interactions": "^7.6.20",
|
|
99
99
|
"@storybook/addon-links": "^7.6.20",
|
|
@@ -124,5 +124,5 @@
|
|
|
124
124
|
"vite-plugin-babel": "^1.2.0",
|
|
125
125
|
"vite-plugin-node-polyfills": "^0.21.0"
|
|
126
126
|
},
|
|
127
|
-
"gitHead": "
|
|
127
|
+
"gitHead": "802a98b5ca81475f8cd7b9dcbb77fce7240b9788"
|
|
128
128
|
}
|
|
@@ -103,7 +103,7 @@ function OverdueInvoicePayment({
|
|
|
103
103
|
alertMessage = '',
|
|
104
104
|
authToken,
|
|
105
105
|
}: Props) {
|
|
106
|
-
const { t } = useLocaleContext();
|
|
106
|
+
const { t, locale } = useLocaleContext();
|
|
107
107
|
const { connect, session } = usePaymentContext();
|
|
108
108
|
const [selectCurrencyId, setSelectCurrencyId] = useState('');
|
|
109
109
|
const [payLoading, setPayLoading] = useState(false);
|
|
@@ -251,12 +251,18 @@ function OverdueInvoicePayment({
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
connect.open({
|
|
254
|
+
locale: locale as 'en' | 'zh',
|
|
254
255
|
containerEl: undefined as unknown as Element,
|
|
255
256
|
saveConnect: false,
|
|
256
257
|
action: 'collect-batch',
|
|
257
258
|
prefix: joinURL(getPrefix(), '/api/did'),
|
|
258
259
|
useSocket: !isCrossOriginRequest,
|
|
259
260
|
extraParams,
|
|
261
|
+
messages: {
|
|
262
|
+
scan: t('common.connect.defaultScan'),
|
|
263
|
+
title: t('payment.customer.invoice.payBatch'),
|
|
264
|
+
confirm: t('common.connect.confirm'),
|
|
265
|
+
} as any,
|
|
260
266
|
onSuccess: () => {
|
|
261
267
|
connect.close();
|
|
262
268
|
handleConnected();
|
|
@@ -605,7 +605,7 @@ const InvoiceList = React.memo((props: Props & { onPay: (invoiceId: string) => v
|
|
|
605
605
|
|
|
606
606
|
export default function CustomerInvoiceList(props: Props) {
|
|
607
607
|
const { action, type } = props;
|
|
608
|
-
const { t } = useLocaleContext();
|
|
608
|
+
const { t, locale } = useLocaleContext();
|
|
609
609
|
const { connect } = usePaymentContext();
|
|
610
610
|
const [state, setState] = useSetState({ paying: '' });
|
|
611
611
|
|
|
@@ -618,6 +618,7 @@ export default function CustomerInvoiceList(props: Props) {
|
|
|
618
618
|
connect.open({
|
|
619
619
|
action: 'collect',
|
|
620
620
|
saveConnect: false,
|
|
621
|
+
locale: locale as 'en' | 'zh',
|
|
621
622
|
useSocket: isCrossOrigin() === false,
|
|
622
623
|
messages: {
|
|
623
624
|
scan: '',
|
package/src/libs/util.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-nested-ternary */
|
|
2
2
|
/* eslint-disable @typescript-eslint/indent */
|
|
3
3
|
import type {
|
|
4
|
+
ChainType,
|
|
4
5
|
PaymentDetails,
|
|
5
6
|
PriceCurrency,
|
|
6
7
|
PriceRecurring,
|
|
@@ -1259,3 +1260,17 @@ export function parseMarkedText(text: string): Array<{
|
|
|
1259
1260
|
|
|
1260
1261
|
return result.filter((p) => p.content !== '');
|
|
1261
1262
|
}
|
|
1263
|
+
|
|
1264
|
+
export function getTokenBalanceLink(method: TPaymentMethod, address: string) {
|
|
1265
|
+
if (!method || !address) {
|
|
1266
|
+
return '';
|
|
1267
|
+
}
|
|
1268
|
+
const explorerHost = (method?.settings?.[method?.type as ChainType] as any)?.explorer_host || '';
|
|
1269
|
+
if (method.type === 'arcblock' && address) {
|
|
1270
|
+
return joinURL(explorerHost, 'accounts', address, 'tokens');
|
|
1271
|
+
}
|
|
1272
|
+
if (['ethereum', 'base'].includes(method.type) && address) {
|
|
1273
|
+
return joinURL(explorerHost, 'address', address);
|
|
1274
|
+
}
|
|
1275
|
+
return '';
|
|
1276
|
+
}
|
package/src/libs/validator.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import isPostalCode, { PostalCodeLocale } from 'validator/lib/isPostalCode';
|
|
2
|
+
import { t } from '../locales';
|
|
2
3
|
|
|
3
4
|
const POSTAL_CODE_SUPPORTED_COUNTRIES: PostalCodeLocale[] = [
|
|
4
5
|
'AD',
|
|
@@ -68,3 +69,16 @@ export function validatePostalCode(postalCode: string, country?: string): boolea
|
|
|
68
69
|
return false;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
72
|
+
|
|
73
|
+
export function getFieldValidation(fieldName: string, validations?: Record<string, any>, locale: string = 'en') {
|
|
74
|
+
if (!validations || !validations[fieldName]) return {};
|
|
75
|
+
const fieldValidation = validations[fieldName];
|
|
76
|
+
const rules: Record<string, any> = {};
|
|
77
|
+
if (fieldValidation.pattern) {
|
|
78
|
+
rules.pattern = {
|
|
79
|
+
value: new RegExp(fieldValidation.pattern),
|
|
80
|
+
message: fieldValidation.pattern_message?.[locale] || t('payment.checkout.invalid', locale),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return rules;
|
|
84
|
+
}
|