【问题标题】:How to check if payment is successful on server side in Stripe如何在 Stripe 的服务器端检查支付是否成功
【发布时间】:2021-01-17 21:52:19
【问题描述】:

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

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

【问题讨论】:

  • 你应该使用 Stripe Webhook:link

标签: stripe-payments


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-10-27
    • 2011-07-29
    • 2019-09-19
    • 1970-01-01
    • 2017-02-08
    • 2013-04-13
    • 1970-01-01
    • 2021-10-22
    • 1970-01-01
    相关资源
    最近更新 更多