NoMethodError:#<Stripe::Customer 的未定义方法“源”

Imr*_*qvi 6 ruby-on-rails stripe-payments ruby-on-rails-4

我使用Stripe gem作为我的付款方式。根据其文档,我确实尝试检索我针对客户添加的卡。客户检索效果很好

customer = Stripe::Customer.retrieve("cus_DWcUQOutnrAD4s")
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用取回卡时

card = customer.sources.retrieve("card_1D5a3J2eZvKYlo2CDJ62mrSM")
Run Code Online (Sandbox Code Playgroud)

它抛出异常说

NoMethodError:<Stripe::Customer: 0x007faae89500c0> 的未定义方法“源”

我用谷歌搜索了很多,但找不到这样的问题,这让我觉得我可能是唯一面临这个问题的人。我确信stripe安装正确,因为我成功添加了customercardsubscription检索它会card引发错误。

Jai*_*put 2

实际上,您需要更新用于Retrieve、add、List、Delete、Update的Stripe Card 方法

以下是从Stripe检索客户的更新语法

Stripe::Customer.retrieve_source(
  'cus_JApI6yov1S9L3n', # Here you should mention your customer id
  'card_1IYTe3SHXYB34571ooz7kV4t', # This will be the Card Id
)
Run Code Online (Sandbox Code Playgroud)

以下是上述请求的示例结果:

{
  "id": "card_1IYTe3SHXYB34571ooz7kV4t",
  "object": "card",
  "address_city": null,
  "address_country": null,
  "address_line1": null,
  "address_line1_check": null,
  "address_line2": null,
  "address_state": null,
  "address_zip": null,
  "address_zip_check": null,
  "brand": "Visa",
  "country": "US",
  "customer": "cus_JApI6yov1S9L3n",
  "cvc_check": "pass",
  "dynamic_last4": null,
  "exp_month": 8,
  "exp_year": 2022,
  "fingerprint": "83DqOn8HS1c0rah5",
  "funding": "credit",
  "last4": "4242",
  "metadata": {},
  "name": null,
  "tokenization_method": null
}
Run Code Online (Sandbox Code Playgroud)

您可以浏览更新后的Stripe API 文档