require File.dirname(__FILE__) + "/../test_helper" class BatchQueryCloseTest < Test::Unit::TestCase # NOTE: DO NOT submit an amount with a cents value of LESS THAN 25 to this host as it will # reply with a bank_resp_code == 200 + cents def setup @transporter = EWS::Transporter.new(@@credentials.config['location']) end def test_mandatory request = EWS::Transaction::Request.new(:transaction_type => :batch_query) assert !request.valid? assert_equal "gateway_id must be supplied", request.errors[:gateway_id] request.gateway_id = @@credentials.chase_batch[:gateway_id] assert !request.valid? assert_equal "password must be supplied", request.errors[:password] request.password = @@credentials.chase_batch[:password] assert request.valid? # yep, that's it. only gateway_id and password are required request = EWS::Transaction::Request.new(:transaction_type => :batch_close) assert !request.valid? assert_equal "gateway_id must be supplied", request.errors[:gateway_id] request.gateway_id = @@credentials.chase_batch[:gateway_id] assert !request.valid? assert_equal "password must be supplied", request.errors[:password] request.password = @@credentials.chase_batch[:password] assert request.valid? end def test_query return unless @@credentials.chase? # send a transaction to ensure there is a batch in progress submit_purchase request = EWS::Transaction::Request.new(@@credentials.chase_batch.merge(:transaction_type => :batch_query)) response = @transporter.submit(request, :json) assert_response_approved response assert_equal "BATINQ", response.authorization_num response = @transporter.submit(request, :rest) assert_response_approved response assert_equal "BATINQ", response.authorization_num response = @transporter.submit(request, :soap) assert_response_approved response assert_equal "BATINQ", response.authorization_num end def test_close_json return unless @@credentials.chase? # send a transaction to ensure there is a batch in progress submit_purchase request = EWS::Transaction::Request.new(@@credentials.chase_batch.merge(:transaction_type => :batch_close)) response = @transporter.submit(request, :json) assert_response_approved response assert_equal "BATCLS", response.authorization_num end def test_close_rest return unless @@credentials.chase? # send a transaction to ensure there is a batch in progress submit_purchase request = EWS::Transaction::Request.new(@@credentials.chase_batch.merge(:transaction_type => :batch_close)) response = @transporter.submit(request, :rest) assert_response_approved response assert_equal "BATCLS", response.authorization_num end def test_close_soap return unless @@credentials.chase? # send a transaction to ensure there is a batch in progress submit_purchase request = EWS::Transaction::Request.new(@@credentials.chase_batch.merge(:transaction_type => :batch_close)) response = @transporter.submit(request, :soap) assert_response_approved response assert_equal "BATCLS", response.authorization_num end def test_cant_close_already_closed_batch return unless @@credentials.chase? # ensure any existing batch is closed submit_batch_close response = submit_batch_close assert !response.approved? assert_nil response.bank_resp_code assert_equal "BAT ALREADY RELS", response.bank_message end # test cards # Visa: 4111111111111111 # MasterCard: 5500000000000004 # American Express: 340000000000009 def test_summation return unless @@credentials.chase? submit_batch_close # ensure we're starting a new batch submit_purchase(:amount => 10.00) submit_purchase(:amount => 15.29) submit_purchase(:amount => 122.75) # 3 transactions, total of 148.04 on VISA submit_purchase({:cc_number => "5500000000000004", :amount => 1754.60}) submit_purchase({:cc_number => "5500000000000004", :amount => 1544.87}) # 2 transactions, total of 3299.47 on Mastercard submit_purchase({:cc_number => "340000000000009", :amount => 43.26}) submit_purchase({:cc_number => "340000000000009", :amount => 185.75}) submit_purchase({:cc_number => "340000000000009", :amount => 877.53}) submit_purchase({:cc_number => "340000000000009", :amount => 7.45}) # 4 transactions, total of 1113.99 on Amex response = submit_batch_query assert_response_approved response assert_equal "BATINQ", response.authorization_num assert_equal "", response.bank_message # now close the batch response = submit_batch_close assert_response_approved response assert_equal "BATCLS", response.authorization_num assert_equal "", response.bank_message end def test_large_summation return unless @@credentials.chase? submit_batch_close # ensure we're starting a new batch 10.times { submit_purchase(:amount => 99999.0) } response = submit_batch_query assert_response_approved response assert_equal "BATINQ", response.authorization_num assert_equal "", response.bank_message # now close the batch response = submit_batch_close assert_response_approved response assert_equal "BATCLS", response.authorization_num assert_equal "", response.bank_message end private def submit_batch_query request = EWS::Transaction::Request.new(@@credentials.chase_batch.merge(:transaction_type => :batch_query)) @transporter.submit(request, :rest) end def submit_batch_close request = EWS::Transaction::Request.new(@@credentials.chase_batch.merge(:transaction_type => :batch_close)) @transporter.submit(request, :json) end def submit_purchase(options = {:amount => 10.0}) params = cc_number_params. merge(@@credentials.chase_batch). merge(:transaction_type => :purchase). merge(options) request = EWS::Transaction::Request.new(params) assert request.valid?, request.errors.inspect # if this is failing, see note at top of page first! assert @transporter.submit(request, :json).approved? end def assert_response_approved(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_equal "000", response.bank_resp_code end end