payment-kit 1.13.77 → 1.13.79
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.
|
@@ -143,7 +143,7 @@ const paginationSchema = Joi.object<{
|
|
|
143
143
|
});
|
|
144
144
|
router.get('/', auth, async (req, res) => {
|
|
145
145
|
const { page, pageSize, ...query } = await paginationSchema.validateAsync(req.query, { stripUnknown: true });
|
|
146
|
-
const where: WhereOptions<PaymentLink> = {};
|
|
146
|
+
const where: WhereOptions<PaymentLink> = { 'metadata.preview': null };
|
|
147
147
|
|
|
148
148
|
if (typeof query.active === 'boolean') {
|
|
149
149
|
where.active = query.active;
|
|
@@ -3,7 +3,7 @@ import { Router } from 'express';
|
|
|
3
3
|
import Joi from 'joi';
|
|
4
4
|
import pick from 'lodash/pick';
|
|
5
5
|
import uniq from 'lodash/uniq';
|
|
6
|
-
import {
|
|
6
|
+
import type { WhereOptions } from 'sequelize';
|
|
7
7
|
|
|
8
8
|
import { checkPassportForPricingTable } from '../integrations/blocklet/passport';
|
|
9
9
|
import logger from '../libs/logger';
|
|
@@ -164,7 +164,7 @@ const paginationSchema = Joi.object<{
|
|
|
164
164
|
});
|
|
165
165
|
router.get('/', auth, async (req, res) => {
|
|
166
166
|
const { page, pageSize, ...query } = await paginationSchema.validateAsync(req.query, { stripUnknown: true });
|
|
167
|
-
const where: WhereOptions<PricingTable> = {
|
|
167
|
+
const where: WhereOptions<PricingTable> = { 'metadata.preview': null };
|
|
168
168
|
|
|
169
169
|
if (typeof query.active === 'boolean') {
|
|
170
170
|
where.active = query.active;
|
|
@@ -289,10 +289,11 @@ router.post('/stash', auth, async (req, res) => {
|
|
|
289
289
|
raw.locked = false;
|
|
290
290
|
raw.livemode = !!req.livemode;
|
|
291
291
|
raw.created_via = req.user?.via;
|
|
292
|
+
raw.metadata = { preview: '1' };
|
|
292
293
|
|
|
293
294
|
let doc = await PricingTable.findByPk(raw.id);
|
|
294
295
|
if (doc) {
|
|
295
|
-
await doc.update({ ...formatPricingTable(req.body), livemode: raw.livemode });
|
|
296
|
+
await doc.update({ ...formatPricingTable(req.body), metadata: raw.metadata, livemode: raw.livemode });
|
|
296
297
|
} else {
|
|
297
298
|
doc = await PricingTable.create(raw as PricingTable);
|
|
298
299
|
}
|
|
@@ -389,28 +389,22 @@ router.put('/:id', auth, async (req, res) => {
|
|
|
389
389
|
if (!subscription) {
|
|
390
390
|
return res.status(404).json({ error: 'Subscription not found' });
|
|
391
391
|
}
|
|
392
|
-
if (['trailing', 'active'].includes(subscription.status) === false) {
|
|
393
|
-
return res.status(400).json({ error: 'Subscription can only be updated when in trailing or active mode' });
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
const lastInvoice = await Invoice.findByPk(subscription.latest_invoice_id);
|
|
397
|
-
if (!lastInvoice) {
|
|
398
|
-
throw new Error('Subscription should have latest invoice');
|
|
399
|
-
}
|
|
400
|
-
const paymentCurrency = await PaymentCurrency.findByPk(subscription.currency_id);
|
|
401
|
-
if (!paymentCurrency) {
|
|
402
|
-
throw new Error('Subscription should have payment currency');
|
|
403
|
-
}
|
|
404
|
-
const customer = await Customer.findByPk(subscription.customer_id);
|
|
405
|
-
if (!customer) {
|
|
406
|
-
throw new Error('Subscription should have customer');
|
|
407
|
-
}
|
|
408
392
|
|
|
409
393
|
// handle updates
|
|
410
394
|
const updates: Partial<TSubscription> = {};
|
|
411
395
|
if (req.body.metadata) {
|
|
412
396
|
updates.metadata = formatMetadata(req.body.metadata);
|
|
413
397
|
}
|
|
398
|
+
if (subscription.isImmutable()) {
|
|
399
|
+
if (updates.metadata) {
|
|
400
|
+
await subscription.update(updates);
|
|
401
|
+
return res.json({ subscription });
|
|
402
|
+
}
|
|
403
|
+
return res.status(400).json({ error: 'Only metadata can be updated when subscription is immutable' });
|
|
404
|
+
}
|
|
405
|
+
if (subscription.isActive() === false) {
|
|
406
|
+
return res.status(400).json({ error: 'Subscription can only be updated when active' });
|
|
407
|
+
}
|
|
414
408
|
if (req.body.description) {
|
|
415
409
|
updates.description = req.body.description;
|
|
416
410
|
}
|
|
@@ -421,6 +415,19 @@ router.put('/:id', auth, async (req, res) => {
|
|
|
421
415
|
updates.proration_behavior = req.body.proration_behavior;
|
|
422
416
|
}
|
|
423
417
|
|
|
418
|
+
const lastInvoice = await Invoice.findByPk(subscription.latest_invoice_id);
|
|
419
|
+
if (!lastInvoice) {
|
|
420
|
+
throw new Error('Subscription should have latest invoice');
|
|
421
|
+
}
|
|
422
|
+
const paymentCurrency = await PaymentCurrency.findByPk(subscription.currency_id);
|
|
423
|
+
if (!paymentCurrency) {
|
|
424
|
+
throw new Error('Subscription should have payment currency');
|
|
425
|
+
}
|
|
426
|
+
const customer = await Customer.findByPk(subscription.customer_id);
|
|
427
|
+
if (!customer) {
|
|
428
|
+
throw new Error('Subscription should have customer');
|
|
429
|
+
}
|
|
430
|
+
|
|
424
431
|
let invoice: Invoice;
|
|
425
432
|
|
|
426
433
|
await sequelize.transaction({ isolationLevel: Transaction.ISOLATION_LEVELS.READ_UNCOMMITTED }, async () => {
|
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.79",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "COMPONENT_STORE_URL=https://test.store.blocklet.dev blocklet dev",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"@abtnode/types": "^1.16.20",
|
|
110
110
|
"@arcblock/eslint-config": "^0.2.4",
|
|
111
111
|
"@arcblock/eslint-config-ts": "^0.2.4",
|
|
112
|
-
"@did-pay/types": "1.13.
|
|
112
|
+
"@did-pay/types": "1.13.79",
|
|
113
113
|
"@types/cookie-parser": "^1.4.6",
|
|
114
114
|
"@types/cors": "^2.8.17",
|
|
115
115
|
"@types/dotenv-flow": "^3.3.3",
|
|
@@ -148,5 +148,5 @@
|
|
|
148
148
|
"parser": "typescript"
|
|
149
149
|
}
|
|
150
150
|
},
|
|
151
|
-
"gitHead": "
|
|
151
|
+
"gitHead": "2e35efe8ba1977c9547af7eeafeb29aeee257a90"
|
|
152
152
|
}
|