由于Stripe无法根据客户的电子邮件地址查找客户,因此我必须将所有这些信息都删除并进行相应的比较(from this SO question)。这很好,但现在customer_i_need
是:
[#<Stripe::Customer:0x3fc836b51efc id=cus_8BETSKddddnJD> JSON: {
"id": "cus_8BETSKddddnJD",
"object": "customer",
"account_balance": 0,
"business_vat_id": null,
"created": 1459377705,
"currency": "usd",
"default_source": "card_17us0SDcysUdddff5P8gqGmWm",
"delinquent": false,
"description": null,
"discount": null,
"email": "bobby@test.com",
"livemode": false,
"metadata": {},
"shipping": null,
"sources": {"object":"list","data":[{"id":"card_17us0SDcysUdddff5P8gqGmWm","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_8BETSKddddnJD","cvc_check":null,"dynamic_last4":null,"exp_month":1,"exp_year":2019,"fingerprint":"aHBJ0hDddffdaB9","funding":"credit","last4":"4242","metadata":{},"name":null,"tokenization_method":null}],"has_more":false,"total_count":1,"url":"/v1/customers/cus_8BETSKddddnJD/sources"},
"subscriptions": {"object":"list","data":[{"id":"sub_8BETB4CWTlBert","object":"subscription","application_fee_percent":null,"cancel_at_period_end":false,"canceled_at":null,"created":1459377705,"current_period_end":1490913705,"current_period_start":1459377705,"customer":"cus_8BETSKddddnJD","discount":null,"ended_at":null,"metadata":{},"plan":{"id":"annual_600","object":"plan","amount":60000,"created":1459172660,"currency":"usd","interval":"year","interval_count":1,"livemode":false,"metadata":{},"name":"annual_600","statement_descriptor":"Trial","trial_period_days":365},"quantity":1,"start":1459377705,"status":"trialing","tax_percent":null,"trial_end":1490913705,"trial_start":1459377705}],"has_more":false,"total_count":1,"url":"/v1/customers/cus_8BETSKddddnJD/subscriptions"}
}]
实际上,我只需要能够将id
(cus_8BETSKddddnJD)添加到我的用户帐户(如果已创建),但我无法访问该值。
我已经尝试了customer_i_need["id"]
,但这不起作用。我也尝试转换customer_i_need.to_json
,然后以同样的方式访问该值,但这也不起作用......我哪里出错?
答案 0 :(得分:1)
在我看来,你得到了一些Stripe::Customer
返回的实例。我希望您可以在该实例上调用id
:
customer_i_need.id
或者因为它看起来像实例是数组中唯一的元素:
array.first.id