@blocklet/payment-react 1.13.129 → 1.13.131
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/components/blockchain/tx.d.ts +13 -0
- package/es/components/blockchain/tx.js +52 -0
- package/es/history/invoice/list.d.ts +13 -0
- package/es/{histroy → history}/invoice/list.js +12 -5
- package/es/history/mini-invoice/list.d.ts +2 -0
- package/es/{histroy → history}/mini-invoice/list.js +42 -35
- package/es/{histroy → history}/payment/list.js +10 -1
- package/es/index.d.ts +5 -4
- package/es/index.js +6 -4
- package/es/locales/en.js +4 -4
- package/es/locales/zh.js +3 -3
- package/es/util.js +5 -2
- package/lib/components/blockchain/tx.d.ts +13 -0
- package/lib/components/blockchain/tx.js +82 -0
- package/lib/history/invoice/list.d.ts +13 -0
- package/lib/{histroy → history}/invoice/list.js +14 -5
- package/lib/history/mini-invoice/list.d.ts +2 -0
- package/lib/{histroy → history}/mini-invoice/list.js +70 -59
- package/lib/{histroy → history}/payment/list.js +12 -1
- package/lib/index.d.ts +5 -4
- package/lib/index.js +11 -3
- package/lib/locales/en.js +4 -4
- package/lib/locales/zh.js +3 -3
- package/lib/util.js +5 -2
- package/package.json +3 -3
- package/src/components/blockchain/tx.tsx +77 -0
- package/src/{histroy → history}/invoice/list.tsx +15 -6
- package/src/{histroy → history}/mini-invoice/list.tsx +52 -49
- package/src/{histroy → history}/payment/list.tsx +11 -1
- package/src/index.ts +5 -3
- package/src/locales/en.tsx +4 -4
- package/src/locales/zh.tsx +3 -3
- package/src/util.ts +5 -2
- package/es/histroy/invoice/list.d.ts +0 -6
- package/es/histroy/mini-invoice/list.d.ts +0 -7
- package/lib/histroy/invoice/list.d.ts +0 -6
- package/lib/histroy/mini-invoice/list.d.ts +0 -7
- /package/es/{histroy → history}/payment/list.d.ts +0 -0
- /package/lib/{histroy → history}/payment/list.d.ts +0 -0
|
@@ -3,7 +3,8 @@ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
|
3
3
|
import type { Paginated, TInvoiceExpanded, TSubscriptionExpanded } from '@blocklet/payment-types';
|
|
4
4
|
import { Box, Button, CircularProgress, Divider, List, ListItem, ListSubheader, Typography } from '@mui/material';
|
|
5
5
|
import { fromUnitToToken } from '@ocap/util';
|
|
6
|
-
import {
|
|
6
|
+
import { useRequest } from 'ahooks';
|
|
7
|
+
import { joinURL } from 'ufo';
|
|
7
8
|
|
|
8
9
|
import api from '../../api';
|
|
9
10
|
import Status from '../../components/status';
|
|
@@ -12,10 +13,11 @@ import {
|
|
|
12
13
|
formatTime,
|
|
13
14
|
formatToDate,
|
|
14
15
|
getInvoiceStatusColor,
|
|
16
|
+
getPrefix,
|
|
15
17
|
getSubscriptionStatusColor,
|
|
16
18
|
} from '../../util';
|
|
17
19
|
|
|
18
|
-
const
|
|
20
|
+
const fetchInvoiceData = (params: Record<string, any> = {}): Promise<Paginated<TInvoiceExpanded>> => {
|
|
19
21
|
const search = new URLSearchParams();
|
|
20
22
|
Object.keys(params).forEach((key) => {
|
|
21
23
|
search.set(key, String(params[key]));
|
|
@@ -23,26 +25,21 @@ const fetchData = (params: Record<string, any> = {}): Promise<Paginated<TInvoice
|
|
|
23
25
|
return api.get(`/api/invoices?${search.toString()}`).then((res: any) => res.data);
|
|
24
26
|
};
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
const fetchSubscriptionData = (id: string): Promise<TSubscriptionExpanded> => {
|
|
29
|
+
return api.get(`/api/subscriptions/${id}`).then((res) => res.data);
|
|
28
30
|
};
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export default function MiniInvoiceList({ subscription }: Props) {
|
|
32
|
+
export default function MiniInvoiceList() {
|
|
33
33
|
const { t } = useLocaleContext();
|
|
34
34
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
{
|
|
41
|
-
reloadDeps: [subscription.id],
|
|
42
|
-
}
|
|
35
|
+
const subscriptionId = new URL(window.location.href).searchParams.get('id');
|
|
36
|
+
|
|
37
|
+
const { data: subscription } = useRequest(() => fetchSubscriptionData(subscriptionId as string));
|
|
38
|
+
const { data } = useRequest(() =>
|
|
39
|
+
fetchInvoiceData({ page: 1, pageSize: 10, status: 'open,paid,uncollectible', subscription_id: subscriptionId })
|
|
43
40
|
);
|
|
44
41
|
|
|
45
|
-
if (
|
|
42
|
+
if (!subscription || !data) {
|
|
46
43
|
return (
|
|
47
44
|
<Position>
|
|
48
45
|
<CircularProgress />
|
|
@@ -50,13 +47,7 @@ export default function MiniInvoiceList({ subscription }: Props) {
|
|
|
50
47
|
);
|
|
51
48
|
}
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<Position>
|
|
56
|
-
<Typography color="text.secondary">{t('payment.customer.invoice.empty')}</Typography>
|
|
57
|
-
</Position>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
50
|
+
const invoices = data.list || [];
|
|
60
51
|
|
|
61
52
|
const infoList = [
|
|
62
53
|
{
|
|
@@ -68,28 +59,32 @@ export default function MiniInvoiceList({ subscription }: Props) {
|
|
|
68
59
|
),
|
|
69
60
|
},
|
|
70
61
|
{
|
|
71
|
-
name: t('
|
|
62
|
+
name: t('common.status'),
|
|
72
63
|
value: <Status label={subscription.status} color={getSubscriptionStatusColor(subscription.status)} />,
|
|
73
64
|
},
|
|
65
|
+
];
|
|
74
66
|
|
|
75
|
-
|
|
67
|
+
if (subscription.status === 'active' || subscription.status === 'trailing') {
|
|
68
|
+
infoList.push({
|
|
76
69
|
name: t('payment.customer.subscriptions.nextInvoice'),
|
|
77
70
|
value: (
|
|
78
71
|
<Typography
|
|
79
72
|
sx={{
|
|
80
73
|
color: '#34BE74',
|
|
81
74
|
fontWeight: 'bold',
|
|
75
|
+
marginRight: '10px',
|
|
82
76
|
}}>
|
|
83
77
|
{formatTime(subscription.current_period_end * 1000)}
|
|
84
78
|
</Typography>
|
|
85
79
|
),
|
|
86
|
-
}
|
|
87
|
-
|
|
80
|
+
});
|
|
81
|
+
}
|
|
88
82
|
|
|
89
83
|
return (
|
|
90
84
|
<Position>
|
|
91
85
|
<Typography title={t('payment.checkout.subscription')} />
|
|
92
86
|
<Box
|
|
87
|
+
className="mini-invoice-wrap"
|
|
93
88
|
sx={{
|
|
94
89
|
display: 'flex',
|
|
95
90
|
flexDirection: 'column',
|
|
@@ -115,28 +110,40 @@ export default function MiniInvoiceList({ subscription }: Props) {
|
|
|
115
110
|
</List>
|
|
116
111
|
</Box>
|
|
117
112
|
<Divider />
|
|
118
|
-
<Box sx={{ marginTop: '12px' }}>
|
|
119
|
-
<List sx={{ overflow: 'auto'
|
|
113
|
+
<Box sx={{ marginTop: '12px', flex: 1 }}>
|
|
114
|
+
<List sx={{ overflow: 'auto' }} className="mini-invoice-list">
|
|
120
115
|
<ListSubheader disableGutters sx={{ padding: 0 }}>
|
|
121
116
|
<Typography component="h2" variant="h6" fontSize="16px">
|
|
122
117
|
{t('payment.customer.invoices')}
|
|
123
118
|
</Typography>
|
|
124
119
|
</ListSubheader>
|
|
125
|
-
{(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
{
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
120
|
+
{(invoices as any).length === 0 ? (
|
|
121
|
+
<Typography color="text.secondary">{t('payment.customer.invoice.empty')}</Typography>
|
|
122
|
+
) : (
|
|
123
|
+
(invoices as any).map((item: any) => {
|
|
124
|
+
return (
|
|
125
|
+
<ListItem key={item.id} disableGutters sx={{ display: 'flex', justifyContent: 'space-between' }}>
|
|
126
|
+
<Typography component="span" sx={{ flex: 3 }}>
|
|
127
|
+
{formatToDate(item.created_at)}
|
|
128
|
+
</Typography>
|
|
129
|
+
<Typography component="span" sx={{ flex: 1, textAlign: 'right' }}>
|
|
130
|
+
{fromUnitToToken(item.total, item.paymentCurrency.decimal)}
|
|
131
|
+
{item.paymentCurrency.symbol}
|
|
132
|
+
</Typography>
|
|
133
|
+
<Typography component="span" sx={{ flex: 2, textAlign: 'right' }}>
|
|
134
|
+
<Status label={item.status} color={getInvoiceStatusColor(item.status)} sx={{ flex: 2 }} />
|
|
135
|
+
</Typography>
|
|
136
|
+
</ListItem>
|
|
137
|
+
);
|
|
138
|
+
})
|
|
139
|
+
)}
|
|
137
140
|
</List>
|
|
138
141
|
</Box>
|
|
139
|
-
<Button
|
|
142
|
+
<Button
|
|
143
|
+
target="_blank"
|
|
144
|
+
variant="contained"
|
|
145
|
+
sx={{ marginTop: '10px 0', width: '100%', color: '#fff!important' }}
|
|
146
|
+
href={joinURL(window.location.origin, getPrefix(), `/customer/subscription/${subscription.id}`)}>
|
|
140
147
|
{t('payment.customer.subscriptions.title')}
|
|
141
148
|
</Button>
|
|
142
149
|
</Box>
|
|
@@ -149,15 +156,11 @@ function Position({ children }: any) {
|
|
|
149
156
|
<Box
|
|
150
157
|
className="mini-invoice-box" // 预留 class 用于设置定位
|
|
151
158
|
sx={{
|
|
152
|
-
position: 'absolute',
|
|
153
|
-
right: 0,
|
|
154
|
-
top: '30px',
|
|
155
|
-
justifyContent: 'center',
|
|
156
159
|
padding: '8px',
|
|
157
|
-
|
|
160
|
+
width: '100%',
|
|
161
|
+
maxWidth: '500px',
|
|
158
162
|
background: '#fff',
|
|
159
|
-
|
|
160
|
-
boxShadow: '0 4px 8px rgba(0, 0, 0, 20%)',
|
|
163
|
+
margin: '0 auto',
|
|
161
164
|
}}>
|
|
162
165
|
{children}
|
|
163
166
|
</Box>
|
|
@@ -6,6 +6,7 @@ import { fromUnitToToken } from '@ocap/util';
|
|
|
6
6
|
import { useInfiniteScroll } from 'ahooks';
|
|
7
7
|
|
|
8
8
|
import api from '../../api';
|
|
9
|
+
import TxLink from '../../components/blockchain/tx';
|
|
9
10
|
import Status from '../../components/status';
|
|
10
11
|
import { formatToDate, getPaymentIntentStatusColor } from '../../util';
|
|
11
12
|
|
|
@@ -91,9 +92,18 @@ export default function CustomerPaymentList({ customer_id }: Props) {
|
|
|
91
92
|
<Box flex={3}>
|
|
92
93
|
<Status label={item.status} color={getPaymentIntentStatusColor(item.status)} />
|
|
93
94
|
</Box>
|
|
94
|
-
<Box flex={
|
|
95
|
+
<Box flex={3}>
|
|
95
96
|
<Typography>{item.description || item.id}</Typography>
|
|
96
97
|
</Box>
|
|
98
|
+
<Box flex={3} sx={{ minWidth: '220px' }}>
|
|
99
|
+
{(item as any).payment_details?.arcblock?.tx_hash && (
|
|
100
|
+
<TxLink
|
|
101
|
+
details={(item as any).payment_details}
|
|
102
|
+
method={(item as any).paymentMethod}
|
|
103
|
+
mode="customer"
|
|
104
|
+
/>
|
|
105
|
+
)}
|
|
106
|
+
</Box>
|
|
97
107
|
</Stack>
|
|
98
108
|
))}
|
|
99
109
|
</Box>
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import api from './api';
|
|
2
2
|
import CheckoutForm from './checkout/form';
|
|
3
3
|
import CheckoutTable from './checkout/table';
|
|
4
|
+
import TxLink from './components/blockchain/tx';
|
|
4
5
|
import ConfirmDialog from './components/confirm';
|
|
5
6
|
import FormInput from './components/input';
|
|
6
7
|
import Livemode from './components/livemode';
|
|
@@ -8,9 +9,9 @@ import PricingTable from './components/pricing-table';
|
|
|
8
9
|
import Status from './components/status';
|
|
9
10
|
import Switch from './components/switch-button';
|
|
10
11
|
import dayjs from './dayjs';
|
|
11
|
-
import CustomerInvoiceList from './
|
|
12
|
-
import MiniInvoiceList from './
|
|
13
|
-
import CustomerPaymentList from './
|
|
12
|
+
import CustomerInvoiceList from './history/invoice/list';
|
|
13
|
+
import MiniInvoiceList from './history/mini-invoice/list';
|
|
14
|
+
import CustomerPaymentList from './history/payment/list';
|
|
14
15
|
import Amount from './payment/amount';
|
|
15
16
|
import PhoneInput from './payment/form/phone';
|
|
16
17
|
import Payment from './payment/index';
|
|
@@ -39,4 +40,5 @@ export {
|
|
|
39
40
|
CustomerInvoiceList,
|
|
40
41
|
CustomerPaymentList,
|
|
41
42
|
MiniInvoiceList,
|
|
43
|
+
TxLink,
|
|
42
44
|
};
|
package/src/locales/en.tsx
CHANGED
|
@@ -207,17 +207,17 @@ export default flat({
|
|
|
207
207
|
pay: 'Pay this invoice',
|
|
208
208
|
paySuccess: 'You have successfully paid the invoice',
|
|
209
209
|
payError: 'Failed to paid the invoice',
|
|
210
|
-
empty: '
|
|
210
|
+
empty: 'There are no invoices here',
|
|
211
211
|
},
|
|
212
212
|
payment: {
|
|
213
|
-
empty: '
|
|
213
|
+
empty: 'There are no payments here',
|
|
214
214
|
},
|
|
215
215
|
subscriptions: {
|
|
216
216
|
plan: 'Plan',
|
|
217
217
|
nextInvoice: 'Next Invoice',
|
|
218
218
|
title: 'Manage subscriptions',
|
|
219
|
-
current: 'Current
|
|
220
|
-
empty: '
|
|
219
|
+
current: 'Current subscription',
|
|
220
|
+
empty: 'There are no subscriptions here',
|
|
221
221
|
},
|
|
222
222
|
},
|
|
223
223
|
},
|
package/src/locales/zh.tsx
CHANGED
|
@@ -203,17 +203,17 @@ export default flat({
|
|
|
203
203
|
pay: '支付此发票',
|
|
204
204
|
paySuccess: '支付成功',
|
|
205
205
|
payError: '支付失败',
|
|
206
|
-
empty: '
|
|
206
|
+
empty: '没有任何发票',
|
|
207
207
|
},
|
|
208
208
|
payment: {
|
|
209
|
-
empty: '
|
|
209
|
+
empty: '没有任何支付',
|
|
210
210
|
},
|
|
211
211
|
subscriptions: {
|
|
212
212
|
plan: '订阅',
|
|
213
213
|
nextInvoice: '下一张发票',
|
|
214
214
|
title: '订阅管理',
|
|
215
215
|
current: '当前订阅',
|
|
216
|
-
empty: '
|
|
216
|
+
empty: '没有任何订阅',
|
|
217
217
|
},
|
|
218
218
|
},
|
|
219
219
|
},
|
package/src/util.ts
CHANGED
|
@@ -324,11 +324,14 @@ export function getCheckoutAmount(
|
|
|
324
324
|
upsell = true
|
|
325
325
|
) {
|
|
326
326
|
let renew = new BN(0);
|
|
327
|
-
|
|
328
327
|
const total = items
|
|
328
|
+
.filter((x) => {
|
|
329
|
+
const price = upsell ? x.upsell_price || x.price : x.price;
|
|
330
|
+
return price != null;
|
|
331
|
+
})
|
|
329
332
|
.reduce((acc, x) => {
|
|
330
333
|
const price = upsell ? x.upsell_price || x.price : x.price;
|
|
331
|
-
if (price
|
|
334
|
+
if (price?.type === 'recurring') {
|
|
332
335
|
renew = renew.add(new BN(getPriceUintAmountByCurrency(price, currency)).mul(new BN(x.quantity)));
|
|
333
336
|
|
|
334
337
|
if (includeFreeTrial) {
|
|
@@ -1,7 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,7 +0,0 @@
|
|
|
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 {};
|
|
File without changes
|
|
File without changes
|