require File.dirname(__FILE__) + "/../test_helper" class PreAuthCompletionTest < Test::Unit::TestCase def setup @transporter = EWS::Transporter.new(@@credentials.config['location']) end def test_mandatory request = EWS::Transaction::Request.new(:transaction_type => :pre_auth_completion) 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 "One of the following must be supplied: cc_number, track1, track2 or transaction_tag.", request.errors[:base] request.cc_number = "4111111111111111" assert !request.valid? assert_equal "cc_expiry must be supplied", request.errors[:cc_expiry] request.cc_expiry = "0913" assert !request.valid? assert_equal "cardholder_name must be supplied", request.errors[:cardholder_name] request.cardholder_name = "Simon Jones" assert !request.valid? assert_equal "amount must be supplied", request.errors[:amount] request.amount = 10 assert !request.valid? assert_equal "authorization_num must be supplied", request.errors[:authorization_num] request.authorization_num = "TH6754" assert request.valid? end def test_by_credit_card request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :pre_auth_completion)) request.amount = 11.25 request.authorization_num = send_pre_auth.authorization_num assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :json) request.authorization_num = send_pre_auth.authorization_num assert_details_correct request, @transporter.submit(request, :rest) request.authorization_num = send_pre_auth.authorization_num assert_details_correct request, @transporter.submit(request, :soap) end def test_by_track1 request = EWS::Transaction::Request.new(track1_params.merge(:transaction_type => :pre_auth_completion)) request.amount = 11.25 request.authorization_num = send_pre_auth.authorization_num assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :json) request.authorization_num = send_pre_auth.authorization_num assert_details_correct request, @transporter.submit(request, :rest) request.authorization_num = send_pre_auth.authorization_num assert_details_correct request, @transporter.submit(request, :soap) end def test_by_track2 request = EWS::Transaction::Request.new(track2_params.merge(:transaction_type => :pre_auth_completion)) request.amount = 11.25 request.authorization_num = send_pre_auth.authorization_num assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :json) request.authorization_num = send_pre_auth.authorization_num assert_details_correct request, @transporter.submit(request, :rest) request.authorization_num = send_pre_auth.authorization_num assert_details_correct request, @transporter.submit(request, :soap) end # A PreAuthCompletion requires a PreAuth request to have been sent previously. def send_pre_auth request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :pre_auth)) request.amount = 11.25 assert request.valid?, request.errors.inspect response = @transporter.submit(request, :json) assert response.approved? response end private :send_pre_auth end