Sha256: 8411f0ac57538facb12d02600dd150fd4bb58d19e5ee62a727d20a768c30defc

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

module PayPal
  module Recurring
    module Response
      class Base
        extend PayPal::Recurring::Utils

        attr_accessor :response

        mapping(
          :token           => :TOKEN,
          :ack             => :ACK,
          :version         => :VERSION,
          :build           => :BUILD,
          :correlaction_id => :CORRELATIONID,
          :requested_at    => :TIMESTAMP
        )

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

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

        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

        def success?
          ack == "Success"
        end

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

        private
        def build_requested_at(stamp) # :nodoc:
          Time.parse(stamp)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
didil-paypal-recurring-1.1.1 lib/paypal/recurring/response/base.rb
paypal-recurring-1.1.0 lib/paypal/recurring/response/base.rb
paypal-recurring-1.0.0 lib/paypal/recurring/response/base.rb
paypal-recurring-0.1.6 lib/paypal/recurring/response/base.rb
paypal-recurring-0.1.5 lib/paypal/recurring/response/base.rb