$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" require 'test/unit' require 'lib/exact4r' require 'ruby-debug' require 'mocha' require File.dirname(__FILE__) + '/credentials' @@credentials = Exact::Credentials.new 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(@@credentials.current_gateway) end def track1_params { :track1 => TEST_TRACK1 }.merge(@@credentials.current_gateway) end def track2_params { :track2 => TEST_TRACK2, :cardholder_name => TEST_CARD_HOLDER }.merge(@@credentials.current_gateway) 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(@@credentials.current_gateway).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 => @@credentials.current_gateway[:gateway_id], :language => 4, :pan => "12345678900987654321", :password => @@credentials.current_gateway[: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