payment-kit 1.13.158 → 1.13.159
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/refunds.ts +16 -1
- package/api/src/routes/subscriptions.ts +17 -1
- package/api/src/store/migrations/20240228-service-actions.ts +23 -0
- package/api/src/store/models/subscription.ts +8 -1
- package/api/src/store/models/types.ts +8 -0
- package/blocklet.yml +1 -1
- package/package.json +4 -4
- package/src/components/subscription/portal/actions.tsx +15 -2
|
@@ -15,7 +15,16 @@ import {
|
|
|
15
15
|
} from '../store/models';
|
|
16
16
|
|
|
17
17
|
const router = Router();
|
|
18
|
-
const auth = authenticate<
|
|
18
|
+
const auth = authenticate<Invoice>({
|
|
19
|
+
component: true,
|
|
20
|
+
roles: ['owner', 'admin'],
|
|
21
|
+
mine: true,
|
|
22
|
+
record: {
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
model: Refund,
|
|
25
|
+
field: 'customer_id',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
19
28
|
|
|
20
29
|
const paginationSchema = Joi.object<{
|
|
21
30
|
page: number;
|
|
@@ -24,6 +33,7 @@ const paginationSchema = Joi.object<{
|
|
|
24
33
|
status?: string;
|
|
25
34
|
invoice_id: string;
|
|
26
35
|
subscription_id: string;
|
|
36
|
+
customer_id: string;
|
|
27
37
|
}>({
|
|
28
38
|
page: Joi.number().integer().min(1).default(1),
|
|
29
39
|
pageSize: Joi.number().integer().min(1).max(100).default(20),
|
|
@@ -31,6 +41,7 @@ const paginationSchema = Joi.object<{
|
|
|
31
41
|
status: Joi.string().empty(''),
|
|
32
42
|
invoice_id: Joi.string().empty(''),
|
|
33
43
|
subscription_id: Joi.string().empty(''),
|
|
44
|
+
customer_id: Joi.string().empty(''),
|
|
34
45
|
});
|
|
35
46
|
router.get('/', auth, async (req, res) => {
|
|
36
47
|
const { page, pageSize, livemode, status, ...query } = await paginationSchema.validateAsync(req.query, {
|
|
@@ -47,6 +58,10 @@ router.get('/', auth, async (req, res) => {
|
|
|
47
58
|
where.invoice_id = query.invoice_id;
|
|
48
59
|
}
|
|
49
60
|
|
|
61
|
+
if (query.customer_id) {
|
|
62
|
+
where.customer_id = query.customer_id;
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
if (query.subscription_id) {
|
|
51
66
|
where.subscription_id = query.subscription_id;
|
|
52
67
|
}
|
|
@@ -29,7 +29,7 @@ import { Product } from '../store/models/product';
|
|
|
29
29
|
import { Refund } from '../store/models/refund';
|
|
30
30
|
import { Subscription, TSubscription } from '../store/models/subscription';
|
|
31
31
|
import { SubscriptionItem } from '../store/models/subscription-item';
|
|
32
|
-
import type { LineItem, SubscriptionUpdateItem } from '../store/models/types';
|
|
32
|
+
import type { LineItem, ServiceAction, SubscriptionUpdateItem } from '../store/models/types';
|
|
33
33
|
import { UsageRecord } from '../store/models/usage-record';
|
|
34
34
|
import { ensureInvoiceAndItems } from './connect/shared';
|
|
35
35
|
import { createUsageRecordQueryFn } from './usage-records';
|
|
@@ -598,6 +598,7 @@ const updateSchema = Joi.object<{
|
|
|
598
598
|
proration_behavior?: string;
|
|
599
599
|
billing_cycle_anchor?: string;
|
|
600
600
|
items: SubscriptionUpdateItem[];
|
|
601
|
+
service_actions?: ServiceAction[];
|
|
601
602
|
}>({
|
|
602
603
|
description: Joi.string().min(1).optional(),
|
|
603
604
|
metadata: Joi.any().optional(),
|
|
@@ -616,6 +617,18 @@ const updateSchema = Joi.object<{
|
|
|
616
617
|
)
|
|
617
618
|
.optional()
|
|
618
619
|
.default([]),
|
|
620
|
+
service_actions: Joi.array()
|
|
621
|
+
.items(
|
|
622
|
+
Joi.object({
|
|
623
|
+
name: Joi.string().required(),
|
|
624
|
+
color: Joi.string().allow('primary', 'secondary', 'success', 'error', 'warning').required(),
|
|
625
|
+
variant: Joi.string().allow('text', 'contained', 'outlined').required(),
|
|
626
|
+
text: Joi.object().required(),
|
|
627
|
+
link: Joi.string().uri().required(),
|
|
628
|
+
})
|
|
629
|
+
)
|
|
630
|
+
.optional()
|
|
631
|
+
.default([]),
|
|
619
632
|
});
|
|
620
633
|
// eslint-disable-next-line consistent-return
|
|
621
634
|
router.put('/:id', authPortal, async (req, res) => {
|
|
@@ -638,6 +651,9 @@ router.put('/:id', authPortal, async (req, res) => {
|
|
|
638
651
|
if (req.body.metadata) {
|
|
639
652
|
updates.metadata = formatMetadata(req.body.metadata);
|
|
640
653
|
}
|
|
654
|
+
if (req.body.service_actions) {
|
|
655
|
+
updates.service_actions = req.body.service_actions;
|
|
656
|
+
}
|
|
641
657
|
if (subscription.isImmutable()) {
|
|
642
658
|
await subscription.update(updates);
|
|
643
659
|
return res.json(subscription);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint-disable no-await-in-loop */
|
|
2
|
+
import { DataTypes } from 'sequelize';
|
|
3
|
+
|
|
4
|
+
import { Migration, safeApplyColumnChanges } from '../migrate';
|
|
5
|
+
|
|
6
|
+
export const up: Migration = async ({ context }) => {
|
|
7
|
+
await safeApplyColumnChanges(context, {
|
|
8
|
+
subscriptions: [
|
|
9
|
+
{
|
|
10
|
+
name: 'service_actions',
|
|
11
|
+
field: {
|
|
12
|
+
type: DataTypes.JSON,
|
|
13
|
+
allowNull: true,
|
|
14
|
+
defaultValue: '[]',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const down: Migration = async ({ context }) => {
|
|
22
|
+
await context.removeColumn('subscriptions', 'service_actions');
|
|
23
|
+
};
|
|
@@ -7,7 +7,7 @@ import { createCustomEvent, createEvent, createStatusEvent } from '../../libs/au
|
|
|
7
7
|
import logger from '../../libs/logger';
|
|
8
8
|
import { createIdGenerator } from '../../libs/util';
|
|
9
9
|
import { Invoice } from './invoice';
|
|
10
|
-
import type { PaymentDetails, PaymentSettings, PriceRecurring } from './types';
|
|
10
|
+
import type { PaymentDetails, PaymentSettings, PriceRecurring, ServiceAction } from './types';
|
|
11
11
|
|
|
12
12
|
export const nextSubscriptionId = createIdGenerator('sub', 24);
|
|
13
13
|
|
|
@@ -108,6 +108,8 @@ export class Subscription extends Model<InferAttributes<Subscription>, InferCrea
|
|
|
108
108
|
declare proration_behavior?: LiteralUnion<'always_invoice' | 'create_prorations' | 'none', string>;
|
|
109
109
|
declare payment_behavior?: LiteralUnion<'allow_incomplete' | 'error_if_incomplete' | 'pending_if_incomplete', string>;
|
|
110
110
|
|
|
111
|
+
declare service_actions?: ServiceAction[];
|
|
112
|
+
|
|
111
113
|
// TODO: following fields not supported
|
|
112
114
|
// application
|
|
113
115
|
// application_fee_percent
|
|
@@ -287,6 +289,11 @@ export class Subscription extends Model<InferAttributes<Subscription>, InferCrea
|
|
|
287
289
|
type: DataTypes.NUMBER,
|
|
288
290
|
allowNull: true,
|
|
289
291
|
},
|
|
292
|
+
service_actions: {
|
|
293
|
+
type: DataTypes.JSON,
|
|
294
|
+
allowNull: true,
|
|
295
|
+
defaultValue: [],
|
|
296
|
+
},
|
|
290
297
|
},
|
|
291
298
|
{
|
|
292
299
|
sequelize,
|
|
@@ -43,6 +43,14 @@ export type PriceCurrency = {
|
|
|
43
43
|
custom_unit_amount: CustomUnitAmount | null;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
export type ServiceAction = {
|
|
47
|
+
name: string;
|
|
48
|
+
color: string;
|
|
49
|
+
variant: string;
|
|
50
|
+
text: { [key: string]: string };
|
|
51
|
+
link: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
46
54
|
export type CustomUnitAmount = {
|
|
47
55
|
maximum: string;
|
|
48
56
|
minimum: string;
|
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.159",
|
|
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.159",
|
|
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.159",
|
|
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": "2663776fb04b0446e2d053eedfb66d1910c507f8"
|
|
153
153
|
}
|
|
@@ -3,7 +3,7 @@ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
|
3
3
|
import Toast from '@arcblock/ux/lib/Toast';
|
|
4
4
|
import { ConfirmDialog, api, formatError, formatToDate, getSubscriptionAction } from '@blocklet/payment-react';
|
|
5
5
|
import type { TSubscriptionExpanded } from '@blocklet/payment-types';
|
|
6
|
-
import { Button, Stack } from '@mui/material';
|
|
6
|
+
import { Button, Link, Stack } from '@mui/material';
|
|
7
7
|
import { useRequest, useSetState } from 'ahooks';
|
|
8
8
|
import { FormProvider, useForm, useFormContext } from 'react-hook-form';
|
|
9
9
|
import { useNavigate } from 'react-router-dom';
|
|
@@ -29,7 +29,7 @@ const fetchUpdateOptions = ({ id, showUpdate }: { id: string; showUpdate: boolea
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
export function SubscriptionActionsInner({ subscription, showUpdate, onChange }: Props) {
|
|
32
|
-
const { t } = useLocaleContext();
|
|
32
|
+
const { t, locale } = useLocaleContext();
|
|
33
33
|
const { reset, getValues } = useFormContext();
|
|
34
34
|
const navigate = useNavigate();
|
|
35
35
|
const action = getSubscriptionAction(subscription);
|
|
@@ -106,6 +106,19 @@ export function SubscriptionActionsInner({ subscription, showUpdate, onChange }:
|
|
|
106
106
|
{t('payment.customer.upgrade.button')}
|
|
107
107
|
</Button>
|
|
108
108
|
)}
|
|
109
|
+
{subscription.service_actions?.map((x) => (
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
<Button
|
|
112
|
+
component={Link}
|
|
113
|
+
key={x.name}
|
|
114
|
+
variant={x.variant}
|
|
115
|
+
color={x.color}
|
|
116
|
+
href={x.link}
|
|
117
|
+
size="small"
|
|
118
|
+
sx={{ textDecoration: 'none !important' }}>
|
|
119
|
+
{x.text[locale] || x.text.en || x.name}
|
|
120
|
+
</Button>
|
|
121
|
+
))}
|
|
109
122
|
{state.action === 'cancel' && state.subscription && (
|
|
110
123
|
<ConfirmDialog
|
|
111
124
|
onConfirm={handleCancel}
|