@blocklet/payment-react 1.19.18 → 1.19.19
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/README.md +313 -0
- package/es/checkout/form.js +2 -2
- package/es/components/auto-topup/index.d.ts +14 -0
- package/es/components/auto-topup/index.js +417 -0
- package/es/components/auto-topup/modal.d.ts +35 -0
- package/es/components/auto-topup/modal.js +734 -0
- package/es/components/auto-topup/product-card.d.ts +13 -0
- package/es/components/auto-topup/product-card.js +173 -0
- package/es/components/collapse.d.ts +13 -0
- package/es/components/collapse.js +76 -0
- package/es/components/input.d.ts +2 -1
- package/es/components/input.js +64 -13
- package/es/components/label.d.ts +2 -1
- package/es/components/label.js +2 -1
- package/es/index.d.ts +4 -1
- package/es/index.js +7 -1
- package/es/libs/util.js +2 -1
- package/es/locales/en.js +56 -0
- package/es/locales/zh.js +56 -0
- package/es/payment/form/index.js +6 -0
- package/es/payment/product-item.js +17 -10
- package/lib/checkout/form.js +2 -2
- package/lib/components/auto-topup/index.d.ts +14 -0
- package/lib/components/auto-topup/index.js +451 -0
- package/lib/components/auto-topup/modal.d.ts +35 -0
- package/lib/components/auto-topup/modal.js +803 -0
- package/lib/components/auto-topup/product-card.d.ts +13 -0
- package/lib/components/auto-topup/product-card.js +149 -0
- package/lib/components/collapse.d.ts +13 -0
- package/lib/components/collapse.js +74 -0
- package/lib/components/input.d.ts +2 -1
- package/lib/components/input.js +66 -24
- package/lib/components/label.d.ts +2 -1
- package/lib/components/label.js +3 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.js +24 -0
- package/lib/libs/util.js +2 -1
- package/lib/locales/en.js +56 -0
- package/lib/locales/zh.js +56 -0
- package/lib/payment/form/index.js +6 -0
- package/lib/payment/product-item.js +18 -10
- package/package.json +9 -9
- package/src/checkout/form.tsx +2 -2
- package/src/components/auto-topup/index.tsx +449 -0
- package/src/components/auto-topup/modal.tsx +773 -0
- package/src/components/auto-topup/product-card.tsx +156 -0
- package/src/components/collapse.tsx +82 -0
- package/src/components/input.tsx +71 -22
- package/src/components/label.tsx +8 -2
- package/src/index.ts +7 -0
- package/src/libs/util.ts +1 -0
- package/src/locales/en.tsx +59 -0
- package/src/locales/zh.tsx +57 -0
- package/src/payment/form/index.tsx +6 -0
- package/src/payment/product-item.tsx +18 -11
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TPaymentCurrency } from '@blocklet/payment-types';
|
|
2
|
+
interface AutoTopupProductCardProps {
|
|
3
|
+
product: any;
|
|
4
|
+
price: any;
|
|
5
|
+
currency: TPaymentCurrency;
|
|
6
|
+
quantity: number;
|
|
7
|
+
onQuantityChange: (quantity: number) => void;
|
|
8
|
+
maxQuantity?: number;
|
|
9
|
+
minQuantity?: number;
|
|
10
|
+
creditCurrency: TPaymentCurrency;
|
|
11
|
+
}
|
|
12
|
+
export default function AutoTopupProductCard({ product, price, currency, quantity, onQuantityChange, maxQuantity, minQuantity, creditCurrency, }: AutoTopupProductCardProps): import("react").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = AutoTopupProductCard;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _material = require("@mui/material");
|
|
9
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _productCard = _interopRequireDefault(require("../../payment/product-card"));
|
|
12
|
+
var _util = require("../../libs/util");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
function AutoTopupProductCard({
|
|
15
|
+
product,
|
|
16
|
+
price,
|
|
17
|
+
currency,
|
|
18
|
+
quantity,
|
|
19
|
+
onQuantityChange,
|
|
20
|
+
maxQuantity = 99,
|
|
21
|
+
minQuantity = 1,
|
|
22
|
+
creditCurrency
|
|
23
|
+
}) {
|
|
24
|
+
const {
|
|
25
|
+
t
|
|
26
|
+
} = (0, _context.useLocaleContext)();
|
|
27
|
+
const [localQuantity, setLocalQuantity] = (0, _react.useState)(quantity);
|
|
28
|
+
const localQuantityNum = Number(localQuantity) || 0;
|
|
29
|
+
const handleQuantityChange = newQuantity => {
|
|
30
|
+
if (!newQuantity) {
|
|
31
|
+
setLocalQuantity(void 0);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (newQuantity >= minQuantity && newQuantity <= maxQuantity) {
|
|
35
|
+
setLocalQuantity(newQuantity);
|
|
36
|
+
onQuantityChange(newQuantity);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const handleQuantityInputChange = event => {
|
|
40
|
+
const value = parseInt(event.target.value || "0", 10);
|
|
41
|
+
if (!Number.isNaN(value)) {
|
|
42
|
+
handleQuantityChange(value);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const creditUnitAmount = Number(price.metadata?.credit_config?.credit_amount || 0);
|
|
46
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Card, {
|
|
47
|
+
variant: "outlined",
|
|
48
|
+
sx: {
|
|
49
|
+
p: 2
|
|
50
|
+
},
|
|
51
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
52
|
+
direction: "row",
|
|
53
|
+
spacing: 2,
|
|
54
|
+
sx: {
|
|
55
|
+
flexDirection: {
|
|
56
|
+
xs: "column",
|
|
57
|
+
sm: "row"
|
|
58
|
+
},
|
|
59
|
+
alignItems: {
|
|
60
|
+
xs: "flex-start",
|
|
61
|
+
sm: "center"
|
|
62
|
+
},
|
|
63
|
+
justifyContent: {
|
|
64
|
+
xs: "flex-start",
|
|
65
|
+
sm: "space-between"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
69
|
+
direction: "row",
|
|
70
|
+
spacing: 2,
|
|
71
|
+
sx: {
|
|
72
|
+
alignItems: "center",
|
|
73
|
+
flex: 1
|
|
74
|
+
},
|
|
75
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_productCard.default, {
|
|
76
|
+
name: product?.name || "",
|
|
77
|
+
description: t("payment.autoTopup.creditsIncluded", {
|
|
78
|
+
name: creditCurrency?.name,
|
|
79
|
+
num: (0, _util.formatNumber)(creditUnitAmount * localQuantityNum)
|
|
80
|
+
}),
|
|
81
|
+
logo: product?.images?.[0],
|
|
82
|
+
size: 40
|
|
83
|
+
})
|
|
84
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
85
|
+
direction: "row",
|
|
86
|
+
spacing: 1,
|
|
87
|
+
sx: {
|
|
88
|
+
alignItems: "center",
|
|
89
|
+
alignSelf: {
|
|
90
|
+
xs: "flex-end",
|
|
91
|
+
sm: "center"
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
95
|
+
variant: "body2",
|
|
96
|
+
sx: {
|
|
97
|
+
color: "text.secondary",
|
|
98
|
+
minWidth: "fit-content"
|
|
99
|
+
},
|
|
100
|
+
children: [t("common.quantity"), ":"]
|
|
101
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.TextField, {
|
|
102
|
+
size: "small",
|
|
103
|
+
value: localQuantity,
|
|
104
|
+
onChange: handleQuantityInputChange,
|
|
105
|
+
type: "number",
|
|
106
|
+
sx: {
|
|
107
|
+
"& .MuiInputBase-root": {
|
|
108
|
+
height: 32
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
slotProps: {
|
|
112
|
+
htmlInput: {
|
|
113
|
+
min: 0,
|
|
114
|
+
max: maxQuantity,
|
|
115
|
+
style: {
|
|
116
|
+
textAlign: "center",
|
|
117
|
+
padding: "4px 8px"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
})]
|
|
122
|
+
})]
|
|
123
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
124
|
+
direction: "row",
|
|
125
|
+
sx: {
|
|
126
|
+
justifyContent: "space-between",
|
|
127
|
+
alignItems: "center",
|
|
128
|
+
mt: 2,
|
|
129
|
+
pt: 2,
|
|
130
|
+
borderTop: "1px solid",
|
|
131
|
+
borderColor: "divider"
|
|
132
|
+
},
|
|
133
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
134
|
+
variant: "body2",
|
|
135
|
+
sx: {
|
|
136
|
+
color: "text.secondary"
|
|
137
|
+
},
|
|
138
|
+
children: t("payment.autoTopup.rechargeAmount")
|
|
139
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
140
|
+
variant: "h6",
|
|
141
|
+
sx: {
|
|
142
|
+
fontWeight: 600,
|
|
143
|
+
color: "text.primary"
|
|
144
|
+
},
|
|
145
|
+
children: (0, _util.formatPrice)(price, currency, product?.unit_label, localQuantity, true)
|
|
146
|
+
})]
|
|
147
|
+
})]
|
|
148
|
+
});
|
|
149
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
trigger: string | ((expanded: boolean) => React.ReactNode) | React.ReactNode;
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
expanded?: boolean;
|
|
5
|
+
addons?: React.ReactNode;
|
|
6
|
+
style?: Record<string, any>;
|
|
7
|
+
value?: string;
|
|
8
|
+
onChange?: (value: string, expanded: boolean) => void;
|
|
9
|
+
lazy?: boolean;
|
|
10
|
+
card?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export default function IconCollapse(rawProps: Props): import("react").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = IconCollapse;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _iconsMaterial = require("@mui/icons-material");
|
|
9
|
+
var _material = require("@mui/material");
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
function IconCollapse(rawProps) {
|
|
12
|
+
const props = Object.assign({
|
|
13
|
+
value: "",
|
|
14
|
+
onChange: () => {},
|
|
15
|
+
children: null,
|
|
16
|
+
expanded: false,
|
|
17
|
+
addons: null,
|
|
18
|
+
style: {},
|
|
19
|
+
lazy: true,
|
|
20
|
+
card: false
|
|
21
|
+
}, rawProps);
|
|
22
|
+
const [expanded, setExpanded] = (0, _react.useState)(props.expanded || false);
|
|
23
|
+
const toggleExpanded = () => {
|
|
24
|
+
const newExpanded = !expanded;
|
|
25
|
+
setExpanded(newExpanded);
|
|
26
|
+
};
|
|
27
|
+
(0, _react.useEffect)(() => {
|
|
28
|
+
setExpanded(props.expanded || false);
|
|
29
|
+
}, [props.expanded]);
|
|
30
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
31
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
32
|
+
direction: "row",
|
|
33
|
+
onClick: e => {
|
|
34
|
+
e.stopPropagation();
|
|
35
|
+
props.onChange?.(props.value || "", !expanded);
|
|
36
|
+
toggleExpanded();
|
|
37
|
+
},
|
|
38
|
+
sx: {
|
|
39
|
+
alignItems: "center",
|
|
40
|
+
justifyContent: "space-between",
|
|
41
|
+
width: 1,
|
|
42
|
+
cursor: "pointer",
|
|
43
|
+
fontWeight: 500,
|
|
44
|
+
color: "text.primary",
|
|
45
|
+
"& :hover": {
|
|
46
|
+
color: "primary.main"
|
|
47
|
+
},
|
|
48
|
+
...(props.card && {
|
|
49
|
+
borderRadius: 1,
|
|
50
|
+
padding: 1,
|
|
51
|
+
pl: 2,
|
|
52
|
+
backgroundColor: "grey.100"
|
|
53
|
+
}),
|
|
54
|
+
...props.style
|
|
55
|
+
},
|
|
56
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
57
|
+
children: typeof props.trigger === "function" ? props.trigger(expanded) : props.trigger
|
|
58
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
59
|
+
direction: "row",
|
|
60
|
+
spacing: 2,
|
|
61
|
+
sx: {
|
|
62
|
+
alignItems: "center"
|
|
63
|
+
},
|
|
64
|
+
children: [props.addons, " ", expanded ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.ExpandLessOutlined, {}) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.ExpandMoreOutlined, {})]
|
|
65
|
+
})]
|
|
66
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Collapse, {
|
|
67
|
+
in: expanded,
|
|
68
|
+
sx: {
|
|
69
|
+
width: "100%"
|
|
70
|
+
},
|
|
71
|
+
children: expanded || props.lazy ? props.children : null
|
|
72
|
+
})]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -11,8 +11,9 @@ type InputProps = TextFieldProps & {
|
|
|
11
11
|
required?: boolean;
|
|
12
12
|
tooltip?: ReactNode | string;
|
|
13
13
|
description?: ReactNode | string;
|
|
14
|
+
layout?: 'vertical' | 'horizontal';
|
|
14
15
|
};
|
|
15
|
-
export default function FormInput({ ref, name, label, placeholder, rules, errorPosition, wrapperStyle, inputProps, required, tooltip, description, ...rest }: InputProps & {
|
|
16
|
+
export default function FormInput({ ref, name, label, placeholder, rules, errorPosition, wrapperStyle, inputProps, required, tooltip, description, layout, slotProps, ...rest }: InputProps & {
|
|
16
17
|
ref?: React.RefObject<HTMLInputElement | null>;
|
|
17
18
|
inputProps?: TextFieldProps['inputProps'];
|
|
18
19
|
}): JSX.Element;
|
package/lib/components/input.js
CHANGED
|
@@ -35,51 +35,93 @@ function FormInput({
|
|
|
35
35
|
required = false,
|
|
36
36
|
tooltip = "",
|
|
37
37
|
description = "",
|
|
38
|
+
layout = "vertical",
|
|
39
|
+
slotProps,
|
|
38
40
|
...rest
|
|
39
41
|
}) {
|
|
40
42
|
const {
|
|
41
43
|
control,
|
|
42
44
|
formState
|
|
43
45
|
} = (0, _reactHookForm.useFormContext)();
|
|
46
|
+
const theme = (0, _material.useTheme)();
|
|
47
|
+
const isMobile = (0, _material.useMediaQuery)(theme.breakpoints.down("sm"));
|
|
44
48
|
const inputRef = (0, _react.useRef)(null);
|
|
45
49
|
(0, _react.useImperativeHandle)(ref, () => {
|
|
46
50
|
return inputRef.current;
|
|
47
51
|
});
|
|
48
52
|
const error = (0, _get.default)(formState.errors, name)?.message;
|
|
53
|
+
const isHorizontal = layout === "horizontal" && !isMobile;
|
|
54
|
+
const mergedSlotProps = {
|
|
55
|
+
htmlInput: {
|
|
56
|
+
...inputProps,
|
|
57
|
+
...slotProps?.htmlInput
|
|
58
|
+
},
|
|
59
|
+
input: Object.assign(rest.InputProps || {}, slotProps?.input || {}, errorPosition === "right" && error ? {
|
|
60
|
+
endAdornment: /* @__PURE__ */(0, _jsxRuntime.jsx)(FormInputError, {
|
|
61
|
+
error
|
|
62
|
+
})
|
|
63
|
+
} : {})
|
|
64
|
+
};
|
|
65
|
+
const renderLabel = () => {
|
|
66
|
+
if (!label) return null;
|
|
67
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_label.default, {
|
|
68
|
+
required,
|
|
69
|
+
tooltip,
|
|
70
|
+
description,
|
|
71
|
+
boxSx: isHorizontal ? {
|
|
72
|
+
width: "fit-content",
|
|
73
|
+
whiteSpace: "nowrap",
|
|
74
|
+
minWidth: "fit-content"
|
|
75
|
+
} : void 0,
|
|
76
|
+
children: label
|
|
77
|
+
});
|
|
78
|
+
};
|
|
49
79
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
|
|
50
80
|
name,
|
|
51
81
|
control,
|
|
52
82
|
rules,
|
|
53
83
|
render: ({
|
|
54
84
|
field
|
|
55
|
-
}) => /* @__PURE__ */(0, _jsxRuntime.
|
|
85
|
+
}) => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
56
86
|
sx: {
|
|
57
87
|
width: "100%",
|
|
58
88
|
...wrapperStyle
|
|
59
89
|
},
|
|
60
|
-
children:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
})
|
|
90
|
+
children: isHorizontal ? /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
91
|
+
direction: "row",
|
|
92
|
+
spacing: 2,
|
|
93
|
+
sx: {
|
|
94
|
+
alignItems: "center",
|
|
95
|
+
justifyContent: "space-between"
|
|
96
|
+
},
|
|
97
|
+
children: [renderLabel(), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.TextField, {
|
|
98
|
+
fullWidth: false,
|
|
99
|
+
error: !!error,
|
|
100
|
+
helperText: errorPosition === "bottom" && error ? error : "",
|
|
101
|
+
placeholder,
|
|
102
|
+
size: "small",
|
|
103
|
+
...field,
|
|
104
|
+
...rest,
|
|
105
|
+
inputRef,
|
|
106
|
+
slotProps: mergedSlotProps,
|
|
107
|
+
sx: {
|
|
108
|
+
flex: 1,
|
|
109
|
+
...rest.sx
|
|
110
|
+
}
|
|
111
|
+
})]
|
|
112
|
+
}) : /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
113
|
+
children: [renderLabel(), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.TextField, {
|
|
114
|
+
fullWidth: true,
|
|
115
|
+
error: !!error,
|
|
116
|
+
helperText: errorPosition === "bottom" && error ? error : "",
|
|
117
|
+
placeholder,
|
|
118
|
+
size: "small",
|
|
119
|
+
...field,
|
|
120
|
+
...rest,
|
|
121
|
+
inputRef,
|
|
122
|
+
slotProps: mergedSlotProps
|
|
123
|
+
})]
|
|
124
|
+
})
|
|
83
125
|
})
|
|
84
126
|
});
|
|
85
127
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { FormLabelProps } from '@mui/material';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
|
-
export default function CustomFormLabel({ children, required, tooltip, description, ...props }: FormLabelProps & {
|
|
3
|
+
export default function CustomFormLabel({ children, required, tooltip, description, boxSx, ...props }: FormLabelProps & {
|
|
4
4
|
required?: boolean;
|
|
5
5
|
tooltip?: ReactNode | string;
|
|
6
6
|
description?: ReactNode | string;
|
|
7
|
+
boxSx?: React.CSSProperties;
|
|
7
8
|
}): import("react").JSX.Element;
|
package/lib/components/label.js
CHANGED
|
@@ -12,12 +12,14 @@ function CustomFormLabel({
|
|
|
12
12
|
required = false,
|
|
13
13
|
tooltip = "",
|
|
14
14
|
description = "",
|
|
15
|
+
boxSx = {},
|
|
15
16
|
...props
|
|
16
17
|
}) {
|
|
17
18
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
18
19
|
sx: {
|
|
19
20
|
mb: 1,
|
|
20
|
-
width: "100%"
|
|
21
|
+
width: "100%",
|
|
22
|
+
...boxSx
|
|
21
23
|
},
|
|
22
24
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.FormLabel, {
|
|
23
25
|
...props,
|
package/lib/index.d.ts
CHANGED
|
@@ -36,6 +36,9 @@ import PaymentBeneficiaries from './components/payment-beneficiaries';
|
|
|
36
36
|
import LoadingButton from './components/loading-button';
|
|
37
37
|
import ResumeSubscription from './components/resume-subscription';
|
|
38
38
|
import DateRangePicker from './components/date-range-picker';
|
|
39
|
+
import AutoTopupModal from './components/auto-topup/modal';
|
|
40
|
+
import AutoTopup from './components/auto-topup';
|
|
41
|
+
import Collapse from './components/collapse';
|
|
39
42
|
export { PaymentThemeProvider } from './theme';
|
|
40
43
|
export * from './libs/util';
|
|
41
44
|
export * from './libs/connect';
|
|
@@ -50,4 +53,4 @@ export * from './hooks/scroll';
|
|
|
50
53
|
export * from './hooks/keyboard';
|
|
51
54
|
export * from './libs/validator';
|
|
52
55
|
export { translations, createTranslator } from './locales';
|
|
53
|
-
export { createLazyComponent, api, dayjs, FormInput, FormLabel, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, TxLink, TxGas, SafeGuard, PricingItem, CountrySelect, Table, TruncatedText, Link, OverdueInvoicePayment, PaymentBeneficiaries, LoadingButton, DonateDetails, ResumeSubscription, CreditGrantsList, CreditTransactionsList, DateRangePicker, CreditStatusChip, };
|
|
56
|
+
export { createLazyComponent, api, dayjs, FormInput, FormLabel, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, TxLink, TxGas, SafeGuard, PricingItem, CountrySelect, Table, TruncatedText, Link, OverdueInvoicePayment, PaymentBeneficiaries, LoadingButton, DonateDetails, ResumeSubscription, CreditGrantsList, CreditTransactionsList, DateRangePicker, CreditStatusChip, AutoTopupModal, AutoTopup, Collapse, };
|
package/lib/index.js
CHANGED
|
@@ -44,6 +44,9 @@ var _exportNames = {
|
|
|
44
44
|
LoadingButton: true,
|
|
45
45
|
ResumeSubscription: true,
|
|
46
46
|
DateRangePicker: true,
|
|
47
|
+
AutoTopupModal: true,
|
|
48
|
+
AutoTopup: true,
|
|
49
|
+
Collapse: true,
|
|
47
50
|
PaymentThemeProvider: true,
|
|
48
51
|
translations: true,
|
|
49
52
|
createTranslator: true
|
|
@@ -60,6 +63,18 @@ Object.defineProperty(exports, "Amount", {
|
|
|
60
63
|
return _amount.default;
|
|
61
64
|
}
|
|
62
65
|
});
|
|
66
|
+
Object.defineProperty(exports, "AutoTopup", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _autoTopup.default;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "AutoTopupModal", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _modal.default;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
63
78
|
Object.defineProperty(exports, "CheckoutDonate", {
|
|
64
79
|
enumerable: true,
|
|
65
80
|
get: function () {
|
|
@@ -78,6 +93,12 @@ Object.defineProperty(exports, "CheckoutTable", {
|
|
|
78
93
|
return _table.default;
|
|
79
94
|
}
|
|
80
95
|
});
|
|
96
|
+
Object.defineProperty(exports, "Collapse", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function () {
|
|
99
|
+
return _collapse.default;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
81
102
|
Object.defineProperty(exports, "ConfirmDialog", {
|
|
82
103
|
enumerable: true,
|
|
83
104
|
get: function () {
|
|
@@ -344,6 +365,9 @@ var _paymentBeneficiaries = _interopRequireDefault(require("./components/payment
|
|
|
344
365
|
var _loadingButton = _interopRequireDefault(require("./components/loading-button"));
|
|
345
366
|
var _resumeSubscription = _interopRequireDefault(require("./components/resume-subscription"));
|
|
346
367
|
var _dateRangePicker = _interopRequireDefault(require("./components/date-range-picker"));
|
|
368
|
+
var _modal = _interopRequireDefault(require("./components/auto-topup/modal"));
|
|
369
|
+
var _autoTopup = _interopRequireDefault(require("./components/auto-topup"));
|
|
370
|
+
var _collapse = _interopRequireDefault(require("./components/collapse"));
|
|
347
371
|
var _theme = require("./theme");
|
|
348
372
|
var _util = require("./libs/util");
|
|
349
373
|
Object.keys(_util).forEach(function (key) {
|
package/lib/libs/util.js
CHANGED
|
@@ -1151,7 +1151,8 @@ function getInvoiceDescriptionAndReason(invoice, locale = "en") {
|
|
|
1151
1151
|
return_stake: (0, _locales.t)("payment.invoice.reason.returnStake", locale),
|
|
1152
1152
|
recharge: (0, _locales.t)("payment.invoice.reason.recharge", locale),
|
|
1153
1153
|
stake_overdraft_protection: (0, _locales.t)("payment.invoice.reason.stake", locale),
|
|
1154
|
-
overdraft_protection: (0, _locales.t)("payment.invoice.reason.fee", locale)
|
|
1154
|
+
overdraft_protection: (0, _locales.t)("payment.invoice.reason.fee", locale),
|
|
1155
|
+
auto_recharge: (0, _locales.t)("payment.invoice.reason.recharge", locale)
|
|
1155
1156
|
};
|
|
1156
1157
|
let invoiceType = (0, _locales.t)("payment.invoice.reason.payment", locale);
|
|
1157
1158
|
if (reason.includes("stake") || reason.includes("recharge") || reason === "overdraft_protection") {
|
package/lib/locales/en.js
CHANGED
|
@@ -36,6 +36,8 @@ module.exports = (0, _flat.default)({
|
|
|
36
36
|
removed: "Resource removed",
|
|
37
37
|
confirm: "Confirm",
|
|
38
38
|
clear: "Clear",
|
|
39
|
+
show: "Show",
|
|
40
|
+
hide: "Hide",
|
|
39
41
|
selectTimeRange: "Select time range",
|
|
40
42
|
startDate: "Start date",
|
|
41
43
|
endDate: "End date",
|
|
@@ -260,6 +262,60 @@ module.exports = (0, _flat.default)({
|
|
|
260
262
|
}
|
|
261
263
|
}
|
|
262
264
|
},
|
|
265
|
+
autoTopup: {
|
|
266
|
+
title: "Auto Top-Up",
|
|
267
|
+
enableLabel: "Auto Top-Up",
|
|
268
|
+
purchaseConfig: "Credit Purchase Configuration",
|
|
269
|
+
triggerThreshold: "When credits are below",
|
|
270
|
+
thresholdPlaceholder: "Enter threshold amount",
|
|
271
|
+
thresholdDescription: "Credits remaining to trigger auto top-up",
|
|
272
|
+
thresholdMinError: "Threshold must be greater than 0",
|
|
273
|
+
thresholdFormatError: "Please enter a valid number",
|
|
274
|
+
creditsIncluded: "{num} {name} included",
|
|
275
|
+
purchaseBelow: "Purchase this package",
|
|
276
|
+
perPackage: "per package",
|
|
277
|
+
quantity: "Quantity",
|
|
278
|
+
selectPaymentMethod: "Select payment method",
|
|
279
|
+
paymentInformation: "Payment Information",
|
|
280
|
+
saveConfiguration: "Save Configuration",
|
|
281
|
+
saveSuccess: "Auto top-up configuration saved successfully",
|
|
282
|
+
disableSuccess: "Auto top-up disabled successfully",
|
|
283
|
+
authorizationRequired: "Payment authorization is required to complete the setup",
|
|
284
|
+
cryptoAuthorizationNote: "You will need to authorize payments from your wallet to enable automatic top-ups",
|
|
285
|
+
tip: "With auto top-up enabled, the system automatically buys the specified credit package when your balance drops below the threshold.",
|
|
286
|
+
authTitle: "Auto Top-Up Authorization",
|
|
287
|
+
authTip: "Please complete the authorization process to enable automatic top-up",
|
|
288
|
+
rechargeAmount: "Top-up Amount per Time",
|
|
289
|
+
currentPaymentMethod: "Current Payment Method",
|
|
290
|
+
changePaymentMethod: "Change Payment Method",
|
|
291
|
+
keepCurrent: "Keep Current",
|
|
292
|
+
changePaymentMethodTip: "You will be redirected to set up a new payment method when saving.",
|
|
293
|
+
noPaymentMethodSetup: "No payment method configured. Please set up a payment method first.",
|
|
294
|
+
addFunds: "Add Funds",
|
|
295
|
+
advanced: "Advanced Options",
|
|
296
|
+
enabled: "Enabled",
|
|
297
|
+
disabled: "Disabled",
|
|
298
|
+
notConfigured: "Auto Top-Up not configured",
|
|
299
|
+
setup: "Enable Auto Top-Up",
|
|
300
|
+
ruleDisplay: "When balance < {threshold}, top-up {amount} to get {credits} credits",
|
|
301
|
+
activeDescription: "Auto top-up is enabled. When Credits drop below {threshold}, the system will automatically purchase {credits} Credits for {amount}",
|
|
302
|
+
activeDescriptionWithCredits: "Auto top-up is enabled. When Credits drop below {threshold}, the system will automatically purchase {credits}.",
|
|
303
|
+
purchaseAmount: "Purchase Amount",
|
|
304
|
+
paymentMethod: "Payment Method",
|
|
305
|
+
walletBalance: "Wallet Balance",
|
|
306
|
+
paymentAddress: "Payment Address",
|
|
307
|
+
inactiveDescription: "Enable auto top-up to automatically renew when {name} are insufficient, effectively avoiding service interruptions.",
|
|
308
|
+
showDetails: "Show Method",
|
|
309
|
+
hideDetails: "Hide Method",
|
|
310
|
+
dailyLimits: {
|
|
311
|
+
maxAmount: "Daily Top-up Amount Limit",
|
|
312
|
+
maxAmountPlaceholder: "0 means unlimited",
|
|
313
|
+
maxAmountDescription: "The maximum amount of top-up you can make each day, 0 means unlimited",
|
|
314
|
+
maxAttempts: "Daily Top-up Attempts Limit",
|
|
315
|
+
maxAttemptsPlaceholder: "0 means unlimited",
|
|
316
|
+
maxAttemptsDescription: "The maximum number of top-up attempts you can make each day, 0 means unlimited"
|
|
317
|
+
}
|
|
318
|
+
},
|
|
263
319
|
customer: {
|
|
264
320
|
payments: "Payment History",
|
|
265
321
|
invoices: "Invoice History",
|
package/lib/locales/zh.js
CHANGED
|
@@ -39,6 +39,8 @@ module.exports = (0, _flat.default)({
|
|
|
39
39
|
confirm: "\u786E\u8BA4",
|
|
40
40
|
cancel: "\u53D6\u6D88",
|
|
41
41
|
clear: "\u6E05\u7A7A",
|
|
42
|
+
show: "\u663E\u793A",
|
|
43
|
+
hide: "\u9690\u85CF",
|
|
42
44
|
selectTimeRange: "\u9009\u62E9\u65F6\u95F4\u8303\u56F4",
|
|
43
45
|
startDate: "\u5F00\u59CB\u65E5\u671F",
|
|
44
46
|
endDate: "\u7ED3\u675F\u65E5\u671F",
|
|
@@ -260,6 +262,60 @@ module.exports = (0, _flat.default)({
|
|
|
260
262
|
}
|
|
261
263
|
}
|
|
262
264
|
},
|
|
265
|
+
autoTopup: {
|
|
266
|
+
title: "\u81EA\u52A8\u5145\u503C",
|
|
267
|
+
enableLabel: "\u81EA\u52A8\u5145\u503C",
|
|
268
|
+
purchaseConfig: "\u8D2D\u4E70\u914D\u7F6E",
|
|
269
|
+
triggerThreshold: "\u5F53\u989D\u5EA6\u4F4E\u4E8E",
|
|
270
|
+
thresholdPlaceholder: "\u8F93\u5165\u89E6\u53D1\u9608\u503C",
|
|
271
|
+
thresholdDescription: "\u89E6\u53D1\u81EA\u52A8\u5145\u503C\u7684\u5269\u4F59\u989D\u5EA6",
|
|
272
|
+
thresholdMinError: "\u9608\u503C\u5FC5\u987B\u5927\u4E8E0",
|
|
273
|
+
thresholdFormatError: "\u8BF7\u8F93\u5165\u6709\u6548\u6570\u5B57",
|
|
274
|
+
creditsIncluded: "\u5305\u542B {num} {name}",
|
|
275
|
+
purchaseBelow: "\u8D2D\u4E70\u6B64\u5957\u9910",
|
|
276
|
+
perPackage: "\u6BCF\u5305",
|
|
277
|
+
quantity: "\u6570\u91CF",
|
|
278
|
+
selectPaymentMethod: "\u9009\u62E9\u652F\u4ED8\u65B9\u5F0F",
|
|
279
|
+
paymentInformation: "\u652F\u4ED8\u4FE1\u606F",
|
|
280
|
+
saveConfiguration: "\u4FDD\u5B58\u914D\u7F6E",
|
|
281
|
+
saveSuccess: "\u81EA\u52A8\u5145\u503C\u914D\u7F6E\u4FDD\u5B58\u6210\u529F",
|
|
282
|
+
disableSuccess: "\u5DF2\u5173\u95ED\u81EA\u52A8\u5145\u503C",
|
|
283
|
+
stripeSetupRequired: "\u9700\u8981\u4FE1\u7528\u5361\u6388\u6743\u4EE5\u8FDB\u884C\u81EA\u52A8\u652F\u4ED8",
|
|
284
|
+
cryptoAuthorizationNote: "\u60A8\u9700\u8981\u4ECE\u94B1\u5305\u6388\u6743\u652F\u4ED8\u4EE5\u542F\u7528\u81EA\u52A8\u5145\u503C",
|
|
285
|
+
tip: "\u542F\u7528\u81EA\u52A8\u5145\u503C\u540E\uFF0C\u5F53\u60A8\u7684\u989D\u5EA6\u4F4E\u4E8E\u9608\u503C\u65F6\uFF0C\u7CFB\u7EDF\u5C06\u81EA\u52A8\u8D2D\u4E70\u6307\u5B9A\u6570\u91CF\u7684\u989D\u5EA6\u5957\u9910\u3002",
|
|
286
|
+
authTitle: "\u81EA\u52A8\u5145\u503C\u6388\u6743",
|
|
287
|
+
authTip: "\u8BF7\u5B8C\u6210\u6388\u6743\u6D41\u7A0B\u4EE5\u542F\u7528\u81EA\u52A8\u5145\u503C",
|
|
288
|
+
rechargeAmount: "\u6BCF\u6B21\u5145\u503C\u91D1\u989D",
|
|
289
|
+
currentPaymentMethod: "\u5F53\u524D\u652F\u4ED8\u65B9\u5F0F",
|
|
290
|
+
changePaymentMethod: "\u66F4\u6362\u652F\u4ED8\u65B9\u5F0F",
|
|
291
|
+
keepCurrent: "\u4FDD\u6301\u5F53\u524D",
|
|
292
|
+
changePaymentMethodTip: "\u4FDD\u5B58\u65F6\u5C06\u5F15\u5BFC\u60A8\u8BBE\u7F6E\u65B0\u7684\u652F\u4ED8\u65B9\u5F0F\u3002",
|
|
293
|
+
noPaymentMethodSetup: "\u672A\u914D\u7F6E\u652F\u4ED8\u65B9\u5F0F\uFF0C\u8BF7\u5148\u8BBE\u7F6E\u652F\u4ED8\u65B9\u5F0F\u3002",
|
|
294
|
+
addFunds: "\u5145\u503C",
|
|
295
|
+
advanced: "\u9AD8\u7EA7\u9009\u9879",
|
|
296
|
+
enabled: "\u5DF2\u542F\u7528",
|
|
297
|
+
disabled: "\u5DF2\u7981\u7528",
|
|
298
|
+
notConfigured: "\u5C1A\u672A\u914D\u7F6E\u81EA\u52A8\u5145\u503C",
|
|
299
|
+
setup: "\u53BB\u542F\u7528",
|
|
300
|
+
ruleDisplay: "\u989D\u5EA6\u4F4E\u4E8E{threshold}\u65F6\uFF0C\u5145\u503C{amount}\u53EF\u83B7\u5F97{credits}\u989D\u5EA6",
|
|
301
|
+
activeDescription: "\u81EA\u52A8\u5145\u503C\u5DF2\u542F\u7528\uFF0C\u5F53 Credits \u4F4E\u4E8E {threshold} \u65F6\uFF0C\u7CFB\u7EDF\u4F1A\u81EA\u52A8\u5145\u503C\u8D2D\u4E70 {credits} Credits\uFF0C\u652F\u4ED8\u91D1\u989D\u4E3A {amount}",
|
|
302
|
+
activeDescriptionWithCredits: "\u81EA\u52A8\u5145\u503C\u5DF2\u542F\u7528\uFF0C\u5F53 Credits \u4F4E\u4E8E {threshold} \u65F6\uFF0C\u7CFB\u7EDF\u4F1A\u81EA\u52A8\u8D2D\u4E70 {credits} \u989D\u5EA6\u3002",
|
|
303
|
+
purchaseAmount: "\u8D2D\u4E70\u6240\u9700\u91D1\u989D",
|
|
304
|
+
paymentMethod: "\u652F\u4ED8\u65B9\u5F0F",
|
|
305
|
+
walletBalance: "\u94B1\u5305\u4F59\u989D",
|
|
306
|
+
paymentAddress: "\u652F\u4ED8\u5730\u5740",
|
|
307
|
+
inactiveDescription: "\u5F00\u542F\u81EA\u52A8\u5145\u503C\uFF0C\u5373\u53EF\u5728 {name} \u4E0D\u8DB3\u65F6\u81EA\u52A8\u7EED\u8D39\uFF0C\u6709\u6548\u907F\u514D\u670D\u52A1\u4E2D\u65AD\u3002",
|
|
308
|
+
showDetails: "\u5C55\u5F00\u652F\u4ED8\u4FE1\u606F",
|
|
309
|
+
hideDetails: "\u6536\u8D77",
|
|
310
|
+
dailyLimits: {
|
|
311
|
+
maxAmount: "\u6BCF\u65E5\u5145\u503C\u91D1\u989D\u4E0A\u9650",
|
|
312
|
+
maxAmountPlaceholder: "0\u8868\u793A\u65E0\u9650\u5236",
|
|
313
|
+
maxAmountDescription: "\u6BCF\u65E5\u53EF\u5145\u503C\u7684\u6700\u5927\u603B\u91D1\u989D\uFF0C0 \u8868\u793A\u65E0\u9650\u5236",
|
|
314
|
+
maxAttempts: "\u6BCF\u65E5\u5145\u503C\u6B21\u6570\u4E0A\u9650",
|
|
315
|
+
maxAttemptsPlaceholder: "0\u8868\u793A\u65E0\u9650\u5236",
|
|
316
|
+
maxAttemptsDescription: "\u6BCF\u65E5\u53EF\u5145\u503C\u7684\u6700\u5927\u6B21\u6570\uFF0C0 \u8868\u793A\u65E0\u9650\u5236"
|
|
317
|
+
}
|
|
318
|
+
},
|
|
263
319
|
customer: {
|
|
264
320
|
payments: "\u652F\u4ED8\u5386\u53F2",
|
|
265
321
|
invoices: "\u8D26\u5355\u5386\u53F2",
|
|
@@ -136,6 +136,7 @@ function PaymentForm({
|
|
|
136
136
|
trigger
|
|
137
137
|
} = (0, _reactHookForm.useFormContext)();
|
|
138
138
|
const errorRef = (0, _react.useRef)(null);
|
|
139
|
+
const processingRef = (0, _react.useRef)(false);
|
|
139
140
|
const quantityInventoryStatus = (0, _react.useMemo)(() => {
|
|
140
141
|
let status = true;
|
|
141
142
|
for (const item of checkoutSession.line_items) {
|
|
@@ -287,6 +288,10 @@ function PaymentForm({
|
|
|
287
288
|
return true;
|
|
288
289
|
}, [session?.user, method, checkoutSession]);
|
|
289
290
|
const handleConnected = async () => {
|
|
291
|
+
if (processingRef.current) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
processingRef.current = true;
|
|
290
295
|
setState({
|
|
291
296
|
paying: true
|
|
292
297
|
});
|
|
@@ -305,6 +310,7 @@ function PaymentForm({
|
|
|
305
310
|
setState({
|
|
306
311
|
paying: false
|
|
307
312
|
});
|
|
313
|
+
processingRef.current = false;
|
|
308
314
|
}
|
|
309
315
|
};
|
|
310
316
|
(0, _react.useEffect)(() => {
|