payment-kit 1.15.22 → 1.15.23

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.
@@ -10,7 +10,7 @@ import { createListParamSchema, getWhereFromKvQuery, MetadataSchema } from '../l
10
10
  import { authenticate } from '../libs/security';
11
11
  import { expandLineItems } from '../libs/session';
12
12
  import { formatMetadata } from '../libs/util';
13
- import { Refund } from '../store/models';
13
+ import { Refund, SetupIntent } from '../store/models';
14
14
  import { Customer } from '../store/models/customer';
15
15
  import { Invoice } from '../store/models/invoice';
16
16
  import { InvoiceItem } from '../store/models/invoice-item';
@@ -131,23 +131,27 @@ router.get('/', authMine, async (req, res) => {
131
131
  subscription = await Subscription.findByPk(query.subscription_id);
132
132
  if (subscription?.payment_details?.arcblock?.staking?.tx_hash) {
133
133
  const method = await PaymentMethod.findOne({ where: { type: 'arcblock', livemode: subscription.livemode } });
134
- if (method) {
134
+ const setup = await SetupIntent.findOne({
135
+ where: {
136
+ customer_id: subscription.customer_id,
137
+ payment_method_id: method?.id,
138
+ metadata: { subscription_id: subscription.id },
139
+ },
140
+ order: [['created_at', 'ASC']],
141
+ });
142
+ const currencyId = setup?.currency_id || subscription.currency_id;
143
+ const currency = await PaymentCurrency.findByPk(currencyId);
144
+ if (method && currency) {
135
145
  const { address } = subscription.payment_details.arcblock.staking;
136
146
  const firstInvoice = await Invoice.findOne({
137
- where: { subscription_id: subscription.id },
147
+ where: { subscription_id: subscription.id, currency_id: currencyId },
138
148
  order: [['created_at', 'ASC']],
139
149
  include: [{ model: PaymentCurrency, as: 'paymentCurrency' }],
140
150
  });
141
- const last = query.o === 'asc' ? list?.[list.length - 1] : list?.[0];
142
- if (subscription.payment_details.arcblock.staking.tx_hash && firstInvoice) {
151
+ if (firstInvoice) {
143
152
  const customer = await Customer.findByPk(firstInvoice.customer_id);
144
- const currency =
145
- // @ts-ignore
146
- firstInvoice?.paymentCurrency ||
147
- (await PaymentCurrency.findOne({
148
- where: { payment_method_id: method.id, is_base_currency: true },
149
- }));
150
153
  const stakeAmountResult = await getSubscriptionStakeAmountSetup(subscription, method);
154
+ // @ts-ignore
151
155
  const stakeAmount = stakeAmountResult?.[currency?.contract] || '0';
152
156
 
153
157
  list.push({
@@ -187,7 +191,6 @@ router.get('/', authMine, async (req, res) => {
187
191
  const stakeRefundRecord = await Refund.findOne({
188
192
  where: { subscription_id: subscription.id, status: 'succeeded', type: 'stake_return' },
189
193
  });
190
-
191
194
  if (stakeRefundRecord) {
192
195
  list.unshift({
193
196
  id: address as string,
@@ -198,18 +201,15 @@ router.get('/', authMine, async (req, res) => {
198
201
  amount_due: '0',
199
202
  amount_paid: stakeRefundRecord.amount,
200
203
  amount_remaining: '0',
201
- ...pick(last, [
202
- 'number',
203
- 'paid',
204
- 'auto_advance',
205
- 'currency_id',
206
- 'customer_id',
207
- 'subscription_id',
208
- 'period_start',
209
- 'period_end',
210
- 'created_at',
211
- 'updated_at',
212
- ]),
204
+ created_at: stakeRefundRecord.created_at,
205
+ updated_at: stakeRefundRecord.updated_at,
206
+ currency_id: stakeRefundRecord.currency_id,
207
+ customer_id: stakeRefundRecord.customer_id,
208
+ subscription_id: subscription.id,
209
+ period_start: subscription.current_period_start,
210
+ period_end: subscription.current_period_end,
211
+ paid: true,
212
+ ...pick(firstInvoice, ['number', 'auto_advance']),
213
213
  // @ts-ignore
214
214
  paymentCurrency: currency,
215
215
  paymentMethod: method,
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.15.22
17
+ version: 1.15.23
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.15.22",
3
+ "version": "1.15.23",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "eject": "vite eject",
@@ -52,7 +52,7 @@
52
52
  "@arcblock/validator": "^1.18.136",
53
53
  "@blocklet/js-sdk": "^1.16.32",
54
54
  "@blocklet/logger": "^1.16.32",
55
- "@blocklet/payment-react": "1.15.22",
55
+ "@blocklet/payment-react": "1.15.23",
56
56
  "@blocklet/sdk": "^1.16.32",
57
57
  "@blocklet/ui-react": "^2.10.51",
58
58
  "@blocklet/uploader": "^0.1.46",
@@ -118,7 +118,7 @@
118
118
  "devDependencies": {
119
119
  "@abtnode/types": "^1.16.32",
120
120
  "@arcblock/eslint-config-ts": "^0.3.3",
121
- "@blocklet/payment-types": "1.15.22",
121
+ "@blocklet/payment-types": "1.15.23",
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": "12a3cbcf04d0c8bdbbf33c04d07cecfb24bd3e9b"
163
+ "gitHead": "94862642b9c4f0f753a47e8c68d9b70315d8f008"
164
164
  }