next-stripe-helper
Advanced tools
Comparing version 1.1.35 to 1.1.36
@@ -212,12 +212,14 @@ "use strict"; | ||
if (subscriptionItem) { | ||
// If the subscription item exists, update its quantity | ||
// Ensure the quantities are treated as numbers | ||
const currentQuantity = Number(subscriptionItem.quantity); | ||
const newQuantity = currentQuantity + additionalQuantity; | ||
// Update the quantity of the subscription item | ||
const updatedSubscriptionItem = await stripe_1.stripe.subscriptionItems.update(subscriptionItem.id, { | ||
quantity: (subscriptionItem.quantity || 0) + additionalQuantity, | ||
proration_behavior, | ||
quantity: newQuantity, | ||
proration_behavior | ||
}); | ||
console.log('Subscription item updated:', updatedSubscriptionItem.id); | ||
return updatedSubscriptionItem; | ||
} | ||
else { | ||
// If the subscription item doesn't exist, create a new subscription item | ||
// Create a new subscription item if it doesn't exist | ||
const newSubscriptionItem = await stripe_1.stripe.subscriptionItems.create({ | ||
@@ -229,3 +231,2 @@ subscription: subscriptionId, | ||
}); | ||
console.log('Subscription item created:', newSubscriptionItem.id); | ||
return newSubscriptionItem; | ||
@@ -248,4 +249,5 @@ } | ||
} | ||
const currentQuantity = Number(subscriptionItem.quantity); | ||
// Calculate the new quantity | ||
const newQuantity = Math.max(subscriptionItem.quantity - removeQuantity, 0); | ||
const newQuantity = Math.max(currentQuantity - removeQuantity, 0); | ||
if (newQuantity === 0) { | ||
@@ -286,4 +288,5 @@ // If the new quantity is 0, delete the subscription item | ||
} | ||
const currentQuantity = Number(subscriptionItem.quantity); | ||
// Calculate the new quantity | ||
const newQuantity = Math.max(subscriptionItem.quantity - removeQuantity, 0); | ||
const newQuantity = Math.max(currentQuantity - removeQuantity, 0); | ||
if (newQuantity === 0) { | ||
@@ -290,0 +293,0 @@ // If the new quantity is 0, delete the subscription item |
{ | ||
"name": "next-stripe-helper", | ||
"version": "1.1.35", | ||
"version": "1.1.36", | ||
"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", |
@@ -363,3 +363,3 @@ # next-stripe-helper | ||
- `priceId` (required): The Stripe Price ID of the item. | ||
- `quantity` (optional): The quantity of the item you are adding. Defaults to 1. Will add to existing quantity. | ||
- `quantity` (optional): The quantity of the item you are adding. Defaults to 1. Will add to existing quantity or add the item to the subsdcription if it doesnt exist. | ||
- `proration_behavior` (optional): Determines how to handle prorations when the billing cycle changes (e.g., when switching plans, resetting billing_cycle_anchor=now, or starting a trial), or if an item’s quantity changes. The default value is always_invoice. ('create_prorations', 'none', 'always_invoice') | ||
@@ -366,0 +366,0 @@ |
Sorry, the diff of this file is not supported yet
98954
1096