#israel_link-checkout

1 messages ยท Page 1 of 1 (latest)

shell ravenBOT
#

๐Ÿ‘‹ 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/1216789213023047700

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

wild sealBOT
clever comet
#

Hi ๐Ÿ‘‹

Why would you expect the Checkout Session to show previously saved payment methods?

celest crypt
#

Because when a customer cancels a plan, my website blocks his access to the features and allows him to purchase a new plan from the price table, but in this case he would have to have the option of using the payment method he had already registered before cancel the plan.

#

Hi o/

clever comet
celest crypt
#

Is it possible to do a checkout with a link through the stripe price table?

clever comet
#

Link would be configured on your account settings. The Stripe pricing table is somewhat limited in what you can configure

celest crypt
#

I found a property within sessions.create() that might help, can you tell me if that would work?
My code is this

import { stripe } from 'lib/stripe';
import { NextRequest, NextResponse } from 'next/server';

const handleCreateCheckoutSession = async (
    stripeId: string,
    priceId: string
) => {
    const stripeCheckoutSession = await stripe.checkout.sessions.create({
        customer: stripeId,
        payment_method_types: ['card', 'boleto'],
        currency: 'brl',
        payment_intent_data: {
            setup_future_usage: 'on_session' // this prop
        },
        billing_address_collection: 'required',
        line_items: [{ price: priceId, quantity: 1 }],
        mode: 'subscription',
        allow_promotion_codes: true,
        cancel_url: process.env.STRIPE_CANCEL_URL,
        success_url: process.env.STRIPE_SUCCESS_URL as string
    });

    return stripeCheckoutSession;
};

export async function POST(request: NextRequest) {
    if (request.method === 'POST') {
        const { stripeCustomerId, priceId } = await request.json();

        const stripeCheckoutSession = await handleCreateCheckoutSession(
            stripeCustomerId,
            priceId
        );

        return new Response(
            JSON.stringify({ sessionId: stripeCheckoutSession.id }),
            {
                status: 200,
                statusText: 'Sucesso'
            }
        );
    }

    return NextResponse.json('Method not allowed', { status: 405 });

    
}
clever comet
#

That would work for a Checkout Session. But I thought you were using a Pricing Table?

celest crypt
#

If it works, I can create my own price table just redirecting to the checkout session with this property

clever comet
#

That would allow the Checkout Session to save payment methods for the customer, yes

celest crypt
#

Ok, I'll try that, I appreciate your patience, just one more question, is it possible to update a user's existing subscription through the checkout screen? or does it just create a new subscription for the user?

clever comet
#

No, Checkout does not allow that. We do have a separate Stripe hosted interface to allow customers to manage their susbcriptions though. It's called the Customer Portal or sometimes the Billing Portal

celest crypt
#

Perfect, thanks for the answers, sorry for any spelling mistakes, my English isn't that good. Anyway, thanks for your time, have a good week and good work.

clever comet
#

No worries! Have a great day!