Sha256: fb204d91b1b253bdf757aea4fc77771663bfcb735ba866ef504a5b58096e0c44

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

module ActiveMerchant
  module Billing
    class PaymentechOrbitalResponse
      cattr_accessor :elements

      self.elements = [ 
        :industry_type, :message_type, :merchant_id,
        :terminal_id, :card_brand, :account_num, 
        :order_id, :tx_ref_num, :tx_ref_idx, :proc_status,
        :approval_status, :resp_code, :avs_resp_code,
        :cvv2_resp_code, :auth_code, :status_msg, :resp_msg,
        :customer_ref_num, :customer_name, :profile_proc_status,
        :customer_profile_message, :resp_time
      ]

      def initialize(doc, options={})
        @doc = REXML::Document.new(doc)
        @options = options
      end

      def success?
        proc_success? && approved?
      end

      def proc_success?
        proc_status == "0"
      end

      def approved?
        approval_status == "1"
      end

      def authorization
        approval_status
      end
      
      def test?
        @options[:test] || false
      end

      def avs_result
        @avs_result ||= AVSResult.new({:code => avs_resp_code})
      end
      
      def cvv_result
        @cvv_result ||= CVVResult.new({:code => cvv2_result_code})
      end

      private
      def tagify(s)
        s.to_s.gsub(/\/(.?)/) { 
          "::#{$1.upcase}" 
        }.gsub(/(?:^|_)(.)/) { 
          $1.upcase 
        }
      end

      def value_at(sym)
        node = REXML::XPath.first(@doc, "//#{tagify(sym)}")
        node ? node.text : nil
      end

      def method_missing(sym, *args, &blk)
        if self.class.elements.include?(sym)
          value_at(sym)
        else
          super(sym, *args, &blk)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
johnideal-activemerchant-1.4.4 lib/active_merchant/billing/gateways/paymentech_orbital/paymentech_orbital_response.rb