require File.dirname(__FILE__) + "/../test_helper" class TaggedOnlineDebitRefundTest < Test::Unit::TestCase def setup @transporter = EWS::Transporter.new(@@credentials.config['location']) end def test_mandatory request = EWS::Transaction::Request.new(:transaction_type => :tagged_online_debit_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 return unless @@credentials.chase? response = do_online_debit_purchase request = EWS::Transaction::Request.new({ :transaction_type => :tagged_online_debit_refund, :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 return unless @@credentials.chase? response = do_online_debit_purchase request = EWS::Transaction::Request.new({ :transaction_type => :tagged_online_debit_refund, :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 return unless @@credentials.chase? response = do_online_debit_purchase request = EWS::Transaction::Request.new({ :transaction_type => :tagged_online_debit_refund, :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_refunds_against_one_seed return unless @@credentials.chase? response = do_online_debit_purchase request = EWS::Transaction::Request.new({ :transaction_type => :tagged_online_debit_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_purchase return unless @@credentials.chase? # do initial recurring seed pre auth pre_request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :recurring_seed_purchase).merge(@@credentials.current_gateway)) 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 refund request = EWS::Transaction::Request.new({ :transaction_type => :tagged_online_debit_refund, :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 response = @transporter.submit(request, :json) assert !response.approved? end def test_not_permitted_after_recurring_seed_pre_auth return unless @@credentials.chase? # do initial recurring seed pre auth pre_request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :recurring_seed_pre_auth).merge(@@credentials.current_gateway)) 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 refund request = EWS::Transaction::Request.new({ :transaction_type => :tagged_online_debit_refund, :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 response = @transporter.submit(request, :json) assert !response.approved? end def test_not_permitted_after_plain_purchase return unless @@credentials.chase? # do initial purchase pre_request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :purchase).merge(@@credentials.current_gateway)) 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 refund request = EWS::Transaction::Request.new({ :transaction_type => :tagged_online_debit_refund, :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 response = @transporter.submit(request, :json) assert !response.approved? end private def do_online_debit_purchase # do initial Online Debit Purchase request = EWS::Transaction::Request.new({ :transaction_type => :idebit_purchase, :amount => 13.00, :pan => TEST_CARD_NUMBER, :cardholder_name => TEST_CARD_HOLDER }.merge(@@credentials.current_gateway)) assert request.valid?, request.errors.inspect response = @transporter.submit(request, :json) assert response.approved? response end end