I want to use Stripe payment but finding some problem to check if payment is successful or not at the server side.
If payment is successful then I want to trigger the database to update the payment for the user.
I am using nodejs for this integration with vue and my nodejs code looks like this:
app.post("/create-checkout-session", async (req, res) => {
const {
amount,
product,
currency
} = req.body;
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
line_items: [
{
price_data: {
currency: currency,
product_data: {
name: product,
},
unit_amount: amount,
},
quantity: 1,
},
],
mode: "payment",
success_url: "http://localhost:3000/successPayment",
cancel_url: "http://localhost:3000/cancel",
});
res.json({ id: session.id });
});
Is there any way to check at server side whether the payment was successful or not? And is it safe to check it here or I have trigger the database once the user reaches the success page?
As the comment says, webhooks are the best way to do this: https://stripe.com/docs/payments/checkout/fulfill-orders#create-event-handler
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.