payment-kit 1.13.271 → 1.13.273
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.
|
@@ -563,7 +563,7 @@ export async function finalizeStripeSubscriptionUpdate({
|
|
|
563
563
|
// remote item not associated with local item
|
|
564
564
|
const created = await SubscriptionItem.create({
|
|
565
565
|
price_id: item.price_id as string,
|
|
566
|
-
quantity: item.quantity as number,
|
|
566
|
+
quantity: (item.quantity || 1) as number,
|
|
567
567
|
livemode: subscription.livemode,
|
|
568
568
|
subscription_id: subscription.id,
|
|
569
569
|
metadata: {
|
|
@@ -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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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);
|
|
@@ -703,7 +703,9 @@ router.put('/:id', authPortal, async (req, res) => {
|
|
|
703
703
|
addedItems.map(async (x) => {
|
|
704
704
|
const price = await Price.findByPk(x.price_id);
|
|
705
705
|
const stripePrice = await ensureStripePrice(price!, paymentMethod, paymentCurrency);
|
|
706
|
-
return
|
|
706
|
+
return price!.recurring?.usage_type === 'metered'
|
|
707
|
+
? { price: stripePrice.id }
|
|
708
|
+
: { price: stripePrice.id, quantity: x.quantity };
|
|
707
709
|
})
|
|
708
710
|
);
|
|
709
711
|
const updatedStripeItems = await Promise.all(
|
|
@@ -716,7 +718,12 @@ router.put('/:id', authPortal, async (req, res) => {
|
|
|
716
718
|
const deletedStripeItems = await Promise.all(
|
|
717
719
|
deletedItems.map(async (x) => {
|
|
718
720
|
const item = await SubscriptionItem.findByPk(x.id);
|
|
719
|
-
|
|
721
|
+
const price = await Price.findByPk(item!.price_id);
|
|
722
|
+
return {
|
|
723
|
+
id: item!.metadata.stripe_id,
|
|
724
|
+
deleted: true,
|
|
725
|
+
clear_usage: price!.recurring?.usage_type === 'metered',
|
|
726
|
+
};
|
|
720
727
|
})
|
|
721
728
|
);
|
|
722
729
|
|
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.273",
|
|
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.
|
|
54
|
+
"@blocklet/payment-react": "1.13.273",
|
|
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.
|
|
119
|
+
"@blocklet/payment-types": "1.13.273",
|
|
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": "
|
|
158
|
+
"gitHead": "565e708d3d02876ec28c679500fa9a99278bbdc7"
|
|
159
159
|
}
|