2013-08-09 3 views
0

레일즈 3.2 웹 애플리케이션을 만들고 Paymill API에 연결합니다. webhooks를 사용하고 있으며 이러한 후크가 내 서버에서 아래 데이터가있는 끝점을 호출하고 있습니다.중첩 POST 양식 데이터에 액세스하는 방법은 무엇입니까?

어떻게 중첩 데이터에 액세스 할 수 있습니까? 구독 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"=>"[email protected]", 
        "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"=>"[email protected]", 
        "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"=>{ 

    } 
} 

답변

0

이 내가 그것을 해결하는 방법입니다 : 변수라는 데이터 : [이벤트]

  1. 가 PARAMS를 추가합니다.
  2. 액세스 예를 들어, 데이터를 다른 정보 [: EVENT_TYPE]
+0

'IF 데이터 [: event_resource] [: 가입] [: ID]'다음 작동하고'PARAMS [이벤트] [: event_resource] : subscription] [: id]'도 작동해야합니다. – Salil

+0

예, 이상하게도 작동하지 않습니다. :) –

관련 문제