2017-09-01 21 views
0

ストライプwebhookをレールに実装する場合、JSON形式でイベントオブジェクトを取得できます。しかし、問題は、JSONを入れ子にしたamount、subscription_idなどの属性を取得できないことです。これらの値をクラスオブジェクトから取得することもできません。これらの値を抽出する方法を教えてください。などRailsのストライプwebhookイベントからストライプデータを取得する方法

#<Stripe::Invoice:0xebc79c id=in_1AwVDUHb727hqFGZ0UF7B8tB> JSON: { 
    "id": "in_1AwVDUHb727hqFGZ0UF7B8tB", 
    "object": "invoice", 
    "amount_due": 2500, 
    "application_fee": null, 
    "attempt_count": 1, 
    "attempted": true, 
    "billing": "charge_automatically", 
    "charge": "ch_1AwVDUHb727hqFGZ702PYTrW", 
    "closed": true, 
    "currency": "aud", 
    "customer": "cus_BJ7S8vrsbh9Lyj", 
    "date": 1504095764, 
    "description": null, 
    "discount": null, 
    "ending_balance": 0, 
    "forgiven": false, 
    "lines": {"object":"list","data":[{"id":"sub_BJ7ScT0lf9yVGV","object":"line_item","amount":2500,"currency":"aud","description":null,"discountable":true,"livemode":false,"metadata":{},"period":{"start":1504095764,"end":1506774164},"plan":{"id":"c844d552154b","object":"plan","amount":2500,"created":1504095762,"currency":"aud","interval":"month","interval_count":1,"livemode":false,"metadata":{},"name":"Plan2","statement_descriptor":null,"trial_period_days":null},"proration":false,"quantity":1,"subscription":null,"subscription_item":"si_1AwVDUHb727hqFGZh2iulZFY","type":"subscription"}],"has_more":false,"total_count":1,"url":"/v1/invoices/in_1AwVDUHb727hqFGZ0UF7B8tB/lines"}, 
    "livemode": false, 
    "metadata": {}, 
    "next_payment_attempt": null, 
    "number": "7b726e08d6-0001", 
    "paid": true, 
    "period_end": 1504095764, 
    "period_start": 1504095764, 
    "receipt_number": null, 
    "starting_balance": 0, 
    "statement_descriptor": null, 
    "subscription": "sub_BJ7ScT0lf9yVGV", 
    "subtotal": 2500, 
    "tax": null, 
    "tax_percent": null, 
    "total": 2500, 
    "webhooks_delivered_at": 1504095765 
} 

私はCUSTOMER_IDのような値を取得したい、subscription_id、plan_id、 はどうやってデータを抽出します:

invoice = Stripe::Invoice.retrieve(:id => "in_1AwVDUHb727hqFGZ0UF7B8tB") 

そして、私は次のような応答を取得します。

は、事前に例えば

答えて

1

あなたがretrieved the invoiceをしたら、あなたは、単にアクセスできるオブジェクトの属性をありがとう:

invoice = Stripe::Invoice.retrieve("in_...") 
customer_id = invoice.customer 
subscription_id = invoice.subscription 

あなたが必要があると思いますので、計画のIDを有していない請求書〜retrieve the subscription最初に:

subscription = Stripe::Subscription.retrieve(subscription_id) 
plan_id = subscription.plan 
+0

ありがとう、それは私のために働く – Pankaj

関連する問題