访问paypal响应的Array值

时间:2012-09-24 11:59:27

标签: ruby-on-rails ruby arrays ruby-on-rails-3 hash

logger.info response.inspect

我明白了:

#<ActiveMerchant::Billing::AdaptivePaymentResponse:0x0000000599dc48 @json="{\"responseEnvelope\":{\"timestamp\":\"2012-09-24T04:34:36.888-07:00\",\"ack\":\"Failure\",\"correlationId\":\"22d02b45ed143\",\"build\":\"3692562\"},\"error\":[{\"errorId\":\"540031\",\"domain\":\"PLATFORM\",\"subdomain\":\"Application\",\"severity\":\"Error\",\"category\":\"Application\",\"message\":\"You do not have permission to issue this refund\"}]}", @response=#<Hashie::Rash error=[#<Hashie::Rash category="Application" domain="PLATFORM" error_id="540031" message="You do not have permission to issue this refund" severity="Error" subdomain="Application">] response_envelope=#<Hashie::Rash ack="Failure" build="3692562" correlation_id="22d02b45ed143" timestamp="2012-09-24T04:34:36.888-07:00">>, @xml_request="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<RefundRequest>\n  <requestEnvelope>\n    <detailLevel>ReturnAll</detailLevel>\n    <errorLanguage>en_US</errorLanguage>\n  </requestEnvelope>\n  <actionType>REFUND</actionType>\n  <payKey>AP-2JV97573KK140871P</payKey>\n  <currencyCode>USD</currencyCode>\n  <feesPayer>EACHRECEIVER</feesPayer>\n</RefundRequest>\n", @request={"RefundRequest"=>{"requestEnvelope"=>{"detailLevel"=>"ReturnAll", "errorLanguage"=>"en_US"}, "actionType"=>"REFUND", "payKey"=>"AP-2JV97573KK140871P", "currencyCode"=>"USD", "feesPayer"=>"EACHRECEIVER"}}, @action="Refund">

response.ack我得到"Failure"

如果我写logger.info response.error.inspect,我会得到:

[#<Hashie::Rash category="Application" domain="PLATFORM" error_id="540031" message="You do not have permission to issue this refund" severity="Error" subdomain="Application">]

如何访问或获取error_id值?

谢谢!

2 个答案:

答案 0 :(得分:1)

由于response.error是一个数组,你必须循环遍历它或只是执行

response.error[0].error_id

答案 1 :(得分:0)

只需使用此代码:

response.error.error_id

供参考,请查看此处:rash on github

简而言之,Rash很方便。 :)