Anyone here implemented stripe checkout payment? <...
# random
e
Anyone here implemented stripe checkout payment? https://stripe.com/docs/payments/checkout 1. Should I generate session id on backend and then redirect user on frontend to checkout page and on success listen to stripe webhook to check payment completed event to store additional user/payment metadata in database? OR 1. Should I directly redirect user to checkout page using stripe-js package with no backend endpoints for generating session. (Everything will be prefilled i.e price id, price etc) and just listen to payment completed webhook for storing user/payment metadata? Any suggestions which approach should I follow or any other better solution available? Thanks Note: I am using node+react
h
I've used the first option and I guess it's recommended. Also it is working fine for me
👍 1
m
Yeah, always generate the checkout session id on the backend (more secure).
On successful payments, you should: 1. have a webhook listener that does the necessary changes in your DB (to reflect the payment) AND 2. have a redirect url that shows some success message to the purchaser.
👍 1
e
I am using stripe checkout so can I use multi currency? That is accept in INR and USD ??
m
I only charge in usd
e
so if someone from India wants to buy your product he has to pay in USD or stripe will convert it into INR??
Copy code
<http://router.post|router.post>('/create-checkout-session', async (req, res) => {
    try {
        const session = await stripe.checkout.sessions.create({
            line_items: [
                {
                    // Provide the exact Price ID (for example, pr_1234) of the product you want to sell
                    price: 'price_5aBok6',
                    quantity: 1,
                },
            ],
            mode: 'subscription',
            success_url: `<http://localhost:3000/upgrade>`,
            cancel_url: `<http://localhost:3000/subscription>`,
        });

        res.send({ id: session.id });
    } catch (error) {
        console.log("error", error)
    }
});
in above code line items information will be sent from frontend to this route correct? and based on that line item info generate session id right?
m
so if someone from India wants to buy your product he has to pay in USD or stripe will convert it into INR??
I don't sell in India yet. Still haven't gotten around to reading the RBI regulations on CC storage.
I'm not familiar with react or node, but here's what I do. The UI sends the PriceId, CancelUrl, SuccessUrl to backend API. The backend API does the following.
message has been deleted
e
Ok got it. Thanks for sharing screneshot very helpful
👍 1
I have doubt lets see users pays for first month and at the end of the month he decides to end subscription then this logic can be implemented using cancel subscription endpoint of stripe is that correct?