Class: PaypalAdaptive::Response
- Inherits:
-
Hash
- Object
- Hash
- PaypalAdaptive::Response
- Defined in:
- lib/response.rb
Instance Method Summary collapse
- #approve_paypal_payment_url(type = nil) ⇒ Object
- #error_message ⇒ Object
- #errors ⇒ Object
-
#initialize(response, env = nil) ⇒ Response
constructor
A new instance of Response.
- #preapproval_paypal_payment_url ⇒ Object
- #success? ⇒ Boolean
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_message ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/response.rb', line 22 def if success? return nil else self['error'].first['message'] rescue nil end end |
#errors ⇒ Object
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_url ⇒ Object
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
10 11 12 |
# File 'lib/response.rb', line 10 def success? self['responseEnvelope']['ack'] == 'Success' end |