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