next-stripe-helper
Advanced tools
Comparing version 1.0.9 to 1.0.10
{ | ||
"name": "next-stripe-helper", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"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": "index.js", |
@@ -230,2 +230,3 @@ # next-stripe-helper | ||
updateUserSubscriptionMetadata, | ||
changeSubscriptionPlan, | ||
listUserSubscriptions, | ||
@@ -263,2 +264,16 @@ cancelUserSubscription | ||
### Change a User's Subscription | ||
Change a users existing subscription using its Stripe ID: | ||
```javascript | ||
const subscriptionDetails = await changeSubscriptionPlan('subscription_id', 'new_plan_id') | ||
``` | ||
Parameters: | ||
- `subscriptionID` (required): The Stripe ID of the existing subscription. | ||
- `new_plan_id` (required): The Stripe plan ID of the new plan. | ||
### Get Detailed Information About a Subscription | ||
@@ -265,0 +280,0 @@ |
@@ -91,2 +91,26 @@ import Stripe from "stripe"; | ||
/** | ||
* Updates a customer's subscription to a new plan. | ||
* | ||
* @param {string} subscriptionId - The ID of the subscription to be updated. | ||
* @param {string} newPlanId - The ID of the new plan to which the subscription should be updated. | ||
* @returns {Promise<Stripe.Subscription>} - A promise that resolves to the updated subscription. | ||
* @throws {Error} - Throws an error if there's an issue updating the subscription. | ||
*/ | ||
async function changeSubscriptionPlan(subscriptionId: string, newPlanId: string): Promise<Stripe.Subscription> { | ||
try { | ||
// Update the subscription to a new plan | ||
const updatedSubscription = await stripe.subscriptions.update(subscriptionId, { | ||
items: [{ | ||
id: subscriptionId, | ||
plan: newPlanId | ||
}] | ||
}); | ||
return updatedSubscription; | ||
} catch (error) { | ||
console.error("Error updating subscription:", error); | ||
throw error; | ||
} | ||
} | ||
async function listUserSubscriptions(customerID: string): Promise<Stripe.Subscription[]> { | ||
@@ -145,4 +169,5 @@ try { | ||
listUserSubscriptions, | ||
changeSubscriptionPlan, | ||
cancelUserSubscription, | ||
getSubscriptionPeriod | ||
} |
43447
531
721