Reputation: 505
I want to save a Stripe card_id to my database based on the JSON response. I'm playing with the examples from the Stripe documentation right now:
customer = Stripe::Customer.retrieve("cus_3Ek7h52yGbLpQo")
customer.cards.create(:card => {:number => "4242424242424242",
:exp_month => 10, :exp_year => 2014})
The JSON looks like this:
#<Stripe::Card:0x3ff2f0191540> JSON: {"id":"card_3GHjrJqMgoyTNy","object":"card","last4":"4242","type":"Visa","exp_month":10,"exp_year":2014,"fingerprint":"Ds0FdzrOSdYMkwC0","customer":"cus_3Ek7h52yGbLpQo","country":"US","name":null,"address_line1":null,"address_line2":null,"address_city":null,"address_state":null,"address_zip":null,"address_country":null,"cvc_check":null,"address_line1_check":null,"address_zip_check":null}
In my controller, after creating the credit card, how can I parse the JSON to get only the card id? Is it even possible?
Upvotes: 0
Views: 1050
Reputation: 3291
You should be able to get the credit card from the response like this:
@card = customer.cards.create(:card => {:number => "4242424242424242",
:exp_month => 10, :exp_year => 2014})
@card.id #this should have the card id in it
Upvotes: 1