【问题标题】:Stripe Checkout does not redirect to checkout page ExpressStripe Checkout 不会重定向到 Express 结帐页面
【发布时间】:2021-02-25 01:32:01
【问题描述】:

我正在尝试使用 Stripe 预建的结帐页面来捕获关注此documentation 的用户的付款详细信息。

我认为我编写的代码是正确的,但不知何故我的应用程序没有将用户重定向到 Stripe 结帐页面。我的代码如下:

在我的 Express 后端:

router.get("/create-check-out", async (req, res, next) => {
  const session = await stripe.checkout.sessions.create({
    payment_method_types: ['card'],
    mode: 'setup',
    customer: req.body.id,
    success_url: 'http://localhost:5000/ll_profile?session_id={CHECKOUT_SESSION_ID}',
    cancel_url: 'http://localhost:5000/ll_profile',
  });
  res.send (session.id);
});

在我的 JavaScript 客户端:

        $.get("/create-check-out", { id: stripe_customer_id}, async (sessionId) => {
          console.log(sessionId)
          stripe.redirectToCheckout({
            sessionId: sessionId,
            name: "Yugue"
          }).then(function(result) {
            console.log(result)
          });

控制台日志不显示sessionIdresult。 问题是在发送 get 请求后,web URL 变为:http://localhost:5000/ll_profile?name= from http://localhost:5000/ll_profile(上面所有代码所在的 URL),并且应用程序卡在同一页面而没有任何重定向操作。我认为它应该像这样重定向到 Stripe 内置结帐页面:

我做错了什么?

【问题讨论】:

    标签: express stripe-payments


    【解决方案1】:

    您很可能在 <form> 元素中找到了按钮,并且 Checkout 重定向和表单提交操作之间存在竞争。您不应该使用表单,或者确保与 Checkout 相关的点击处理程序使用的是preventDefault()

    如果不是这样,请分享您的 DOM 结构和点击处理程序的更多上下文。

    【讨论】:

    • 哦,是的,我做错了什么。实际上,它位于
      元素内。非常感谢布伦丹·摩尔,你是救世主!!
    猜你喜欢
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    • 2011-12-27
    • 2022-09-29
    • 2016-09-29
    • 2021-10-01
    • 2020-05-20
    • 2022-11-19
    相关资源
    最近更新 更多