next-stripe-helper
Advanced tools
Comparing version 1.1.41 to 1.1.42
@@ -333,20 +333,35 @@ "use strict"; | ||
const subscriptionItem = subscription.items.data.find(item => item.price.id === priceId); | ||
if (!subscriptionItem) { | ||
throw new Error('Subscription item not found for the specified price'); | ||
} | ||
newQuantity = Number(newQuantity); | ||
if (newQuantity === 0) { | ||
// Delete the subscription item if the new quantity is 0 | ||
await stripe_1.stripe.subscriptionItems.del(subscriptionItem.id, { | ||
proration_behavior | ||
}); | ||
return null; | ||
if (subscriptionItem) { | ||
if (newQuantity === 0) { | ||
// Delete the subscription item if the new quantity is 0 | ||
await stripe_1.stripe.subscriptionItems.del(subscriptionItem.id, { | ||
proration_behavior | ||
}); | ||
return null; | ||
} | ||
else { | ||
// Update the quantity of the subscription item | ||
const updatedSubscriptionItem = await stripe_1.stripe.subscriptionItems.update(subscriptionItem.id, { | ||
quantity: newQuantity, | ||
proration_behavior | ||
}); | ||
return updatedSubscriptionItem; | ||
} | ||
} | ||
else { | ||
// Update the quantity of the subscription item | ||
const updatedSubscriptionItem = await stripe_1.stripe.subscriptionItems.update(subscriptionItem.id, { | ||
quantity: newQuantity, | ||
proration_behavior | ||
}); | ||
return updatedSubscriptionItem; | ||
if (newQuantity > 0) { | ||
// Create a new subscription item if it doesn't exist and the new quantity is greater than 0 | ||
const newSubscriptionItem = await stripe_1.stripe.subscriptionItems.create({ | ||
subscription: subscriptionID, | ||
price: priceId, | ||
quantity: newQuantity, | ||
proration_behavior | ||
}); | ||
return newSubscriptionItem; | ||
} | ||
else { | ||
// No action needed if the new quantity is 0 and the item doesn't exist on the subscription | ||
return null; | ||
} | ||
} | ||
@@ -353,0 +368,0 @@ } |
{ | ||
"name": "next-stripe-helper", | ||
"version": "1.1.41", | ||
"version": "1.1.42", | ||
"description": "Easily add Stripe boilerplate code to Nextjs, like webhook handling, and subscription updates. This package provides a thin wrapper around the Stripe API, and makes integrating Stripe and NextJS a lot faster!", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -390,2 +390,6 @@ # next-stripe-helper | ||
This function will ADD an item to a subscription, or UPDATE the quantity if an item is already present on the subscription. | ||
If the quantity is 0, the item will be DELETED from the subscription. | ||
This will use the current payment method by default. | ||
@@ -392,0 +396,0 @@ Customer must have an existing subscription. |
Sorry, the diff of this file is not supported yet
108216
1176
988