@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
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = MiniInvoiceList;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
|
+
var _material = require("@mui/material");
|
|
10
|
+
var _util = require("@ocap/util");
|
|
11
|
+
var _ahooks = require("ahooks");
|
|
12
|
+
var _api = _interopRequireDefault(require("../../api"));
|
|
13
|
+
var _status = _interopRequireDefault(require("../../components/status"));
|
|
14
|
+
var _util2 = require("../../util");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
const fetchData = (params = {}) => {
|
|
17
|
+
const search = new URLSearchParams();
|
|
18
|
+
Object.keys(params).forEach(key => {
|
|
19
|
+
search.set(key, String(params[key]));
|
|
20
|
+
});
|
|
21
|
+
return _api.default.get(`/api/invoices?${search.toString()}`).then(res => res.data);
|
|
22
|
+
};
|
|
23
|
+
const pageSize = 10;
|
|
24
|
+
function MiniInvoiceList({
|
|
25
|
+
subscription
|
|
26
|
+
}) {
|
|
27
|
+
const {
|
|
28
|
+
t
|
|
29
|
+
} = (0, _context.useLocaleContext)();
|
|
30
|
+
const {
|
|
31
|
+
data,
|
|
32
|
+
loading
|
|
33
|
+
} = (0, _ahooks.useInfiniteScroll)(d => {
|
|
34
|
+
const page = d ? Math.ceil(d.list.length / pageSize) + 1 : 1;
|
|
35
|
+
return fetchData({
|
|
36
|
+
page,
|
|
37
|
+
pageSize,
|
|
38
|
+
status: "open,paid,uncollectible",
|
|
39
|
+
subscription_id: subscription.id
|
|
40
|
+
});
|
|
41
|
+
}, {
|
|
42
|
+
reloadDeps: [subscription.id]
|
|
43
|
+
});
|
|
44
|
+
if (loading || !data) {
|
|
45
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(Position, {
|
|
46
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {})
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (data && data.list.length === 0) {
|
|
50
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(Position, {
|
|
51
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
52
|
+
color: "text.secondary",
|
|
53
|
+
children: t("payment.customer.invoice.empty")
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const infoList = [{
|
|
58
|
+
name: t("payment.customer.subscriptions.plan"),
|
|
59
|
+
value: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
60
|
+
fontWeight: 600,
|
|
61
|
+
sx: {
|
|
62
|
+
marginRight: "10px"
|
|
63
|
+
},
|
|
64
|
+
children: (0, _util2.formatSubscriptionProduct)(subscription.items)
|
|
65
|
+
})
|
|
66
|
+
}, {
|
|
67
|
+
name: t("payment.common.status"),
|
|
68
|
+
value: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
|
|
69
|
+
label: subscription.status,
|
|
70
|
+
color: (0, _util2.getSubscriptionStatusColor)(subscription.status)
|
|
71
|
+
})
|
|
72
|
+
}, {
|
|
73
|
+
name: t("payment.customer.subscriptions.nextInvoice"),
|
|
74
|
+
value: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
75
|
+
sx: {
|
|
76
|
+
color: "#34BE74",
|
|
77
|
+
fontWeight: "bold"
|
|
78
|
+
},
|
|
79
|
+
children: (0, _util2.formatTime)(subscription.current_period_end * 1e3)
|
|
80
|
+
})
|
|
81
|
+
}];
|
|
82
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(Position, {
|
|
83
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
84
|
+
title: t("payment.checkout.subscription")
|
|
85
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
86
|
+
sx: {
|
|
87
|
+
display: "flex",
|
|
88
|
+
flexDirection: "column",
|
|
89
|
+
alignItem: "center",
|
|
90
|
+
justifyContent: "flex-start",
|
|
91
|
+
padding: "16px",
|
|
92
|
+
width: "100%",
|
|
93
|
+
height: "100%"
|
|
94
|
+
},
|
|
95
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
96
|
+
component: "h3",
|
|
97
|
+
sx: {
|
|
98
|
+
textAlign: "center"
|
|
99
|
+
},
|
|
100
|
+
variant: "h5",
|
|
101
|
+
gutterBottom: true,
|
|
102
|
+
children: t("payment.customer.subscriptions.current")
|
|
103
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
104
|
+
sx: {
|
|
105
|
+
marginTop: "12px"
|
|
106
|
+
},
|
|
107
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.List, {
|
|
108
|
+
children: infoList.map(({
|
|
109
|
+
name,
|
|
110
|
+
value
|
|
111
|
+
}) => {
|
|
112
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.ListItem, {
|
|
113
|
+
disableGutters: true,
|
|
114
|
+
sx: {
|
|
115
|
+
display: "flex",
|
|
116
|
+
justifyContent: "space-between"
|
|
117
|
+
},
|
|
118
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
119
|
+
component: "span",
|
|
120
|
+
children: name
|
|
121
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
122
|
+
component: "span",
|
|
123
|
+
children: value
|
|
124
|
+
})]
|
|
125
|
+
}, name);
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Divider, {}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
129
|
+
sx: {
|
|
130
|
+
marginTop: "12px"
|
|
131
|
+
},
|
|
132
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.List, {
|
|
133
|
+
sx: {
|
|
134
|
+
overflow: "auto",
|
|
135
|
+
maxHeight: {
|
|
136
|
+
xs: "240px",
|
|
137
|
+
md: "360px",
|
|
138
|
+
padding: 0
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.ListSubheader, {
|
|
142
|
+
disableGutters: true,
|
|
143
|
+
sx: {
|
|
144
|
+
padding: 0
|
|
145
|
+
},
|
|
146
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
147
|
+
component: "h2",
|
|
148
|
+
variant: "h6",
|
|
149
|
+
fontSize: "16px",
|
|
150
|
+
children: t("payment.customer.invoices")
|
|
151
|
+
})
|
|
152
|
+
}), (data.list || []).map(item => {
|
|
153
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.ListItem, {
|
|
154
|
+
disableGutters: true,
|
|
155
|
+
sx: {
|
|
156
|
+
display: "flex",
|
|
157
|
+
justifyContent: "space-between"
|
|
158
|
+
},
|
|
159
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
160
|
+
component: "span",
|
|
161
|
+
children: (0, _util2.formatToDate)(item.created_at)
|
|
162
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
163
|
+
component: "span",
|
|
164
|
+
children: [(0, _util.fromUnitToToken)(item.total, item.paymentCurrency.decimal), "\xA0", item.paymentCurrency.symbol]
|
|
165
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
|
|
166
|
+
label: item.status,
|
|
167
|
+
color: (0, _util2.getInvoiceStatusColor)(item.status)
|
|
168
|
+
})]
|
|
169
|
+
}, item.id);
|
|
170
|
+
})]
|
|
171
|
+
})
|
|
172
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
173
|
+
target: "_top",
|
|
174
|
+
variant: "contained",
|
|
175
|
+
sx: {
|
|
176
|
+
marginTop: "auto",
|
|
177
|
+
width: "100%"
|
|
178
|
+
},
|
|
179
|
+
href: "",
|
|
180
|
+
children: t("payment.customer.subscriptions.title")
|
|
181
|
+
})]
|
|
182
|
+
})]
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
function Position({
|
|
186
|
+
children
|
|
187
|
+
}) {
|
|
188
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
189
|
+
className: "mini-invoice-box",
|
|
190
|
+
sx: {
|
|
191
|
+
position: "absolute",
|
|
192
|
+
right: 0,
|
|
193
|
+
top: "30px",
|
|
194
|
+
justifyContent: "center",
|
|
195
|
+
padding: "8px",
|
|
196
|
+
minWidth: "400px",
|
|
197
|
+
background: "#fff",
|
|
198
|
+
zIndex: 9,
|
|
199
|
+
boxShadow: "0 4px 8px rgba(0, 0, 0, 20%)"
|
|
200
|
+
},
|
|
201
|
+
children
|
|
202
|
+
});
|
|
203
|
+
}
|
package/lib/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/lib/index.js
CHANGED
|
@@ -14,12 +14,13 @@ var _exportNames = {
|
|
|
14
14
|
Status: true,
|
|
15
15
|
Switch: true,
|
|
16
16
|
dayjs: true,
|
|
17
|
+
CustomerInvoiceList: true,
|
|
18
|
+
MiniInvoiceList: true,
|
|
19
|
+
CustomerPaymentList: true,
|
|
17
20
|
Amount: true,
|
|
18
21
|
PhoneInput: true,
|
|
19
22
|
Payment: true,
|
|
20
23
|
ProductSkeleton: true,
|
|
21
|
-
CustomerInvoiceList: true,
|
|
22
|
-
CustomerPaymentList: true,
|
|
23
24
|
translations: true,
|
|
24
25
|
createTranslator: true
|
|
25
26
|
};
|
|
@@ -56,7 +57,7 @@ Object.defineProperty(exports, "CustomerInvoiceList", {
|
|
|
56
57
|
Object.defineProperty(exports, "CustomerPaymentList", {
|
|
57
58
|
enumerable: true,
|
|
58
59
|
get: function () {
|
|
59
|
-
return
|
|
60
|
+
return _list3.default;
|
|
60
61
|
}
|
|
61
62
|
});
|
|
62
63
|
Object.defineProperty(exports, "FormInput", {
|
|
@@ -71,6 +72,12 @@ Object.defineProperty(exports, "Livemode", {
|
|
|
71
72
|
return _livemode.default;
|
|
72
73
|
}
|
|
73
74
|
});
|
|
75
|
+
Object.defineProperty(exports, "MiniInvoiceList", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () {
|
|
78
|
+
return _list2.default;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
74
81
|
Object.defineProperty(exports, "Payment", {
|
|
75
82
|
enumerable: true,
|
|
76
83
|
get: function () {
|
|
@@ -141,12 +148,13 @@ var _pricingTable = _interopRequireDefault(require("./components/pricing-table")
|
|
|
141
148
|
var _status = _interopRequireDefault(require("./components/status"));
|
|
142
149
|
var _switchButton = _interopRequireDefault(require("./components/switch-button"));
|
|
143
150
|
var _dayjs = _interopRequireDefault(require("./dayjs"));
|
|
151
|
+
var _list = _interopRequireDefault(require("./histroy/invoice/list"));
|
|
152
|
+
var _list2 = _interopRequireDefault(require("./histroy/mini-invoice/list"));
|
|
153
|
+
var _list3 = _interopRequireDefault(require("./histroy/payment/list"));
|
|
144
154
|
var _amount = _interopRequireDefault(require("./payment/amount"));
|
|
145
155
|
var _phone = _interopRequireDefault(require("./payment/form/phone"));
|
|
146
156
|
var _index = _interopRequireDefault(require("./payment/index"));
|
|
147
157
|
var _productSkeleton = _interopRequireDefault(require("./payment/product-skeleton"));
|
|
148
|
-
var _list = _interopRequireDefault(require("./portal/invoice/list"));
|
|
149
|
-
var _list2 = _interopRequireDefault(require("./portal/payment/list"));
|
|
150
158
|
var _util = require("./util");
|
|
151
159
|
Object.keys(_util).forEach(function (key) {
|
|
152
160
|
if (key === "default" || key === "__esModule") return;
|
package/lib/locales/en.js
CHANGED
|
@@ -215,6 +215,8 @@ module.exports = (0, _flat.default)({
|
|
|
215
215
|
empty: "Seems you do not have any payment here"
|
|
216
216
|
},
|
|
217
217
|
subscriptions: {
|
|
218
|
+
plan: "Plan",
|
|
219
|
+
nextInvoice: "Next Invoice",
|
|
218
220
|
title: "Manage subscriptions",
|
|
219
221
|
current: "Current subscriptions",
|
|
220
222
|
empty: "Seems you do not have any subscriptions here"
|
package/lib/locales/zh.js
CHANGED
|
@@ -215,6 +215,8 @@ module.exports = (0, _flat.default)({
|
|
|
215
215
|
empty: "\u4F60\u6CA1\u6709\u4EFB\u4F55\u652F\u4ED8"
|
|
216
216
|
},
|
|
217
217
|
subscriptions: {
|
|
218
|
+
plan: "\u8BA2\u9605",
|
|
219
|
+
nextInvoice: "\u4E0B\u4E00\u5F20\u53D1\u7968",
|
|
218
220
|
title: "\u8BA2\u9605\u7BA1\u7406",
|
|
219
221
|
current: "\u5F53\u524D\u8BA2\u9605",
|
|
220
222
|
empty: "\u4F60\u8FD8\u6CA1\u6709\u4EFB\u4F55\u8BA2\u9605"
|
|
@@ -258,6 +258,7 @@ function PaymentForm({
|
|
|
258
258
|
handleSubmit(onSubmit)();
|
|
259
259
|
} else {
|
|
260
260
|
session?.login({
|
|
261
|
+
// @ts-ignored
|
|
261
262
|
onSuccess: onUserLoggedIn,
|
|
262
263
|
extraParams: {}
|
|
263
264
|
});
|
|
@@ -395,6 +396,9 @@ function PaymentForm({
|
|
|
395
396
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
396
397
|
variant: "h5",
|
|
397
398
|
component: "div",
|
|
399
|
+
sx: {
|
|
400
|
+
fontSize: "18px"
|
|
401
|
+
},
|
|
398
402
|
children: x.symbol
|
|
399
403
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
400
404
|
sx: {
|
package/lib/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/lib/payment/index.js
CHANGED
|
@@ -9,6 +9,7 @@ module.exports = Payment;
|
|
|
9
9
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
10
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
11
11
|
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
12
|
+
var _iconsMaterial = require("@mui/icons-material");
|
|
12
13
|
var _material = require("@mui/material");
|
|
13
14
|
var _system = require("@mui/system");
|
|
14
15
|
var _ahooks = require("ahooks");
|
|
@@ -40,7 +41,8 @@ function Payment({
|
|
|
40
41
|
error,
|
|
41
42
|
mode,
|
|
42
43
|
onPaid,
|
|
43
|
-
onError
|
|
44
|
+
onError,
|
|
45
|
+
goBack
|
|
44
46
|
}) {
|
|
45
47
|
const {
|
|
46
48
|
t
|
|
@@ -50,6 +52,12 @@ function Payment({
|
|
|
50
52
|
livemode,
|
|
51
53
|
setLivemode
|
|
52
54
|
} = (0, _payment.usePaymentContext)();
|
|
55
|
+
const [delay, setDelay] = (0, _react.useState)(false);
|
|
56
|
+
(0, _react.useEffect)(() => {
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
setDelay(true);
|
|
59
|
+
}, 500);
|
|
60
|
+
}, []);
|
|
53
61
|
(0, _react.useEffect)(() => {
|
|
54
62
|
if (checkoutSession) {
|
|
55
63
|
if (livemode !== checkoutSession.livemode) {
|
|
@@ -66,7 +74,7 @@ function Payment({
|
|
|
66
74
|
description: (0, _util.formatError)(error)
|
|
67
75
|
});
|
|
68
76
|
}
|
|
69
|
-
if (!checkoutSession) {
|
|
77
|
+
if (!checkoutSession || !delay) {
|
|
70
78
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(Root, {
|
|
71
79
|
mode,
|
|
72
80
|
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
@@ -104,6 +112,7 @@ function Payment({
|
|
|
104
112
|
customer,
|
|
105
113
|
onPaid,
|
|
106
114
|
onError,
|
|
115
|
+
goBack,
|
|
107
116
|
mode
|
|
108
117
|
});
|
|
109
118
|
}
|
|
@@ -119,7 +128,8 @@ function PaymentInner({
|
|
|
119
128
|
completed,
|
|
120
129
|
mode,
|
|
121
130
|
onPaid,
|
|
122
|
-
onError
|
|
131
|
+
onError,
|
|
132
|
+
goBack
|
|
123
133
|
}) {
|
|
124
134
|
const {
|
|
125
135
|
t
|
|
@@ -215,9 +225,19 @@ function PaymentInner({
|
|
|
215
225
|
};
|
|
216
226
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactHookForm.FormProvider, {
|
|
217
227
|
...methods,
|
|
218
|
-
children: /* @__PURE__ */(0, _jsxRuntime.
|
|
228
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(Root, {
|
|
219
229
|
mode,
|
|
220
|
-
children: /* @__PURE__ */(0, _jsxRuntime.
|
|
230
|
+
children: [mode !== "standalone" ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.ArrowBackOutlined, {
|
|
231
|
+
sx: {
|
|
232
|
+
mr: 0.5,
|
|
233
|
+
color: "text.secondary",
|
|
234
|
+
alignSelf: "flex-start",
|
|
235
|
+
margin: "16px 0",
|
|
236
|
+
cursor: "pointer"
|
|
237
|
+
},
|
|
238
|
+
onClick: goBack,
|
|
239
|
+
fontSize: "medium"
|
|
240
|
+
}) : null, /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
221
241
|
className: "cko-container",
|
|
222
242
|
sx: {
|
|
223
243
|
gap: {
|
|
@@ -260,7 +280,7 @@ function PaymentInner({
|
|
|
260
280
|
}), mode === "standalone" && /* @__PURE__ */(0, _jsxRuntime.jsx)(_footer.default, {
|
|
261
281
|
className: "cko-footer"
|
|
262
282
|
})]
|
|
263
|
-
})
|
|
283
|
+
})]
|
|
264
284
|
})
|
|
265
285
|
});
|
|
266
286
|
}
|
|
@@ -370,11 +390,11 @@ const Root = exports.Root = (0, _system.styled)(_material.Box)`
|
|
|
370
390
|
}
|
|
371
391
|
|
|
372
392
|
.cko-payment-card:nth-child(odd) {
|
|
373
|
-
margin-right:
|
|
393
|
+
margin-right: 8px;
|
|
374
394
|
}
|
|
375
395
|
|
|
376
396
|
.cko-payment-card-unselect:nth-child(odd) {
|
|
377
|
-
margin-right:
|
|
397
|
+
margin-right: 8px;
|
|
378
398
|
}
|
|
379
399
|
|
|
380
400
|
.cko-payment-card::after {
|
package/lib/types/index.d.ts
CHANGED
package/lib/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/lib/util.js
CHANGED
|
@@ -12,6 +12,7 @@ exports.formatError = void 0;
|
|
|
12
12
|
exports.formatLineItemPricing = formatLineItemPricing;
|
|
13
13
|
exports.formatPriceAmount = exports.formatPrice = exports.formatPrettyMsLocale = exports.formatLocale = void 0;
|
|
14
14
|
exports.formatRecurring = formatRecurring;
|
|
15
|
+
exports.formatSubscriptionProduct = formatSubscriptionProduct;
|
|
15
16
|
exports.formatTime = formatTime;
|
|
16
17
|
exports.formatToDate = formatToDate;
|
|
17
18
|
exports.formatToDatetime = formatToDatetime;
|
|
@@ -485,6 +486,10 @@ function sleep(ms) {
|
|
|
485
486
|
setTimeout(resolve, ms);
|
|
486
487
|
});
|
|
487
488
|
}
|
|
489
|
+
function formatSubscriptionProduct(items, maxLength = 2) {
|
|
490
|
+
const names = items.map(x => x.price.product?.name).filter(Boolean);
|
|
491
|
+
return names.slice(0, maxLength).join(", ") + (names.length > maxLength ? ` and ${names.length - maxLength} more` : "");
|
|
492
|
+
}
|
|
488
493
|
const getSubscriptionTimeSummary = subscription => {
|
|
489
494
|
const lines = [`Started on ${formatToDate(subscription.start_date * 1e3)}`];
|
|
490
495
|
if (subscription.status === "active" || subscription.status === "trialing") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.128",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@arcblock/did-connect": "^2.9.
|
|
56
|
-
"@arcblock/ux": "^2.9.
|
|
55
|
+
"@arcblock/did-connect": "^2.9.23",
|
|
56
|
+
"@arcblock/ux": "^2.9.23",
|
|
57
57
|
"@mui/icons-material": "^5.15.6",
|
|
58
58
|
"@mui/lab": "^5.0.0-alpha.162",
|
|
59
59
|
"@mui/material": "^5.15.6",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"@babel/core": "^7.19.3",
|
|
90
90
|
"@babel/preset-env": "^7.19.3",
|
|
91
91
|
"@babel/preset-react": "^7.18.6",
|
|
92
|
-
"@blocklet/payment-types": "1.13.
|
|
92
|
+
"@blocklet/payment-types": "1.13.128",
|
|
93
93
|
"@storybook/addon-essentials": "^7.6.10",
|
|
94
94
|
"@storybook/addon-interactions": "^7.6.10",
|
|
95
95
|
"@storybook/addon-links": "^7.6.10",
|
|
@@ -118,5 +118,5 @@
|
|
|
118
118
|
"vite-plugin-babel": "^1.2.0",
|
|
119
119
|
"vite-plugin-node-polyfills": "^0.19.0"
|
|
120
120
|
},
|
|
121
|
-
"gitHead": "
|
|
121
|
+
"gitHead": "b518cfcb827855501a03f0675cb9025e75b8538e"
|
|
122
122
|
}
|
package/src/checkout/form.tsx
CHANGED
|
@@ -21,7 +21,7 @@ const fetchCheckoutSession = async (id: string): Promise<CheckoutContext> => {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
// FIXME: @wangshijun support popup
|
|
24
|
-
export default function CheckoutForm({ id, onPaid, onError, mode, extraParams }: CheckoutProps) {
|
|
24
|
+
export default function CheckoutForm({ id, onPaid, onError, mode, goBack, extraParams }: CheckoutProps) {
|
|
25
25
|
if (!id.startsWith('plink_') && !id.startsWith('cs_')) {
|
|
26
26
|
throw new Error('Either a checkoutSession or a paymentLink id is required.');
|
|
27
27
|
}
|
|
@@ -62,6 +62,7 @@ export default function CheckoutForm({ id, onPaid, onError, mode, extraParams }:
|
|
|
62
62
|
error={apiError || state.appError}
|
|
63
63
|
onPaid={handlePaid}
|
|
64
64
|
onError={handleError}
|
|
65
|
+
goBack={goBack}
|
|
65
66
|
mode={mode as string}
|
|
66
67
|
/>
|
|
67
68
|
);
|
package/src/checkout/table.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
|
2
2
|
import Toast from '@arcblock/ux/lib/Toast';
|
|
3
3
|
import type { TPricingTableExpanded } from '@blocklet/payment-types';
|
|
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
|
|
|
@@ -65,6 +66,10 @@ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }
|
|
|
65
66
|
});
|
|
66
67
|
};
|
|
67
68
|
|
|
69
|
+
const goBack = () => {
|
|
70
|
+
setSessionId('');
|
|
71
|
+
};
|
|
72
|
+
|
|
68
73
|
if (!sessionId) {
|
|
69
74
|
if (mode === 'standalone') {
|
|
70
75
|
return (
|
|
@@ -81,5 +86,9 @@ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }
|
|
|
81
86
|
return <PricingTable mode="select" table={data} onSelect={handleSelect} />;
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
return
|
|
89
|
+
return (
|
|
90
|
+
<Box>
|
|
91
|
+
<CheckoutForm id={sessionId} onPaid={onPaid} onError={onError} mode={mode} goBack={goBack} />
|
|
92
|
+
</Box>
|
|
93
|
+
);
|
|
85
94
|
}
|
|
@@ -127,7 +127,8 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
|
|
|
127
127
|
flexWrap="wrap"
|
|
128
128
|
direction="row"
|
|
129
129
|
gap="calc(10px + 3%)"
|
|
130
|
-
justifyContent={alignItems === 'center' ? 'center' : 'flex-start'}
|
|
130
|
+
justifyContent={alignItems === 'center' ? 'center' : 'flex-start'}
|
|
131
|
+
className="price-table-wrap">
|
|
131
132
|
{grouped[state.interval as string]?.map(
|
|
132
133
|
(x: TPricingTableItem & { is_selected?: boolean; is_disabled?: boolean }) => {
|
|
133
134
|
let action = x.subscription_data?.trial_period_days
|
|
@@ -108,7 +108,7 @@ export default function CustomerInvoiceList({ customer_id }: Props) {
|
|
|
108
108
|
<Button variant="text" type="button" color="inherit" onClick={loadMore} disabled={loadingMore}>
|
|
109
109
|
{loadingMore
|
|
110
110
|
? t('common.loadingMore', { resource: t('payment.customer.invoices') })
|
|
111
|
-
: t('common.loadMore', { resource: t('
|
|
111
|
+
: t('common.loadMore', { resource: t('payment.customer.invoices') })}
|
|
112
112
|
</Button>
|
|
113
113
|
)}
|
|
114
114
|
{!hasMore && data.count > pageSize && (
|