require File.dirname(__FILE__) + "/../test_helper" class TaggedRefundTest < 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_purchase)) 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_refund) 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_refund, :amount => 11.25, :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_refund, :amount => 11.25, :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_refund, :amount => 11.25, :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_refunds_against_one_seed request = EWS::Transaction::Request.new({ :transaction_type => :tagged_refund, :amount => 3.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) # can't refund more than original amount response = @transporter.submit(request, :json) assert !response.approved? end def test_not_permitted_after_recurring_seed_pre_auth # do initial recurring seed pre auth pre_request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :recurring_seed_pre_auth)) pre_request.amount = 11.25 assert pre_request.valid?, pre_request.errors.inspect pre_response = @transporter.submit(pre_request, :json) assert pre_response.approved? # now do the tagged refund request = EWS::Transaction::Request.new({ :transaction_type => :tagged_refund, :amount => 11.25, :transaction_tag => pre_response.transaction_tag, :authorization_num => pre_response.authorization_num }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect response = @transporter.submit(request, :json) assert !response.approved? end def test_permitted_after_plain_purchase # do initial purchase pre_request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :purchase)) pre_request.amount = 11.25 assert pre_request.valid?, pre_request.errors.inspect pre_response = @transporter.submit(pre_request, :json) assert pre_response.approved? # now do the tagged refund request = EWS::Transaction::Request.new({ :transaction_type => :tagged_refund, :amount => 11.25, :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