简体   繁体   English

STRIPE:此客户没有附加付款来源或默认付款方式。 RUBY 在轨道上

[英]STRIPE : This customer has no attached payment source or default payment method. RUBY ON RAILS

I've got some issues, i'm trying to implement subscription with stripe > it works when there is for exemple 3 items in my order > it create a subscription for the 3 items.我遇到了一些问题,我正在尝试使用条带实现订阅>当我的订单中有 3 件商品时它可以工作>它为这 3 件商品创建订阅。 The problem is that if the customer wants to stop sub only for ONE element, i dont know how to handle this...问题是,如果客户只想为一个元素停止 sub,我不知道如何处理这个......

So i was wondering to create a subscription for each element, this is my code所以我想为每个元素创建一个订阅,这是我的代码

    customer = Stripe::Customer.create
    @order.line_items.each do |line_item|
      product = Stripe::Product.create(
        {
          name: line_item.product.name,
          metadata: {
            product_id: line_item.product.id,
            line_item_id: line_item.id
          }
        }
      )

      price = Stripe::Price.create(
        {
          product: product.id,
          unit_amount: line_item.product.price_cents,
          currency: 'eur',
          recurring: {
            interval: 'month'
          }
        }
      )

      Stripe::Subscription.create({
        customer: customer.id,
        items: [
          {price: price.id, quantity: line_item.quantity}
        ]
      })

but i got this error This customer has no attached payment source or default payment method.但我收到此错误此客户没有附加付款来源或默认付款方式。 and i dont know how to attach it, even with documentation..而且我不知道如何附加它,即使有文档..

any help please?请问有什么帮助吗? thank you谢谢你

As said in comments ;评论中所述; To fix the error in the title:要修复标题中的错误:

  • You need to first have the "payment method", if you haven't already, create one:您需要首先拥有“付款方式”,如果您还没有,请创建一个:
    • Maybe using Stripe.js and it's elements API.也许使用 Stripe.js 和它的元素 API。
    • Which nowadays has "payment" element, allowing users to choose their payment-method.现在有“支付”元素,允许用户选择他们的支付方式。
    • And supports Setup-Intent's "client_secret" (beside Payment-Intent's), submittable using confirmSetup(...) method.并支持 Setup-Intent 的“client_secret”(在 Payment-Intent 旁边),可使用confirmSetup(...)方法提交。

Then (using Stripe API):然后(使用 Stripe API):

  • Attach said "payment method" to the Customer:将上述“付款方式”附加给客户:

    • (Optionally) set it as their default for invoices (with invoice_settings.default_payment_method ). (可选)将其设置为发票的默认值(使用invoice_settings.default_payment_method )。
  • And, while creating the subscription, pass the customer (that which you atteched said "payment method" to).并且,在创建订阅时,传递customer (您所说的“付款方式”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM