NoMethodError:#<stripe :: customer

时间:2018-09-01 14:34:05

标签: ruby-on-rails ruby-on-rails-4 stripe-payments

=“”

我使用Stripe gem作为我的付款方式的未定义方法`sources'。根据其documentation,我确实尝试取回了我针对客户添加的卡。使用

进行客户检索工作正常
customer = Stripe::Customer.retrieve("cus_DWcUQOutnrAD4s")

但是当我尝试使用

检索卡时
card = customer.sources.retrieve("card_1D5a3J2eZvKYlo2CDJ62mrSM")

引发异常

  

NoMethodError:的未定义方法'sources'

我在Google上搜索了很多,但甚至找不到这样的问题,这使我认为我可能是唯一面临此问题的人。我确定正确安装了stripe是因为我成功添加了customercardsubscription,但是对card的检索引发了错误。

1 个答案:

答案 0 :(得分:0)

实际上,您需要更新用于检索、添加、列出、删除、更新条带卡方法

这里是更新后的语法,用于从 Stripe

检索客户卡
Stripe::Customer.retrieve_source(
  'cus_JApI6yov1S9L3n', # Here you should mention your customer id
  'card_1IYTe3SHXYB34571ooz7kV4t', # This will be the Card Id
)

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

{
  "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
}

您可以浏览更新后的Stripe API document