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_url(type = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/response.rb', line 30

def approve_paypal_payment_url(type=nil)
  if self['payKey'].nil?
    return nil
  elsif ['mini', 'embedded'].include?(type.to_s)
    return "#{@@paypal_base_url}/webapps/adaptivepayment/flow/pay?expType=#{type.to_s}&paykey=#{self['payKey']}"
  end
  
  "#{@@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



40
41
42
# File 'lib/response.rb', line 40

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