payment-kit 1.13.145 → 1.13.147
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/.eslintrc.js +1 -0
- package/api/src/libs/api.ts +22 -7
- package/api/src/routes/subscriptions.ts +22 -4
- package/api/tests/libs/util.spec.ts +16 -0
- package/blocklet.yml +1 -1
- package/package.json +4 -4
- package/src/components/invoice/list.tsx +12 -14
- package/src/components/payment-intent/list.tsx +2 -2
- package/src/components/subscription/list.tsx +12 -13
- package/src/libs/util.ts +1 -1
- package/src/pages/admin/customers/customers/index.tsx +12 -13
- package/src/pages/checkout/pricing-table.tsx +1 -1
package/.eslintrc.js
CHANGED
package/api/src/libs/api.ts
CHANGED
|
@@ -71,9 +71,10 @@ export function getWhereFromQuery(query: string) {
|
|
|
71
71
|
return handleCondition(parsed);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export const getWhereFromKvQuery = (query: string) => {
|
|
74
|
+
export const getWhereFromKvQuery = (query: string, isSubWhere?: boolean) => {
|
|
75
75
|
const out: any = {};
|
|
76
76
|
const likes: any = [];
|
|
77
|
+
const subLikes: any = [];
|
|
77
78
|
query.split(' ').forEach((kv: string) => {
|
|
78
79
|
const [k, v] = kv.split(':');
|
|
79
80
|
|
|
@@ -81,19 +82,33 @@ export const getWhereFromKvQuery = (query: string) => {
|
|
|
81
82
|
let value = decodeURIComponent(v).replace('+', ' ');
|
|
82
83
|
if ((k as any).indexOf('like') > -1) {
|
|
83
84
|
let kk = k?.slice(5);
|
|
85
|
+
|
|
84
86
|
if (kk === 'did' || kk === 'name' || kk === 'email') {
|
|
85
|
-
kk = `$customer.${kk}$`;
|
|
87
|
+
kk = isSubWhere ? kk : `$customer.${kk}$`;
|
|
88
|
+
value = { [kk as any]: { [Op.like]: `%${v}%` } } as any;
|
|
89
|
+
subLikes.push(value);
|
|
90
|
+
} else {
|
|
91
|
+
value = { [kk as any]: { [Op.like]: `%${v}%` } } as any;
|
|
92
|
+
likes.push(value);
|
|
86
93
|
}
|
|
87
|
-
value = { [kk as any]: { [Op.like]: `%${v}%` } } as any;
|
|
88
|
-
|
|
89
|
-
likes.push(value);
|
|
90
94
|
} else {
|
|
91
95
|
out[k as string] = value;
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
});
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
|
|
100
|
+
if (isSubWhere) {
|
|
101
|
+
return [
|
|
102
|
+
{
|
|
103
|
+
[Op.or]: likes,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
[Op.or]: subLikes,
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
if (likes.length || subLikes.length) {
|
|
111
|
+
out[Op.or] = subLikes.concat(likes);
|
|
97
112
|
}
|
|
98
113
|
return out;
|
|
99
114
|
};
|
|
@@ -157,23 +157,41 @@ router.get('/search', auth, async (req, res) => {
|
|
|
157
157
|
allowUnknown: true,
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
-
const where = q ? getWhereFromKvQuery(q) : getWhereFromQuery(query);
|
|
160
|
+
const where = q ? getWhereFromKvQuery(q, true) : getWhereFromQuery(query);
|
|
161
161
|
if (typeof livemode === 'boolean') {
|
|
162
162
|
where.livemode = livemode;
|
|
163
163
|
}
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
// fix here https://github.com/blocklet/payment-kit/issues/394
|
|
165
|
+
const { rows: list1, count: count1 } = await Subscription.findAndCountAll({
|
|
166
|
+
where: where[0],
|
|
166
167
|
order: [['created_at', 'DESC']],
|
|
167
168
|
offset: (page - 1) * pageSize,
|
|
168
169
|
limit: pageSize,
|
|
170
|
+
distinct: true,
|
|
169
171
|
include: [
|
|
172
|
+
{ model: Customer, as: 'customer' },
|
|
170
173
|
{ model: PaymentCurrency, as: 'paymentCurrency' },
|
|
171
174
|
{ model: PaymentMethod, as: 'paymentMethod' },
|
|
172
175
|
{ model: SubscriptionItem, as: 'items' },
|
|
173
|
-
{ model: Customer, as: 'customer' },
|
|
174
176
|
],
|
|
175
177
|
});
|
|
176
178
|
|
|
179
|
+
const { rows: list2, count: count2 } = await Subscription.findAndCountAll({
|
|
180
|
+
order: [['created_at', 'DESC']],
|
|
181
|
+
offset: (page - 1) * pageSize,
|
|
182
|
+
limit: pageSize,
|
|
183
|
+
distinct: true,
|
|
184
|
+
include: [
|
|
185
|
+
{ model: Customer, as: 'customer', where: where[1] },
|
|
186
|
+
{ model: PaymentCurrency, as: 'paymentCurrency' },
|
|
187
|
+
{ model: PaymentMethod, as: 'paymentMethod' },
|
|
188
|
+
{ model: SubscriptionItem, as: 'items' },
|
|
189
|
+
],
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const count = count1 + count2;
|
|
193
|
+
const list = list1.concat(list2);
|
|
194
|
+
|
|
177
195
|
res.json({ count, list });
|
|
178
196
|
});
|
|
179
197
|
|
|
@@ -216,4 +216,20 @@ describe('getWhereFromKvQuery', () => {
|
|
|
216
216
|
],
|
|
217
217
|
});
|
|
218
218
|
});
|
|
219
|
+
|
|
220
|
+
it('should return a customer likes object when the subWhere is true', () => {
|
|
221
|
+
const q = 'like-did:123 like-number:1533';
|
|
222
|
+
const result = getWhereFromKvQuery(q, true);
|
|
223
|
+
expect(result).toEqual([
|
|
224
|
+
{
|
|
225
|
+
[Op.or]: [
|
|
226
|
+
{ number: { [Op.like]: `%1533%` } }
|
|
227
|
+
],
|
|
228
|
+
}, {
|
|
229
|
+
[Op.or]: [
|
|
230
|
+
{ did: { [Op.like]: `%123%` } }
|
|
231
|
+
],
|
|
232
|
+
}
|
|
233
|
+
]);
|
|
234
|
+
});
|
|
219
235
|
});
|
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.147",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "cross-env COMPONENT_STORE_URL=https://test.store.blocklet.dev blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@arcblock/jwt": "^1.18.110",
|
|
51
51
|
"@arcblock/ux": "^2.9.29",
|
|
52
52
|
"@blocklet/logger": "1.16.23",
|
|
53
|
-
"@blocklet/payment-react": "1.13.
|
|
53
|
+
"@blocklet/payment-react": "1.13.147",
|
|
54
54
|
"@blocklet/sdk": "1.16.23",
|
|
55
55
|
"@blocklet/ui-react": "^2.9.29",
|
|
56
56
|
"@blocklet/uploader": "^0.0.73",
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"devDependencies": {
|
|
111
111
|
"@abtnode/types": "1.16.23",
|
|
112
112
|
"@arcblock/eslint-config-ts": "^0.2.4",
|
|
113
|
-
"@blocklet/payment-types": "1.13.
|
|
113
|
+
"@blocklet/payment-types": "1.13.147",
|
|
114
114
|
"@types/cookie-parser": "^1.4.6",
|
|
115
115
|
"@types/cors": "^2.8.17",
|
|
116
116
|
"@types/dotenv-flow": "^3.3.3",
|
|
@@ -149,5 +149,5 @@
|
|
|
149
149
|
"parser": "typescript"
|
|
150
150
|
}
|
|
151
151
|
},
|
|
152
|
-
"gitHead": "
|
|
152
|
+
"gitHead": "9fd7b32ada89697a6e5c8b5a1c5c4729dca50c51"
|
|
153
153
|
}
|
|
@@ -3,9 +3,8 @@ import { getDurableData } from '@arcblock/ux/lib/Datatable';
|
|
|
3
3
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
4
4
|
import { Status, api, formatTime, getInvoiceStatusColor } from '@blocklet/payment-react';
|
|
5
5
|
import type { TInvoiceExpanded } from '@blocklet/payment-types';
|
|
6
|
-
import {
|
|
6
|
+
import { CircularProgress, ToggleButton, ToggleButtonGroup, Typography } from '@mui/material';
|
|
7
7
|
import { fromUnitToToken } from '@ocap/util';
|
|
8
|
-
import { useRequest } from 'ahooks';
|
|
9
8
|
import { useEffect, useState } from 'react';
|
|
10
9
|
import { useNavigate } from 'react-router-dom';
|
|
11
10
|
|
|
@@ -95,21 +94,20 @@ export default function InvoiceList({ customer_id, subscription_id, features, st
|
|
|
95
94
|
page: persisted.page ? persisted.page + 1 : 1,
|
|
96
95
|
});
|
|
97
96
|
|
|
98
|
-
const
|
|
99
|
-
useEffect(() => {
|
|
100
|
-
debounce(() => {
|
|
101
|
-
refresh();
|
|
102
|
-
}, 1000)();
|
|
103
|
-
}, [search, refresh]);
|
|
97
|
+
const [data, setData] = useState({}) as any;
|
|
104
98
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
const refresh = () =>
|
|
100
|
+
fetchData(search).then((res: any) => {
|
|
101
|
+
setData(res);
|
|
102
|
+
});
|
|
108
103
|
|
|
109
|
-
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
debounce(refresh, 1000)();
|
|
106
|
+
}, [search]);
|
|
107
|
+
|
|
108
|
+
if (!data.list) {
|
|
110
109
|
return <CircularProgress />;
|
|
111
110
|
}
|
|
112
|
-
|
|
113
111
|
const columns = [
|
|
114
112
|
{
|
|
115
113
|
label: t('common.amount'),
|
|
@@ -218,7 +216,7 @@ export default function InvoiceList({ customer_id, subscription_id, features, st
|
|
|
218
216
|
durableKeys={['page', 'rowsPerPage']}
|
|
219
217
|
data={data.list}
|
|
220
218
|
columns={columns}
|
|
221
|
-
loading={
|
|
219
|
+
loading={!data.list}
|
|
222
220
|
onChange={onTableChange}
|
|
223
221
|
options={{
|
|
224
222
|
count: data.count,
|
|
@@ -93,7 +93,7 @@ export default function PaymentList({ customer_id, invoice_id, features }: ListP
|
|
|
93
93
|
}, 1000)();
|
|
94
94
|
}, [search]);
|
|
95
95
|
|
|
96
|
-
if (!data) {
|
|
96
|
+
if (!data.length) {
|
|
97
97
|
return <CircularProgress />;
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -187,7 +187,7 @@ export default function PaymentList({ customer_id, invoice_id, features }: ListP
|
|
|
187
187
|
durableKeys={['page', 'rowsPerPage']}
|
|
188
188
|
data={data.list || []}
|
|
189
189
|
columns={columns}
|
|
190
|
-
loading={!data}
|
|
190
|
+
loading={!data.list}
|
|
191
191
|
onChange={onTableChange}
|
|
192
192
|
options={{
|
|
193
193
|
count: data.count,
|
|
@@ -3,8 +3,7 @@ import { getDurableData } from '@arcblock/ux/lib/Datatable';
|
|
|
3
3
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
4
4
|
import { Status, api, formatTime } from '@blocklet/payment-react';
|
|
5
5
|
import type { TSubscriptionExpanded } from '@blocklet/payment-types';
|
|
6
|
-
import {
|
|
7
|
-
import { useRequest } from 'ahooks';
|
|
6
|
+
import { CircularProgress, ToggleButton, ToggleButtonGroup } from '@mui/material';
|
|
8
7
|
import { useEffect, useState } from 'react';
|
|
9
8
|
import { useNavigate } from 'react-router-dom';
|
|
10
9
|
|
|
@@ -79,18 +78,18 @@ export default function SubscriptionList({ customer_id, features, status }: List
|
|
|
79
78
|
page: persisted.page ? persisted.page + 1 : 1,
|
|
80
79
|
});
|
|
81
80
|
|
|
82
|
-
const
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
debounce(() => {
|
|
85
|
-
refresh();
|
|
86
|
-
}, 1000)();
|
|
87
|
-
}, [search, refresh]);
|
|
81
|
+
const [data, setData] = useState({}) as any;
|
|
88
82
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
const refresh = () =>
|
|
84
|
+
fetchData(search).then((res: any) => {
|
|
85
|
+
setData(res);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
debounce(refresh, 1000)();
|
|
90
|
+
}, [search]);
|
|
92
91
|
|
|
93
|
-
if (
|
|
92
|
+
if (!data.list) {
|
|
94
93
|
return <CircularProgress />;
|
|
95
94
|
}
|
|
96
95
|
|
|
@@ -184,7 +183,7 @@ export default function SubscriptionList({ customer_id, features, status }: List
|
|
|
184
183
|
durableKeys={['page', 'rowsPerPage']}
|
|
185
184
|
data={data.list}
|
|
186
185
|
columns={columns}
|
|
187
|
-
loading={
|
|
186
|
+
loading={!data.list}
|
|
188
187
|
onChange={onTableChange}
|
|
189
188
|
options={{
|
|
190
189
|
count: data.count,
|
package/src/libs/util.ts
CHANGED
|
@@ -194,7 +194,7 @@ export function getSupportedPaymentCurrencies(items: TLineItemExpanded[]) {
|
|
|
194
194
|
|
|
195
195
|
export const debounce = (fun: Function, wait: number) => {
|
|
196
196
|
let timeout: any = null;
|
|
197
|
-
return function () {
|
|
197
|
+
return function inner() {
|
|
198
198
|
if (timeout) {
|
|
199
199
|
clearTimeout(timeout);
|
|
200
200
|
}
|
|
@@ -4,8 +4,7 @@ import DidAddress from '@arcblock/ux/lib/DID';
|
|
|
4
4
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
5
5
|
import { api, formatTime } from '@blocklet/payment-react';
|
|
6
6
|
import type { TCustomer } from '@blocklet/payment-types';
|
|
7
|
-
import {
|
|
8
|
-
import { useRequest } from 'ahooks';
|
|
7
|
+
import { Avatar, CircularProgress, Stack, Typography } from '@mui/material';
|
|
9
8
|
import { useEffect, useState } from 'react';
|
|
10
9
|
import { useNavigate } from 'react-router-dom';
|
|
11
10
|
|
|
@@ -40,18 +39,18 @@ export default function CustomersList() {
|
|
|
40
39
|
page: persisted.page ? persisted.page + 1 : 1,
|
|
41
40
|
});
|
|
42
41
|
|
|
43
|
-
const
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
debounce(() => {
|
|
46
|
-
refresh();
|
|
47
|
-
}, 1000)();
|
|
48
|
-
}, [search, refresh]);
|
|
42
|
+
const [data, setData] = useState({}) as any;
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
const refresh = () =>
|
|
45
|
+
fetchData(search).then((res: any) => {
|
|
46
|
+
setData(res);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
debounce(refresh, 1000)();
|
|
51
|
+
}, [search]);
|
|
53
52
|
|
|
54
|
-
if (
|
|
53
|
+
if (!data.list) {
|
|
55
54
|
return <CircularProgress />;
|
|
56
55
|
}
|
|
57
56
|
|
|
@@ -144,7 +143,7 @@ export default function CustomersList() {
|
|
|
144
143
|
}
|
|
145
144
|
},
|
|
146
145
|
}}
|
|
147
|
-
loading={
|
|
146
|
+
loading={!data.list}
|
|
148
147
|
onChange={onTableChange}
|
|
149
148
|
/>
|
|
150
149
|
);
|