#inderjit-janjua_code

1 messages ¡ Page 1 of 1 (latest)

jaunty drumBOT
#

👋 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/1290591583657525269

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

somber flame
#

hi! it can be possible, can you describe your issue/use case in more detail?

lusty slate
#

I may be asking a stupid question but here it goes

This flow doesn't have a confirm payment call made by the backend of the app, rather the confirm payment call is made by the front end of the app

#

What I did is the same

#

So i've used the Elements library to get the payment details but when confirming the payment, i'm making my own back end API call

somber flame
#

any context on what page in the docs that diagram is from?

lusty slate
#
import { NextResponse, NextRequest } from 'next/server';

const stripeSecretKey = process.env.STRIPE_SECRET_KEY;

if (!stripeSecretKey) {
    throw new Error('Stripe secret key is not defined in environment variables.');
}

const stripe = require('stripe')(stripeSecretKey, {
    apiVersion: '2024-06-20', // Specify the latest API version here
});

export async function POST(req: NextRequest) {
    try {
        const { paymentIntentId, connectedAccountId, returnUrl, paymentMethodId } = await req.json();

        if (!paymentIntentId) {
            return NextResponse.json({ error: "Missing paymentIntentId" }, { status: 400 });
        }

        // Confirm the payment intent with optional payment method (if provided)
        const paymentIntent = await stripe.paymentIntents.confirm(
            paymentIntentId, 
            {
                payment_method: paymentMethodId,
                return_url: returnUrl 
            },  
            {
                stripeAccount: connectedAccountId, // Adding the Stripe-Account header
            }
        );

        return NextResponse.json({
            paymentIntentId: paymentIntent.id,
            status: paymentIntent.status
        },);

    } catch (error: any) {
        return NextResponse.json({ error: error.message }, { status: 500 });
    }
}
somber flame
#

well if you really want the payment attempt to happen on the backend, then the guide you want is https://docs.stripe.com/payments/finalize-payments-on-the-server and you'd create "ConfirmationTokens". There isn't a guide specifically for Connect but it's the same idea as what you already built(passing stripeAccount where needed).

lusty slate
#

This is my back end API call

lusty slate
#

Will research some more

#

Ahhh interesting

#

Can I ask is there an issue if I make the call in the front end?

#

Most of my calls are backend

#

But if my confirm payment API call is the only one thats being made on the front end, would that be an issue

somber flame
#

I mean in most cases you want the confirm payment call to be on the frontend.

lusty slate
#

I thought so

somber flame
#

because for example it's easier to retry things like declines, and also 3D Secure has to happen on the frontend anyway, so if you try on the backend and it's required, you need to do a return trip to the frontend anyway to then handle and present 3DS.

lusty slate
#

Okay thank you

somber flame
#

but it's totally possible to do that flow(attempt on backend, only go back to frontend if required), tha'ts what that guide I linked is, if that's a flow that's easier/more sensible for your existing system

lusty slate
#

Perfect

#

Thank you so much

#

I love how smart you all are

#

You get what i'm trying to do