#smartbettormicah-developer_code

1 messages ¡ Page 1 of 1 (latest)

prime copperBOT
#

👋 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.

timid spruce
#

Hi there

naive lark
#

Hello

timid spruce
naive lark
#

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

timid spruce
#

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?

naive lark
#

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

timid spruce
#

I don't think you got the full Customer Portal Session id there

naive lark
#

bps_1RJihrHM5Jv8uc5MGFU6YRNh Is this the session id?

timid spruce
#

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

naive lark
#

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

prime copperBOT
timid spruce
#

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.

#

Its an array of objects

naive lark
#

Gotcha so it is a mapping of product to prices

timid spruce
#

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

naive lark
#

That makes sense! What about for the proration behavior?

timid spruce