Sha256: f3690c6d2a235be4334f86937ab909995483e83c5fb257558c7d0254078c86bf

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

module Oschadbank
  class Response
    include Constants

    def initialize(params)
      @params = params

      check_required!
    end

    def request_type
      TR_TYPE.invert[@params['TRTYPE'].to_s]
    end

    def pre_auth?
      request_type == :pre_auth
    end

    def auth?
      request_type == :auth
    end

    def charge?
      request_type == :charge
    end

    def refund?
      request_type == :refund
    end

    def success?
      RESULT_SUCCESS.include?(result_code) && RC_SUCCESS.include?(rc_code)
    end

    def status_code
      rc_code
    end

    def status_message
      "#{result_message} (#{rc_message})"
    end

    def order_id
      @params['Order']
    end

    def currency
      @params['Currency']
    end

    def amount
      @params['Amount'] && @params['Amount'].to_f
    end

    def rrn
      @params['RRN']
    end

    def int_ref
      @params['IntRef']
    end

    def auth_code
      @params['AuthCode']
    end

    private

    def check_required!
      required_params = ['Order', 'Result', 'RC', 'TRTYPE']
      required_params.each do |param|
        raise ParamRequred.new(param) if @params[param].to_s.empty?
      end
    end

    def result_code
      @params['Result'].to_s
    end

    def rc_code
      @params['RC'].to_s
    end

    def result_message
      RESULT_MESSAGES[result_code]
    end

    def rc_message
      RC_MESSAGES[rc_code]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oschadbank-0.1.0 lib/oschadbank/response.rb