$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" require 'test/unit' require 'lib/exact4r' require 'ruby-debug' require 'mocha' # address & authentication for testing against api.e-xact.com # LOCATION = "https://api.e-xact.com/" unless defined?(LOCATION) # EMERGIS_BASIC_AUTH = {:gateway_id => "A04052-01", :password => "2b1jvtds"} unless defined?(EMERGIS_BASIC_AUTH) # CHASE_BASIC_AUTH = {:gateway_id => "A05296-01", :password => "exactbatchdemo"} unless defined?(CHASE_BASIC_AUTH) # VITAL_BASIC_AUTH = {:gateway_id => "A05296-01", :password => "exactbatchdemo"} unless defined?(VITAL_BASIC_AUTH) # MONERIS_BASIC_AUTH = {:gateway_id => "A00049-01", :password => "test1"} unless defined?(MONERIS_BASIC_AUTH) # address & authentication for local testing LOCATION = "http://ws.local/" unless defined?(LOCATION) # I am a Passenger... EMERGIS_BASIC_AUTH = {:gateway_id => "AD0009-01", :password => "8L588rmd"} unless defined?(EMERGIS_BASIC_AUTH) CHASE_BASIC_AUTH = {:gateway_id => "AD0008-01", :password => "7nfcpc7n"} unless defined?(CHASE_BASIC_AUTH) VITAL_BASIC_AUTH = {:gateway_id => "AD0007-01", :password => "3uLi726f"} unless defined?(VITAL_BASIC_AUTH) MONERIS_BASIC_AUTH = {:gateway_id => "AD0154-01", :password => "77hgy56y"} unless defined?(MONERIS_BASIC_AUTH) TEST_CARD_NUMBER = "4111111111111111" unless defined?(TEST_CARD_NUMBER) TEST_CARD_EXPIRY = "0913" unless defined?(TEST_CARD_EXPIRY) TEST_CARD_HOLDER = "Simon Jones" unless defined?(TEST_CARD_HOLDER) TEST_TRACK1 = "%B4111111111111111^Jones/Simon ^1309101063510010000000306000000?" unless defined?(TEST_TRACK1) TEST_TRACK2 = ";4111111111111111=1309101420320192611?" unless defined?(TEST_TRACK2) def cc_number_params { :cc_number => TEST_CARD_NUMBER, :cc_expiry => TEST_CARD_EXPIRY, :cardholder_name => TEST_CARD_HOLDER }.merge(EMERGIS_BASIC_AUTH) end def track1_params { :track1 => TEST_TRACK1 }.merge(EMERGIS_BASIC_AUTH) end def track2_params { :track2 => TEST_TRACK2, :cardholder_name => TEST_CARD_HOLDER }.merge(EMERGIS_BASIC_AUTH) end def assert_details_correct(request, response) assert_not_nil response, "response should not be nil" assert response.approved?, "#{response.error_number} / #{response.error_description} / #{response.exact_message} / #{response.bank_message}" assert_not_nil response.transaction_tag assert_not_nil response.authorization_num assert_equal request.amount.to_s, response.amount.to_s assert_card_details response end def assert_card_details(response) assert_match /............1111/, response.cc_number assert_equal TEST_CARD_HOLDER, response.cardholder_name assert_equal TEST_CARD_EXPIRY, response.cc_expiry unless %w(35 50 54).include?(response.transaction_type) end def basic_params(options = {}) { :transaction_type => :purchase, :amount => "10.13", :cardholder_name => "Simon Brown", :cc_number => "4111111111111111", :cc_expiry => "1012" }.merge(EMERGIS_BASIC_AUTH).merge(options) end # sample values for every request parameter def sample_everything_params { :amount => 10.12, :authorization_num => "12345", :cardholder_name => TEST_CARD_HOLDER, :cavv => "123456789", :cavv_algorithm => 11, :cc_expiry => TEST_CARD_EXPIRY, :cc_number => TEST_CARD_NUMBER, :cc_verification_str1 => "Some String", :cc_verification_str2 => "1234", :client_email => "simon@example.com", :client_ip => "127.0.0.1", :customer_ref => "REF-321", :cvd_presence_ind => 2, :ecommerce_flag => 9, :gateway_id => EMERGIS_BASIC_AUTH[:gateway_id], :language => 4, :pan => "12345678900987654321", :password => EMERGIS_BASIC_AUTH[:password], :reference_3 => "REF-123", :reference_no => "REF-456", :secure_auth_required => 2, :secure_auth_result => 5, :surcharge_amount => 11.34, :tax1_amount => 9.87, :tax1_number => "789", :tax2_amount => 1.23, :tax2_number => "321", :track1 => TEST_TRACK1, :track2 => TEST_TRACK2, :transaction_tag => 5678, :transaction_type => "00", # :purchase :user_name => "user name", :xid => "x678", :zip_code => "10010" } end