require File.dirname(__FILE__) + "/../test_helper" # # A ReferencedVoid behaves the same as a TaggedVoid, except, instead of using transaction_tag, # authorization_num and amount to lookup the transaction to be voided, you use reference_no, # customer_ref and amount. # class ReferencedVoidTest < Test::Unit::TestCase def setup @transporter = EWS::Transporter.new(@@credentials.config['location']) # do initial purchase request = EWS::Transaction::Request.new(cc_number_params.merge({ :transaction_type => :purchase, :amount => 11.25, :reference_no => "reference_no_#{rand(10)}", :customer_ref => "customer_ref_#{rand(10)}" })) assert request.valid?, request.errors.inspect @purchase = @transporter.submit(request, :json) assert @purchase.approved? end def test_mandatory request = EWS::Transaction::Request.new(:transaction_type => :referenced_void) 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 "reference_no must be supplied", request.errors[:reference_no] request.reference_no = "something" assert !request.valid? assert_equal "customer_ref must be supplied", request.errors[:customer_ref] request.customer_ref = "something" assert !request.valid? assert_equal "amount must be supplied", request.errors[:amount] request.amount = 11.25 assert request.valid? # don't set any CC information [:cc_number, :pan, :track1, :track2, :transaction_tag].each do |attr_name| request.send("#{attr_name}=", "something") assert !request.valid? assert_equal "#{attr_name} must not be set for referenced_void transactions", request.errors[attr_name] request.send("#{attr_name}=", nil) end end def test_json request = EWS::Transaction::Request.new({ :transaction_type => :referenced_void, :amount => 11.25, :reference_no => @purchase.reference_no, :customer_ref => @purchase.customer_ref }.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 => :referenced_void, :amount => 11.25, :reference_no => @purchase.reference_no, :customer_ref => @purchase.customer_ref }.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 => :referenced_void, :amount => 11.25, :reference_no => @purchase.reference_no, :customer_ref => @purchase.customer_ref }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :soap) end def test_requires_correct_amount request = EWS::Transaction::Request.new({ :transaction_type => :referenced_void, :amount => 3.50, :reference_no => @purchase.reference_no, :customer_ref => @purchase.customer_ref }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect response = @transporter.submit(request, :json) assert !response.approved? request.amount = 13.50 response = @transporter.submit(request, :rest) assert !response.approved? request.amount = 11.25 assert_details_correct request, @transporter.submit(request, :soap) end def test_multiple_voids_against_one_transaction request = EWS::Transaction::Request.new({ :transaction_type => :referenced_void, :amount => 11.25, :reference_no => @purchase.reference_no, :customer_ref => @purchase.customer_ref }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :json) # can't void an already-voided transaction response = @transporter.submit(request, :json) assert !response.approved? end end