NoMethodError: undefined method `sources' for #<Stripe::Customer

Viewed 814

I'm using Stripe gem for my payment method. According to its documentation I did tried to retrieve the card which I added against a customer. Customer retrieval worked fine with

customer = Stripe::Customer.retrieve("cus_DWcUQOutnrAD4s")

but when I tried to retrieve card using

card = customer.sources.retrieve("card_1D5a3J2eZvKYlo2CDJ62mrSM")

It throws exception saying

NoMethodError: undefined method `sources' for < Stripe::Customer: 0x007faae89500c0>

I googled much but could not find even the question like that which made me thinking that I might be the only person facing this issue. I am sure that stripe is installed correctly because I am successfully adding customer, card and subscription but it is the retrieval of card which throws the error.

1 Answers

Actually, you would need to update your Stripe Card methods used for Retrieve, add, List, Delete, Update.

Here is the updated syntax to retrieve the Customer Card from Stripe

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

Here is the sample result from above request:

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

You can go through the updated Stripe API document

Related