payment-kit 1.13.154 → 1.13.156
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/api/src/routes/subscriptions.ts +28 -18
- package/blocklet.yml +1 -1
- package/package.json +4 -4
- package/src/pages/admin/index.tsx +9 -1
|
@@ -255,25 +255,31 @@ router.put('/:id/cancel', authPortal, async (req, res) => {
|
|
|
255
255
|
updates.cancelation_details = { reason: 'cancellation_requested', feedback, comment };
|
|
256
256
|
updates.canceled_at = now;
|
|
257
257
|
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
258
|
} else {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
updates.
|
|
275
|
-
updates.cancel_at
|
|
276
|
-
|
|
259
|
+
if (['owner', 'admin'].includes(req.user?.role as string) === false) {
|
|
260
|
+
return res.status(403).json({ error: 'Not authorized to perform this action' });
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (at === 'now') {
|
|
264
|
+
updates.status = 'canceled';
|
|
265
|
+
updates.cancel_at = now;
|
|
266
|
+
updates.canceled_at = now;
|
|
267
|
+
await addSubscriptionJob(subscription, 'cancel', true, updates.cancel_at);
|
|
268
|
+
} else if (at === 'current_period_end') {
|
|
269
|
+
updates.cancel_at_period_end = true;
|
|
270
|
+
updates.cancel_at = subscription.current_period_end;
|
|
271
|
+
updates.canceled_at = now;
|
|
272
|
+
await addSubscriptionJob(subscription, 'cancel', true, updates.cancel_at);
|
|
273
|
+
} else {
|
|
274
|
+
updates.cancel_at = dayjs(time).unix();
|
|
275
|
+
updates.canceled_at = now;
|
|
276
|
+
await addSubscriptionJob(
|
|
277
|
+
subscription,
|
|
278
|
+
'cancel',
|
|
279
|
+
updates.cancel_at < subscription.current_period_end,
|
|
280
|
+
updates.cancel_at
|
|
281
|
+
);
|
|
282
|
+
}
|
|
277
283
|
}
|
|
278
284
|
|
|
279
285
|
if (subscription.payment_details?.stripe?.subscription_id) {
|
|
@@ -302,6 +308,10 @@ router.put('/:id/cancel', authPortal, async (req, res) => {
|
|
|
302
308
|
|
|
303
309
|
// trigger refund
|
|
304
310
|
if (updates.cancel_at < subscription.current_period_end && refund !== 'none') {
|
|
311
|
+
if (['owner', 'admin'].includes(req.user?.role as string) === false) {
|
|
312
|
+
return res.status(403).json({ error: 'Not authorized to perform this action' });
|
|
313
|
+
}
|
|
314
|
+
|
|
305
315
|
const result = await getSubscriptionRefundSetup(subscription, updates.cancel_at);
|
|
306
316
|
if (result.unused !== '0') {
|
|
307
317
|
const item = await Refund.create({
|
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.156",
|
|
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.156",
|
|
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.156",
|
|
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": "88f9908f07e00a0958472c9399f427d96d91b2c4"
|
|
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 />
|