payment-kit 1.13.155 → 1.13.157

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.
@@ -163,7 +163,7 @@ router.get('/search', auth, async (req, res) => {
163
163
  }
164
164
  // fix here https://github.com/blocklet/payment-kit/issues/394
165
165
  const { rows: list1, count: count1 } = await Subscription.findAndCountAll({
166
- where: where[0],
166
+ where: q ? where[0] : where,
167
167
  order: [['created_at', 'DESC']],
168
168
  offset: (page - 1) * pageSize,
169
169
  limit: pageSize,
@@ -176,21 +176,26 @@ router.get('/search', auth, async (req, res) => {
176
176
  ],
177
177
  });
178
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
- });
179
+ let count = count1;
180
+ let list = list1;
191
181
 
192
- const count = count1 + count2;
193
- const list = list1.concat(list2);
182
+ if (q) {
183
+ const { rows: list2, count: count2 } = await Subscription.findAndCountAll({
184
+ order: [['created_at', 'DESC']],
185
+ offset: (page - 1) * pageSize,
186
+ limit: pageSize,
187
+ distinct: true,
188
+ include: [
189
+ { model: Customer, as: 'customer', where: where[1] },
190
+ { model: PaymentCurrency, as: 'paymentCurrency' },
191
+ { model: PaymentMethod, as: 'paymentMethod' },
192
+ { model: SubscriptionItem, as: 'items' },
193
+ ],
194
+ });
195
+
196
+ count = count1 + count2;
197
+ list = list1.concat(list2 || []);
198
+ }
194
199
 
195
200
  res.json({ count, list });
196
201
  });
@@ -255,25 +260,31 @@ router.put('/:id/cancel', authPortal, async (req, res) => {
255
260
  updates.cancelation_details = { reason: 'cancellation_requested', feedback, comment };
256
261
  updates.canceled_at = now;
257
262
  await addSubscriptionJob(subscription, 'cancel', true, updates.cancel_at);
258
- } else if (at === 'now') {
259
- updates.status = 'canceled';
260
- updates.cancel_at = now;
261
- updates.canceled_at = now;
262
- await addSubscriptionJob(subscription, 'cancel', true, updates.cancel_at);
263
- } else if (at === 'current_period_end') {
264
- updates.cancel_at_period_end = true;
265
- updates.cancel_at = subscription.current_period_end;
266
- updates.canceled_at = now;
267
- await addSubscriptionJob(subscription, 'cancel', true, updates.cancel_at);
268
263
  } else {
269
- updates.cancel_at = dayjs(time).unix();
270
- updates.canceled_at = now;
271
- await addSubscriptionJob(
272
- subscription,
273
- 'cancel',
274
- updates.cancel_at < subscription.current_period_end,
275
- updates.cancel_at
276
- );
264
+ if (['owner', 'admin'].includes(req.user?.role as string) === false) {
265
+ return res.status(403).json({ error: 'Not authorized to perform this action' });
266
+ }
267
+
268
+ if (at === 'now') {
269
+ updates.status = 'canceled';
270
+ updates.cancel_at = now;
271
+ updates.canceled_at = now;
272
+ await addSubscriptionJob(subscription, 'cancel', true, updates.cancel_at);
273
+ } else if (at === 'current_period_end') {
274
+ updates.cancel_at_period_end = true;
275
+ updates.cancel_at = subscription.current_period_end;
276
+ updates.canceled_at = now;
277
+ await addSubscriptionJob(subscription, 'cancel', true, updates.cancel_at);
278
+ } else {
279
+ updates.cancel_at = dayjs(time).unix();
280
+ updates.canceled_at = now;
281
+ await addSubscriptionJob(
282
+ subscription,
283
+ 'cancel',
284
+ updates.cancel_at < subscription.current_period_end,
285
+ updates.cancel_at
286
+ );
287
+ }
277
288
  }
278
289
 
279
290
  if (subscription.payment_details?.stripe?.subscription_id) {
@@ -302,6 +313,10 @@ router.put('/:id/cancel', authPortal, async (req, res) => {
302
313
 
303
314
  // trigger refund
304
315
  if (updates.cancel_at < subscription.current_period_end && refund !== 'none') {
316
+ if (['owner', 'admin'].includes(req.user?.role as string) === false) {
317
+ return res.status(403).json({ error: 'Not authorized to perform this action' });
318
+ }
319
+
305
320
  const result = await getSubscriptionRefundSetup(subscription, updates.cancel_at);
306
321
  if (result.unused !== '0') {
307
322
  const item = await Refund.create({
package/blocklet.yml CHANGED
@@ -14,7 +14,7 @@ repository:
14
14
  type: git
15
15
  url: git+https://github.com/blocklet/payment-kit.git
16
16
  specVersion: 1.2.8
17
- version: 1.13.155
17
+ version: 1.13.157
18
18
  logo: logo.png
19
19
  files:
20
20
  - dist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payment-kit",
3
- "version": "1.13.155",
3
+ "version": "1.13.157",
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.155",
53
+ "@blocklet/payment-react": "1.13.157",
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.155",
113
+ "@blocklet/payment-types": "1.13.157",
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": "5d5aa97dafe27016e6b189511d34abe51571041e"
152
+ "gitHead": "8764322e8013a37f6cf9c6843ef7701f2bddc412"
153
153
  }
@@ -1,7 +1,7 @@
1
1
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
2
  import { PaymentProvider, Switch, usePaymentContext } from '@blocklet/payment-react';
3
3
  import { Box, Chip, Stack } from '@mui/material';
4
- import React, { Suspense, isValidElement, startTransition } from 'react';
4
+ import React, { Suspense, isValidElement, startTransition, useEffect } from 'react';
5
5
  import { useNavigate, useParams } from 'react-router-dom';
6
6
 
7
7
  import Layout from '../../components/layout/admin';
@@ -107,7 +107,15 @@ function Admin() {
107
107
  }
108
108
 
109
109
  export default function WrappedAdmin() {
110
+ const navigate = useNavigate();
110
111
  const { session, connectApi } = useSessionContext();
112
+
113
+ useEffect(() => {
114
+ if (session.user && ['owner', 'admin'].includes(session.user.role) === false) {
115
+ navigate('/customer');
116
+ }
117
+ }, [session.user]);
118
+
111
119
  return (
112
120
  <PaymentProvider session={session} connect={connectApi}>
113
121
  <Admin />