Class: PaypalAdaptive::Response
- Inherits:
-
Hash
- Object
- Hash
- PaypalAdaptive::Response
- Defined in:
- lib/paypal_adaptive/response.rb
Instance Method Summary collapse
-
#approve_paypal_payment_url(opts = {}) ⇒ Object
URL to redirect to in order for the user to approve the payment.
- #error_message ⇒ Object
- #errors ⇒ Object
-
#initialize(response = {}, env = nil) ⇒ Response
constructor
A new instance of Response.
-
#nested_under_indifferent_access ⇒ Object
workaround for rails 3.1.1, see github.com/tc/paypal_adaptive/issues/23.
- #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/paypal_adaptive/response.rb', line 3 def initialize(response={}, env=nil) config = PaypalAdaptive.config(env) @paypal_base_url = config.paypal_base_url self.merge!(response) end |
Instance Method Details
#approve_paypal_payment_url(opts = {}) ⇒ Object
URL to redirect to in order for the user to approve the payment
options:
-
country: default country code for the user
-
type: mini / light
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/paypal_adaptive/response.rb', line 34 def approve_paypal_payment_url(opts = {}) if opts.is_a?(Symbol) || opts.is_a?(String) warn "[DEPRECATION] use approve_paypal_payment_url(:type => #{opts})" opts = {:type => opts} end return nil if self['payKey'].nil? if ['mini', 'light'].include?(opts[:type].to_s) "#{@paypal_base_url}/webapps/adaptivepayment/flow/pay?expType=#{opts[:type]}&paykey=#{self['payKey']}" else base = @paypal_base_url base = base + "/#{opts[:country]}" if opts[:country] "#{base}/webscr?cmd=_ap-payment&paykey=#{self['payKey']}" end end |
#error_message ⇒ Object
25 26 27 |
# File 'lib/paypal_adaptive/response.rb', line 25 def = errors.first['message'] rescue nil end |
#errors ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/paypal_adaptive/response.rb', line 15 def errors if success? return [] else errors = self['error'] errors ||= self['payErrorList']['payError'].collect { |e| e['error'] } rescue nil errors end end |
#nested_under_indifferent_access ⇒ Object
workaround for rails 3.1.1, see github.com/tc/paypal_adaptive/issues/23
55 56 57 |
# File 'lib/paypal_adaptive/response.rb', line 55 def nested_under_indifferent_access self end |
#preapproval_paypal_payment_url ⇒ Object
50 51 52 |
# File 'lib/paypal_adaptive/response.rb', line 50 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 13 |
# File 'lib/paypal_adaptive/response.rb', line 10 def success? !! (self['responseEnvelope']['ack'].to_s =~ /^Success$/i && !(self['paymentExecStatus'].to_s =~ /^ERROR$/i)) end |