【问题标题】:Stripe cancel url does not cancel the payment, so stripe does not send a cancel payintentStripe 取消 url 不会取消付款,因此 Stripe 不会发送取消付款意图
【发布时间】:2022-01-12 18:16:34
【问题描述】:

我正在使用带有节点 js 的条带进行付款,并且我正在创建一个会话并使用条带结帐界面。我正在使用 webhook 来监听事件,当支付创建或成功时,条纹发送 payment_intent.succeeded 所以我用它做一些事情。但问题是当我点击取消 url 取消付款时,stripe 不会取消付款或发送 payment_intent.canceled 这是一个问题,因为那时我不知道付款是否取消,我不能做我想做的事打算做。这是我的代码:

// This will share the stripe publickey with the frontend
const webhook = async (req, res) => {
  // Signature verification
  const playload = req.body;
  const sig = req.headers["stripe-signature"];
  const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET;

  let event;

  try {
    // Checking if the response is actually from stripe
    event = stripe.webhooks.constructEvent(playload, sig, endpointSecret);
  } catch (error) {
    console.log(error.message);
    res.status(400).json({ success: false });
    return;
  }

  // Getting the ad id
  const adID = event.data.object.metadata.id;
  const userEmail = event.data.object.metadata.email;

  // Checking if the payment did faile
  if (
    event.type === "payment_intent.canceled" ||
    event.type === "charge.failed" ||
    event.type === "charge.expired"
  ) {
    const paymentIntent = event.data.object;
    console.log(`PaymentIntent ${paymentIntent.status}`);

    // Sending the deleting request
    await axios.delete(`${process.env.SERVER_URL}/api/v1/single-ad`, {
      data: { id: adID, email: userEmail },
    });

    return res.status(200).json({ message: "Ad is successfully deleted" });
  }

if 语句永远不会执行,因为如果支付被取消,stripe 不会发回任何东西。

【问题讨论】:

    标签: node.js stripe-payments stripes


    【解决方案1】:

    CheckoutSession 上的 cancel_url 字段不会自动取消与 CheckoutSession 关联的 PaymentIntent。

    因此,预计不会发生这种情况:

    但是问题是当我点击cancel url取消支付时,stripe没有取消支付或者发送payment_intent.canceled

    cancel_url 用于如果客户按下结帐页面右上角的“返回”按钮,以取消付款页面。因此,这将是您指定的用于吸引客户的网站的 URL。

    即使在导航到 cancel_url 之后,CheckoutSession 仍然可用(直到手动过期或默认在创建后 24 小时过期)或您的代码取消底层 PaymentIntent。

    【讨论】:

      猜你喜欢
      • 2015-01-12
      • 2017-01-28
      • 2017-01-27
      • 2023-03-05
      • 2018-11-21
      • 2013-12-02
      • 2013-03-04
      • 2021-05-14
      • 2013-12-21
      相关资源
      最近更新 更多