New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

next-stripe-helper

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-stripe-helper - npm Package Compare versions

Comparing version 1.1.16 to 1.1.17

18

dist/subscriptions/index.d.ts

@@ -38,3 +38,17 @@ import Stripe from "stripe";

*/
declare function changeSubscriptionPlan(subscriptionId: string, options: Stripe.SubscriptionUpdateParams): Promise<Stripe.Subscription>;
declare function updateSubscriptionPlan(subscriptionId: string, options: Stripe.SubscriptionUpdateParams): Promise<Stripe.Subscription>;
/**
* Updates a customer's subscription to a new plan. Deletes the old one plan, adds the new one to the subscription, and charges the prorated price.
*
*
* @param {string} subscriptionId - Subscription ID
*
* @param {string} oldItemId - Item ID that you want to update.
*
* @param {string} newPriceId - PRICE ID that you want to change to.
*
* @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.
*/
declare function changeSubscriptionPlan(subscriptionId: string, oldItemId: string, newPriceId: string): Promise<Stripe.Subscription>;
declare function listUserSubscriptions(customerID: string): Promise<Stripe.Subscription[]>;

@@ -53,2 +67,2 @@ declare function cancelUserSubscription(subscriptionID: string): Promise<Stripe.Subscription>;

}>;
export { createSubscription, getUserCurrentPlan, getUserSubscription, getUserSubscriptions, getUserSubscriptionDetails, updateUserSubscriptionMetadata, listUserSubscriptions, changeSubscriptionPlan, cancelUserSubscription, getSubscriptionPeriod };
export { createSubscription, getUserCurrentPlan, getUserSubscription, getUserSubscriptions, getUserSubscriptionDetails, updateUserSubscriptionMetadata, listUserSubscriptions, changeSubscriptionPlan, updateSubscriptionPlan, cancelUserSubscription, getSubscriptionPeriod };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSubscriptionPeriod = exports.cancelUserSubscription = exports.changeSubscriptionPlan = exports.listUserSubscriptions = exports.updateUserSubscriptionMetadata = exports.getUserSubscriptionDetails = exports.getUserSubscriptions = exports.getUserSubscription = exports.getUserCurrentPlan = exports.createSubscription = void 0;
exports.getSubscriptionPeriod = exports.cancelUserSubscription = exports.updateSubscriptionPlan = exports.changeSubscriptionPlan = exports.listUserSubscriptions = exports.updateUserSubscriptionMetadata = exports.getUserSubscriptionDetails = exports.getUserSubscriptions = exports.getUserSubscription = exports.getUserCurrentPlan = exports.createSubscription = void 0;
const stripe_1 = require("../utils/stripe");

@@ -116,3 +116,3 @@ /**

*/
async function changeSubscriptionPlan(subscriptionId, options) {
async function updateSubscriptionPlan(subscriptionId, options) {
try {

@@ -128,2 +128,38 @@ // Update the subscription to a new plan

}
exports.updateSubscriptionPlan = updateSubscriptionPlan;
/**
* Updates a customer's subscription to a new plan. Deletes the old one plan, adds the new one to the subscription, and charges the prorated price.
*
*
* @param {string} subscriptionId - Subscription ID
*
* @param {string} oldItemId - Item ID that you want to update.
*
* @param {string} newPriceId - PRICE ID that you want to change to.
*
* @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, oldItemId, newPriceId) {
try {
// Update the subscription to a new plan
const updatedSubscription = await stripe_1.stripe.subscriptions.update(subscriptionId, {
proration_behavior: "always_invoice",
items: [
{
id: oldItemId,
deleted: true,
},
{
price: newPriceId,
},
],
});
return updatedSubscription;
}
catch (error) {
console.error("Error updating subscription:", error);
throw error;
}
}
exports.changeSubscriptionPlan = changeSubscriptionPlan;

@@ -130,0 +166,0 @@ async function listUserSubscriptions(customerID) {

2

package.json
{
"name": "next-stripe-helper",
"version": "1.1.16",
"version": "1.1.17",
"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",

@@ -283,7 +283,23 @@ # next-stripe-helper

### Update a User's Subscription
Update a users existing subscription:
This will use the current payment method by default.
Customer must have an existing subscription.
```javascript
const subscriptionDetails = await changeSubscriptionPlan('subscription_id', 'options object')
```
Parameters:
- `subscriptionID` (required): The Stripe ID of the existing subscription.
- `options` : The Stripe api subscription update parameters.
### Change a User's Subscription
Change a users existing subscription using its Stripe ID:
Change a users existing subscription first item product/price using its Stripe ID:
Deletes the old one plan and adds the new one to the subscription.
Deletes the old one plan/price and adds the new one to the subscription item.
This will use the current payment method by default.

@@ -290,0 +306,0 @@ Customer must have an existing subscription.

@@ -124,3 +124,3 @@ import Stripe from "stripe";

*/
async function changeSubscriptionPlan(subscriptionId:string, options: Stripe.SubscriptionUpdateParams): Promise<Stripe.Subscription> {
async function updateSubscriptionPlan(subscriptionId:string, options: Stripe.SubscriptionUpdateParams): Promise<Stripe.Subscription> {
try {

@@ -138,2 +138,40 @@

/**
* Updates a customer's subscription to a new plan. Deletes the old one plan, adds the new one to the subscription, and charges the prorated price.
*
*
* @param {string} subscriptionId - Subscription ID
*
* @param {string} oldItemId - Item ID that you want to update.
*
* @param {string} newPriceId - PRICE ID that you want to change to.
*
* @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, oldItemId:string, newPriceId:string): Promise<Stripe.Subscription> {
try {
// Update the subscription to a new plan
const updatedSubscription = await stripe.subscriptions.update(subscriptionId, {
proration_behavior: "always_invoice",
items: [
{
id: oldItemId,
deleted: true,
},
{
price: newPriceId,
},
],
});
return updatedSubscription;
} catch (error) {
console.error("Error updating subscription:", error);
throw error;
}
}
async function listUserSubscriptions(customerID: string): Promise<Stripe.Subscription[]> {

@@ -194,4 +232,5 @@ try {

changeSubscriptionPlan,
updateSubscriptionPlan,
cancelUserSubscription,
getSubscriptionPeriod
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc