#WW-checkout
1 messages · Page 1 of 1 (latest)
Do you mind sharing a code snippet please?
router.get("/create-checkout-session", async (req, res) => {
const { email } = req.query;
if (email) {
const customer = await stripe.customers.create({
email: email,
});
const session = await stripe.checkout.sessions.create({
billing_address_collection: "auto",
line_items: [
{
price: STRIPE_PRICE_CODE,
quantity: 1,
},
],
mode: "subscription",
customer: customer.id,
success_url: `${process.env.REACT_APP_BACKEND_URL}main/update-checkout-details?success=true&session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${process.env.REACT_APP_BACKEND_URL}main/update-checkout-details?canceled=true`,
});
return res.redirect(303, session.url);
}
return res.redirect(303, process.env.REACT_APP_FRONTEND_URL);
});
@pure gale Code^
Do you have a request id or account id please?
Your Checkout link looks incorrect, a correct link should look like https://checkout.stripe.com/pay/cs_xyz
@pure gale why it's incorrect? I referred the code from https://stripe.com/docs/billing/quickstart
account id: acct_1KInOrAm8Ra3D9Rz
This link is not working for me tho
- We don't want user to input their email manually, that's why we are not using the static URL
for the same, I have created customer first and passed that in stripe.checkout.sessions.create method
Yes, this makes sense, after the customer enters their email once in your system, you create the Stripe Customer object and use its ID to create the Checkout Session.
This will prefill their email in the Checkout Session
The link I shared above is an example of how the format of the Checkout link looks like
So what we are doing is, I have create a get API (The link which I have share above): there we are creating the customer and session (code I shared above) and then redirecting customer to stripe checkout return res.redirect(303, session.url);
Your Checkout Session URL looks correct to me: https://checkout.stripe.com/pay/cs_live_a1OrU2LSj9gC1IHR7erynlfyUBDD7jV7VOdAd35pa1a4aKOoXscZxdDDiH#fidkdWxOYHwnPyd1blppbHNgWjA0TkxrSndEaD1XZDZBPFd%2FX2lqb1RnYkhKMlVkaGt2Z1J9Zk1iPWdTUU88VWo3TUI8UnRufVBtMHFhaFBubEZEf0FfMkl1VW9CNWpUdF12YHBucmROVXBXNTV%2FM2dqQ25wdycpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl
My suspicion is this is either not returned to the client correctly, or the client is not displaying it correctly
Do you mind trying with res.redirect(303, session.url);
Without the return
hm let me try
@pure gale removed the return, but it's still not working
- same, working on local but not on prod
we don't need to do any whitelisting of URLs right?
We do have a list of IP addresses where the API may resolve to: https://stripe.com/docs/ips
I am not sure if this is the issue.
Do you mind writing in via https://support.stripe.com please?
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
I will find someone in my team more familiar with Checkout and node to look into this for you.
Thank you 🙇