#inderjit-janjua_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/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.
- inderjit-janjua_code, 4 minutes ago, 22 messages
- inderjit-janjua_api, 5 days ago, 14 messages
- inderjit-janjua_api, 5 days ago, 10 messages
hi! it can be possible, can you describe your issue/use case in more detail?
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
any context on what page in the docs that diagram is from?
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 });
}
}
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).
This is my back end API call
Okay understood
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
I mean in most cases you want the confirm payment call to be on the frontend.
I thought so
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.
Okay thank you
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