payment-kit 1.13.76 → 1.13.78
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 +24 -17
- package/blocklet.yml +1 -1
- package/package.json +3 -3
|
@@ -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 () => {
|
|
@@ -677,7 +684,7 @@ router.put('/:id', auth, async (req, res) => {
|
|
|
677
684
|
// Clean up subscriptions that have invalid invoices and payments
|
|
678
685
|
router.delete('/cleanup', auth, async (req, res) => {
|
|
679
686
|
const status = String(req.query.status || 'uncollectible');
|
|
680
|
-
if (['open', 'uncollectible'].includes(status)) {
|
|
687
|
+
if (['open', 'uncollectible'].includes(status) === false) {
|
|
681
688
|
res.json({ error: 'status must be either open or uncollectible' });
|
|
682
689
|
return;
|
|
683
690
|
}
|
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.78",
|
|
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.78",
|
|
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": "a92496a9ecca1977ef963241fae4d2ac79510dbd"
|
|
152
152
|
}
|