创建信用卡后如何解析Stripe JSON响应? [英] How to parse Stripe JSON response after credit card creation?

查看:155
本文介绍了创建信用卡后如何解析Stripe JSON响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于JSON响应将Stripe card_id保存到我的数据库.我现在正在使用Stripe文档中的示例:

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})

JSON如下:

#<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}

在我的控制器中,创建信用卡后,如何解析JSON以仅获取卡ID?甚至有可能吗?

In my controller, after creating the credit card, how can I parse the JSON to get only the card id? Is it even possible?

推荐答案

您应该能够从这样的响应中获取信用卡:

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

这篇关于创建信用卡后如何解析Stripe JSON响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆