简体   繁体   English

如何在 Stripe 的服务器端检查支付是否成功

[英]How to check if payment is successful on server side in Stripe

I want to use Stripe payment but finding some problem to check if payment is successful or not at the server side.我想使用 Stripe 支付,但在服务器端检查支付是否成功时发现了一些问题。

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:我正在使用 nodejs 与 vue 集成,我的 nodejs 代码如下所示:

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正如评论所说,webhook 是执行此操作的最佳方式: https://stripe.com/docs/payments/checkout/fulfill-orders#create-event-handler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM