payment-kit 1.13.138 → 1.13.140

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.
@@ -228,25 +228,26 @@ router.put('/:id/cancel', authPortal, async (req, res) => {
228
228
  comment: `Requested by ${req.user?.role}:${req.user?.did}`,
229
229
  },
230
230
  };
231
+ const now = dayjs().unix() + 3;
231
232
  if (req.user?.via === 'portal') {
232
233
  updates.cancel_at_period_end = true;
233
234
  updates.cancel_at = subscription.current_period_end;
234
235
  updates.cancelation_details = { reason: 'cancellation_requested', feedback, comment };
235
- updates.canceled_at = dayjs().unix();
236
+ updates.canceled_at = now;
236
237
  await addSubscriptionJob(subscription, 'cancel', true, updates.cancel_at);
237
238
  } else if (at === 'now') {
238
239
  updates.status = 'canceled';
239
- updates.cancel_at = dayjs().unix();
240
- updates.canceled_at = dayjs().unix();
240
+ updates.cancel_at = now;
241
+ updates.canceled_at = now;
241
242
  await addSubscriptionJob(subscription, 'cancel', true, updates.cancel_at);
242
243
  } else if (at === 'current_period_end') {
243
244
  updates.cancel_at_period_end = true;
244
245
  updates.cancel_at = subscription.current_period_end;
245
- updates.canceled_at = dayjs().unix();
246
+ updates.canceled_at = now;
246
247
  await addSubscriptionJob(subscription, 'cancel', true, updates.cancel_at);
247
248
  } else {
248
249
  updates.cancel_at = dayjs(time).unix();
249
- updates.canceled_at = dayjs().unix();
250
+ updates.canceled_at = now;
250
251
  await addSubscriptionJob(
251
252
  subscription,
252
253
  'cancel',
@@ -259,15 +260,20 @@ router.put('/:id/cancel', authPortal, async (req, res) => {
259
260
  const method = await PaymentMethod.findByPk(subscription.default_payment_method_id);
260
261
  if (method && method.type === 'stripe') {
261
262
  const client = method.getStripeClient();
262
- if (updates.cancel_at_period_end) {
263
- await client.subscriptions.update(subscription.payment_details.stripe.subscription_id, {
264
- cancel_at_period_end: updates.cancel_at_period_end,
265
- });
266
- } else {
267
- await client.subscriptions.update(subscription.payment_details.stripe.subscription_id, {
268
- cancel_at: updates.cancel_at,
269
- proration_behavior: 'none',
270
- });
263
+ try {
264
+ if (updates.cancel_at_period_end) {
265
+ await client.subscriptions.update(subscription.payment_details.stripe.subscription_id, {
266
+ cancel_at_period_end: updates.cancel_at_period_end,
267
+ });
268
+ } else {
269
+ await client.subscriptions.update(subscription.payment_details.stripe.subscription_id, {
270
+ cancel_at: updates.cancel_at,
271
+ proration_behavior: 'none',
272
+ });
273
+ }
274
+ } catch (err) {
275
+ // FIXME: how do we handle failure here?
276
+ logger.error('subscription cancel failed on stripe', { subscription: req.params.id, updates, error: err });
271
277
  }
272
278
  }
273
279
  }
@@ -619,9 +625,6 @@ router.put('/:id', authPortal, async (req, res) => {
619
625
  if (!paymentMethod) {
620
626
  throw new Error('Subscription should have payment method');
621
627
  }
622
- if (paymentMethod.type === 'stripe') {
623
- throw new Error('Update is not supported for subscriptions paid with stripe');
624
- }
625
628
 
626
629
  const paymentCurrency = await PaymentCurrency.findByPk(subscription.currency_id);
627
630
  if (!paymentCurrency) {
@@ -643,6 +646,10 @@ router.put('/:id', authPortal, async (req, res) => {
643
646
  }
644
647
 
645
648
  if (Array.isArray(req.body.items) && req.body.items.length > 0) {
649
+ if (paymentMethod.type === 'stripe') {
650
+ throw new Error('Update is not supported for subscriptions paid with stripe');
651
+ }
652
+
646
653
  // validate the request
647
654
  const { existingItems, addedItems, updatedItems, deletedItems, newItems } =
648
655
  await validateSubscriptionUpdateRequest(subscription, req.body.items);
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.138
17
+ version: 1.13.140
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.138",
3
+ "version": "1.13.140",
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.138",
53
+ "@blocklet/payment-react": "1.13.140",
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.138",
113
+ "@blocklet/payment-types": "1.13.140",
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": "2865a4ed4a06029cd97a4f0914c1c3c61b5182cb"
152
+ "gitHead": "7b3ce2e76dfaab3fb7a445c014b73d898cbd5481"
153
153
  }