require File.dirname(__FILE__) + "/../test_helper" class TaggedPreAuthTest < Test::Unit::TestCase def setup @transporter = EWS::Transporter.new(@@credentials.config['location']) # do initial recurring seed request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :recurring_seed_pre_auth)) request.amount = 11.25 assert request.valid?, request.errors.inspect @response = @transporter.submit(request, :json) assert @response.approved? end def test_mandatory request = EWS::Transaction::Request.new(:transaction_type => :tagged_pre_auth) 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.transaction_tag = 1234 assert !request.valid? assert_equal "authorization_num must be supplied", request.errors[:authorization_num] request.authorization_num = "TH6754" assert !request.valid? assert_equal "amount must be supplied", request.errors[:amount] request.amount = 11.25 assert request.valid? request.cc_number = "4111111111111111" assert !request.valid? assert_equal "do not set cc_number for tagged transactions", request.errors[:cc_number] end def test_json request = EWS::Transaction::Request.new({ :transaction_type => :tagged_pre_auth, :amount => 12.50, :transaction_tag => @response.transaction_tag, :authorization_num => @response.authorization_num }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :json) end def test_rest request = EWS::Transaction::Request.new({ :transaction_type => :tagged_pre_auth, :amount => 12.50, :transaction_tag => @response.transaction_tag, :authorization_num => @response.authorization_num }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :rest) end def test_soap request = EWS::Transaction::Request.new({ :transaction_type => :tagged_pre_auth, :amount => 12.50, :transaction_tag => @response.transaction_tag, :authorization_num => @response.authorization_num }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :soap) end def test_multiple_pre_auths_against_one_seed request = EWS::Transaction::Request.new({ :transaction_type => :tagged_pre_auth, :amount => 12.50, :transaction_tag => @response.transaction_tag, :authorization_num => @response.authorization_num }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :json) assert_details_correct request, @transporter.submit(request, :json) assert_details_correct request, @transporter.submit(request, :json) end def test_after_recurring_seed_purchase # do initial recurring seed purchase pre_request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :recurring_seed_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? # now do the tagged pre auth request = EWS::Transaction::Request.new({ :transaction_type => :tagged_pre_auth, :amount => 12.50, :transaction_tag => pre_response.transaction_tag, :authorization_num => pre_response.authorization_num }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :json) end end