Class: Paypal::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/paypal_api/support/response.rb,
lib/paypal_api/support/response.rb

Direct Known Subclasses

AdaptivePaymentsResponse

Constant Summary collapse

@@error_codes =
{
  '10527' => :acct,
  '10525' => :amt,
  '10508' => :exp_date,
  '10504' => :cvv2,
  '10502' => :acct,
  '10501' => :reference_id,
  '10509' => :ip_address,
  '10510' => :acct,
  '10519' => :acct,
  '10521' => :acct,
  '10526' => :currency_code
}
@@human_readable =
{
  :acct => "credit card number",
  :amt => "charge amount",
  :exp_date => "expiration date",
  :cvv2 => "security code",
  :reference_id => "billing agreement",
  :currency_code => "currency code"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stringio) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/paypal_api/support/response.rb', line 6

def initialize(stringio)
  @raw_response = stringio.class == StringIO ? stringio.read : stringio
  @parsed_response = CGI.parse(@raw_response)

  @success = @parsed_response["ACK"] == ["Success"]

  unless @success
    @error_message = @parsed_response["L_LONGMESSAGE0"][0]
    @error_code = @parsed_response["L_ERRORCODE0"][0]
  end
end

Instance Attribute Details

#error_codeObject

Returns the value of attribute error_code.



4
5
6
# File 'lib/paypal_api/support/response.rb', line 4

def error_code
  @error_code
end

#parsed_responseObject

Returns the value of attribute parsed_response.



4
5
6
# File 'lib/paypal_api/support/response.rb', line 4

def parsed_response
  @parsed_response
end

#paypal_error_fieldObject

Returns the value of attribute paypal_error_field.



4
5
6
# File 'lib/paypal_api/support/response.rb', line 4

def paypal_error_field
  @paypal_error_field
end

#raw_responseObject

Returns the value of attribute raw_response.



4
5
6
# File 'lib/paypal_api/support/response.rb', line 4

def raw_response
  @raw_response
end

Instance Method Details

#[](key) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/paypal_api/support/response.rb', line 18

def [](key)
  if key.class == Symbol
    @parsed_response[symbol_to_key(key)][0]
  else
    @parsed_response[key][0]
  end
end

#error_fieldObject



38
39
40
# File 'lib/paypal_api/support/response.rb', line 38

def error_field
  @paypal_error_field || (@@error_codes[@error_code] ? @@human_readable[@@error_codes[@error_code]] : nil)
end

#error_inputObject



34
35
36
# File 'lib/paypal_api/support/response.rb', line 34

def error_input
  @@error_codes[@error_code]
end

#error_messageObject



42
43
44
# File 'lib/paypal_api/support/response.rb', line 42

def error_message
  @error_message + "[#{@error_code}]"
end

#method_missing?(key) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/paypal_api/support/response.rb', line 30

def method_missing?(key)
  return @parsed_response[symbol_to_key(key)]
end

#success?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/paypal_api/support/response.rb', line 26

def success?
  return @success
end