javascript - 此 PaymentMethod 之前使用过但未附加到客户或已与客户分离,并且可能不会再次使用

标签 javascript python stripe-payments

这里有一个奇怪的问题。按照文档,我将 PaymentMethod 附加到现有客户,但它不起作用。粗略地说,我:

  • 创建客户
  • 与客户创建付款意向
  • 创建一个带有支付意图的卡片元素
  • 客户输入卡信息
  • 确认支付成功并发回后台
  • 如果意图成功并且客户选择保存他们的卡,则使用意图方法和客户
  • 创建付款方式
  • 得到错误

  • 编码:
  • python :stripe.Customer.create(email=user.email, name=user.full_name)
  • python :stripe.PaymentIntent.create(amount=amount, currency="aud", customer=user.stripe_customer_id)
  • js: Stripe('{{ stripe_publishable_key }}').elements().create("card");
  • 用户:输入卡信息
  • js: stripe.confirmCardPayment('{{ clientSecret }}', { payment_method: { card: card, billing_details: { // name: 'Jenny Rosen' }, } }).then(function (result) { if (result.error) { // Show error to your customer (e.g., insufficient funds) console.log(result.error.message); var displayError = document.getElementById('card-errors'); displayError.textContent = result.error.message; } else { // The payment has been processed! if (result.paymentIntent.status === 'succeeded') { // 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. $('#fake-submit').click(); } } });
  • python :stripe.PaymentMethod.attach(stripe.PaymentIntent.retrieve(intent_id).payment_method, customer=user.stripe_customer_id)
  • 错误:Request req_request_id: This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.
  • 最佳答案

    Stripe 文档似乎存在问题。

    https://stripe.com/docs/payments/save-after-payment#web-collect-card-details他们有:

        setup_future_usage: 'off_session'
    

    但是在 https://stripe.com/docs/payments/save-and-reuse#web-collect-card-details他们错过了这条关键线。

    但是在您的情况下,用户是否选择是否要将卡保存在前端?那你就不用在后台存卡了,可以存到confirmCardPayment电话:https://stripe.com/docs/js/payment_intents/confirm_card_payment#stripe_confirm_card_payment-data-save_payment_method :

    save_payment_method boolean

    If the PaymentIntent is associated with a customer and this parameter is set to true, the provided payment method will be attached to the customer. Default is false.

    关于javascript - 此 PaymentMethod 之前使用过但未附加到客户或已与客户分离,并且可能不会再次使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60333494/

    相关文章:

    python - 如何一次而不是顺序替换多个子字符串?

    angular - 为什么在 Stripe 付款请求按钮上出现错误?

    javascript - 更改 Flot 条形图上的字体系列

    javascript - 如何通过 Javascript 定位另一个元素

    python - 在哪里可以找到 itertools.combinations() 函数的源代码

    python - 如何使用 lambda 将样式应用于 Pandas DataFrame

    javascript - Stripe 支付金额

    javascript - 通过 javascript api 调用(不是节点)获取 Stripe 客户信息,如何?

    javascript - 获取 li 元素的文本

    javascript - div 部分边框被切断