Class: PaypalAdaptive::Response

Inherits:
Hash
  • Object
show all
Defined in:
lib/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response, env = nil) ⇒ Response

Returns a new instance of Response.



3
4
5
6
7
8
# File 'lib/response.rb', line 3

def initialize(response, env=nil)
  @@config ||= PaypalAdaptive::Config.new(env)
  @@paypal_base_url ||= @@config.paypal_base_url
  
  self.merge!(response)
end

Instance Method Details

#approve_paypal_payment_urlObject



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

def approve_paypal_payment_url
  self['payKey'].nil? ? nil : "#{@@paypal_base_url}/webscr?cmd=_ap-payment&paykey=#{self['payKey']}"
end

#error_messageObject



22
23
24
25
26
27
28
# File 'lib/response.rb', line 22

def error_message
  if success?
    return nil
  else
    self['error'].first['message'] rescue nil
  end
end

#errorsObject



14
15
16
17
18
19
20
# File 'lib/response.rb', line 14

def errors
  if success?
    return []
  else
    self['error']
  end
end

#preapproval_paypal_payment_urlObject



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

def preapproval_paypal_payment_url
  self['preapprovalKey'].nil? ? nil : "#{@@paypal_base_url}/webscr?cmd=_ap-preapproval&preapprovalkey=#{self['preapprovalKey']}"
end

#success?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/response.rb', line 10

def success?
  self['responseEnvelope']['ack'] == 'Success'
end