#adam_api

1 messages ยท Page 1 of 1 (latest)

frigid sorrelBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฑ๏ธ We automatically close idle threads, which makes them read-only. Make sure you stick around to chat in realtime!

๐Ÿ”— 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/1212020332802744402

๐Ÿ“ Have more to share? You can add more detail below, including code, screenshots, videos, etc.

โฒ๏ธ 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. Thank you for your patience!

grave ravineBOT
#

Hello! We'll be with you shortly. 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.

cedar quiver
#

try {
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price: priceId,
quantity: 1,
adjustable_quantity: {
enabled: true,
minimum: 1,
maximum: 10,
},
quantity: 1,
},
],
mode: 'payment',
success_url: 'https://thewirednomad.com/success?session_id={CHECKOUT_SESSION_ID}',
cancel_url: 'https://thewirednomad.com/cancel.html',
});

// Include clientSecret in the response
res.json({ id: session.id, clientSecret: session.client_secret });

} catch (error) {
res.status(500).json({ error: 'Internal server error' });
}
});

// Handle successful order
app.get('/successfulOrder', async (req, res) => {
const session_id = req.query.session_id;

try {
const session = await stripe.checkout.sessions.retrieve(session_id);
const customer = await stripe.customers.retrieve(session.customer);

res.send(`<html><body><h1>Thanks for your order, ${customer.name}!</h1></body></html>`);

} catch (error) {
res.status(500).json({ error: 'Internal server error' });
}
});

// Export the Express app as a Firebase Cloud Function
exports.api = functions.https.onRequest(app);

signal ridge
#

๐Ÿ‘‹ happy to help

cedar quiver
#

Payment successful, but no success page still

signal ridge
#

you're creating a normal checkout session here, instead of an embedded one

cedar quiver
#

oh?

signal ridge
#

as you can see you need to specify ui_mode: 'embedded' in order to create an embedded form

cedar quiver
cedar quiver
#

All I want to do is have the redirect behavior as described in the link I just posted

#

It's true I don't need my own success.html for that?

cedar quiver
#

that should fix it..

signal ridge
#

whether it's an embedded or a hosted Checkout Session

cedar quiver
#

oh.

#

but my success html is not the same as res.send(<html><body><h1>Thanks for your order, ${customer.name}!</h1></body></html>);

#

so which one is it? does it use success.html or does it do <html><body><h1>Thanks for your order, ${customer.name}!</h1></body></html>

signal ridge
#

I guess you named your success url /successfulOrder from the code you mentioned above

#

app.get('/successfulOrder',

cedar quiver
#

actually it's success.html. but again, I thought this wouldn't use my success.html

#

because why else would the code have res.send(<html><body><h1>Thanks for your order, ${customer.name}!</h1></body></html>);

#

?

signal ridge
#

@cedar quiver your app has a /successfulOrder URL that you can use, why redirect to success.html I'm not sure I understand

cedar quiver
#

where am I directing to success.html?

#

I even purposely removed the success.html I previously had from the folder

#

ah crap

signal ridge
#

yes

cedar quiver
#

nice. thanks

#

lastly, is there anyway to test this without actually needing to go through a real payment?

signal ridge
#

yes in test mode you can create checkout sessions and pay with the test cards

#

Use test cards to validate your Stripe integration without moving real money. Test a variety of international scenarios, including successful and declined payments, card errors, disputes, and bank authentication. You can also test non-card payment methods and redirects.

cedar quiver
#

Perfect thanks