【问题标题】:Getting stripe payment intent method error获取条纹支付意图方法错误
【发布时间】:2021-01-21 06:15:35
【问题描述】:

下面的 javascript 代码有效,它返回带有付款方式的响应,例如“pm_1HZDptHMQMk5h2YU0kai****”,我使用这种付款方式来收取付款,条纹的响应如下。

“提供的 PaymentMethod 之前曾与没有 Customer 附件的 PaymentIntent 一起使用,与没有 Customer 附件的连接帐户共享,或者与 Customer 分离。它可能不会再次使用。要多次使用 PaymentMethod,您必须附加首先给客户”。

我无法弄清楚我没有在任何地方使用 paymentMethod 的问题。但它仍然给我上面的信息。

顺便说一句,我尝试使用setup_future_usage: 'on_session' and 'off_session' values

  var stripe = Stripe('pk_test_51H1xOmHMQMk5h2YUX7ShAMdjy9************************');
var elements = stripe.elements();
var style = {
  base: {
    color: "#32325d",
  }
};

var card = elements.create("card", { style: style });
card.mount("#card-element");
card.on('change', ({error}) => {
  const displayError = document.getElementById('card-errors');
  if (error) {
    displayError.textContent = error.message;
  } else {
    displayError.textContent = '';
  }
});

var form = document.getElementById('payment-form');

form.addEventListener('submit', function(ev) {
  ev.preventDefault();
  stripe.confirmCardPayment('pi_1HZDaPHMQMk5h2YUga3QwB2E******************', {
    payment_method: {
      card: card,
      billing_details: {
        name: 'Jony',
      }
    },
    setup_future_usage: 'on_session'
  }).then(function(result) {
    if (result.error) {
        console.log(result);
      // Show error to your customer (e.g., insufficient funds)
      console.log(result.error.message);
    } else {
      // The payment has been processed!
      if (result.paymentIntent.status === 'succeeded') {
          alert('success');
        // Show a success message to your customer
        // There's a risk of the customer closing the window before callback
        // execution. Set up a webhook or plugin to listen for the
        // payment_intent.succeeded event that handles any business critical
        // post-payment actions.
      }
    }
  });
});

【问题讨论】:

    标签: javascript php stripe-payments


    【解决方案1】:

    如果您要单独创建 PaymentMethod(在实际将其用于 PaymentIntent 之前),您应该遵循 https://stripe.com/docs/payments/save-and-reuse

    如果您想一次性创建 PaymentMethod 并通过 PaymentIntent 进行收费,您应该关注https://stripe.com/docs/payments/save-during-payment

    顺便说一句,我尝试使用 setup_future_usage: 'on_session' 和 'off_session' 值。

    如果您按照上面的第二个链接进行操作,但不适用于已经存在并以某种方式使用的 PaymentMethod。

    【讨论】:

    • 我已经按照第一个的确切链接,你能具体到确切的行吗。
    • 您要确保的关键一件事是您为 SetupIntent 提供了 customer
    猜你喜欢
    • 2020-03-06
    • 2014-12-06
    • 2020-11-07
    • 2017-03-02
    • 2021-03-17
    • 2017-04-29
    • 2022-08-13
    • 2017-09-14
    • 2018-03-25
    相关资源
    最近更新 更多