【问题标题】:Stripe::Customer.create not attaching the payment method to customerStripe::Customer.create 未将付款方式附加到客户
【发布时间】:2021-03-26 03:07:22
【问题描述】:

我正在创建一个设置意图并从中接收付款方式的 ID。然后我使用以下代码创建客户

customer = Stripe::Customer.create({
      email: current_user.email,
      description: "Customer for subscription",
      payment_method: params[:payment_method]
    })

它正在返回以下响应

{
  "id": "cus_IZmhg4VhIwFUBI",
  "object": "customer",
  "address": null,
  "balance": 0,
  "created": 1608037176,
  "currency": null,
  "default_source": null,
  "delinquent": false,
  "description": "Customer for subscription",
  "discount": null,
  "email": "customer@example.com",
  "invoice_prefix": "76BF0C5E",
  "invoice_settings": {
    "custom_fields": null,
    "default_payment_method": null,
    "footer": null
  },
  "livemode": false,
  "metadata": {
  },
  "name": null,
  "next_invoice_sequence": 1,
  "phone": null,
  "preferred_locales": [

  ],
  "shipping": null,
  "tax_exempt": "none"
}

问题是,它没有将付款方式附加到客户,当我尝试使用客户对象创建订阅时,它返回以下错误:

Stripe::InvalidRequestError(此客户没有附加付款来源或默认付款方式。):

但是当我查看仪表板时,付款方式已经附在客户身上

【问题讨论】:

  • 你为payment_method传递什么样的数据?
  • 我正在传递我从设置意图中获得的付款 ID。当我检查仪表板时,付款已附加到客户,但不知何故,当我将客户 ID 传递给订阅时,它返回该客户没有附加付款

标签: ruby-on-rails stripe-payments


【解决方案1】:

附上payment_method,你可以list them for the customer。然后,您需要为客户明确设置invoice_settings.default_payment_method,这将用于创建订阅。

【讨论】:

  • 也不工作。当我为客户列出付款方式时,它会出现,但在明确设置 invoice_settings.default_payment_method...Stripe::InvalidRequestError (The customer does not have a payment method with the ID pm_1HyszfKNXDR22L81DER6eWTE. The payment method must be attached to the customer.): 后仍然出现相同的错误
  • 是的,这需要先附加,然后您才能运行客户更新。正如您在其他答案中发现的那样,您也可以在创建客户期间进行设置:stripe.com/docs/api/customers/…
【解决方案2】:

受@Nolan 回答的启发,我通过在创建客户时将付款 ID 传递给 invoice_settings.default_payment_method 解决了这个问题。以下是代码sn-p:

customer = Stripe::Customer.create({
      email: current_user.email,
      description: "Customer for subscription",
      payment_method: params[:payment_method],
      invoice_settings: {
        default_payment_method: params[:payment_method] 
      } 
    })

【讨论】:

  • 很高兴你把它整理好了!
猜你喜欢
  • 1970-01-01
  • 2018-12-13
  • 2020-10-13
  • 2016-05-22
  • 1970-01-01
  • 2015-03-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-13
相关资源
最近更新 更多