#smartbettormicah-developer_code
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1367253586706305154
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- smartbettormicah-developer_api, 2 days ago, 7 messages
Hi there
Hello
You need to control what the customer can or can't do in the Billing Portal via the Billing Portal Configuration. https://docs.stripe.com/customer-management/integrate-customer-portal
So yes, if you don't want them to be able to cancel, you need to turn off that feature in the Billing Portal configuration
const session = await stripe.billingPortal.sessions.create({
customer: customerId,
return_url: ${request.headers.get('origin')}/account,
});
How would i change this code. I am not seeing the proper syntax for js in that doc
const configuration = await stripe.billingPortal.configurations.create({
features: {
subscription_cancel: {
enabled: false
}
}
});
// Create a billing portal session with the configuration
const session = await stripe.billingPortal.sessions.create({
customer: customerId,
return_url: `${request.headers.get('origin')}/account`,
configuration: configuration.id
});
When I add a configuration object it does not properly redirect, it just pops up and closes immediately
You need to a) have a configuration that does the things you want and b) provide that configuration when creating a session, as you've done in your most recent code snippet
Can you elaborate on what is going wrong? Can you give me the Customer Portal Session id that you are creating?
export async function POST(request: Request) {
try {
const { customerId } = await request.json();
if (!customerId) {
return NextResponse.json(
{ error: 'Customer ID is required' },
{ status: 400 }
);
}
// Create a portal configuration with only subscription_cancel disabled
const configuration = await stripe.billingPortal.configurations.create({
features: {
subscription_cancel: {
enabled: false
}
}
});
console.log(customerId, 'customerId');
// Create a billing portal session with the configuration
const session = await stripe.billingPortal.sessions.create({
customer: customerId,
return_url: `${request.headers.get('origin')}/account`,
configuration: configuration.id
});
return NextResponse.json({ url: session.url });
} catch (error) {
console.log(error);
console.error('Error creating portal session:', error);
return NextResponse.json(
{ error: 'Failed to create portal session' },
{ status: 500 }
);
}
}
Yes I create it like this and sorry I was not specific enough. The Customer portal session. id that is created is live_YWNjdF8xTm0wdkJITTVKdjh1YzVNLF9TRUF4R0c0VzdlNHdzbTI2QkZuYk9Ra1AyQ2ZZUXE40100ZCxXZ81B. The problem is that it is not showing the update option and add card option
I don't think you got the full Customer Portal Session id there
bps_1RJihrHM5Jv8uc5MGFU6YRNh Is this the session id?
Yep, let me look
That's because the Billing Portal Configuration that you've used doesn't really do anything
I would suggest that you take some time and read the docs on the Customer Portal to understand what the Configuration really does - it defines explicitly what things can and cannot be done in a particular portal session
Okay I have questions on two of the params
features.subscription_update.products: What is the syntax for this, if I want to put two products I tried a list of strings but got and error
features.subscription_update.proration_behavior: Could you explain what each of the options means, it is not clear
I really recommend keeping the API reference close to hand when you're working on something like this - we provide good detail on every parameter.
This parameter is a list/array of Products & Prices. It means that Subscriptions that are subscribed to products in this list are elligible for Subscription updates
Its an array of objects
Gotcha so it is a mapping of product to prices
Its a list of Products & Prices that are elligible for updates; there is a one-to-many relationship between Products & Prices, so you might have 5 Prices on a Product
That makes sense! What about for the proration behavior?
Prorations in Subscriptions are a complicated topic and we have an entire guide on them: https://docs.stripe.com/billing/subscriptions/prorations