【问题标题】:How can I pass custom data to Stripe webhook?如何将自定义数据传递给 Stripe webhook?
【发布时间】:2021-11-08 01:55:38
【问题描述】:

我正在创建和处理这样的条带付款:

    // Create payment intent
    const { data } = await axios.post('/api/payments/get-payment-intent', { slug: post.slug })

    // Use payment intent to charge the card
    const result = await stripe.confirmCardPayment(data.paymentIntentSecert, {
      payment_method: {
        card: elements.getElement(CardElement),
      },
    })

为了能够完成订单,我需要能够将一些数据(产品的id 和买家的username)传递到付款成功完成后执行的 webhook(@ 987654324@事件)。

我该怎么做?

我尝试将metadata 键添加到confirmCardPayment(),如下所示:

    const result = await stripe.confirmCardPayment(data.paymentIntentSecert, {
      payment_method: {
        card: elements.getElement(CardElement),
        metadata: {
          username: user.username,
          postId: post.id
        }
      },
    })

但是元数据没有显示在 webhook 接收到的对象上。

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    无法使用confirmCardPayment() 更新 PaymentIntent 元数据。

    您首先需要将用户名和 postId 传递给您的后端服务器。

    例子

    const { data } = await axios.post('/api/payments/get-payment-intent', { 
        username:user.username, 
        postId: post.Id 
    });
    

    随后create the PaymentIntent with the metadata

    创建 PaymentIntent 的 Node.js 示例

    const paymentIntent = await stripe.paymentIntents.create({
      amount: 2000,
      currency: 'usd',
      metadata: {
          username,
          postId
      },
    });
    

    【讨论】:

      猜你喜欢
      • 2016-10-14
      • 2018-05-18
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 2021-07-04
      • 1970-01-01
      • 1970-01-01
      • 2016-09-14
      相关资源
      最近更新 更多