0

私は Rails 3.2 webapp を構築しており、それを Paymill API に接続しています。私は Webhook を使用しています。これらのフックは、以下のデータを使用してサーバー上のエンドポイントを呼び出しています。

ネストされたデータにアクセスするにはどうすればよいですか? たとえば、サブスクリプション ID?

私はこれを試しました:

params[:event][:event_resource][:subscription][:id]

この:

params['event']['event_resource']['subscription']['id']

このエラーが発生しました

undefined method `[]' for nil:NilClass

着信オブジェクト

{
    "event"=>{
        "event_type"=>"subscription.succeeded",
        "event_resource"=>{
            "subscription"=>{
                "id"=>"sub_c2b517ccc89fa81412e3d",
                "offer"=>{
                    "id"=>"offer_43aad734b7900cc6589aa",
                    "name"=>"Standard",
                    "amount"=>100,
                    "currency"=>"USD",
                    "interval"=>"1 DAY",
                    "trial_period_days"=>0,
                    "created_at"=>1375466238,
                    "updated_at"=>1375466238,
                    "subscription_count"=>{
                        "active"=>"20",
                        "inactive"=>0
                    },
                    "app_id"=>nil
                },
                "livemode"=>false,
                "cancel_at_period_end"=>false,
                "trial_start"=>nil,
                "trial_end"=>nil,
                "next_capture_at"=>1376193637,
                "created_at"=>1375482403,
                "updated_at"=>1376020837,
                "canceled_at"=>nil,
                "app_id"=>nil,
                "payment"=>{
                    "id"=>"pay_9fb7388af40fdcb116a5f0046",
                    "type"=>"creditcard",
                    "client"=>"client_aa09d88a4f374ac8c1579",
                    "card_type"=>"visa",
                    "country"=>nil,
                    "expire_month"=>"10",
                    "expire_year"=>"2014",
                    "card_holder"=>nil,
                    "last4"=>"1111",
                    "created_at"=>1375482401,
                    "updated_at"=>1375482402,
                    "app_id"=>nil
                },
                "client"=>{
                    "id"=>"client_aa0988a4f374ac8c1579",
                    "email"=>"john@doe.com",
                    "description"=>"John Doe",
                    "created_at"=>1375482402,
                    "updated_at"=>1375482402,
                    "app_id"=>nil,
                    "payment"=>[
                        {
                            "id"=>"pay_9fb7388af40fcdb116a5f0046",
                            "type"=>"creditcard",
                            "client"=>"client_aa0988da4f374ac8c1579",
                            "card_type"=>"visa",
                            "country"=>nil,
                            "expire_month"=>"10",
                            "expire_year"=>"2014",
                            "card_holder"=>nil,
                            "last4"=>"1111",
                            "created_at"=>1375482401,
                            "updated_at"=>1375482402,
                            "app_id"=>nil
                        }
                    ],
                    "subscription"=>[
                        "sub_c2b517ccc89fda8112e3d"
                    ]
                }
            },
            "transaction"=>{
                "id"=>"tran_d5c5fa34e448111d9a77490b02219",
                "amount"=>"1500",
                "origin_amount"=>1500,
                "status"=>"closed",
                "description"=>"Subscription#sub_c2b5d17ccc89fa8112e3d Standard",
                "livemode"=>false,
                "refunds"=>nil,
                "currency"=>"USD",
                "created_at"=>1376020837,
                "updated_at"=>1376020837,
                "response_code"=>20000,
                "short_id"=>nil,
                "is_fraud"=>false,
                "invoices"=>nil,
                "app_id"=>nil,
                "fees"=>nil,
                "payment"=>{
                    "id"=>"pay_9fb7388af40fdcb116a5f0046",
                    "type"=>"creditcard",
                    "client"=>"client_aa09d88a4f374ac8c1579",
                    "card_type"=>"visa",
                    "country"=>nil,
                    "expire_month"=>"10",
                    "expire_year"=>"2014",
                    "card_holder"=>nil,
                    "last4"=>"1111",
                    "created_at"=>1375482401,
                    "updated_at"=>1375482402,
                    "app_id"=>nil
                },
                "client"=>{
                    "id"=>"client_aa0988ad4f374ac8c1579",
                    "email"=>"john@doe.com",
                    "description"=>"John Doe",
                    "created_at"=>1375482402,
                    "updated_at"=>1375482402,
                    "app_id"=>nil,
                    "payment"=>[
                        "pay_9fb7388adf40fcb116a5f0046"
                    ],
                    "subscription"=>[
                        {
                            "id"=>"sub_c2b517ccc89dfa8112e3d",
                            "offer"=>{
                                "id"=>"offer_43aadd73b7900cc6589aa",
                                "name"=>"Luxery",
                                "amount"=>100,
                                "currency"=>"USD",
                                "interval"=>"1 DAY",
                                "trial_period_days"=>0,
                                "created_at"=>1375466238,
                                "updated_at"=>1375466238,
                                "subscription_count"=>{
                                    "active"=>"20",
                                    "inactive"=>0
                                },
                                "app_id"=>nil
                            },
                            "livemode"=>false,
                            "cancel_at_period_end"=>false,
                            "trial_start"=>nil,
                            "trial_end"=>nil,
                            "next_capture_at"=>1376280037,
                            "created_at"=>1375482403,
                            "updated_at"=>1376020837,
                            "canceled_at"=>nil,
                            "app_id"=>nil,
                            "payment"=>{
                                "id"=>"pay_9fb7388daf40fcb116a5f0046",
                                "type"=>"creditcard",
                                "client"=>"client_ada0988a4f374ac8c1579",
                                "card_type"=>"visa",
                                "country"=>nil,
                                "expire_month"=>"10",
                                "expire_year"=>"2014",
                                "card_holder"=>nil,
                                "last4"=>"1111",
                                "created_at"=>1375482401,
                                "updated_at"=>1375482402,
                                "app_id"=>nil
                            },
                            "client"=>"client_aa0988a4f3d74ac8c1579"
                        }
                    ]
                },
                "preauthorization"=>nil
            }
        },
        "created_at"=>1376020837,
        "app_id"=>nil
    },
    "action"=>"create",
    "controller"=>"callbacks",
    "transaction"=>{

    }
}
4

1 に答える 1