@blocklet/payment-react 1.15.3 → 1.15.5
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/checkout/donate.d.ts +1 -1
- package/es/checkout/donate.js +13 -7
- package/es/checkout/table.js +55 -36
- package/es/components/pricing-table.js +255 -210
- package/es/contexts/payment.js +6 -3
- package/es/history/invoice/list.d.ts +2 -0
- package/es/history/invoice/list.js +34 -4
- package/es/libs/util.js +2 -1
- package/es/payment/index.js +0 -3
- package/es/payment/product-card.js +2 -2
- package/lib/checkout/donate.d.ts +1 -1
- package/lib/checkout/donate.js +18 -13
- package/lib/checkout/table.js +12 -1
- package/lib/components/pricing-table.js +41 -2
- package/lib/contexts/payment.js +12 -5
- package/lib/history/invoice/list.d.ts +2 -0
- package/lib/history/invoice/list.js +32 -4
- package/lib/libs/util.js +2 -1
- package/lib/payment/index.js +0 -3
- package/lib/payment/product-card.js +1 -2
- package/package.json +6 -6
- package/src/checkout/donate.tsx +14 -14
- package/src/checkout/table.tsx +15 -1
- package/src/components/pricing-table.tsx +43 -1
- package/src/contexts/payment.tsx +7 -3
- package/src/history/invoice/list.tsx +37 -1
- package/src/libs/util.ts +2 -1
- package/src/payment/index.tsx +0 -3
- package/src/payment/product-card.tsx +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Avatar, Stack, Typography } from "@mui/material";
|
|
2
|
+
import { Avatar, Box, Stack, Typography } from "@mui/material";
|
|
3
3
|
export default function ProductCard({ size, variant, name, logo, description, extra }) {
|
|
4
4
|
const s = { width: size, height: size };
|
|
5
5
|
return /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 1, flex: 2, sx: { width: "100%" }, children: [
|
|
@@ -39,7 +39,7 @@ export default function ProductCard({ size, variant, name, logo, description, ex
|
|
|
39
39
|
children: description
|
|
40
40
|
}
|
|
41
41
|
),
|
|
42
|
-
extra && /* @__PURE__ */ jsx(
|
|
42
|
+
extra && /* @__PURE__ */ jsx(Box, { sx: { fontSize: "0.85rem" }, color: "text.lighter", children: extra })
|
|
43
43
|
]
|
|
44
44
|
}
|
|
45
45
|
)
|
package/lib/checkout/donate.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ declare function CheckoutDonate(props: DonateProps): import("react").JSX.Element
|
|
|
26
26
|
declare namespace CheckoutDonate {
|
|
27
27
|
var defaultProps: {
|
|
28
28
|
theme: string;
|
|
29
|
-
livemode:
|
|
29
|
+
livemode: undefined;
|
|
30
30
|
timeout: number;
|
|
31
31
|
mode: string;
|
|
32
32
|
inlineOptions: {
|
package/lib/checkout/donate.js
CHANGED
|
@@ -17,6 +17,7 @@ var _api = _interopRequireDefault(require("../libs/api"));
|
|
|
17
17
|
var _util = require("../libs/util");
|
|
18
18
|
var _form = _interopRequireDefault(require("./form"));
|
|
19
19
|
var _theme = require("../theme");
|
|
20
|
+
var _payment = require("../contexts/payment");
|
|
20
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
22
|
const donationCache = {};
|
|
22
23
|
const createOrUpdateDonation = (settings, livemode = true) => {
|
|
@@ -249,7 +250,7 @@ function SupporterSimple({
|
|
|
249
250
|
})]
|
|
250
251
|
});
|
|
251
252
|
}
|
|
252
|
-
function useDonation(settings, livemode
|
|
253
|
+
function useDonation(settings, livemode, mode = "default") {
|
|
253
254
|
const [state, setState] = (0, _ahooks.useSetState)({
|
|
254
255
|
open: false,
|
|
255
256
|
supporterLoaded: false,
|
|
@@ -288,7 +289,7 @@ function useDonation(settings, livemode = true, mode = "default") {
|
|
|
288
289
|
}
|
|
289
290
|
function CheckoutDonateInner({
|
|
290
291
|
settings,
|
|
291
|
-
livemode,
|
|
292
|
+
livemode = true,
|
|
292
293
|
timeout,
|
|
293
294
|
onPaid,
|
|
294
295
|
onError,
|
|
@@ -474,35 +475,39 @@ function CheckoutDonateInner({
|
|
|
474
475
|
onError,
|
|
475
476
|
action: settings.appearance?.button?.text,
|
|
476
477
|
mode: "inline",
|
|
477
|
-
theme
|
|
478
|
+
theme,
|
|
479
|
+
extraParams: {
|
|
480
|
+
livemode
|
|
481
|
+
}
|
|
478
482
|
})
|
|
479
483
|
})
|
|
480
484
|
})]
|
|
481
485
|
});
|
|
482
486
|
}
|
|
483
487
|
function CheckoutDonate(props) {
|
|
488
|
+
const {
|
|
489
|
+
livemode
|
|
490
|
+
} = (0, _payment.usePaymentContext)();
|
|
491
|
+
const content = /* @__PURE__ */(0, _jsxRuntime.jsx)(CheckoutDonateInner, {
|
|
492
|
+
...props,
|
|
493
|
+
livemode: props.livemode === void 0 ? livemode : props.livemode
|
|
494
|
+
});
|
|
484
495
|
if (props.theme === "inherit") {
|
|
485
|
-
return
|
|
486
|
-
...props
|
|
487
|
-
});
|
|
496
|
+
return content;
|
|
488
497
|
}
|
|
489
498
|
if (props.theme && typeof props.theme === "object") {
|
|
490
499
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_theme.PaymentThemeProvider, {
|
|
491
500
|
theme: props.theme,
|
|
492
|
-
children:
|
|
493
|
-
...props
|
|
494
|
-
})
|
|
501
|
+
children: content
|
|
495
502
|
});
|
|
496
503
|
}
|
|
497
504
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_theme.PaymentThemeProvider, {
|
|
498
|
-
children:
|
|
499
|
-
...props
|
|
500
|
-
})
|
|
505
|
+
children: content
|
|
501
506
|
});
|
|
502
507
|
}
|
|
503
508
|
CheckoutDonate.defaultProps = {
|
|
504
509
|
theme: "default",
|
|
505
|
-
livemode:
|
|
510
|
+
livemode: void 0,
|
|
506
511
|
timeout: 5e3,
|
|
507
512
|
mode: "default",
|
|
508
513
|
inlineOptions: {
|
package/lib/checkout/table.js
CHANGED
|
@@ -100,7 +100,18 @@ function CheckoutTableInner({
|
|
|
100
100
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
101
101
|
direction: "column",
|
|
102
102
|
alignItems: "center",
|
|
103
|
-
|
|
103
|
+
sx: {
|
|
104
|
+
overflow: {
|
|
105
|
+
xs: "auto",
|
|
106
|
+
md: "hidden"
|
|
107
|
+
},
|
|
108
|
+
height: "100%",
|
|
109
|
+
pt: {
|
|
110
|
+
xs: 2.5,
|
|
111
|
+
md: 7.5
|
|
112
|
+
},
|
|
113
|
+
px: 2.5
|
|
114
|
+
},
|
|
104
115
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_system.Box, {
|
|
105
116
|
sx: {
|
|
106
117
|
display: "flex",
|
|
@@ -67,8 +67,19 @@ function PricingTable({
|
|
|
67
67
|
const {
|
|
68
68
|
settings: {
|
|
69
69
|
paymentMethods = []
|
|
70
|
-
}
|
|
70
|
+
},
|
|
71
|
+
livemode,
|
|
72
|
+
setLivemode,
|
|
73
|
+
refresh
|
|
71
74
|
} = (0, _payment.usePaymentContext)();
|
|
75
|
+
const isMobileSafariEnv = (0, _util2.isMobileSafari)();
|
|
76
|
+
(0, _react.useEffect)(() => {
|
|
77
|
+
if (table) {
|
|
78
|
+
if (livemode !== table.livemode) {
|
|
79
|
+
setLivemode(table.livemode);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, [table, livemode, setLivemode, refresh]);
|
|
72
83
|
const [currency, setCurrency] = (0, _react.useState)(table.currency || {});
|
|
73
84
|
const {
|
|
74
85
|
recurring,
|
|
@@ -152,6 +163,13 @@ function PricingTable({
|
|
|
152
163
|
width: 100%;
|
|
153
164
|
gap: 20px;
|
|
154
165
|
}
|
|
166
|
+
.price-table-wrap {
|
|
167
|
+
scrollbar-width: none;
|
|
168
|
+
-ms-overflow-style: none;
|
|
169
|
+
&::-webkit-scrollbar {
|
|
170
|
+
display: none;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
155
173
|
@media (max-width: ${({
|
|
156
174
|
theme
|
|
157
175
|
}) => theme.breakpoints.values.sm}px) {
|
|
@@ -177,6 +195,15 @@ function PricingTable({
|
|
|
177
195
|
}
|
|
178
196
|
`;
|
|
179
197
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(Root, {
|
|
198
|
+
sx: {
|
|
199
|
+
flex: 1,
|
|
200
|
+
overflow: {
|
|
201
|
+
xs: isMobileSafariEnv ? "visible" : "hidden",
|
|
202
|
+
md: "hidden"
|
|
203
|
+
},
|
|
204
|
+
display: "flex",
|
|
205
|
+
flexDirection: "column"
|
|
206
|
+
},
|
|
180
207
|
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
181
208
|
direction: "column",
|
|
182
209
|
alignItems: alignItems === "center" ? "center" : "flex-start",
|
|
@@ -184,6 +211,11 @@ function PricingTable({
|
|
|
184
211
|
gap: {
|
|
185
212
|
xs: 3,
|
|
186
213
|
sm: mode === "select" ? 3 : 5
|
|
214
|
+
},
|
|
215
|
+
height: "100%",
|
|
216
|
+
overflow: {
|
|
217
|
+
xs: "auto",
|
|
218
|
+
md: "hidden"
|
|
187
219
|
}
|
|
188
220
|
},
|
|
189
221
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
@@ -263,6 +295,11 @@ function PricingTable({
|
|
|
263
295
|
direction: "row",
|
|
264
296
|
gap: "20px",
|
|
265
297
|
justifyContent: alignItems === "center" ? "center" : "flex-start",
|
|
298
|
+
sx: {
|
|
299
|
+
flex: "0 1 auto",
|
|
300
|
+
overflow: "auto",
|
|
301
|
+
pb: 2.5
|
|
302
|
+
},
|
|
266
303
|
className: "price-table-wrap",
|
|
267
304
|
children: productList?.map(x => {
|
|
268
305
|
let action = x.subscription_data?.trial_period_days ? t("payment.checkout.try") : t("payment.checkout.subscription");
|
|
@@ -293,8 +330,10 @@ function PricingTable({
|
|
|
293
330
|
md: "320px"
|
|
294
331
|
},
|
|
295
332
|
maxWidth: "360px",
|
|
333
|
+
minWidth: "300px",
|
|
296
334
|
padding: "20px",
|
|
297
|
-
position: "relative"
|
|
335
|
+
position: "relative",
|
|
336
|
+
height: "fit-content"
|
|
298
337
|
},
|
|
299
338
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
300
339
|
textAlign: "center",
|
package/lib/contexts/payment.js
CHANGED
|
@@ -24,13 +24,18 @@ const {
|
|
|
24
24
|
exports.SettingsConsumer = Consumer;
|
|
25
25
|
let settingsPromise = null;
|
|
26
26
|
const getSettings = () => {
|
|
27
|
-
const
|
|
27
|
+
const livemode = localStorage.getItem("livemode") !== "false";
|
|
28
|
+
const cacheKey = `payment-settings-${window.location.pathname}-${livemode}`;
|
|
28
29
|
const cachedData = sessionStorage.getItem(cacheKey);
|
|
29
30
|
if (cachedData) {
|
|
30
31
|
return JSON.parse(cachedData);
|
|
31
32
|
}
|
|
32
33
|
if (!settingsPromise) {
|
|
33
|
-
settingsPromise = _api.default.get("/api/settings"
|
|
34
|
+
settingsPromise = _api.default.get("/api/settings", {
|
|
35
|
+
params: {
|
|
36
|
+
livemode
|
|
37
|
+
}
|
|
38
|
+
}).then(({
|
|
34
39
|
data
|
|
35
40
|
}) => {
|
|
36
41
|
sessionStorage.setItem(cacheKey, JSON.stringify(data));
|
|
@@ -59,14 +64,16 @@ function PaymentProvider({
|
|
|
59
64
|
if (baseUrl) {
|
|
60
65
|
window.__PAYMENT_KIT_BASE_URL = baseUrl;
|
|
61
66
|
}
|
|
67
|
+
const [livemode, setLivemode] = (0, _ahooks.useLocalStorageState)("livemode", {
|
|
68
|
+
defaultValue: true
|
|
69
|
+
});
|
|
62
70
|
const {
|
|
63
71
|
data,
|
|
64
72
|
error,
|
|
65
73
|
run,
|
|
66
74
|
loading
|
|
67
|
-
} = (0, _ahooks.useRequest)(getSettings
|
|
68
|
-
|
|
69
|
-
defaultValue: true
|
|
75
|
+
} = (0, _ahooks.useRequest)(getSettings, {
|
|
76
|
+
refreshDeps: [livemode]
|
|
70
77
|
});
|
|
71
78
|
const prefix = (0, _util.getPrefix)();
|
|
72
79
|
const [payable, setPayable] = (0, _react.useState)(true);
|
|
@@ -10,6 +10,7 @@ type Props = {
|
|
|
10
10
|
target?: string;
|
|
11
11
|
action?: string;
|
|
12
12
|
type?: 'list' | 'table';
|
|
13
|
+
onTableDataChange?: Function;
|
|
13
14
|
};
|
|
14
15
|
declare function CustomerInvoiceList(props: Props): JSX.Element;
|
|
15
16
|
declare namespace CustomerInvoiceList {
|
|
@@ -24,6 +25,7 @@ declare namespace CustomerInvoiceList {
|
|
|
24
25
|
target: string;
|
|
25
26
|
action: string;
|
|
26
27
|
type: string;
|
|
28
|
+
onTableDataChange: () => void;
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
31
|
export default CustomerInvoiceList;
|
|
@@ -67,7 +67,8 @@ const InvoiceTable = _react.default.memo(props => {
|
|
|
67
67
|
currency_id,
|
|
68
68
|
subscription_id,
|
|
69
69
|
include_staking,
|
|
70
|
-
include_recovered_from
|
|
70
|
+
include_recovered_from,
|
|
71
|
+
onTableDataChange
|
|
71
72
|
} = props;
|
|
72
73
|
const listKey = "invoice-table";
|
|
73
74
|
const {
|
|
@@ -83,7 +84,8 @@ const InvoiceTable = _react.default.memo(props => {
|
|
|
83
84
|
data = {
|
|
84
85
|
list: [],
|
|
85
86
|
count: 0
|
|
86
|
-
}
|
|
87
|
+
},
|
|
88
|
+
refresh
|
|
87
89
|
} = (0, _ahooks.useRequest)(() => fetchData({
|
|
88
90
|
...search,
|
|
89
91
|
status,
|
|
@@ -96,6 +98,24 @@ const InvoiceTable = _react.default.memo(props => {
|
|
|
96
98
|
}), {
|
|
97
99
|
refreshDeps: [search]
|
|
98
100
|
});
|
|
101
|
+
(0, _react.useEffect)(() => {
|
|
102
|
+
if (onTableDataChange) {
|
|
103
|
+
onTableDataChange(data);
|
|
104
|
+
}
|
|
105
|
+
}, [data]);
|
|
106
|
+
const subscription = (0, _subscription.useSubscription)("events");
|
|
107
|
+
(0, _react.useEffect)(() => {
|
|
108
|
+
if (subscription && customer_id) {
|
|
109
|
+
subscription.on("invoice.paid", ({
|
|
110
|
+
response
|
|
111
|
+
}) => {
|
|
112
|
+
if (response.customer_id === customer_id) {
|
|
113
|
+
_Toast.default.success(t("payment.customer.invoice.paySuccess"));
|
|
114
|
+
refresh();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}, [subscription]);
|
|
99
119
|
const columns = [{
|
|
100
120
|
label: t("common.amount"),
|
|
101
121
|
name: "total",
|
|
@@ -270,7 +290,8 @@ const InvoiceList = _react.default.memo(props => {
|
|
|
270
290
|
pageSize,
|
|
271
291
|
target,
|
|
272
292
|
action,
|
|
273
|
-
onPay
|
|
293
|
+
onPay,
|
|
294
|
+
onTableDataChange
|
|
274
295
|
} = props;
|
|
275
296
|
const size = pageSize || 10;
|
|
276
297
|
const subscription = (0, _subscription.useSubscription)("events");
|
|
@@ -300,12 +321,18 @@ const InvoiceList = _react.default.memo(props => {
|
|
|
300
321
|
}, {
|
|
301
322
|
reloadDeps: [customer_id, subscription_id, status, include_staking, include_recovered_from]
|
|
302
323
|
});
|
|
324
|
+
(0, _react.useEffect)(() => {
|
|
325
|
+
if (onTableDataChange) {
|
|
326
|
+
onTableDataChange(data);
|
|
327
|
+
}
|
|
328
|
+
}, [data]);
|
|
303
329
|
(0, _react.useEffect)(() => {
|
|
304
330
|
if (subscription && customer_id) {
|
|
305
331
|
subscription.on("invoice.paid", async ({
|
|
306
332
|
response
|
|
307
333
|
}) => {
|
|
308
334
|
if (response.customer_id === customer_id) {
|
|
335
|
+
_Toast.default.success(t("payment.customer.invoice.paySuccess"));
|
|
309
336
|
await reloadAsync();
|
|
310
337
|
}
|
|
311
338
|
});
|
|
@@ -538,7 +565,8 @@ CustomerInvoiceList.defaultProps = {
|
|
|
538
565
|
pageSize: 10,
|
|
539
566
|
target: "_self",
|
|
540
567
|
action: "",
|
|
541
|
-
type: "list"
|
|
568
|
+
type: "list",
|
|
569
|
+
onTableDataChange: () => {}
|
|
542
570
|
};
|
|
543
571
|
const Root = (0, _system.styled)(_material.Stack)`
|
|
544
572
|
@media (max-width: ${({
|
package/lib/libs/util.js
CHANGED
|
@@ -1012,5 +1012,6 @@ function truncateText(text, maxLength, useWidth = false) {
|
|
|
1012
1012
|
return `${truncated}...`;
|
|
1013
1013
|
}
|
|
1014
1014
|
function getCustomerAvatar(did, updated_at, imageSize = 48) {
|
|
1015
|
-
|
|
1015
|
+
const updated = typeof updated_at === "number" ? updated_at : (0, _dayjs.default)(updated_at).unix();
|
|
1016
|
+
return `/.well-known/service/user/avatar/${did}?imageFilter=resize&w=${imageSize}&h=${imageSize}&updateAt=${updated || (0, _dayjs.default)().unix()}`;
|
|
1016
1017
|
}
|
package/lib/payment/index.js
CHANGED
|
@@ -320,9 +320,6 @@ function Payment({
|
|
|
320
320
|
if (checkoutSession) {
|
|
321
321
|
if (livemode !== checkoutSession.livemode) {
|
|
322
322
|
setLivemode(checkoutSession.livemode);
|
|
323
|
-
setTimeout(() => {
|
|
324
|
-
refresh();
|
|
325
|
-
}, 10);
|
|
326
323
|
}
|
|
327
324
|
}
|
|
328
325
|
}, [checkoutSession, livemode, setLivemode, refresh]);
|
|
@@ -72,8 +72,7 @@ function ProductCard({
|
|
|
72
72
|
},
|
|
73
73
|
color: "text.lighter",
|
|
74
74
|
children: description
|
|
75
|
-
}), extra && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.
|
|
76
|
-
variant: "body1",
|
|
75
|
+
}), extra && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
77
76
|
sx: {
|
|
78
77
|
fontSize: "0.85rem"
|
|
79
78
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.5",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@arcblock/did-connect": "^2.10.
|
|
57
|
-
"@arcblock/ux": "^2.10.
|
|
56
|
+
"@arcblock/did-connect": "^2.10.33",
|
|
57
|
+
"@arcblock/ux": "^2.10.33",
|
|
58
58
|
"@arcblock/ws": "^1.18.135",
|
|
59
|
-
"@blocklet/ui-react": "^2.10.
|
|
59
|
+
"@blocklet/ui-react": "^2.10.33",
|
|
60
60
|
"@mui/icons-material": "^5.16.6",
|
|
61
61
|
"@mui/lab": "^5.0.0-alpha.173",
|
|
62
62
|
"@mui/material": "^5.16.6",
|
|
@@ -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.15.
|
|
95
|
+
"@blocklet/payment-types": "1.15.5",
|
|
96
96
|
"@storybook/addon-essentials": "^7.6.20",
|
|
97
97
|
"@storybook/addon-interactions": "^7.6.20",
|
|
98
98
|
"@storybook/addon-links": "^7.6.20",
|
|
@@ -122,5 +122,5 @@
|
|
|
122
122
|
"vite-plugin-babel": "^1.2.0",
|
|
123
123
|
"vite-plugin-node-polyfills": "^0.21.0"
|
|
124
124
|
},
|
|
125
|
-
"gitHead": "
|
|
125
|
+
"gitHead": "013d9fb8161d6021b66da18916f49242dc156580"
|
|
126
126
|
}
|
package/src/checkout/donate.tsx
CHANGED
|
@@ -38,6 +38,7 @@ import { formatAmount, formatBNStr, formatDateTime, formatError, getCustomerAvat
|
|
|
38
38
|
import { CheckoutProps, PaymentThemeOptions } from '../types';
|
|
39
39
|
import CheckoutForm from './form';
|
|
40
40
|
import { PaymentThemeProvider } from '../theme';
|
|
41
|
+
import { usePaymentContext } from '../contexts/payment';
|
|
41
42
|
|
|
42
43
|
export type DonateHistory = {
|
|
43
44
|
supporters: TCheckoutSessionExpanded[];
|
|
@@ -261,7 +262,7 @@ function SupporterSimple({ supporters = [], totalAmount = '0', currency, method
|
|
|
261
262
|
);
|
|
262
263
|
}
|
|
263
264
|
|
|
264
|
-
function useDonation(settings: DonationSettings, livemode: boolean
|
|
265
|
+
function useDonation(settings: DonationSettings, livemode: boolean, mode = 'default') {
|
|
265
266
|
const [state, setState] = useSetState({
|
|
266
267
|
open: false,
|
|
267
268
|
supporterLoaded: false,
|
|
@@ -307,7 +308,7 @@ function useDonation(settings: DonationSettings, livemode: boolean = true, mode
|
|
|
307
308
|
|
|
308
309
|
function CheckoutDonateInner({
|
|
309
310
|
settings,
|
|
310
|
-
livemode,
|
|
311
|
+
livemode = true,
|
|
311
312
|
timeout,
|
|
312
313
|
onPaid,
|
|
313
314
|
onError,
|
|
@@ -477,6 +478,9 @@ function CheckoutDonateInner({
|
|
|
477
478
|
action={settings.appearance?.button?.text}
|
|
478
479
|
mode="inline"
|
|
479
480
|
theme={theme}
|
|
481
|
+
extraParams={{
|
|
482
|
+
livemode,
|
|
483
|
+
}}
|
|
480
484
|
/>
|
|
481
485
|
</Box>
|
|
482
486
|
</Dialog>
|
|
@@ -486,26 +490,22 @@ function CheckoutDonateInner({
|
|
|
486
490
|
}
|
|
487
491
|
|
|
488
492
|
export default function CheckoutDonate(props: DonateProps) {
|
|
493
|
+
const { livemode } = usePaymentContext();
|
|
494
|
+
const content = (
|
|
495
|
+
<CheckoutDonateInner {...props} livemode={props.livemode === undefined ? livemode : props.livemode} />
|
|
496
|
+
);
|
|
489
497
|
if (props.theme === 'inherit') {
|
|
490
|
-
return
|
|
498
|
+
return content;
|
|
491
499
|
}
|
|
492
500
|
if (props.theme && typeof props.theme === 'object') {
|
|
493
|
-
return
|
|
494
|
-
<PaymentThemeProvider theme={props.theme}>
|
|
495
|
-
<CheckoutDonateInner {...props} />
|
|
496
|
-
</PaymentThemeProvider>
|
|
497
|
-
);
|
|
501
|
+
return <PaymentThemeProvider theme={props.theme}>{content}</PaymentThemeProvider>;
|
|
498
502
|
}
|
|
499
|
-
return
|
|
500
|
-
<PaymentThemeProvider>
|
|
501
|
-
<CheckoutDonateInner {...props} />
|
|
502
|
-
</PaymentThemeProvider>
|
|
503
|
-
);
|
|
503
|
+
return <PaymentThemeProvider>{content}</PaymentThemeProvider>;
|
|
504
504
|
}
|
|
505
505
|
|
|
506
506
|
CheckoutDonate.defaultProps = {
|
|
507
507
|
theme: 'default',
|
|
508
|
-
livemode:
|
|
508
|
+
livemode: undefined,
|
|
509
509
|
timeout: 5000,
|
|
510
510
|
mode: 'default',
|
|
511
511
|
inlineOptions: {
|
package/src/checkout/table.tsx
CHANGED
|
@@ -84,7 +84,21 @@ function CheckoutTableInner({ id, mode, onPaid, onError, onChange, extraParams,
|
|
|
84
84
|
if (!sessionId && !hashSessionId) {
|
|
85
85
|
if (mode === 'standalone') {
|
|
86
86
|
return (
|
|
87
|
-
<Stack
|
|
87
|
+
<Stack
|
|
88
|
+
direction="column"
|
|
89
|
+
alignItems="center"
|
|
90
|
+
sx={{
|
|
91
|
+
overflow: {
|
|
92
|
+
xs: 'auto',
|
|
93
|
+
md: 'hidden',
|
|
94
|
+
},
|
|
95
|
+
height: '100%',
|
|
96
|
+
pt: {
|
|
97
|
+
xs: 2.5,
|
|
98
|
+
md: 7.5,
|
|
99
|
+
},
|
|
100
|
+
px: 2.5,
|
|
101
|
+
}}>
|
|
88
102
|
<Box
|
|
89
103
|
sx={{
|
|
90
104
|
display: 'flex',
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
formatRecurring,
|
|
32
32
|
getPriceCurrencyOptions,
|
|
33
33
|
getPriceUintAmountByCurrency,
|
|
34
|
+
isMobileSafari,
|
|
34
35
|
} from '../libs/util';
|
|
35
36
|
import Amount from '../payment/amount';
|
|
36
37
|
import { useMobile } from '../hooks/mobile';
|
|
@@ -84,7 +85,20 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
|
|
|
84
85
|
const { isMobile } = useMobile();
|
|
85
86
|
const {
|
|
86
87
|
settings: { paymentMethods = [] },
|
|
88
|
+
livemode,
|
|
89
|
+
setLivemode,
|
|
90
|
+
refresh,
|
|
87
91
|
} = usePaymentContext();
|
|
92
|
+
const isMobileSafariEnv = isMobileSafari();
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (table) {
|
|
96
|
+
if (livemode !== table.livemode) {
|
|
97
|
+
setLivemode(table.livemode);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, [table, livemode, setLivemode, refresh]);
|
|
101
|
+
|
|
88
102
|
const [currency, setCurrency] = useState(table.currency || {});
|
|
89
103
|
const { recurring, grouped } = useMemo(() => groupItemsByRecurring(table.items, currency), [table.items, currency]);
|
|
90
104
|
const recurringKeysList = useMemo(() => {
|
|
@@ -167,6 +181,13 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
|
|
|
167
181
|
width: 100%;
|
|
168
182
|
gap: 20px;
|
|
169
183
|
}
|
|
184
|
+
.price-table-wrap {
|
|
185
|
+
scrollbar-width: none;
|
|
186
|
+
-ms-overflow-style: none;
|
|
187
|
+
&::-webkit-scrollbar {
|
|
188
|
+
display: none;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
170
191
|
@media (max-width: ${({ theme }) => theme.breakpoints.values.sm}px) {
|
|
171
192
|
// .price-table-item {
|
|
172
193
|
// width: 90% !important;
|
|
@@ -188,7 +209,16 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
|
|
|
188
209
|
}
|
|
189
210
|
`;
|
|
190
211
|
return (
|
|
191
|
-
<Root
|
|
212
|
+
<Root
|
|
213
|
+
sx={{
|
|
214
|
+
flex: 1,
|
|
215
|
+
overflow: {
|
|
216
|
+
xs: isMobileSafariEnv ? 'visible' : 'hidden',
|
|
217
|
+
md: 'hidden',
|
|
218
|
+
},
|
|
219
|
+
display: 'flex',
|
|
220
|
+
flexDirection: 'column',
|
|
221
|
+
}}>
|
|
192
222
|
<Stack
|
|
193
223
|
direction="column"
|
|
194
224
|
alignItems={alignItems === 'center' ? 'center' : 'flex-start'}
|
|
@@ -197,6 +227,11 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
|
|
|
197
227
|
xs: 3,
|
|
198
228
|
sm: mode === 'select' ? 3 : 5,
|
|
199
229
|
},
|
|
230
|
+
height: '100%',
|
|
231
|
+
overflow: {
|
|
232
|
+
xs: 'auto',
|
|
233
|
+
md: 'hidden',
|
|
234
|
+
},
|
|
200
235
|
}}>
|
|
201
236
|
<Stack className="btn-row" flexDirection="row">
|
|
202
237
|
{recurringKeysList.length > 0 && (
|
|
@@ -277,6 +312,11 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
|
|
|
277
312
|
direction="row"
|
|
278
313
|
gap="20px"
|
|
279
314
|
justifyContent={alignItems === 'center' ? 'center' : 'flex-start'}
|
|
315
|
+
sx={{
|
|
316
|
+
flex: '0 1 auto',
|
|
317
|
+
overflow: 'auto',
|
|
318
|
+
pb: 2.5,
|
|
319
|
+
}}
|
|
280
320
|
className="price-table-wrap">
|
|
281
321
|
{productList?.map((x: TPricingTableItem & { is_selected?: boolean; is_disabled?: boolean }) => {
|
|
282
322
|
let action: string = x.subscription_data?.trial_period_days
|
|
@@ -312,9 +352,11 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
|
|
|
312
352
|
md: '320px',
|
|
313
353
|
},
|
|
314
354
|
maxWidth: '360px',
|
|
355
|
+
minWidth: '300px',
|
|
315
356
|
|
|
316
357
|
padding: '20px',
|
|
317
358
|
position: 'relative',
|
|
359
|
+
height: 'fit-content',
|
|
318
360
|
}}>
|
|
319
361
|
<Box textAlign="center">
|
|
320
362
|
<Stack
|
package/src/contexts/payment.tsx
CHANGED
|
@@ -41,14 +41,15 @@ const { Provider, Consumer } = PaymentContext;
|
|
|
41
41
|
|
|
42
42
|
let settingsPromise: Promise<any> | null = null;
|
|
43
43
|
const getSettings = () => {
|
|
44
|
-
const
|
|
44
|
+
const livemode = localStorage.getItem('livemode') !== 'false';
|
|
45
|
+
const cacheKey = `payment-settings-${window.location.pathname}-${livemode}`;
|
|
45
46
|
const cachedData = sessionStorage.getItem(cacheKey);
|
|
46
47
|
if (cachedData) {
|
|
47
48
|
return JSON.parse(cachedData);
|
|
48
49
|
}
|
|
49
50
|
if (!settingsPromise) {
|
|
50
51
|
settingsPromise = api
|
|
51
|
-
.get('/api/settings')
|
|
52
|
+
.get('/api/settings', { params: { livemode } })
|
|
52
53
|
.then(({ data }) => {
|
|
53
54
|
sessionStorage.setItem(cacheKey, JSON.stringify(data));
|
|
54
55
|
return data;
|
|
@@ -78,8 +79,11 @@ function PaymentProvider({ session, connect, children, baseUrl }: PaymentContext
|
|
|
78
79
|
window.__PAYMENT_KIT_BASE_URL = baseUrl;
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
const { data, error, run, loading } = useRequest(getSettings);
|
|
82
82
|
const [livemode, setLivemode] = useLocalStorageState('livemode', { defaultValue: true });
|
|
83
|
+
|
|
84
|
+
const { data, error, run, loading } = useRequest(getSettings, {
|
|
85
|
+
refreshDeps: [livemode],
|
|
86
|
+
});
|
|
83
87
|
const prefix = getPrefix();
|
|
84
88
|
const [payable, setPayable] = useState(true);
|
|
85
89
|
|