How to parse Stripe JSON response after credit card creation?

耗尽温柔 提交于 2019-12-12 10:24:58

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/20960027/how-to-parse-stripe-json-response-after-credit-card-creation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!