require File.dirname(__FILE__) + "/../test_helper" class TransactionDetailsTest < Test::Unit::TestCase def setup @transporter = EWS::Transporter.new(@@credentials.config['location']) end def test_mandatory request = EWS::Transaction::Request.new(:transaction_type => :transaction_details) assert !request.valid? assert_equal "gateway_id must be supplied", request.errors[:gateway_id] request.gateway_id = @@credentials.current_gateway[:gateway_id] assert !request.valid? assert_equal "password must be supplied", request.errors[:password] request.password = @@credentials.current_gateway[:password] assert !request.valid? assert_equal "transaction_tag must be supplied", request.errors[:transaction_tag] request.transaction_tag = 1234 assert request.valid? end def test_credit_transaction_details # do initial purchase pre_request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :purchase)) pre_request.amount = 10.1 assert pre_request.valid?, pre_request.errors.inspect pre_response = @transporter.submit(pre_request, :json) assert pre_response.approved? request = EWS::Transaction::Request.new({ :transaction_type => :transaction_details, :transaction_tag => pre_response.transaction_tag }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect [:json, :rest, :soap].each do |encoding| response = @transporter.submit(request, encoding) assert_equal "############1111", response.cc_number assert_details_match_original_response pre_response, response, encoding end end def test_supplying_auth_num_decrypts_cc_number # do initial purchase pre_request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :purchase)) pre_request.amount = 10.1 assert pre_request.valid?, pre_request.errors.inspect pre_response = @transporter.submit(pre_request, :json) assert pre_response.approved? request = EWS::Transaction::Request.new({ :transaction_type => :transaction_details, :transaction_tag => pre_response.transaction_tag, :authorization_num => pre_response.authorization_num }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect [:json, :rest, :soap].each do |encoding| response = @transporter.submit(request, encoding) assert_equal "4111111111111111", response.cc_number assert_details_match_original_response pre_response, response, encoding end end def test_encodes_parameters # do initial purchase pre_request = EWS::Transaction::Request.new(cc_number_params.merge({ :transaction_type => :purchase, :reference_no => "barry&=x=jones" })) pre_request.amount = 10.1 assert pre_request.valid?, pre_request.errors.inspect pre_response = @transporter.submit(pre_request, :json) assert pre_response.approved? request = EWS::Transaction::Request.new({ :transaction_type => :transaction_details, :transaction_tag => pre_response.transaction_tag, :authorization_num => pre_response.authorization_num, :reference_no => "barry&=x=jones" }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect [:json, :rest, :soap].each do |encoding| response = @transporter.submit(request, encoding) assert_not_nil response, "should not be nil for #{encoding}" assert response.approved?, "#{encoding}: #{response.error_number} / #{response.error_description} / #{response.exact_message}" assert_equal "4111111111111111", response.cc_number, "should match for #{encoding}" assert_details_match_original_response pre_response, response, encoding end end def test_debit_transaction_details return unless @@credentials.chase? # do initial purchase pre_request = EWS::Transaction::Request.new({ :transaction_type => :idebit_purchase, :amount => 10.1, :pan => TEST_CARD_NUMBER, :cardholder_name => TEST_CARD_HOLDER }.merge(@@credentials.current_gateway)) assert pre_request.valid?, pre_request.errors.inspect pre_response = @transporter.submit(pre_request, :json) assert pre_response.approved? request = EWS::Transaction::Request.new({ :transaction_type => :transaction_details, :transaction_tag => pre_response.transaction_tag }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect [:json, :rest, :soap].each do |encoding| response = @transporter.submit(request, encoding) assert_equal "############1111", response.cc_number assert_details_match_original_response pre_response, response, encoding end end def assert_details_match_original_response(original_response, details_response, encoding) # exclude: client_ip, pan, cc_number [:logon_message, :error_number, :error_description, :transaction_error, :transaction_approved, :exact_resp_code, :exact_message, :bank_resp_code, :bank_message, :bank_resp_code_2, :sequence_no, :avs, :cvv2, :retrieval_ref_no, :cavv_response, :merchant_name, :merchant_address, :merchant_city, :merchant_province, :merchant_country, :merchant_postal, :merchant_url, :gateway_id, :password, :transaction_type, :amount, :surcharge_amount, :transaction_tag, :track1, :track2, :authorization_num, :cc_expiry, :cardholder_name, :cc_verification_str1, :cc_verification_str2, :cvd_presence_ind, :tax1_amount, :tax1_number, :tax2_amount, :tax2_number, :secure_auth_required, :secure_auth_result, :ecommerce_flag, :xid, :cavv, :cavv_algorithm, :reference_no, :customer_ref, :reference_3, :language, :client_email, :user_name, :zip_code].each do |attr_name| next if attr_name == :cc_expiry && %(35 50 54).include?(original_response.transaction_type) o_value = original_response.send(attr_name).to_s d_value = details_response.send(attr_name).to_s assert_equal o_value, d_value, "Encoding: #{encoding} - #{attr_name}: #{o_value} / #{d_value}" end end private :assert_details_match_original_response end