@blocklet/payment-react 1.16.17 → 1.16.18
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/contexts/payment.js +9 -1
- package/es/history/invoice/list.js +39 -9
- package/es/libs/util.js +10 -3
- package/es/locales/en.js +5 -1
- package/es/locales/zh.js +5 -1
- package/es/payment/form/index.js +4 -1
- package/lib/contexts/payment.js +4 -1
- package/lib/history/invoice/list.js +30 -8
- package/lib/libs/util.js +7 -3
- package/lib/locales/en.js +5 -1
- package/lib/locales/zh.js +5 -1
- package/lib/payment/form/index.js +1 -1
- package/package.json +8 -8
- package/src/contexts/payment.tsx +9 -1
- package/src/history/invoice/list.tsx +43 -9
- package/src/libs/util.ts +8 -1
- package/src/locales/en.tsx +4 -0
- package/src/locales/zh.tsx +4 -0
- package/src/payment/form/index.tsx +6 -1
package/es/contexts/payment.js
CHANGED
|
@@ -38,7 +38,15 @@ function PaymentProvider({ session, connect, children, baseUrl }) {
|
|
|
38
38
|
window.__PAYMENT_KIT_BASE_URL = baseUrl;
|
|
39
39
|
}
|
|
40
40
|
const [livemode, setLivemode] = useLocalStorageState("livemode", { defaultValue: true });
|
|
41
|
-
const {
|
|
41
|
+
const {
|
|
42
|
+
data = {
|
|
43
|
+
paymentMethods: [],
|
|
44
|
+
baseCurrency: {}
|
|
45
|
+
},
|
|
46
|
+
error,
|
|
47
|
+
run,
|
|
48
|
+
loading
|
|
49
|
+
} = useRequest(getSettings, {
|
|
42
50
|
refreshDeps: [livemode]
|
|
43
51
|
});
|
|
44
52
|
const prefix = getPrefix();
|
|
@@ -5,8 +5,9 @@ import { OpenInNewOutlined } from "@mui/icons-material";
|
|
|
5
5
|
import { Box, Button, CircularProgress, Hidden, Stack, Typography } from "@mui/material";
|
|
6
6
|
import { styled } from "@mui/system";
|
|
7
7
|
import { useInfiniteScroll, useRequest, useSetState } from "ahooks";
|
|
8
|
-
import React, { useEffect, useState } from "react";
|
|
8
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
9
9
|
import { joinURL } from "ufo";
|
|
10
|
+
import debounce from "lodash/debounce";
|
|
10
11
|
import Status from "../../components/status.js";
|
|
11
12
|
import { usePaymentContext } from "../../contexts/payment.js";
|
|
12
13
|
import { useSubscription } from "../../hooks/subscription.js";
|
|
@@ -100,18 +101,32 @@ const InvoiceTable = React.memo((props) => {
|
|
|
100
101
|
refreshDeps: [search, status, customer_id, currency_id, subscription_id, include_staking, include_recovered_from]
|
|
101
102
|
}
|
|
102
103
|
);
|
|
104
|
+
const prevData = useRef(data);
|
|
103
105
|
useEffect(() => {
|
|
104
106
|
if (onTableDataChange) {
|
|
105
|
-
onTableDataChange(data);
|
|
107
|
+
onTableDataChange(data, prevData.current);
|
|
108
|
+
prevData.current = data;
|
|
106
109
|
}
|
|
107
110
|
}, [data]);
|
|
108
111
|
const subscription = useSubscription("events");
|
|
112
|
+
const debouncedHandleInvoicePaid = debounce(
|
|
113
|
+
async () => {
|
|
114
|
+
Toast.close();
|
|
115
|
+
Toast.success(t("payment.customer.invoice.paySuccess"));
|
|
116
|
+
await refresh();
|
|
117
|
+
},
|
|
118
|
+
1e3,
|
|
119
|
+
{
|
|
120
|
+
leading: false,
|
|
121
|
+
trailing: true,
|
|
122
|
+
maxWait: 5e3
|
|
123
|
+
}
|
|
124
|
+
);
|
|
109
125
|
useEffect(() => {
|
|
110
126
|
if (subscription && customer_id) {
|
|
111
127
|
subscription.on("invoice.paid", ({ response }) => {
|
|
112
128
|
if (response.customer_id === customer_id) {
|
|
113
|
-
|
|
114
|
-
refresh();
|
|
129
|
+
debouncedHandleInvoicePaid();
|
|
115
130
|
}
|
|
116
131
|
});
|
|
117
132
|
}
|
|
@@ -186,7 +201,8 @@ const InvoiceTable = React.memo((props) => {
|
|
|
186
201
|
customBodyRenderLite: (val, index) => {
|
|
187
202
|
const invoice = data?.list[index];
|
|
188
203
|
const link = getInvoiceLink(invoice, action);
|
|
189
|
-
|
|
204
|
+
const hidePay = invoice.billing_reason === "overdraft-protection";
|
|
205
|
+
if (action && !hidePay) {
|
|
190
206
|
return link.connect ? /* @__PURE__ */ jsx(Button, { variant: "text", size: "small", onClick: () => onPay(invoice.id), sx: { color: "text.link" }, children: t("payment.customer.invoice.pay") }) : /* @__PURE__ */ jsx(
|
|
191
207
|
Button,
|
|
192
208
|
{
|
|
@@ -286,17 +302,31 @@ const InvoiceList = React.memo((props) => {
|
|
|
286
302
|
reloadDeps: [customer_id, subscription_id, status, include_staking, include_recovered_from]
|
|
287
303
|
}
|
|
288
304
|
);
|
|
305
|
+
const prevData = useRef(data);
|
|
289
306
|
useEffect(() => {
|
|
290
307
|
if (onTableDataChange) {
|
|
291
|
-
onTableDataChange(data);
|
|
308
|
+
onTableDataChange(data, prevData.current);
|
|
309
|
+
prevData.current = data;
|
|
292
310
|
}
|
|
293
311
|
}, [data]);
|
|
312
|
+
const debouncedHandleInvoicePaid = debounce(
|
|
313
|
+
async () => {
|
|
314
|
+
Toast.close();
|
|
315
|
+
Toast.success(t("payment.customer.invoice.paySuccess"));
|
|
316
|
+
await reloadAsync();
|
|
317
|
+
},
|
|
318
|
+
1e3,
|
|
319
|
+
{
|
|
320
|
+
leading: false,
|
|
321
|
+
trailing: true,
|
|
322
|
+
maxWait: 5e3
|
|
323
|
+
}
|
|
324
|
+
);
|
|
294
325
|
useEffect(() => {
|
|
295
326
|
if (subscription && customer_id) {
|
|
296
|
-
subscription.on("invoice.paid",
|
|
327
|
+
subscription.on("invoice.paid", ({ response }) => {
|
|
297
328
|
if (response.customer_id === customer_id) {
|
|
298
|
-
|
|
299
|
-
await reloadAsync();
|
|
329
|
+
debouncedHandleInvoicePaid();
|
|
300
330
|
}
|
|
301
331
|
});
|
|
302
332
|
}
|
package/es/libs/util.js
CHANGED
|
@@ -863,10 +863,12 @@ export function getInvoiceDescriptionAndReason(invoice, locale = "en") {
|
|
|
863
863
|
slash_stake: t("payment.invoice.reason.slashStake", locale),
|
|
864
864
|
stake: t("payment.invoice.reason.stake", locale),
|
|
865
865
|
return_stake: t("payment.invoice.reason.returnStake", locale),
|
|
866
|
-
recharge: t("payment.invoice.reason.recharge", locale)
|
|
866
|
+
recharge: t("payment.invoice.reason.recharge", locale),
|
|
867
|
+
stake_overdraft_protection: t("payment.invoice.reason.stake", locale),
|
|
868
|
+
overdraft_protection: t("payment.invoice.reason.fee", locale)
|
|
867
869
|
};
|
|
868
870
|
let invoiceType = t("payment.invoice.reason.payment", locale);
|
|
869
|
-
if (reason.includes("stake") || reason.includes("recharge")) {
|
|
871
|
+
if (reason.includes("stake") || reason.includes("recharge") || reason === "overdraft_protection") {
|
|
870
872
|
invoiceType = reasonMap[reason];
|
|
871
873
|
}
|
|
872
874
|
if (description?.startsWith("Subscription ") || description?.startsWith("Slash stake")) {
|
|
@@ -882,7 +884,12 @@ export function getInvoiceDescriptionAndReason(invoice, locale = "en") {
|
|
|
882
884
|
"Stake for subscription": t("payment.invoice.reason.staking", locale),
|
|
883
885
|
"Return Subscription staking": t("payment.invoice.reason.returnStake", locale),
|
|
884
886
|
"Recharge for subscription": t("payment.invoice.reason.rechargeForSubscription", locale),
|
|
885
|
-
"Add funds for subscription": t("payment.invoice.reason.rechargeForSubscription", locale)
|
|
887
|
+
"Add funds for subscription": t("payment.invoice.reason.rechargeForSubscription", locale),
|
|
888
|
+
"Overdraft protection": t("payment.invoice.reason.overdraftProtection", locale),
|
|
889
|
+
"Stake for subscription overdraft protection": t(
|
|
890
|
+
"payment.invoice.reason.stakeForSubscriptionOverdraftProtection",
|
|
891
|
+
locale
|
|
892
|
+
)
|
|
886
893
|
};
|
|
887
894
|
return {
|
|
888
895
|
description: descMap[description] || description,
|
package/es/locales/en.js
CHANGED
|
@@ -315,7 +315,11 @@ export default flat({
|
|
|
315
315
|
stakeForChangePlan: "Subscription plan update",
|
|
316
316
|
stakeForChangePayment: "Subscription payment method update",
|
|
317
317
|
recharge: "Add funds",
|
|
318
|
-
rechargeForSubscription: "Add funds for subscription"
|
|
318
|
+
rechargeForSubscription: "Add funds for subscription",
|
|
319
|
+
overdraftProtection: "Overdraft protection Fee",
|
|
320
|
+
stakeForSubscriptionOverdraftProtection: "Subscription overdraft protection",
|
|
321
|
+
gas: "Gas",
|
|
322
|
+
fee: "Fee"
|
|
319
323
|
}
|
|
320
324
|
},
|
|
321
325
|
subscription: {
|
package/es/locales/zh.js
CHANGED
|
@@ -315,7 +315,11 @@ export default flat({
|
|
|
315
315
|
stakeForChangePlan: "\u8BA2\u9605\u5957\u9910\u66F4\u65B0",
|
|
316
316
|
stakeForChangePayment: "\u8BA2\u9605\u652F\u4ED8\u65B9\u5F0F\u66F4\u65B0",
|
|
317
317
|
recharge: "\u5145\u503C",
|
|
318
|
-
rechargeForSubscription: "\u8BA2\u9605\u5145\u503C"
|
|
318
|
+
rechargeForSubscription: "\u8BA2\u9605\u5145\u503C",
|
|
319
|
+
overdraftProtection: "\u900F\u652F\u4FDD\u62A4\u8D39",
|
|
320
|
+
stakeForSubscriptionOverdraftProtection: "\u8BA2\u9605\u900F\u652F\u4FDD\u62A4",
|
|
321
|
+
gas: "\u624B\u7EED\u8D39",
|
|
322
|
+
fee: "\u670D\u52A1\u8D39"
|
|
319
323
|
}
|
|
320
324
|
},
|
|
321
325
|
subscription: {
|
package/es/payment/form/index.js
CHANGED
|
@@ -452,7 +452,10 @@ export default function PaymentForm({
|
|
|
452
452
|
state.customerLimited && /* @__PURE__ */ jsx(
|
|
453
453
|
ConfirmDialog,
|
|
454
454
|
{
|
|
455
|
-
onConfirm: () => window.open(
|
|
455
|
+
onConfirm: () => window.open(
|
|
456
|
+
joinURL(getPrefix(), `/customer/invoice/past-due?referer=${encodeURIComponent(window.location.href)}`),
|
|
457
|
+
"_self"
|
|
458
|
+
),
|
|
456
459
|
onCancel: () => setState({ customerLimited: false }),
|
|
457
460
|
confirm: t("payment.customer.pastDue.alert.confirm"),
|
|
458
461
|
title: t("payment.customer.pastDue.alert.title"),
|
package/lib/contexts/payment.js
CHANGED
|
@@ -13,6 +13,7 @@ var _system = require("@mui/system");
|
|
|
13
13
|
var _ahooks = require("ahooks");
|
|
14
14
|
var _react = _interopRequireWildcard(require("react"));
|
|
15
15
|
var _ufo = require("ufo");
|
|
16
|
+
var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
16
17
|
var _status = _interopRequireDefault(require("../../components/status"));
|
|
17
18
|
var _payment = require("../../contexts/payment");
|
|
18
19
|
var _subscription = require("../../hooks/subscription");
|
|
@@ -100,20 +101,30 @@ const InvoiceTable = _react.default.memo(props => {
|
|
|
100
101
|
}), {
|
|
101
102
|
refreshDeps: [search, status, customer_id, currency_id, subscription_id, include_staking, include_recovered_from]
|
|
102
103
|
});
|
|
104
|
+
const prevData = (0, _react.useRef)(data);
|
|
103
105
|
(0, _react.useEffect)(() => {
|
|
104
106
|
if (onTableDataChange) {
|
|
105
|
-
onTableDataChange(data);
|
|
107
|
+
onTableDataChange(data, prevData.current);
|
|
108
|
+
prevData.current = data;
|
|
106
109
|
}
|
|
107
110
|
}, [data]);
|
|
108
111
|
const subscription = (0, _subscription.useSubscription)("events");
|
|
112
|
+
const debouncedHandleInvoicePaid = (0, _debounce.default)(async () => {
|
|
113
|
+
_Toast.default.close();
|
|
114
|
+
_Toast.default.success(t("payment.customer.invoice.paySuccess"));
|
|
115
|
+
await refresh();
|
|
116
|
+
}, 1e3, {
|
|
117
|
+
leading: false,
|
|
118
|
+
trailing: true,
|
|
119
|
+
maxWait: 5e3
|
|
120
|
+
});
|
|
109
121
|
(0, _react.useEffect)(() => {
|
|
110
122
|
if (subscription && customer_id) {
|
|
111
123
|
subscription.on("invoice.paid", ({
|
|
112
124
|
response
|
|
113
125
|
}) => {
|
|
114
126
|
if (response.customer_id === customer_id) {
|
|
115
|
-
|
|
116
|
-
refresh();
|
|
127
|
+
debouncedHandleInvoicePaid();
|
|
117
128
|
}
|
|
118
129
|
});
|
|
119
130
|
}
|
|
@@ -207,7 +218,8 @@ const InvoiceTable = _react.default.memo(props => {
|
|
|
207
218
|
customBodyRenderLite: (val, index) => {
|
|
208
219
|
const invoice = data?.list[index];
|
|
209
220
|
const link = getInvoiceLink(invoice, action);
|
|
210
|
-
|
|
221
|
+
const hidePay = invoice.billing_reason === "overdraft-protection";
|
|
222
|
+
if (action && !hidePay) {
|
|
211
223
|
return link.connect ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
212
224
|
variant: "text",
|
|
213
225
|
size: "small",
|
|
@@ -340,19 +352,29 @@ const InvoiceList = _react.default.memo(props => {
|
|
|
340
352
|
}, {
|
|
341
353
|
reloadDeps: [customer_id, subscription_id, status, include_staking, include_recovered_from]
|
|
342
354
|
});
|
|
355
|
+
const prevData = (0, _react.useRef)(data);
|
|
343
356
|
(0, _react.useEffect)(() => {
|
|
344
357
|
if (onTableDataChange) {
|
|
345
|
-
onTableDataChange(data);
|
|
358
|
+
onTableDataChange(data, prevData.current);
|
|
359
|
+
prevData.current = data;
|
|
346
360
|
}
|
|
347
361
|
}, [data]);
|
|
362
|
+
const debouncedHandleInvoicePaid = (0, _debounce.default)(async () => {
|
|
363
|
+
_Toast.default.close();
|
|
364
|
+
_Toast.default.success(t("payment.customer.invoice.paySuccess"));
|
|
365
|
+
await reloadAsync();
|
|
366
|
+
}, 1e3, {
|
|
367
|
+
leading: false,
|
|
368
|
+
trailing: true,
|
|
369
|
+
maxWait: 5e3
|
|
370
|
+
});
|
|
348
371
|
(0, _react.useEffect)(() => {
|
|
349
372
|
if (subscription && customer_id) {
|
|
350
|
-
subscription.on("invoice.paid",
|
|
373
|
+
subscription.on("invoice.paid", ({
|
|
351
374
|
response
|
|
352
375
|
}) => {
|
|
353
376
|
if (response.customer_id === customer_id) {
|
|
354
|
-
|
|
355
|
-
await reloadAsync();
|
|
377
|
+
debouncedHandleInvoicePaid();
|
|
356
378
|
}
|
|
357
379
|
});
|
|
358
380
|
}
|
package/lib/libs/util.js
CHANGED
|
@@ -1046,10 +1046,12 @@ function getInvoiceDescriptionAndReason(invoice, locale = "en") {
|
|
|
1046
1046
|
slash_stake: (0, _locales.t)("payment.invoice.reason.slashStake", locale),
|
|
1047
1047
|
stake: (0, _locales.t)("payment.invoice.reason.stake", locale),
|
|
1048
1048
|
return_stake: (0, _locales.t)("payment.invoice.reason.returnStake", locale),
|
|
1049
|
-
recharge: (0, _locales.t)("payment.invoice.reason.recharge", locale)
|
|
1049
|
+
recharge: (0, _locales.t)("payment.invoice.reason.recharge", locale),
|
|
1050
|
+
stake_overdraft_protection: (0, _locales.t)("payment.invoice.reason.stake", locale),
|
|
1051
|
+
overdraft_protection: (0, _locales.t)("payment.invoice.reason.fee", locale)
|
|
1050
1052
|
};
|
|
1051
1053
|
let invoiceType = (0, _locales.t)("payment.invoice.reason.payment", locale);
|
|
1052
|
-
if (reason.includes("stake") || reason.includes("recharge")) {
|
|
1054
|
+
if (reason.includes("stake") || reason.includes("recharge") || reason === "overdraft_protection") {
|
|
1053
1055
|
invoiceType = reasonMap[reason];
|
|
1054
1056
|
}
|
|
1055
1057
|
if (description?.startsWith("Subscription ") || description?.startsWith("Slash stake")) {
|
|
@@ -1065,7 +1067,9 @@ function getInvoiceDescriptionAndReason(invoice, locale = "en") {
|
|
|
1065
1067
|
"Stake for subscription": (0, _locales.t)("payment.invoice.reason.staking", locale),
|
|
1066
1068
|
"Return Subscription staking": (0, _locales.t)("payment.invoice.reason.returnStake", locale),
|
|
1067
1069
|
"Recharge for subscription": (0, _locales.t)("payment.invoice.reason.rechargeForSubscription", locale),
|
|
1068
|
-
"Add funds for subscription": (0, _locales.t)("payment.invoice.reason.rechargeForSubscription", locale)
|
|
1070
|
+
"Add funds for subscription": (0, _locales.t)("payment.invoice.reason.rechargeForSubscription", locale),
|
|
1071
|
+
"Overdraft protection": (0, _locales.t)("payment.invoice.reason.overdraftProtection", locale),
|
|
1072
|
+
"Stake for subscription overdraft protection": (0, _locales.t)("payment.invoice.reason.stakeForSubscriptionOverdraftProtection", locale)
|
|
1069
1073
|
};
|
|
1070
1074
|
return {
|
|
1071
1075
|
description: descMap[description] || description,
|
package/lib/locales/en.js
CHANGED
|
@@ -322,7 +322,11 @@ module.exports = (0, _flat.default)({
|
|
|
322
322
|
stakeForChangePlan: "Subscription plan update",
|
|
323
323
|
stakeForChangePayment: "Subscription payment method update",
|
|
324
324
|
recharge: "Add funds",
|
|
325
|
-
rechargeForSubscription: "Add funds for subscription"
|
|
325
|
+
rechargeForSubscription: "Add funds for subscription",
|
|
326
|
+
overdraftProtection: "Overdraft protection Fee",
|
|
327
|
+
stakeForSubscriptionOverdraftProtection: "Subscription overdraft protection",
|
|
328
|
+
gas: "Gas",
|
|
329
|
+
fee: "Fee"
|
|
326
330
|
}
|
|
327
331
|
},
|
|
328
332
|
subscription: {
|
package/lib/locales/zh.js
CHANGED
|
@@ -322,7 +322,11 @@ module.exports = (0, _flat.default)({
|
|
|
322
322
|
stakeForChangePlan: "\u8BA2\u9605\u5957\u9910\u66F4\u65B0",
|
|
323
323
|
stakeForChangePayment: "\u8BA2\u9605\u652F\u4ED8\u65B9\u5F0F\u66F4\u65B0",
|
|
324
324
|
recharge: "\u5145\u503C",
|
|
325
|
-
rechargeForSubscription: "\u8BA2\u9605\u5145\u503C"
|
|
325
|
+
rechargeForSubscription: "\u8BA2\u9605\u5145\u503C",
|
|
326
|
+
overdraftProtection: "\u900F\u652F\u4FDD\u62A4\u8D39",
|
|
327
|
+
stakeForSubscriptionOverdraftProtection: "\u8BA2\u9605\u900F\u652F\u4FDD\u62A4",
|
|
328
|
+
gas: "\u624B\u7EED\u8D39",
|
|
329
|
+
fee: "\u670D\u52A1\u8D39"
|
|
326
330
|
}
|
|
327
331
|
},
|
|
328
332
|
subscription: {
|
|
@@ -521,7 +521,7 @@ function PaymentForm({
|
|
|
521
521
|
})]
|
|
522
522
|
})
|
|
523
523
|
}), state.customerLimited && /* @__PURE__ */(0, _jsxRuntime.jsx)(_confirm.default, {
|
|
524
|
-
onConfirm: () => window.open((0, _ufo.joinURL)((0, _util.getPrefix)(),
|
|
524
|
+
onConfirm: () => window.open((0, _ufo.joinURL)((0, _util.getPrefix)(), `/customer/invoice/past-due?referer=${encodeURIComponent(window.location.href)}`), "_self"),
|
|
525
525
|
onCancel: () => setState({
|
|
526
526
|
customerLimited: false
|
|
527
527
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.18",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -53,15 +53,15 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@arcblock/did-connect": "^2.
|
|
57
|
-
"@arcblock/ux": "^2.
|
|
58
|
-
"@arcblock/ws": "^1.18.
|
|
59
|
-
"@blocklet/ui-react": "^2.
|
|
56
|
+
"@arcblock/did-connect": "^2.11.15",
|
|
57
|
+
"@arcblock/ux": "^2.11.15",
|
|
58
|
+
"@arcblock/ws": "^1.18.165",
|
|
59
|
+
"@blocklet/ui-react": "^2.11.15",
|
|
60
60
|
"@mui/icons-material": "^5.16.6",
|
|
61
61
|
"@mui/lab": "^5.0.0-alpha.173",
|
|
62
62
|
"@mui/material": "^5.16.6",
|
|
63
63
|
"@mui/system": "^5.16.6",
|
|
64
|
-
"@ocap/util": "^1.18.
|
|
64
|
+
"@ocap/util": "^1.18.165",
|
|
65
65
|
"@stripe/react-stripe-js": "^2.7.3",
|
|
66
66
|
"@stripe/stripe-js": "^2.4.0",
|
|
67
67
|
"@vitejs/plugin-legacy": "^5.4.1",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"@babel/core": "^7.25.2",
|
|
93
93
|
"@babel/preset-env": "^7.25.2",
|
|
94
94
|
"@babel/preset-react": "^7.24.7",
|
|
95
|
-
"@blocklet/payment-types": "1.16.
|
|
95
|
+
"@blocklet/payment-types": "1.16.18",
|
|
96
96
|
"@storybook/addon-essentials": "^7.6.20",
|
|
97
97
|
"@storybook/addon-interactions": "^7.6.20",
|
|
98
98
|
"@storybook/addon-links": "^7.6.20",
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"vite-plugin-babel": "^1.2.0",
|
|
124
124
|
"vite-plugin-node-polyfills": "^0.21.0"
|
|
125
125
|
},
|
|
126
|
-
"gitHead": "
|
|
126
|
+
"gitHead": "ea644d08efdbfba6034a3ec09eac4d7160bcba66"
|
|
127
127
|
}
|
package/src/contexts/payment.tsx
CHANGED
|
@@ -81,7 +81,15 @@ function PaymentProvider({ session, connect, children, baseUrl }: PaymentContext
|
|
|
81
81
|
|
|
82
82
|
const [livemode, setLivemode] = useLocalStorageState('livemode', { defaultValue: true });
|
|
83
83
|
|
|
84
|
-
const {
|
|
84
|
+
const {
|
|
85
|
+
data = {
|
|
86
|
+
paymentMethods: [],
|
|
87
|
+
baseCurrency: {},
|
|
88
|
+
},
|
|
89
|
+
error,
|
|
90
|
+
run,
|
|
91
|
+
loading,
|
|
92
|
+
} = useRequest(getSettings, {
|
|
85
93
|
refreshDeps: [livemode],
|
|
86
94
|
});
|
|
87
95
|
const prefix = getPrefix();
|
|
@@ -11,9 +11,10 @@ import { OpenInNewOutlined } from '@mui/icons-material';
|
|
|
11
11
|
import { Box, Button, CircularProgress, Hidden, Stack, Typography } from '@mui/material';
|
|
12
12
|
import { styled } from '@mui/system';
|
|
13
13
|
import { useInfiniteScroll, useRequest, useSetState } from 'ahooks';
|
|
14
|
-
import React, { useEffect, useState } from 'react';
|
|
14
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
15
15
|
import { joinURL } from 'ufo';
|
|
16
16
|
|
|
17
|
+
import debounce from 'lodash/debounce';
|
|
17
18
|
import Status from '../../components/status';
|
|
18
19
|
import { usePaymentContext } from '../../contexts/payment';
|
|
19
20
|
import { useSubscription } from '../../hooks/subscription';
|
|
@@ -131,21 +132,38 @@ const InvoiceTable = React.memo((props: Props & { onPay: (invoiceId: string) =>
|
|
|
131
132
|
refreshDeps: [search, status, customer_id, currency_id, subscription_id, include_staking, include_recovered_from],
|
|
132
133
|
}
|
|
133
134
|
);
|
|
135
|
+
|
|
136
|
+
const prevData = useRef(data);
|
|
137
|
+
|
|
134
138
|
useEffect(() => {
|
|
135
139
|
if (onTableDataChange) {
|
|
136
|
-
onTableDataChange(data);
|
|
140
|
+
onTableDataChange(data, prevData.current);
|
|
141
|
+
prevData.current = data;
|
|
137
142
|
}
|
|
138
143
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
139
144
|
}, [data]);
|
|
140
145
|
|
|
141
146
|
const subscription = useSubscription('events');
|
|
142
147
|
|
|
148
|
+
const debouncedHandleInvoicePaid = debounce(
|
|
149
|
+
async () => {
|
|
150
|
+
Toast.close();
|
|
151
|
+
Toast.success(t('payment.customer.invoice.paySuccess'));
|
|
152
|
+
await refresh();
|
|
153
|
+
},
|
|
154
|
+
1000,
|
|
155
|
+
{
|
|
156
|
+
leading: false,
|
|
157
|
+
trailing: true,
|
|
158
|
+
maxWait: 5000,
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
|
|
143
162
|
useEffect(() => {
|
|
144
163
|
if (subscription && customer_id) {
|
|
145
164
|
subscription.on('invoice.paid', ({ response }: { response: TInvoiceExpanded }) => {
|
|
146
165
|
if (response.customer_id === customer_id) {
|
|
147
|
-
|
|
148
|
-
refresh();
|
|
166
|
+
debouncedHandleInvoicePaid();
|
|
149
167
|
}
|
|
150
168
|
});
|
|
151
169
|
}
|
|
@@ -241,7 +259,8 @@ const InvoiceTable = React.memo((props: Props & { onPay: (invoiceId: string) =>
|
|
|
241
259
|
customBodyRenderLite: (val: string, index: number) => {
|
|
242
260
|
const invoice = data?.list[index] as TInvoiceExpanded;
|
|
243
261
|
const link = getInvoiceLink(invoice, action);
|
|
244
|
-
|
|
262
|
+
const hidePay = invoice.billing_reason === 'overdraft-protection';
|
|
263
|
+
if (action && !hidePay) {
|
|
245
264
|
return link.connect ? (
|
|
246
265
|
<Button variant="text" size="small" onClick={() => onPay(invoice.id)} sx={{ color: 'text.link' }}>
|
|
247
266
|
{t('payment.customer.invoice.pay')}
|
|
@@ -356,20 +375,35 @@ const InvoiceList = React.memo((props: Props & { onPay: (invoiceId: string) => v
|
|
|
356
375
|
}
|
|
357
376
|
);
|
|
358
377
|
|
|
378
|
+
const prevData = useRef(data);
|
|
379
|
+
|
|
359
380
|
useEffect(() => {
|
|
360
381
|
if (onTableDataChange) {
|
|
361
|
-
onTableDataChange(data);
|
|
382
|
+
onTableDataChange(data, prevData.current);
|
|
383
|
+
prevData.current = data;
|
|
362
384
|
}
|
|
363
385
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
364
386
|
}, [data]);
|
|
365
387
|
|
|
388
|
+
const debouncedHandleInvoicePaid = debounce(
|
|
389
|
+
async () => {
|
|
390
|
+
Toast.close();
|
|
391
|
+
Toast.success(t('payment.customer.invoice.paySuccess'));
|
|
392
|
+
await reloadAsync();
|
|
393
|
+
},
|
|
394
|
+
1000,
|
|
395
|
+
{
|
|
396
|
+
leading: false,
|
|
397
|
+
trailing: true,
|
|
398
|
+
maxWait: 5000,
|
|
399
|
+
}
|
|
400
|
+
);
|
|
366
401
|
// Listen to invoice.paid event and refresh data
|
|
367
402
|
useEffect(() => {
|
|
368
403
|
if (subscription && customer_id) {
|
|
369
|
-
subscription.on('invoice.paid',
|
|
404
|
+
subscription.on('invoice.paid', ({ response }: { response: TInvoiceExpanded }) => {
|
|
370
405
|
if (response.customer_id === customer_id) {
|
|
371
|
-
|
|
372
|
-
await reloadAsync();
|
|
406
|
+
debouncedHandleInvoicePaid();
|
|
373
407
|
}
|
|
374
408
|
});
|
|
375
409
|
}
|
package/src/libs/util.ts
CHANGED
|
@@ -1121,9 +1121,11 @@ export function getInvoiceDescriptionAndReason(invoice: TInvoiceExpanded, locale
|
|
|
1121
1121
|
stake: t('payment.invoice.reason.stake', locale),
|
|
1122
1122
|
return_stake: t('payment.invoice.reason.returnStake', locale),
|
|
1123
1123
|
recharge: t('payment.invoice.reason.recharge', locale),
|
|
1124
|
+
stake_overdraft_protection: t('payment.invoice.reason.stake', locale),
|
|
1125
|
+
overdraft_protection: t('payment.invoice.reason.fee', locale),
|
|
1124
1126
|
};
|
|
1125
1127
|
let invoiceType = t('payment.invoice.reason.payment', locale);
|
|
1126
|
-
if (reason.includes('stake') || reason.includes('recharge')) {
|
|
1128
|
+
if (reason.includes('stake') || reason.includes('recharge') || reason === 'overdraft_protection') {
|
|
1127
1129
|
invoiceType = reasonMap[reason as keyof typeof reasonMap];
|
|
1128
1130
|
}
|
|
1129
1131
|
if (description?.startsWith('Subscription ') || description?.startsWith('Slash stake')) {
|
|
@@ -1140,6 +1142,11 @@ export function getInvoiceDescriptionAndReason(invoice: TInvoiceExpanded, locale
|
|
|
1140
1142
|
'Return Subscription staking': t('payment.invoice.reason.returnStake', locale),
|
|
1141
1143
|
'Recharge for subscription': t('payment.invoice.reason.rechargeForSubscription', locale),
|
|
1142
1144
|
'Add funds for subscription': t('payment.invoice.reason.rechargeForSubscription', locale),
|
|
1145
|
+
'Overdraft protection': t('payment.invoice.reason.overdraftProtection', locale),
|
|
1146
|
+
'Stake for subscription overdraft protection': t(
|
|
1147
|
+
'payment.invoice.reason.stakeForSubscriptionOverdraftProtection',
|
|
1148
|
+
locale
|
|
1149
|
+
),
|
|
1143
1150
|
};
|
|
1144
1151
|
|
|
1145
1152
|
return {
|
package/src/locales/en.tsx
CHANGED
|
@@ -329,6 +329,10 @@ export default flat({
|
|
|
329
329
|
stakeForChangePayment: 'Subscription payment method update',
|
|
330
330
|
recharge: 'Add funds',
|
|
331
331
|
rechargeForSubscription: 'Add funds for subscription',
|
|
332
|
+
overdraftProtection: 'Overdraft protection Fee',
|
|
333
|
+
stakeForSubscriptionOverdraftProtection: 'Subscription overdraft protection',
|
|
334
|
+
gas: 'Gas',
|
|
335
|
+
fee: 'Fee',
|
|
332
336
|
},
|
|
333
337
|
},
|
|
334
338
|
subscription: {
|
package/src/locales/zh.tsx
CHANGED
|
@@ -319,6 +319,10 @@ export default flat({
|
|
|
319
319
|
stakeForChangePayment: '订阅支付方式更新',
|
|
320
320
|
recharge: '充值',
|
|
321
321
|
rechargeForSubscription: '订阅充值',
|
|
322
|
+
overdraftProtection: '透支保护费',
|
|
323
|
+
stakeForSubscriptionOverdraftProtection: '订阅透支保护',
|
|
324
|
+
gas: '手续费',
|
|
325
|
+
fee: '服务费',
|
|
322
326
|
},
|
|
323
327
|
},
|
|
324
328
|
subscription: {
|
|
@@ -523,7 +523,12 @@ export default function PaymentForm({
|
|
|
523
523
|
</Fade>
|
|
524
524
|
{state.customerLimited && (
|
|
525
525
|
<ConfirmDialog
|
|
526
|
-
onConfirm={() =>
|
|
526
|
+
onConfirm={() =>
|
|
527
|
+
window.open(
|
|
528
|
+
joinURL(getPrefix(), `/customer/invoice/past-due?referer=${encodeURIComponent(window.location.href)}`),
|
|
529
|
+
'_self'
|
|
530
|
+
)
|
|
531
|
+
}
|
|
527
532
|
onCancel={() => setState({ customerLimited: false })}
|
|
528
533
|
confirm={t('payment.customer.pastDue.alert.confirm')}
|
|
529
534
|
title={t('payment.customer.pastDue.alert.title')}
|