payment-kit 1.13.271 → 1.13.272

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.
@@ -277,19 +277,50 @@ export async function ensureInvoiceForCheckout({
277
277
  logger.info(`Invoice already created for checkout session ${checkoutSession.id}: ${checkoutSession.invoice_id}`);
278
278
  const invoice = await Invoice.findByPk(checkoutSession.invoice_id);
279
279
  if (invoice) {
280
- await invoice.update({ status: 'open' });
281
- logger.info(`Invoice status reset for checkout session ${checkoutSession.id}: ${checkoutSession.invoice_id}`);
282
- if (invoice.payment_intent_id) {
283
- await PaymentIntent.update({ status: 'requires_capture' }, { where: { id: invoice.payment_intent_id } });
284
- logger.info(
285
- `PaymentIntent status reset for checkout session ${checkoutSession.id}: ${invoice.payment_intent_id}`
286
- );
280
+ if (invoice.status === 'paid') {
281
+ logger.info(`Invoice already paid for checkout session ${checkoutSession.id}: ${checkoutSession.invoice_id}`);
282
+ throw new Error('Invoice already paid');
283
+ }
284
+
285
+ // invoice currency is aligned
286
+ if (invoice.currency_id === checkoutSession.currency_id) {
287
+ await invoice.update({ status: 'open' });
288
+ logger.info(`Invoice status reset for checkout session ${checkoutSession.id}: ${checkoutSession.invoice_id}`);
289
+
290
+ if (invoice.payment_intent_id) {
291
+ await PaymentIntent.update({ status: 'requires_capture' }, { where: { id: invoice.payment_intent_id } });
292
+ logger.info(
293
+ `PaymentIntent status reset for checkout session ${checkoutSession.id}: ${invoice.payment_intent_id}`
294
+ );
295
+ }
296
+
297
+ return {
298
+ invoice,
299
+ items: await InvoiceItem.findAll({ where: { invoice_id: checkoutSession.invoice_id } }),
300
+ };
301
+ }
302
+
303
+ // invalid currency not aligned: we should generate new invoice
304
+ await invoice.update({ status: 'void' });
305
+ logger.info(`Invoice marked void for checkout session ${checkoutSession.id}: ${checkoutSession.invoice_id}`);
306
+ const method = await PaymentMethod.findByPk(invoice.default_payment_method_id);
307
+ if (method?.type === 'stripe' && invoice.metadata?.stripe_id) {
308
+ const client = method.getStripeClient();
309
+ client.invoices
310
+ .voidInvoice(invoice.metadata.stripe_id)
311
+ .then(() => {
312
+ logger.info(
313
+ `Invoice marked void on stripe for checkout session ${checkoutSession.id}: ${checkoutSession.invoice_id}`
314
+ );
315
+ })
316
+ .catch((err) => {
317
+ logger.error(
318
+ `Invoice marked void on stripe failed for checkout session ${checkoutSession.id}: ${checkoutSession.invoice_id}`,
319
+ err
320
+ );
321
+ });
287
322
  }
288
323
  }
289
- return {
290
- invoice,
291
- items: await InvoiceItem.findAll({ where: { invoice_id: checkoutSession.invoice_id } }),
292
- };
293
324
  }
294
325
 
295
326
  const currency = await PaymentCurrency.findByPk(checkoutSession.currency_id);
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.271
17
+ version: 1.13.272
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.271",
3
+ "version": "1.13.272",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "eject": "vite eject",
@@ -51,7 +51,7 @@
51
51
  "@arcblock/ux": "^2.9.90",
52
52
  "@arcblock/validator": "^1.18.123",
53
53
  "@blocklet/logger": "1.16.26",
54
- "@blocklet/payment-react": "1.13.271",
54
+ "@blocklet/payment-react": "1.13.272",
55
55
  "@blocklet/sdk": "1.16.26",
56
56
  "@blocklet/ui-react": "^2.9.90",
57
57
  "@blocklet/uploader": "^0.1.6",
@@ -116,7 +116,7 @@
116
116
  "devDependencies": {
117
117
  "@abtnode/types": "1.16.26",
118
118
  "@arcblock/eslint-config-ts": "^0.3.0",
119
- "@blocklet/payment-types": "1.13.271",
119
+ "@blocklet/payment-types": "1.13.272",
120
120
  "@types/cookie-parser": "^1.4.7",
121
121
  "@types/cors": "^2.8.17",
122
122
  "@types/dotenv-flow": "^3.3.3",
@@ -155,5 +155,5 @@
155
155
  "parser": "typescript"
156
156
  }
157
157
  },
158
- "gitHead": "cf476c72b4c54fd56881e03828e4b2c764e76e84"
158
+ "gitHead": "b8ed6f58120859dfec4c8dfa1352a9f3b57aad17"
159
159
  }