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

问题描述

我想使用 Stripe 支付,但在服务器端发现一些问题来检查支付是否成功。

如果支付成功,那么我想触发数据库用户更新支付。

我使用 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 });
});

有没有办法在服务器端检查支付是否成功?在这里检查是否安全,或者一旦用户到达成功页面我就触发了数据库

解决方法

正如评论所说,网络钩子是最好的方法:https://stripe.com/docs/payments/checkout/fulfill-orders#create-event-handler