@blocklet/payment-react 1.13.126 → 1.13.128
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/form.d.ts +1 -1
- package/es/checkout/form.js +2 -1
- package/es/checkout/table.js +5 -1
- package/es/components/pricing-table.js +1 -0
- package/es/{portal → histroy}/invoice/list.js +1 -1
- package/es/histroy/mini-invoice/list.d.ts +7 -0
- package/es/histroy/mini-invoice/list.js +125 -0
- package/es/index.d.ts +4 -3
- package/es/index.js +5 -3
- package/es/locales/en.js +2 -0
- package/es/locales/zh.js +2 -0
- package/es/payment/form/index.js +2 -1
- package/es/payment/index.d.ts +2 -2
- package/es/payment/index.js +65 -45
- package/es/types/index.d.ts +1 -0
- package/es/util.d.ts +2 -1
- package/es/util.js +4 -0
- package/lib/checkout/form.d.ts +1 -1
- package/lib/checkout/form.js +2 -0
- package/lib/checkout/table.js +12 -5
- package/lib/components/pricing-table.js +1 -0
- package/lib/{portal → histroy}/invoice/list.js +1 -1
- package/lib/histroy/mini-invoice/list.d.ts +7 -0
- package/lib/histroy/mini-invoice/list.js +203 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +13 -5
- package/lib/locales/en.js +2 -0
- package/lib/locales/zh.js +2 -0
- package/lib/payment/form/index.js +4 -0
- package/lib/payment/index.d.ts +2 -2
- package/lib/payment/index.js +28 -8
- package/lib/types/index.d.ts +1 -0
- package/lib/util.d.ts +2 -1
- package/lib/util.js +5 -0
- package/package.json +5 -5
- package/src/checkout/form.tsx +2 -1
- package/src/checkout/table.tsx +10 -1
- package/src/components/pricing-table.tsx +2 -1
- package/src/{portal → histroy}/invoice/list.tsx +1 -1
- package/src/histroy/mini-invoice/list.tsx +165 -0
- package/src/index.ts +4 -2
- package/src/locales/en.tsx +2 -0
- package/src/locales/zh.tsx +2 -0
- package/src/payment/form/index.tsx +2 -1
- package/src/payment/index.tsx +23 -4
- package/src/types/index.ts +1 -0
- package/src/util.ts +8 -0
- /package/es/{portal → histroy}/invoice/list.d.ts +0 -0
- /package/es/{portal → histroy}/payment/list.d.ts +0 -0
- /package/es/{portal → histroy}/payment/list.js +0 -0
- /package/lib/{portal → histroy}/invoice/list.d.ts +0 -0
- /package/lib/{portal → histroy}/payment/list.d.ts +0 -0
- /package/lib/{portal → histroy}/payment/list.js +0 -0
- /package/src/{portal → histroy}/payment/list.tsx +0 -0
package/es/checkout/form.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CheckoutProps } from '../types';
|
|
3
|
-
declare function CheckoutForm({ id, onPaid, onError, mode, extraParams }: CheckoutProps): import("react").JSX.Element;
|
|
3
|
+
declare function CheckoutForm({ id, onPaid, onError, mode, goBack, extraParams }: CheckoutProps): import("react").JSX.Element;
|
|
4
4
|
declare namespace CheckoutForm {
|
|
5
5
|
var defaultProps: {
|
|
6
6
|
onPaid: any;
|
package/es/checkout/form.js
CHANGED
|
@@ -14,7 +14,7 @@ const fetchCheckoutSession = async (id) => {
|
|
|
14
14
|
const { data } = await api.get(`/api/checkout-sessions/retrieve/${id}`);
|
|
15
15
|
return data;
|
|
16
16
|
};
|
|
17
|
-
export default function CheckoutForm({ id, onPaid, onError, mode, extraParams }) {
|
|
17
|
+
export default function CheckoutForm({ id, onPaid, onError, mode, goBack, extraParams }) {
|
|
18
18
|
if (!id.startsWith("plink_") && !id.startsWith("cs_")) {
|
|
19
19
|
throw new Error("Either a checkoutSession or a paymentLink id is required.");
|
|
20
20
|
}
|
|
@@ -49,6 +49,7 @@ export default function CheckoutForm({ id, onPaid, onError, mode, extraParams })
|
|
|
49
49
|
error: apiError || state.appError,
|
|
50
50
|
onPaid: handlePaid,
|
|
51
51
|
onError: handleError,
|
|
52
|
+
goBack,
|
|
52
53
|
mode
|
|
53
54
|
}
|
|
54
55
|
);
|
package/es/checkout/table.js
CHANGED
|
@@ -2,6 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
3
|
import Toast from "@arcblock/ux/lib/Toast";
|
|
4
4
|
import { Alert, Stack, Typography } from "@mui/material";
|
|
5
|
+
import { Box } from "@mui/system";
|
|
5
6
|
import { useRequest } from "ahooks";
|
|
6
7
|
import { useState } from "react";
|
|
7
8
|
import api from "../api.js";
|
|
@@ -55,6 +56,9 @@ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }
|
|
|
55
56
|
Toast.error(err.message);
|
|
56
57
|
});
|
|
57
58
|
};
|
|
59
|
+
const goBack = () => {
|
|
60
|
+
setSessionId("");
|
|
61
|
+
};
|
|
58
62
|
if (!sessionId) {
|
|
59
63
|
if (mode === "standalone") {
|
|
60
64
|
return /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "center", spacing: 4, children: [
|
|
@@ -67,5 +71,5 @@ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }
|
|
|
67
71
|
}
|
|
68
72
|
return /* @__PURE__ */ jsx(PricingTable, { mode: "select", table: data, onSelect: handleSelect });
|
|
69
73
|
}
|
|
70
|
-
return /* @__PURE__ */ jsx(CheckoutForm, { id: sessionId, onPaid, onError, mode });
|
|
74
|
+
return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(CheckoutForm, { id: sessionId, onPaid, onError, mode, goBack }) });
|
|
71
75
|
}
|
|
@@ -106,6 +106,7 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
|
|
|
106
106
|
direction: "row",
|
|
107
107
|
gap: "calc(10px + 3%)",
|
|
108
108
|
justifyContent: alignItems === "center" ? "center" : "flex-start",
|
|
109
|
+
className: "price-table-wrap",
|
|
109
110
|
children: grouped[state.interval]?.map(
|
|
110
111
|
(x) => {
|
|
111
112
|
let action = x.subscription_data?.trial_period_days ? t("payment.checkout.try") : t("payment.checkout.subscription");
|
|
@@ -77,7 +77,7 @@ export default function CustomerInvoiceList({ customer_id }) {
|
|
|
77
77
|
))
|
|
78
78
|
] }, date)),
|
|
79
79
|
/* @__PURE__ */ jsxs(Box, { children: [
|
|
80
|
-
hasMore && /* @__PURE__ */ jsx(Button, { variant: "text", type: "button", color: "inherit", onClick: loadMore, disabled: loadingMore, children: loadingMore ? t("common.loadingMore", { resource: t("payment.customer.invoices") }) : t("common.loadMore", { resource: t("
|
|
80
|
+
hasMore && /* @__PURE__ */ jsx(Button, { variant: "text", type: "button", color: "inherit", onClick: loadMore, disabled: loadingMore, children: loadingMore ? t("common.loadingMore", { resource: t("payment.customer.invoices") }) : t("common.loadMore", { resource: t("payment.customer.invoices") }) }),
|
|
81
81
|
!hasMore && data.count > pageSize && /* @__PURE__ */ jsx(Typography, { color: "text.secondary", children: t("common.noMore", { resource: t("payment.customer.invoices") }) })
|
|
82
82
|
] })
|
|
83
83
|
] });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { TSubscriptionExpanded } from '@blocklet/payment-types';
|
|
3
|
+
type Props = {
|
|
4
|
+
subscription: TSubscriptionExpanded;
|
|
5
|
+
};
|
|
6
|
+
export default function MiniInvoiceList({ subscription }: Props): import("react").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
|
+
import { Box, Button, CircularProgress, Divider, List, ListItem, ListSubheader, Typography } from "@mui/material";
|
|
4
|
+
import { fromUnitToToken } from "@ocap/util";
|
|
5
|
+
import { useInfiniteScroll } from "ahooks";
|
|
6
|
+
import api from "../../api.js";
|
|
7
|
+
import Status from "../../components/status.js";
|
|
8
|
+
import {
|
|
9
|
+
formatSubscriptionProduct,
|
|
10
|
+
formatTime,
|
|
11
|
+
formatToDate,
|
|
12
|
+
getInvoiceStatusColor,
|
|
13
|
+
getSubscriptionStatusColor
|
|
14
|
+
} from "../../util.js";
|
|
15
|
+
const fetchData = (params = {}) => {
|
|
16
|
+
const search = new URLSearchParams();
|
|
17
|
+
Object.keys(params).forEach((key) => {
|
|
18
|
+
search.set(key, String(params[key]));
|
|
19
|
+
});
|
|
20
|
+
return api.get(`/api/invoices?${search.toString()}`).then((res) => res.data);
|
|
21
|
+
};
|
|
22
|
+
const pageSize = 10;
|
|
23
|
+
export default function MiniInvoiceList({ subscription }) {
|
|
24
|
+
const { t } = useLocaleContext();
|
|
25
|
+
const { data, loading } = useInfiniteScroll(
|
|
26
|
+
(d) => {
|
|
27
|
+
const page = d ? Math.ceil(d.list.length / pageSize) + 1 : 1;
|
|
28
|
+
return fetchData({ page, pageSize, status: "open,paid,uncollectible", subscription_id: subscription.id });
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
reloadDeps: [subscription.id]
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
if (loading || !data) {
|
|
35
|
+
return /* @__PURE__ */ jsx(Position, { children: /* @__PURE__ */ jsx(CircularProgress, {}) });
|
|
36
|
+
}
|
|
37
|
+
if (data && data.list.length === 0) {
|
|
38
|
+
return /* @__PURE__ */ jsx(Position, { children: /* @__PURE__ */ jsx(Typography, { color: "text.secondary", children: t("payment.customer.invoice.empty") }) });
|
|
39
|
+
}
|
|
40
|
+
const infoList = [
|
|
41
|
+
{
|
|
42
|
+
name: t("payment.customer.subscriptions.plan"),
|
|
43
|
+
value: /* @__PURE__ */ jsx(Typography, { fontWeight: 600, sx: { marginRight: "10px" }, children: formatSubscriptionProduct(subscription.items) })
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: t("payment.common.status"),
|
|
47
|
+
value: /* @__PURE__ */ jsx(Status, { label: subscription.status, color: getSubscriptionStatusColor(subscription.status) })
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: t("payment.customer.subscriptions.nextInvoice"),
|
|
51
|
+
value: /* @__PURE__ */ jsx(
|
|
52
|
+
Typography,
|
|
53
|
+
{
|
|
54
|
+
sx: {
|
|
55
|
+
color: "#34BE74",
|
|
56
|
+
fontWeight: "bold"
|
|
57
|
+
},
|
|
58
|
+
children: formatTime(subscription.current_period_end * 1e3)
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
return /* @__PURE__ */ jsxs(Position, { children: [
|
|
64
|
+
/* @__PURE__ */ jsx(Typography, { title: t("payment.checkout.subscription") }),
|
|
65
|
+
/* @__PURE__ */ jsxs(
|
|
66
|
+
Box,
|
|
67
|
+
{
|
|
68
|
+
sx: {
|
|
69
|
+
display: "flex",
|
|
70
|
+
flexDirection: "column",
|
|
71
|
+
alignItem: "center",
|
|
72
|
+
justifyContent: "flex-start",
|
|
73
|
+
padding: "16px",
|
|
74
|
+
width: "100%",
|
|
75
|
+
height: "100%"
|
|
76
|
+
},
|
|
77
|
+
children: [
|
|
78
|
+
/* @__PURE__ */ jsx(Typography, { component: "h3", sx: { textAlign: "center" }, variant: "h5", gutterBottom: true, children: t("payment.customer.subscriptions.current") }),
|
|
79
|
+
/* @__PURE__ */ jsx(Box, { sx: { marginTop: "12px" }, children: /* @__PURE__ */ jsx(List, { children: infoList.map(({ name, value }) => {
|
|
80
|
+
return /* @__PURE__ */ jsxs(ListItem, { disableGutters: true, sx: { display: "flex", justifyContent: "space-between" }, children: [
|
|
81
|
+
/* @__PURE__ */ jsx(Typography, { component: "span", children: name }),
|
|
82
|
+
/* @__PURE__ */ jsx(Typography, { component: "span", children: value })
|
|
83
|
+
] }, name);
|
|
84
|
+
}) }) }),
|
|
85
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
|
86
|
+
/* @__PURE__ */ jsx(Box, { sx: { marginTop: "12px" }, children: /* @__PURE__ */ jsxs(List, { sx: { overflow: "auto", maxHeight: { xs: "240px", md: "360px", padding: 0 } }, children: [
|
|
87
|
+
/* @__PURE__ */ jsx(ListSubheader, { disableGutters: true, sx: { padding: 0 }, children: /* @__PURE__ */ jsx(Typography, { component: "h2", variant: "h6", fontSize: "16px", children: t("payment.customer.invoices") }) }),
|
|
88
|
+
(data.list || []).map((item) => {
|
|
89
|
+
return /* @__PURE__ */ jsxs(ListItem, { disableGutters: true, sx: { display: "flex", justifyContent: "space-between" }, children: [
|
|
90
|
+
/* @__PURE__ */ jsx(Typography, { component: "span", children: formatToDate(item.created_at) }),
|
|
91
|
+
/* @__PURE__ */ jsxs(Typography, { component: "span", children: [
|
|
92
|
+
fromUnitToToken(item.total, item.paymentCurrency.decimal),
|
|
93
|
+
"\xA0",
|
|
94
|
+
item.paymentCurrency.symbol
|
|
95
|
+
] }),
|
|
96
|
+
/* @__PURE__ */ jsx(Status, { label: item.status, color: getInvoiceStatusColor(item.status) })
|
|
97
|
+
] }, item.id);
|
|
98
|
+
})
|
|
99
|
+
] }) }),
|
|
100
|
+
/* @__PURE__ */ jsx(Button, { target: "_top", variant: "contained", sx: { marginTop: "auto", width: "100%" }, href: "", children: t("payment.customer.subscriptions.title") })
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
] });
|
|
105
|
+
}
|
|
106
|
+
function Position({ children }) {
|
|
107
|
+
return /* @__PURE__ */ jsx(
|
|
108
|
+
Box,
|
|
109
|
+
{
|
|
110
|
+
className: "mini-invoice-box",
|
|
111
|
+
sx: {
|
|
112
|
+
position: "absolute",
|
|
113
|
+
right: 0,
|
|
114
|
+
top: "30px",
|
|
115
|
+
justifyContent: "center",
|
|
116
|
+
padding: "8px",
|
|
117
|
+
minWidth: "400px",
|
|
118
|
+
background: "#fff",
|
|
119
|
+
zIndex: 9,
|
|
120
|
+
boxShadow: "0 4px 8px rgba(0, 0, 0, 20%)"
|
|
121
|
+
},
|
|
122
|
+
children
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
}
|
package/es/index.d.ts
CHANGED
|
@@ -8,13 +8,14 @@ import PricingTable from './components/pricing-table';
|
|
|
8
8
|
import Status from './components/status';
|
|
9
9
|
import Switch from './components/switch-button';
|
|
10
10
|
import dayjs from './dayjs';
|
|
11
|
+
import CustomerInvoiceList from './histroy/invoice/list';
|
|
12
|
+
import MiniInvoiceList from './histroy/mini-invoice/list';
|
|
13
|
+
import CustomerPaymentList from './histroy/payment/list';
|
|
11
14
|
import Amount from './payment/amount';
|
|
12
15
|
import PhoneInput from './payment/form/phone';
|
|
13
16
|
import Payment from './payment/index';
|
|
14
17
|
import ProductSkeleton from './payment/product-skeleton';
|
|
15
|
-
import CustomerInvoiceList from './portal/invoice/list';
|
|
16
|
-
import CustomerPaymentList from './portal/payment/list';
|
|
17
18
|
export * from './util';
|
|
18
19
|
export * from './contexts/payment';
|
|
19
20
|
export { translations, createTranslator } from './locales';
|
|
20
|
-
export { api, dayjs, FormInput, PhoneInput, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, Payment, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, };
|
|
21
|
+
export { api, dayjs, FormInput, PhoneInput, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, Payment, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, MiniInvoiceList, };
|
package/es/index.js
CHANGED
|
@@ -8,12 +8,13 @@ import PricingTable from "./components/pricing-table.js";
|
|
|
8
8
|
import Status from "./components/status.js";
|
|
9
9
|
import Switch from "./components/switch-button.js";
|
|
10
10
|
import dayjs from "./dayjs.js";
|
|
11
|
+
import CustomerInvoiceList from "./histroy/invoice/list.js";
|
|
12
|
+
import MiniInvoiceList from "./histroy/mini-invoice/list.js";
|
|
13
|
+
import CustomerPaymentList from "./histroy/payment/list.js";
|
|
11
14
|
import Amount from "./payment/amount.js";
|
|
12
15
|
import PhoneInput from "./payment/form/phone.js";
|
|
13
16
|
import Payment from "./payment/index.js";
|
|
14
17
|
import ProductSkeleton from "./payment/product-skeleton.js";
|
|
15
|
-
import CustomerInvoiceList from "./portal/invoice/list.js";
|
|
16
|
-
import CustomerPaymentList from "./portal/payment/list.js";
|
|
17
18
|
export * from "./util.js";
|
|
18
19
|
export * from "./contexts/payment.js";
|
|
19
20
|
export { translations, createTranslator } from "./locales/index.js";
|
|
@@ -33,5 +34,6 @@ export {
|
|
|
33
34
|
ProductSkeleton,
|
|
34
35
|
Amount,
|
|
35
36
|
CustomerInvoiceList,
|
|
36
|
-
CustomerPaymentList
|
|
37
|
+
CustomerPaymentList,
|
|
38
|
+
MiniInvoiceList
|
|
37
39
|
};
|
package/es/locales/en.js
CHANGED
|
@@ -208,6 +208,8 @@ export default flat({
|
|
|
208
208
|
empty: "Seems you do not have any payment here"
|
|
209
209
|
},
|
|
210
210
|
subscriptions: {
|
|
211
|
+
plan: "Plan",
|
|
212
|
+
nextInvoice: "Next Invoice",
|
|
211
213
|
title: "Manage subscriptions",
|
|
212
214
|
current: "Current subscriptions",
|
|
213
215
|
empty: "Seems you do not have any subscriptions here"
|
package/es/locales/zh.js
CHANGED
|
@@ -208,6 +208,8 @@ export default flat({
|
|
|
208
208
|
empty: "\u4F60\u6CA1\u6709\u4EFB\u4F55\u652F\u4ED8"
|
|
209
209
|
},
|
|
210
210
|
subscriptions: {
|
|
211
|
+
plan: "\u8BA2\u9605",
|
|
212
|
+
nextInvoice: "\u4E0B\u4E00\u5F20\u53D1\u7968",
|
|
211
213
|
title: "\u8BA2\u9605\u7BA1\u7406",
|
|
212
214
|
current: "\u5F53\u524D\u8BA2\u9605",
|
|
213
215
|
empty: "\u4F60\u8FD8\u6CA1\u6709\u4EFB\u4F55\u8BA2\u9605"
|
package/es/payment/form/index.js
CHANGED
|
@@ -209,6 +209,7 @@ export default function PaymentForm({
|
|
|
209
209
|
handleSubmit(onSubmit)();
|
|
210
210
|
} else {
|
|
211
211
|
session?.login({
|
|
212
|
+
// @ts-ignored
|
|
212
213
|
onSuccess: onUserLoggedIn,
|
|
213
214
|
extraParams: {}
|
|
214
215
|
});
|
|
@@ -306,7 +307,7 @@ export default function PaymentForm({
|
|
|
306
307
|
children: /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", children: [
|
|
307
308
|
/* @__PURE__ */ jsx(Avatar, { src: x.logo, alt: x.name, sx: { width: 30, height: 30, marginRight: "10px" } }),
|
|
308
309
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
309
|
-
/* @__PURE__ */ jsx(Typography, { variant: "h5", component: "div", children: x.symbol }),
|
|
310
|
+
/* @__PURE__ */ jsx(Typography, { variant: "h5", component: "div", sx: { fontSize: "18px" }, children: x.symbol }),
|
|
310
311
|
/* @__PURE__ */ jsx(Typography, { sx: { fontSize: 14 }, color: "text.secondary", gutterBottom: true, children: x.method.name })
|
|
311
312
|
] })
|
|
312
313
|
] })
|
package/es/payment/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ type Props = CheckoutContext & CheckoutCallbacks & {
|
|
|
5
5
|
completed?: boolean;
|
|
6
6
|
error?: any;
|
|
7
7
|
};
|
|
8
|
-
declare function Payment({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, completed, error, mode, onPaid, onError, }: Props): import("react").JSX.Element;
|
|
8
|
+
declare function Payment({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, completed, error, mode, onPaid, onError, goBack, }: Props): import("react").JSX.Element;
|
|
9
9
|
declare namespace Payment {
|
|
10
10
|
var defaultProps: {
|
|
11
11
|
completed: boolean;
|
|
@@ -16,7 +16,7 @@ export default Payment;
|
|
|
16
16
|
type MainProps = CheckoutContext & CheckoutCallbacks & {
|
|
17
17
|
completed?: boolean;
|
|
18
18
|
};
|
|
19
|
-
export declare function PaymentInner({ checkoutSession, paymentMethods, paymentLink, paymentIntent, customer, completed, mode, onPaid, onError, }: MainProps): import("react").JSX.Element;
|
|
19
|
+
export declare function PaymentInner({ checkoutSession, paymentMethods, paymentLink, paymentIntent, customer, completed, mode, onPaid, onError, goBack, }: MainProps): import("react").JSX.Element;
|
|
20
20
|
export declare namespace PaymentInner {
|
|
21
21
|
var defaultProps: {
|
|
22
22
|
completed: boolean;
|
package/es/payment/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
3
|
import Toast from "@arcblock/ux/lib/Toast";
|
|
4
|
+
import { ArrowBackOutlined } from "@mui/icons-material";
|
|
4
5
|
import { Box, Fade, Stack } from "@mui/material";
|
|
5
6
|
import { styled } from "@mui/system";
|
|
6
7
|
import { useSetState } from "ahooks";
|
|
7
|
-
import { useEffect } from "react";
|
|
8
|
+
import { useEffect, useState } from "react";
|
|
8
9
|
import { FormProvider, useForm } from "react-hook-form";
|
|
9
10
|
import api from "../api.js";
|
|
10
11
|
import { usePaymentContext } from "../contexts/payment.js";
|
|
@@ -31,10 +32,17 @@ export default function Payment({
|
|
|
31
32
|
error,
|
|
32
33
|
mode,
|
|
33
34
|
onPaid,
|
|
34
|
-
onError
|
|
35
|
+
onError,
|
|
36
|
+
goBack
|
|
35
37
|
}) {
|
|
36
38
|
const { t } = useLocaleContext();
|
|
37
39
|
const { refresh, livemode, setLivemode } = usePaymentContext();
|
|
40
|
+
const [delay, setDelay] = useState(false);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
setDelay(true);
|
|
44
|
+
}, 500);
|
|
45
|
+
}, []);
|
|
38
46
|
useEffect(() => {
|
|
39
47
|
if (checkoutSession) {
|
|
40
48
|
if (livemode !== checkoutSession.livemode) {
|
|
@@ -48,7 +56,7 @@ export default function Payment({
|
|
|
48
56
|
if (error) {
|
|
49
57
|
return /* @__PURE__ */ jsx(PaymentError, { title: "Oops", description: formatError(error) });
|
|
50
58
|
}
|
|
51
|
-
if (!checkoutSession) {
|
|
59
|
+
if (!checkoutSession || !delay) {
|
|
52
60
|
return /* @__PURE__ */ jsx(Root, { mode, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-container", children: [
|
|
53
61
|
/* @__PURE__ */ jsx(Stack, { className: "cko-overview", children: /* @__PURE__ */ jsx(OverviewSkeleton, {}) }),
|
|
54
62
|
/* @__PURE__ */ jsx(Stack, { className: "cko-payment", children: /* @__PURE__ */ jsx(PaymentSkeleton, {}) }),
|
|
@@ -84,6 +92,7 @@ export default function Payment({
|
|
|
84
92
|
customer,
|
|
85
93
|
onPaid,
|
|
86
94
|
onError,
|
|
95
|
+
goBack,
|
|
87
96
|
mode
|
|
88
97
|
}
|
|
89
98
|
);
|
|
@@ -100,7 +109,8 @@ export function PaymentInner({
|
|
|
100
109
|
completed,
|
|
101
110
|
mode,
|
|
102
111
|
onPaid,
|
|
103
|
-
onError
|
|
112
|
+
onError,
|
|
113
|
+
goBack
|
|
104
114
|
}) {
|
|
105
115
|
const { t } = useLocaleContext();
|
|
106
116
|
const { settings, session } = usePaymentContext();
|
|
@@ -166,45 +176,55 @@ export function PaymentInner({
|
|
|
166
176
|
Toast.error(formatError(err));
|
|
167
177
|
}
|
|
168
178
|
};
|
|
169
|
-
return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
),
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
179
|
+
return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsxs(Root, { mode, children: [
|
|
180
|
+
mode !== "standalone" ? /* @__PURE__ */ jsx(
|
|
181
|
+
ArrowBackOutlined,
|
|
182
|
+
{
|
|
183
|
+
sx: { mr: 0.5, color: "text.secondary", alignSelf: "flex-start", margin: "16px 0", cursor: "pointer" },
|
|
184
|
+
onClick: goBack,
|
|
185
|
+
fontSize: "medium"
|
|
186
|
+
}
|
|
187
|
+
) : null,
|
|
188
|
+
/* @__PURE__ */ jsxs(Stack, { className: "cko-container", sx: { gap: { sm: mode === "standalone" ? 0 : 8 } }, children: [
|
|
189
|
+
/* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-overview", direction: "column", children: [
|
|
190
|
+
mode === "standalone" ? /* @__PURE__ */ jsx(PaymentHeader, { checkoutSession: state.checkoutSession }) : null,
|
|
191
|
+
/* @__PURE__ */ jsx(
|
|
192
|
+
PaymentSummary,
|
|
193
|
+
{
|
|
194
|
+
checkoutSession: state.checkoutSession,
|
|
195
|
+
currency,
|
|
196
|
+
onUpsell,
|
|
197
|
+
onDownsell,
|
|
198
|
+
onApplyCrossSell,
|
|
199
|
+
onCancelCrossSell
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
] }) }),
|
|
203
|
+
/* @__PURE__ */ jsxs(Stack, { className: "cko-payment", direction: "column", spacing: 4, children: [
|
|
204
|
+
completed && /* @__PURE__ */ jsx(
|
|
205
|
+
PaymentSuccess,
|
|
206
|
+
{
|
|
207
|
+
payee: getStatementDescriptor(state.checkoutSession.line_items),
|
|
208
|
+
action: state.checkoutSession.mode,
|
|
209
|
+
message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t(`payment.checkout.completed.${state.checkoutSession.mode}`)
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
!completed && /* @__PURE__ */ jsx(
|
|
213
|
+
PaymentForm,
|
|
214
|
+
{
|
|
215
|
+
checkoutSession: state.checkoutSession,
|
|
216
|
+
paymentMethods,
|
|
217
|
+
paymentIntent,
|
|
218
|
+
customer,
|
|
219
|
+
onPaid,
|
|
220
|
+
onError,
|
|
221
|
+
mode
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
] }),
|
|
225
|
+
mode === "standalone" && /* @__PURE__ */ jsx(CheckoutFooter, { className: "cko-footer" })
|
|
226
|
+
] })
|
|
227
|
+
] }) });
|
|
208
228
|
}
|
|
209
229
|
export const Root = styled(Box)`
|
|
210
230
|
box-sizing: border-box;
|
|
@@ -312,11 +332,11 @@ export const Root = styled(Box)`
|
|
|
312
332
|
}
|
|
313
333
|
|
|
314
334
|
.cko-payment-card:nth-child(odd) {
|
|
315
|
-
margin-right:
|
|
335
|
+
margin-right: 8px;
|
|
316
336
|
}
|
|
317
337
|
|
|
318
338
|
.cko-payment-card-unselect:nth-child(odd) {
|
|
319
|
-
margin-right:
|
|
339
|
+
margin-right: 8px;
|
|
320
340
|
}
|
|
321
341
|
|
|
322
342
|
.cko-payment-card::after {
|
package/es/types/index.d.ts
CHANGED
package/es/util.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { PriceCurrency, PriceRecurring, TCheckoutSessionExpanded, TLineItemExpanded, TPaymentCurrency, TPaymentMethodExpanded, TPrice, TSubscriptionExpanded } from '@blocklet/payment-types';
|
|
2
|
+
import type { PriceCurrency, PriceRecurring, TCheckoutSessionExpanded, TLineItemExpanded, TPaymentCurrency, TPaymentMethodExpanded, TPrice, TSubscriptionExpanded, TSubscriptionItemExpanded } from '@blocklet/payment-types';
|
|
3
3
|
export declare const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
|
|
4
4
|
export declare const getPrefix: () => any;
|
|
5
5
|
export declare function formatToDate(date: Date | string | number, locale?: string): any;
|
|
@@ -47,6 +47,7 @@ export declare function findCurrency(methods: TPaymentMethodExpanded[], currency
|
|
|
47
47
|
export declare function isValidCountry(code: string): boolean;
|
|
48
48
|
export declare function stopEvent(e: React.SyntheticEvent<any>): void;
|
|
49
49
|
export declare function sleep(ms: number): Promise<unknown>;
|
|
50
|
+
export declare function formatSubscriptionProduct(items: TSubscriptionItemExpanded[], maxLength?: number): string;
|
|
50
51
|
export declare const getSubscriptionTimeSummary: (subscription: TSubscriptionExpanded) => string;
|
|
51
52
|
export declare const getSubscriptionAction: (subscription: TSubscriptionExpanded) => {
|
|
52
53
|
action: string;
|
package/es/util.js
CHANGED
|
@@ -402,6 +402,10 @@ export function sleep(ms) {
|
|
|
402
402
|
setTimeout(resolve, ms);
|
|
403
403
|
});
|
|
404
404
|
}
|
|
405
|
+
export function formatSubscriptionProduct(items, maxLength = 2) {
|
|
406
|
+
const names = items.map((x) => x.price.product?.name).filter(Boolean);
|
|
407
|
+
return names.slice(0, maxLength).join(", ") + (names.length > maxLength ? ` and ${names.length - maxLength} more` : "");
|
|
408
|
+
}
|
|
405
409
|
export const getSubscriptionTimeSummary = (subscription) => {
|
|
406
410
|
const lines = [`Started on ${formatToDate(subscription.start_date * 1e3)}`];
|
|
407
411
|
if (subscription.status === "active" || subscription.status === "trialing") {
|
package/lib/checkout/form.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CheckoutProps } from '../types';
|
|
3
|
-
declare function CheckoutForm({ id, onPaid, onError, mode, extraParams }: CheckoutProps): import("react").JSX.Element;
|
|
3
|
+
declare function CheckoutForm({ id, onPaid, onError, mode, goBack, extraParams }: CheckoutProps): import("react").JSX.Element;
|
|
4
4
|
declare namespace CheckoutForm {
|
|
5
5
|
var defaultProps: {
|
|
6
6
|
onPaid: any;
|
package/lib/checkout/form.js
CHANGED
|
@@ -30,6 +30,7 @@ function CheckoutForm({
|
|
|
30
30
|
onPaid,
|
|
31
31
|
onError,
|
|
32
32
|
mode,
|
|
33
|
+
goBack,
|
|
33
34
|
extraParams
|
|
34
35
|
}) {
|
|
35
36
|
if (!id.startsWith("plink_") && !id.startsWith("cs_")) {
|
|
@@ -72,6 +73,7 @@ function CheckoutForm({
|
|
|
72
73
|
error: apiError || state.appError,
|
|
73
74
|
onPaid: handlePaid,
|
|
74
75
|
onError: handleError,
|
|
76
|
+
goBack,
|
|
75
77
|
mode
|
|
76
78
|
});
|
|
77
79
|
}
|
package/lib/checkout/table.js
CHANGED
|
@@ -8,6 +8,7 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
8
8
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
9
|
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
10
10
|
var _material = require("@mui/material");
|
|
11
|
+
var _system = require("@mui/system");
|
|
11
12
|
var _ahooks = require("ahooks");
|
|
12
13
|
var _react = require("react");
|
|
13
14
|
var _api = _interopRequireDefault(require("../api"));
|
|
@@ -85,6 +86,9 @@ function CheckoutTable({
|
|
|
85
86
|
_Toast.default.error(err.message);
|
|
86
87
|
});
|
|
87
88
|
};
|
|
89
|
+
const goBack = () => {
|
|
90
|
+
setSessionId("");
|
|
91
|
+
};
|
|
88
92
|
if (!sessionId) {
|
|
89
93
|
if (mode === "standalone") {
|
|
90
94
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
@@ -108,10 +112,13 @@ function CheckoutTable({
|
|
|
108
112
|
onSelect: handleSelect
|
|
109
113
|
});
|
|
110
114
|
}
|
|
111
|
-
return /* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_system.Box, {
|
|
116
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_form.default, {
|
|
117
|
+
id: sessionId,
|
|
118
|
+
onPaid,
|
|
119
|
+
onError,
|
|
120
|
+
mode,
|
|
121
|
+
goBack
|
|
122
|
+
})
|
|
116
123
|
});
|
|
117
124
|
}
|
|
@@ -125,6 +125,7 @@ function PricingTable({
|
|
|
125
125
|
direction: "row",
|
|
126
126
|
gap: "calc(10px + 3%)",
|
|
127
127
|
justifyContent: alignItems === "center" ? "center" : "flex-start",
|
|
128
|
+
className: "price-table-wrap",
|
|
128
129
|
children: grouped[state.interval]?.map(x => {
|
|
129
130
|
let action = x.subscription_data?.trial_period_days ? t("payment.checkout.try") : t("payment.checkout.subscription");
|
|
130
131
|
if (mode === "select") {
|
|
@@ -137,7 +137,7 @@ function CustomerInvoiceList({
|
|
|
137
137
|
children: loadingMore ? t("common.loadingMore", {
|
|
138
138
|
resource: t("payment.customer.invoices")
|
|
139
139
|
}) : t("common.loadMore", {
|
|
140
|
-
resource: t("
|
|
140
|
+
resource: t("payment.customer.invoices")
|
|
141
141
|
})
|
|
142
142
|
}), !hasMore && data.count > pageSize && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
143
143
|
color: "text.secondary",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { TSubscriptionExpanded } from '@blocklet/payment-types';
|
|
3
|
+
type Props = {
|
|
4
|
+
subscription: TSubscriptionExpanded;
|
|
5
|
+
};
|
|
6
|
+
export default function MiniInvoiceList({ subscription }: Props): import("react").JSX.Element;
|
|
7
|
+
export {};
|