@blocklet/payment-react 1.19.17 → 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 +19 -12
- 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 +21 -12
- 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 +20 -13
|
@@ -33,7 +33,7 @@ export default function ProductItem({
|
|
|
33
33
|
}
|
|
34
34
|
}) {
|
|
35
35
|
const { t, locale } = useLocaleContext();
|
|
36
|
-
const { settings } = usePaymentContext();
|
|
36
|
+
const { settings, setPayable } = usePaymentContext();
|
|
37
37
|
const pricing = formatLineItemPricing(item, currency, { trialEnd, trialInDays }, locale);
|
|
38
38
|
const saving = formatUpsellSaving(items, currency);
|
|
39
39
|
const metered = item.price?.recurring?.usage_type === "metered" ? t("common.metered") : "";
|
|
@@ -48,27 +48,34 @@ export default function ProductItem({
|
|
|
48
48
|
const minQuantity = Math.max(adjustableQuantity.minimum || 1, 1);
|
|
49
49
|
const quantityAvailable = Math.min(item.price.quantity_limit_per_checkout, item.price.quantity_available);
|
|
50
50
|
const maxQuantity = quantityAvailable ? Math.min(adjustableQuantity.maximum || Infinity, quantityAvailable) : adjustableQuantity.maximum || Infinity;
|
|
51
|
+
const localQuantityNum = localQuantity || 0;
|
|
51
52
|
const handleQuantityChange = (newQuantity) => {
|
|
53
|
+
if (!newQuantity) {
|
|
54
|
+
setLocalQuantity(void 0);
|
|
55
|
+
setPayable(false);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
setPayable(true);
|
|
52
59
|
if (newQuantity >= minQuantity && newQuantity <= maxQuantity) {
|
|
53
|
-
setLocalQuantity(newQuantity);
|
|
54
60
|
if (formatQuantityInventory(item.price, newQuantity, locale)) {
|
|
55
61
|
return;
|
|
56
62
|
}
|
|
63
|
+
setLocalQuantity(newQuantity);
|
|
57
64
|
onQuantityChange(item.price_id, newQuantity);
|
|
58
65
|
}
|
|
59
66
|
};
|
|
60
67
|
const handleQuantityIncrease = () => {
|
|
61
|
-
if (
|
|
62
|
-
handleQuantityChange(
|
|
68
|
+
if (localQuantityNum < maxQuantity) {
|
|
69
|
+
handleQuantityChange(localQuantityNum + 1);
|
|
63
70
|
}
|
|
64
71
|
};
|
|
65
72
|
const handleQuantityDecrease = () => {
|
|
66
|
-
if (
|
|
67
|
-
handleQuantityChange(
|
|
73
|
+
if (localQuantityNum > minQuantity) {
|
|
74
|
+
handleQuantityChange(localQuantityNum - 1);
|
|
68
75
|
}
|
|
69
76
|
};
|
|
70
77
|
const handleQuantityInputChange = (event) => {
|
|
71
|
-
const value = parseInt(event.target.value, 10);
|
|
78
|
+
const value = parseInt(event.target.value || "0", 10);
|
|
72
79
|
if (!Number.isNaN(value)) {
|
|
73
80
|
handleQuantityChange(value);
|
|
74
81
|
}
|
|
@@ -76,7 +83,7 @@ export default function ProductItem({
|
|
|
76
83
|
const formatCreditInfo = () => {
|
|
77
84
|
if (!isCreditProduct) return null;
|
|
78
85
|
const isRecurring = item.price.type === "recurring";
|
|
79
|
-
const totalCredit = formatNumber(creditAmount * localQuantity);
|
|
86
|
+
const totalCredit = formatNumber(creditAmount * (localQuantity || 0));
|
|
80
87
|
let message = "";
|
|
81
88
|
if (isRecurring) {
|
|
82
89
|
message = t("payment.checkout.credit.recurringInfo", {
|
|
@@ -106,7 +113,7 @@ export default function ProductItem({
|
|
|
106
113
|
}
|
|
107
114
|
return pricing.primary;
|
|
108
115
|
}, [trialInDays, trialEnd, pricing, item, locale]);
|
|
109
|
-
const quantityInventoryError = formatQuantityInventory(item.price,
|
|
116
|
+
const quantityInventoryError = formatQuantityInventory(item.price, localQuantityNum, locale);
|
|
110
117
|
return /* @__PURE__ */ jsxs(
|
|
111
118
|
Stack,
|
|
112
119
|
{
|
|
@@ -215,7 +222,7 @@ export default function ProductItem({
|
|
|
215
222
|
{
|
|
216
223
|
size: "small",
|
|
217
224
|
onClick: handleQuantityDecrease,
|
|
218
|
-
disabled:
|
|
225
|
+
disabled: localQuantityNum <= minQuantity,
|
|
219
226
|
sx: { minWidth: 32, width: 32, height: 32 },
|
|
220
227
|
children: /* @__PURE__ */ jsx(Remove, { fontSize: "small" })
|
|
221
228
|
}
|
|
@@ -231,7 +238,7 @@ export default function ProductItem({
|
|
|
231
238
|
htmlInput: {
|
|
232
239
|
min: minQuantity,
|
|
233
240
|
max: maxQuantity,
|
|
234
|
-
style: { textAlign: "center", padding: "4px" }
|
|
241
|
+
style: { textAlign: "center", padding: "4px", minWidth: 80 }
|
|
235
242
|
}
|
|
236
243
|
}
|
|
237
244
|
}
|
|
@@ -241,7 +248,7 @@ export default function ProductItem({
|
|
|
241
248
|
{
|
|
242
249
|
size: "small",
|
|
243
250
|
onClick: handleQuantityIncrease,
|
|
244
|
-
disabled:
|
|
251
|
+
disabled: localQuantityNum >= maxQuantity,
|
|
245
252
|
sx: { minWidth: 32, width: 32, height: 32 },
|
|
246
253
|
children: /* @__PURE__ */ jsx(Add, { fontSize: "small" })
|
|
247
254
|
}
|
package/lib/checkout/form.js
CHANGED
|
@@ -62,11 +62,11 @@ function CheckoutForm({
|
|
|
62
62
|
window.history.replaceState(null, "", (0, _ufo.joinURL)((0, _util.getPrefix)(), `/checkout/pay/${data.checkoutSession.id}?${(0, _util.mergeExtraParams)(extraParams)}`));
|
|
63
63
|
}
|
|
64
64
|
}, [type, mode, data, extraParams]);
|
|
65
|
-
const handlePaid =
|
|
65
|
+
const handlePaid = result => {
|
|
66
66
|
setState({
|
|
67
67
|
completed: true
|
|
68
68
|
});
|
|
69
|
-
onPaid?.(
|
|
69
|
+
onPaid?.(result);
|
|
70
70
|
};
|
|
71
71
|
const handleError = err => {
|
|
72
72
|
console.error(err);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SxProps } from '@mui/material';
|
|
3
|
+
import type { AutoRechargeConfig } from '@blocklet/payment-types';
|
|
4
|
+
export interface AutoTopupCardProps {
|
|
5
|
+
currencyId: string;
|
|
6
|
+
onConfigChange?: (config: AutoRechargeConfig) => void;
|
|
7
|
+
sx?: SxProps;
|
|
8
|
+
mode?: 'default' | 'simple' | 'custom';
|
|
9
|
+
children?: (openModal: () => void, config: AutoRechargeConfig | null, paymentData: {
|
|
10
|
+
paymentInfo: any;
|
|
11
|
+
balanceInfo: any;
|
|
12
|
+
} | null, loading: boolean) => React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export default function AutoTopupCard({ currencyId, onConfigChange, sx, mode, children, }: AutoTopupCardProps): JSX.Element | null;
|
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = AutoTopupCard;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _material = require("@mui/material");
|
|
10
|
+
var _iconsMaterial = require("@mui/icons-material");
|
|
11
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
12
|
+
var _reactRouterDom = require("react-router-dom");
|
|
13
|
+
var _ufo = require("ufo");
|
|
14
|
+
var _ahooks = require("ahooks");
|
|
15
|
+
var _util = require("../../libs/util");
|
|
16
|
+
var _navigation = require("../../libs/navigation");
|
|
17
|
+
var _payment = require("../../contexts/payment");
|
|
18
|
+
var _api = _interopRequireDefault(require("../../libs/api"));
|
|
19
|
+
var _modal = _interopRequireDefault(require("./modal"));
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
|
+
const fetchConfig = async (customerId, currencyId) => {
|
|
22
|
+
const {
|
|
23
|
+
data
|
|
24
|
+
} = await _api.default.get(`/api/auto-recharge-configs/customer/${customerId}`, {
|
|
25
|
+
params: {
|
|
26
|
+
currency_id: currencyId
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return data;
|
|
30
|
+
};
|
|
31
|
+
const fetchCurrencyBalance = async (currencyId, payerAddress) => {
|
|
32
|
+
const {
|
|
33
|
+
data
|
|
34
|
+
} = await _api.default.get("/api/customers/payer-token", {
|
|
35
|
+
params: {
|
|
36
|
+
currencyId,
|
|
37
|
+
payerAddress
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return data;
|
|
41
|
+
};
|
|
42
|
+
const cardStyle = {
|
|
43
|
+
height: "100%",
|
|
44
|
+
width: "100%",
|
|
45
|
+
border: "1px solid",
|
|
46
|
+
borderColor: "divider",
|
|
47
|
+
boxShadow: 1,
|
|
48
|
+
borderRadius: 1,
|
|
49
|
+
backgroundColor: "background.default"
|
|
50
|
+
};
|
|
51
|
+
function AutoTopupCard({
|
|
52
|
+
currencyId,
|
|
53
|
+
onConfigChange = () => {},
|
|
54
|
+
sx = {},
|
|
55
|
+
mode = "default",
|
|
56
|
+
children = void 0
|
|
57
|
+
}) {
|
|
58
|
+
const {
|
|
59
|
+
t
|
|
60
|
+
} = (0, _context.useLocaleContext)();
|
|
61
|
+
const navigate = (0, _reactRouterDom.useNavigate)();
|
|
62
|
+
const {
|
|
63
|
+
session
|
|
64
|
+
} = (0, _payment.usePaymentContext)();
|
|
65
|
+
const [modalOpen, setModalOpen] = (0, _react.useState)(false);
|
|
66
|
+
const [paymentData, setPaymentData] = (0, _react.useState)(null);
|
|
67
|
+
const [quickSetupMode, setQuickSetupMode] = (0, _react.useState)(false);
|
|
68
|
+
const [expanded, setExpanded] = (0, _react.useState)(mode === "default");
|
|
69
|
+
const customerId = session?.user?.did || "";
|
|
70
|
+
const {
|
|
71
|
+
data: config,
|
|
72
|
+
loading,
|
|
73
|
+
refresh
|
|
74
|
+
} = (0, _ahooks.useRequest)(() => fetchConfig(customerId, currencyId), {
|
|
75
|
+
refreshDeps: [customerId, currencyId],
|
|
76
|
+
ready: !!customerId && !!currencyId,
|
|
77
|
+
onSuccess: data => {
|
|
78
|
+
loadPaymentInfo(data);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const loadPaymentInfo = (0, _react.useCallback)(async data => {
|
|
82
|
+
if (!data?.recharge_currency_id) return;
|
|
83
|
+
try {
|
|
84
|
+
const paymentMethodType = data?.paymentMethod?.type;
|
|
85
|
+
const paymentInfo = data?.payment_settings?.payment_method_options?.[paymentMethodType];
|
|
86
|
+
const balanceInfo = paymentInfo?.payer && paymentMethodType !== "stripe" ? await fetchCurrencyBalance(data.recharge_currency_id, paymentInfo.payer) : null;
|
|
87
|
+
setPaymentData({
|
|
88
|
+
paymentInfo,
|
|
89
|
+
balanceInfo
|
|
90
|
+
});
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error("Failed to load payment info:", error);
|
|
93
|
+
}
|
|
94
|
+
}, []);
|
|
95
|
+
const handleRecharge = e => {
|
|
96
|
+
if (!paymentData?.paymentInfo?.payer) return;
|
|
97
|
+
const url = (0, _ufo.joinURL)((0, _util.getPrefix)(), `/customer/recharge/${config?.recharge_currency_id}?rechargeAddress=${paymentData.paymentInfo.payer}`);
|
|
98
|
+
const link = (0, _navigation.createLink)(url, true);
|
|
99
|
+
(0, _navigation.handleNavigation)(e, link, navigate);
|
|
100
|
+
};
|
|
101
|
+
const handleConfigSuccess = newConfig => {
|
|
102
|
+
refresh();
|
|
103
|
+
onConfigChange?.(newConfig);
|
|
104
|
+
setModalOpen(false);
|
|
105
|
+
setQuickSetupMode(false);
|
|
106
|
+
};
|
|
107
|
+
const handleToggleExpanded = () => {
|
|
108
|
+
setExpanded(!expanded);
|
|
109
|
+
};
|
|
110
|
+
if (loading) {
|
|
111
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Card, {
|
|
112
|
+
sx: {
|
|
113
|
+
...cardStyle,
|
|
114
|
+
...sx
|
|
115
|
+
},
|
|
116
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CardContent, {
|
|
117
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
118
|
+
sx: {
|
|
119
|
+
display: "flex",
|
|
120
|
+
justifyContent: "center",
|
|
121
|
+
alignItems: "center",
|
|
122
|
+
minHeight: 80
|
|
123
|
+
},
|
|
124
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {
|
|
125
|
+
size: 24
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (!config) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const renderPurchaseDetails = () => {
|
|
135
|
+
const {
|
|
136
|
+
paymentInfo,
|
|
137
|
+
balanceInfo
|
|
138
|
+
} = paymentData || {};
|
|
139
|
+
if (!paymentInfo) {
|
|
140
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
141
|
+
variant: "body2",
|
|
142
|
+
sx: {
|
|
143
|
+
color: "text.secondary"
|
|
144
|
+
},
|
|
145
|
+
children: t("payment.autoTopup.notConfigured")
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const purchaseAmount = (0, _util.formatPrice)(config.price, config.rechargeCurrency, config.price.product?.unit_label, config.quantity, true);
|
|
149
|
+
if (config?.paymentMethod?.type === "stripe") {
|
|
150
|
+
const cardBrand = (paymentInfo?.card_brand || "Card").charAt(0).toUpperCase() + (paymentInfo?.card_brand || "Card").slice(1).toLowerCase();
|
|
151
|
+
const last4 = paymentInfo?.card_last4;
|
|
152
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
153
|
+
spacing: 1,
|
|
154
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
155
|
+
sx: {
|
|
156
|
+
display: "flex",
|
|
157
|
+
alignItems: "center",
|
|
158
|
+
gap: 0.5
|
|
159
|
+
},
|
|
160
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
161
|
+
variant: "body2",
|
|
162
|
+
sx: {
|
|
163
|
+
color: "text.secondary"
|
|
164
|
+
},
|
|
165
|
+
children: [t("payment.autoTopup.purchaseAmount"), "\uFF1A"]
|
|
166
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
167
|
+
variant: "body2",
|
|
168
|
+
sx: {
|
|
169
|
+
fontWeight: 600,
|
|
170
|
+
color: "text.primary"
|
|
171
|
+
},
|
|
172
|
+
children: purchaseAmount
|
|
173
|
+
})]
|
|
174
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
175
|
+
sx: {
|
|
176
|
+
display: "flex",
|
|
177
|
+
alignItems: "center",
|
|
178
|
+
gap: 0.5
|
|
179
|
+
},
|
|
180
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
181
|
+
variant: "body2",
|
|
182
|
+
sx: {
|
|
183
|
+
color: "text.secondary"
|
|
184
|
+
},
|
|
185
|
+
children: [t("payment.autoTopup.paymentMethod"), "\uFF1A"]
|
|
186
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
187
|
+
direction: "row",
|
|
188
|
+
spacing: 1,
|
|
189
|
+
sx: {
|
|
190
|
+
alignItems: "center"
|
|
191
|
+
},
|
|
192
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.CreditCard, {
|
|
193
|
+
fontSize: "small",
|
|
194
|
+
sx: {
|
|
195
|
+
color: "text.secondary"
|
|
196
|
+
}
|
|
197
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
198
|
+
variant: "body2",
|
|
199
|
+
sx: {
|
|
200
|
+
color: "text.primary",
|
|
201
|
+
fontWeight: 500
|
|
202
|
+
},
|
|
203
|
+
children: [cardBrand, "(", last4, ")"]
|
|
204
|
+
})]
|
|
205
|
+
})]
|
|
206
|
+
})]
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
210
|
+
spacing: 1,
|
|
211
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
212
|
+
sx: {
|
|
213
|
+
display: "flex",
|
|
214
|
+
alignItems: "center",
|
|
215
|
+
gap: 0.5
|
|
216
|
+
},
|
|
217
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
218
|
+
variant: "body2",
|
|
219
|
+
sx: {
|
|
220
|
+
color: "text.secondary"
|
|
221
|
+
},
|
|
222
|
+
children: [t("payment.autoTopup.purchaseAmount"), "\uFF1A"]
|
|
223
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
224
|
+
variant: "body2",
|
|
225
|
+
sx: {
|
|
226
|
+
fontWeight: 600,
|
|
227
|
+
color: "text.primary"
|
|
228
|
+
},
|
|
229
|
+
children: purchaseAmount
|
|
230
|
+
})]
|
|
231
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
232
|
+
sx: {
|
|
233
|
+
display: "flex",
|
|
234
|
+
alignItems: "center",
|
|
235
|
+
justifyContent: "space-between"
|
|
236
|
+
},
|
|
237
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
238
|
+
sx: {
|
|
239
|
+
display: "flex",
|
|
240
|
+
alignItems: "center",
|
|
241
|
+
gap: 0.5
|
|
242
|
+
},
|
|
243
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
244
|
+
variant: "body2",
|
|
245
|
+
sx: {
|
|
246
|
+
color: "text.secondary"
|
|
247
|
+
},
|
|
248
|
+
children: [t("payment.autoTopup.walletBalance"), "\uFF1A"]
|
|
249
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Tooltip, {
|
|
250
|
+
title: paymentInfo?.payer ? `${t("payment.autoTopup.paymentAddress")}: ${paymentInfo.payer}` : "",
|
|
251
|
+
placement: "top",
|
|
252
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
253
|
+
sx: {
|
|
254
|
+
display: "flex",
|
|
255
|
+
alignItems: "center",
|
|
256
|
+
gap: 0.5
|
|
257
|
+
},
|
|
258
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.AccountBalanceWalletOutlined, {
|
|
259
|
+
sx: {
|
|
260
|
+
fontSize: 16,
|
|
261
|
+
color: "text.secondary"
|
|
262
|
+
}
|
|
263
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
264
|
+
variant: "body2",
|
|
265
|
+
sx: {
|
|
266
|
+
fontWeight: 600,
|
|
267
|
+
color: "text.primary"
|
|
268
|
+
},
|
|
269
|
+
children: balanceInfo ? `${(0, _util.formatBNStr)(balanceInfo?.token || "0", config?.rechargeCurrency?.decimal || 18)} ${config?.rechargeCurrency?.symbol || ""}` : "--"
|
|
270
|
+
})]
|
|
271
|
+
})
|
|
272
|
+
}), balanceInfo && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Button, {
|
|
273
|
+
size: "small",
|
|
274
|
+
variant: "text",
|
|
275
|
+
onClick: handleRecharge,
|
|
276
|
+
sx: {
|
|
277
|
+
color: "primary.main",
|
|
278
|
+
display: "flex",
|
|
279
|
+
alignItems: "center"
|
|
280
|
+
},
|
|
281
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.AddOutlined, {
|
|
282
|
+
fontSize: "small"
|
|
283
|
+
}), t("payment.autoTopup.addFunds")]
|
|
284
|
+
})]
|
|
285
|
+
})
|
|
286
|
+
})]
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
const openModal = () => setModalOpen(true);
|
|
290
|
+
const renderInnerView = () => {
|
|
291
|
+
if (mode === "custom") {
|
|
292
|
+
return children && typeof children === "function" ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
293
|
+
children: children(openModal, config, paymentData, loading)
|
|
294
|
+
}) : /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
295
|
+
children: ["Please provide a valid render function", /* @__PURE__ */(0, _jsxRuntime.jsx)("pre", {
|
|
296
|
+
children: "(openModal, config, paymentData, loading) => ReactNode"
|
|
297
|
+
})]
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Card, {
|
|
301
|
+
sx: {
|
|
302
|
+
...cardStyle,
|
|
303
|
+
...sx
|
|
304
|
+
},
|
|
305
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.CardContent, {
|
|
306
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
307
|
+
direction: "row",
|
|
308
|
+
className: "auto-topup-header",
|
|
309
|
+
sx: {
|
|
310
|
+
justifyContent: "space-between",
|
|
311
|
+
alignItems: "center",
|
|
312
|
+
borderBottom: "1px solid",
|
|
313
|
+
borderColor: "divider",
|
|
314
|
+
pb: 1.5
|
|
315
|
+
},
|
|
316
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
317
|
+
variant: "subtitle2",
|
|
318
|
+
sx: {
|
|
319
|
+
fontWeight: 600,
|
|
320
|
+
color: "text.primary"
|
|
321
|
+
},
|
|
322
|
+
children: t("payment.autoTopup.title")
|
|
323
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
324
|
+
sx: {
|
|
325
|
+
display: "flex",
|
|
326
|
+
alignItems: "center",
|
|
327
|
+
gap: 0.5
|
|
328
|
+
},
|
|
329
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
330
|
+
size: "small",
|
|
331
|
+
onClick: openModal,
|
|
332
|
+
sx: {
|
|
333
|
+
p: 0.5,
|
|
334
|
+
color: "text.secondary",
|
|
335
|
+
"&:hover": {
|
|
336
|
+
bgcolor: "grey.50",
|
|
337
|
+
color: "text.primary"
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.SettingsOutlined, {
|
|
341
|
+
fontSize: "small"
|
|
342
|
+
})
|
|
343
|
+
})
|
|
344
|
+
})]
|
|
345
|
+
}), config?.enabled ? /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
346
|
+
spacing: 1.5,
|
|
347
|
+
className: "auto-topup-content",
|
|
348
|
+
sx: {
|
|
349
|
+
pt: 1.5
|
|
350
|
+
},
|
|
351
|
+
children: [(() => {
|
|
352
|
+
const threshold = `${(0, _util.formatNumber)(config.threshold)} ${config.currency?.symbol || ""}`;
|
|
353
|
+
const credits = `${(0, _util.formatNumber)(Number(config.price.metadata?.credit_config?.credit_amount || 0) * Number(config.quantity))} ${config.currency?.name || ""}`;
|
|
354
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
355
|
+
variant: "body2",
|
|
356
|
+
sx: {
|
|
357
|
+
color: "text.secondary"
|
|
358
|
+
},
|
|
359
|
+
children: [t("payment.autoTopup.activeDescriptionWithCredits", {
|
|
360
|
+
threshold,
|
|
361
|
+
credits
|
|
362
|
+
}), mode === "simple" && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
363
|
+
component: "span",
|
|
364
|
+
size: "small",
|
|
365
|
+
variant: "text",
|
|
366
|
+
onClick: handleToggleExpanded,
|
|
367
|
+
sx: {
|
|
368
|
+
color: "primary.main",
|
|
369
|
+
minWidth: "auto",
|
|
370
|
+
ml: 1,
|
|
371
|
+
p: 0,
|
|
372
|
+
fontSize: "inherit",
|
|
373
|
+
textTransform: "none",
|
|
374
|
+
"&:hover": {
|
|
375
|
+
backgroundColor: "transparent",
|
|
376
|
+
textDecoration: "underline"
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
children: expanded ? t("payment.autoTopup.hideDetails") : t("payment.autoTopup.showDetails")
|
|
380
|
+
})]
|
|
381
|
+
});
|
|
382
|
+
})(), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Collapse, {
|
|
383
|
+
in: mode === "default" || expanded,
|
|
384
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
385
|
+
sx: {
|
|
386
|
+
bgcolor: "grey.50",
|
|
387
|
+
borderRadius: 1,
|
|
388
|
+
p: 1.5
|
|
389
|
+
},
|
|
390
|
+
children: renderPurchaseDetails()
|
|
391
|
+
})
|
|
392
|
+
})]
|
|
393
|
+
}) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
394
|
+
className: "auto-topup-content",
|
|
395
|
+
sx: {
|
|
396
|
+
minHeight: 80,
|
|
397
|
+
display: "flex",
|
|
398
|
+
flexDirection: "column",
|
|
399
|
+
alignItems: "center",
|
|
400
|
+
justifyContent: "center",
|
|
401
|
+
pt: 1.5,
|
|
402
|
+
gap: 2
|
|
403
|
+
},
|
|
404
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
405
|
+
variant: "body2",
|
|
406
|
+
sx: {
|
|
407
|
+
color: "text.secondary",
|
|
408
|
+
textAlign: "left"
|
|
409
|
+
},
|
|
410
|
+
children: [t("payment.autoTopup.inactiveDescription", {
|
|
411
|
+
name: config?.currency?.name
|
|
412
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
413
|
+
component: "span",
|
|
414
|
+
variant: "text",
|
|
415
|
+
size: "small",
|
|
416
|
+
onClick: () => {
|
|
417
|
+
setQuickSetupMode(true);
|
|
418
|
+
setModalOpen(true);
|
|
419
|
+
},
|
|
420
|
+
sx: {
|
|
421
|
+
color: "primary.main",
|
|
422
|
+
minWidth: "auto",
|
|
423
|
+
ml: 1,
|
|
424
|
+
p: 0,
|
|
425
|
+
fontSize: "inherit",
|
|
426
|
+
textTransform: "none",
|
|
427
|
+
"&:hover": {
|
|
428
|
+
backgroundColor: "transparent",
|
|
429
|
+
textDecoration: "underline"
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
children: t("payment.autoTopup.setup")
|
|
433
|
+
})]
|
|
434
|
+
})
|
|
435
|
+
})]
|
|
436
|
+
})
|
|
437
|
+
});
|
|
438
|
+
};
|
|
439
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
440
|
+
children: [renderInnerView(), modalOpen && /* @__PURE__ */(0, _jsxRuntime.jsx)(_modal.default, {
|
|
441
|
+
open: modalOpen,
|
|
442
|
+
onClose: () => {
|
|
443
|
+
setModalOpen(false);
|
|
444
|
+
setQuickSetupMode(false);
|
|
445
|
+
},
|
|
446
|
+
currencyId,
|
|
447
|
+
onSuccess: handleConfigSuccess,
|
|
448
|
+
defaultEnabled: quickSetupMode
|
|
449
|
+
})]
|
|
450
|
+
});
|
|
451
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AutoRechargeConfig } from '@blocklet/payment-types';
|
|
2
|
+
export interface AutoTopupFormData {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
threshold: string;
|
|
5
|
+
quantity: number;
|
|
6
|
+
payment_method_id: string;
|
|
7
|
+
recharge_currency_id: string;
|
|
8
|
+
price_id: string;
|
|
9
|
+
change_payment_method?: boolean;
|
|
10
|
+
customer_name?: string;
|
|
11
|
+
customer_email?: string;
|
|
12
|
+
daily_limits: {
|
|
13
|
+
max_attempts: number;
|
|
14
|
+
max_amount: number;
|
|
15
|
+
};
|
|
16
|
+
billing_address?: {
|
|
17
|
+
country?: string;
|
|
18
|
+
state?: string;
|
|
19
|
+
line1?: string;
|
|
20
|
+
line2?: string;
|
|
21
|
+
city?: string;
|
|
22
|
+
postal_code?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface AutoTopupModalProps {
|
|
26
|
+
open: boolean;
|
|
27
|
+
onClose: () => void;
|
|
28
|
+
customerId?: string;
|
|
29
|
+
currencyId: string;
|
|
30
|
+
onSuccess?: (config: AutoRechargeConfig) => void;
|
|
31
|
+
onError?: (error: any) => void;
|
|
32
|
+
defaultEnabled?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare const waitForAutoRechargeComplete: (configId: string) => Promise<any>;
|
|
35
|
+
export default function AutoTopup({ open, onClose, currencyId, onSuccess, onError, defaultEnabled, }: AutoTopupModalProps): JSX.Element;
|