payment-kit 1.14.0 → 1.14.2

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.
@@ -1,5 +1,5 @@
1
1
  import { BN } from '@ocap/util';
2
- import type { WhereOptions } from 'sequelize';
2
+ import { Op, type WhereOptions } from 'sequelize';
3
3
  import { PaymentIntent, Refund } from '../store/models';
4
4
 
5
5
  export async function getRefundAmountSetup({
@@ -20,7 +20,9 @@ export async function getRefundAmountSetup({
20
20
  throw new Error('PaymentIntent not found');
21
21
  }
22
22
  const where: WhereOptions<Refund> = {
23
- status: ['succeeded'],
23
+ status: {
24
+ [Op.not]: 'canceled',
25
+ },
24
26
  payment_intent_id: paymentIntentId,
25
27
  };
26
28
  if (currencyId) {
@@ -6,6 +6,7 @@ import pick from 'lodash/pick';
6
6
  import type { LiteralUnion } from 'type-fest';
7
7
  import { withQuery } from 'ufo';
8
8
 
9
+ import { Op } from 'sequelize';
9
10
  import {
10
11
  Customer,
11
12
  Invoice,
@@ -642,7 +643,13 @@ export async function getRemainingStakes(subscriptionIds: string[], subscription
642
643
  await Promise.all(
643
644
  subscriptionIds.map(async (subscriptionId) => {
644
645
  const refund = await Refund.findOne({
645
- where: { subscription_id: subscriptionId, status: 'succeeded', type: 'stake_return' },
646
+ where: {
647
+ subscription_id: subscriptionId,
648
+ status: {
649
+ [Op.not]: 'canceled',
650
+ },
651
+ type: 'stake_return',
652
+ },
646
653
  });
647
654
  if (!refund) {
648
655
  // this subscription not return stake
@@ -224,6 +224,14 @@ const handleSubscriptionWhenActive = async (subscription: Subscription) => {
224
224
  }
225
225
  }
226
226
 
227
+ // change to active if still in trialing
228
+ if (subscription.status === 'trialing') {
229
+ const now = dayjs().unix();
230
+ if (subscription.trial_end && subscription.trial_end <= now) {
231
+ await subscription.update({ status: 'active' });
232
+ }
233
+ }
234
+
227
235
  const invoice = await handleSubscriptionInvoice({
228
236
  subscription,
229
237
  filter: () => true, // include all items
@@ -1008,12 +1008,14 @@ router.put('/:id', authPortal, async (req, res) => {
1008
1008
  await subscription.update(updates);
1009
1009
  } else {
1010
1010
  const now = dayjs().unix();
1011
+ let jobRunAt = 0;
1011
1012
  let shouldCycle = false;
1012
1013
  let periodChanged = false;
1013
1014
  if (value.trial_end && subscription.isActive()) {
1014
1015
  if (value.trial_end === 'now') {
1015
1016
  if (subscription.status === 'trialing') {
1016
1017
  updates.trial_end = now;
1018
+ jobRunAt = now;
1017
1019
  shouldCycle = true;
1018
1020
  periodChanged = true;
1019
1021
  } else {
@@ -1021,6 +1023,8 @@ router.put('/:id', authPortal, async (req, res) => {
1021
1023
  }
1022
1024
  } else if ((value.trial_end as number) > now) {
1023
1025
  updates.trial_end = value.trial_end as number;
1026
+ jobRunAt = updates.trial_end;
1027
+ shouldCycle = true;
1024
1028
  periodChanged = true;
1025
1029
  } else {
1026
1030
  throw new Error('trial_end must be a future timestamp');
@@ -1062,7 +1066,7 @@ router.put('/:id', authPortal, async (req, res) => {
1062
1066
  });
1063
1067
  }
1064
1068
  if (shouldCycle) {
1065
- await addSubscriptionJob(subscription, 'cycle', true, now);
1069
+ await addSubscriptionJob(subscription, 'cycle', true, jobRunAt);
1066
1070
  logger.info('subscription job rescheduled on period end', { subscription: subscription.id });
1067
1071
  }
1068
1072
  }
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.14.0
17
+ version: 1.14.2
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.14.0",
3
+ "version": "1.14.2",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "eject": "vite eject",
@@ -52,7 +52,7 @@
52
52
  "@arcblock/validator": "^1.18.124",
53
53
  "@blocklet/js-sdk": "1.16.28",
54
54
  "@blocklet/logger": "1.16.28",
55
- "@blocklet/payment-react": "1.14.0",
55
+ "@blocklet/payment-react": "1.14.2",
56
56
  "@blocklet/sdk": "1.16.28",
57
57
  "@blocklet/ui-react": "^2.10.3",
58
58
  "@blocklet/uploader": "^0.1.20",
@@ -118,7 +118,7 @@
118
118
  "devDependencies": {
119
119
  "@abtnode/types": "1.16.28",
120
120
  "@arcblock/eslint-config-ts": "^0.3.2",
121
- "@blocklet/payment-types": "1.14.0",
121
+ "@blocklet/payment-types": "1.14.2",
122
122
  "@types/cookie-parser": "^1.4.7",
123
123
  "@types/cors": "^2.8.17",
124
124
  "@types/debug": "^4.1.12",
@@ -160,5 +160,5 @@
160
160
  "parser": "typescript"
161
161
  }
162
162
  },
163
- "gitHead": "f39e47fae8a2c10598c6ee28e10b76f338b14c97"
163
+ "gitHead": "a4a936dc1b6bb74eb02674cd619d453410b1aa86"
164
164
  }