Class: PayPal::Recurring::Response::Base

Inherits:
Object
  • Object
show all
Extended by:
Utils
Defined in:
lib/paypal/recurring/response/base.rb

Direct Known Subclasses

Checkout, Details, ManageProfile, Payment, Profile, Refund

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

convert_to_time, mapping

Constructor Details

#initialize(response = nil) ⇒ Base

Returns a new instance of Base.



18
19
20
# File 'lib/paypal/recurring/response/base.rb', line 18

def initialize(response = nil)
  @response = response
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/paypal/recurring/response/base.rb', line 7

def response
  @response
end

Instance Method Details

#errorsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/paypal/recurring/response/base.rb', line 28

def errors
  @errors ||= begin
    index = 0
    [].tap do |errors|
      while params[:"L_ERRORCODE#{index}"]
        errors << {
          :code => params[:"L_ERRORCODE#{index}"],
          :messages => [
            params[:"L_SHORTMESSAGE#{index}"],
            params[:"L_LONGMESSAGE#{index}"]
          ]
        }

        index += 1
      end
    end
  end
end

#paramsObject



22
23
24
25
26
# File 'lib/paypal/recurring/response/base.rb', line 22

def params
  @params ||= CGI.parse(response.body).inject({}) do |buffer, (name, value)|
    buffer.merge(name.to_sym => value.first)
  end
end

#success?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/paypal/recurring/response/base.rb', line 47

def success?
  ack == "Success"
end

#valid?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/paypal/recurring/response/base.rb', line 51

def valid?
  errors.empty? && success?
end