微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何在 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。