require File.dirname(__FILE__) + "/../test_helper" # # A TaggedUpdate request allows a merchant to edit the reference_no and customer_ref values of a # previous transaction. Please note that this is NOT a financial transaction, it merely allows # you to change the values stored in our DB for a given transaction. # # In common with all other tagged transactions, you supply the transaction_tag and authorization_num # for the transaction whose values you wish to change, along with the new values for reference_no # and/or customer_ref. # # NOTE: nil, empty string ("") or whitespace string (" ") are not permitted, and, although the # request will be approved, the relevant attribute WILL NOT CHANGE. # class TaggedUpdateTest < Test::Unit::TestCase def setup @transporter = EWS::Transporter.new(@@credentials.config['location']) # do initial purchase request request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :purchase)) request.amount = 11.25 request.reference_no = "reference_no" request.customer_ref = "customer_ref" assert request.valid?, request.errors.inspect @purchase = @transporter.submit(request, :json) assert @purchase.approved?, @purchase.to_yaml end def test_mandatory request = EWS::Transaction::Request.new(:transaction_type => :tagged_update) 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?, request.errors.inspect 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 = tagged_update_request(@purchase) assert request.valid?, request.errors.inspect response = @transporter.submit(request, :json) assert response.approved? # we're getting the details of the original transction returned assert_equal @purchase.transaction_tag, response.transaction_tag assert_equal "something_new", response.reference_no assert_equal "something_old", response.customer_ref end def test_rest request = tagged_update_request(@purchase) assert request.valid?, request.errors.inspect response = @transporter.submit(request, :rest) # we're getting the details of the original transction returned assert_equal @purchase.transaction_tag, response.transaction_tag assert_equal "something_new", response.reference_no assert_equal "something_old", response.customer_ref end def test_soap request = tagged_update_request(@purchase) assert request.valid?, request.errors.inspect response = @transporter.submit(request, :soap) # we're getting the details of the original transction returned assert_equal @purchase.transaction_tag, response.transaction_tag assert_equal "something_new", response.reference_no assert_equal "something_old", response.customer_ref end def test_multiple_updates request1 = tagged_update_request(@purchase) assert request1.valid?, request1.errors.inspect response1 = @transporter.submit(request1, :soap) assert_equal "something_new", response1.reference_no assert_equal "something_old", response1.customer_ref request2 = tagged_update_request(@purchase, { :reference_no => "bananas", :customer_ref => "oranges" }) assert request2.valid?, request2.errors.inspect response2 = @transporter.submit(request2, :soap) assert_equal "bananas", response2.reference_no assert_equal "oranges", response2.customer_ref end def test_updating_single_attribute # change only reference_no request1 = tagged_update_request(@purchase, {:customer_ref => nil}) assert request1.valid?, request1.errors.inspect response1 = @transporter.submit(request1, :soap) assert_equal "something_new", response1.reference_no assert_equal "customer_ref", response1.customer_ref # change only customer_ref request2 = tagged_update_request(@purchase, {:reference_no => nil}) assert request2.valid?, request2.errors.inspect response2 = @transporter.submit(request2, :soap) assert_equal "something_new", response2.reference_no assert_equal "something_old", response2.customer_ref end def test_empty_strings_ignored request1 = tagged_update_request(@purchase, {:customer_ref => ""}) assert request1.valid?, request1.errors.inspect response1 = @transporter.submit(request1, :soap) assert_equal "something_new", response1.reference_no assert_equal "customer_ref", response1.customer_ref end def test_whitepaces_strings_ignored request1 = tagged_update_request(@purchase, {:customer_ref => " "}) assert request1.valid?, request1.errors.inspect response1 = @transporter.submit(request1, :soap) assert_equal "something_new", response1.reference_no assert_equal "customer_ref", response1.customer_ref end def tagged_update_request(original_txn, options = {}) EWS::Transaction::Request.new({ :transaction_type => :tagged_update, :transaction_tag => original_txn.transaction_tag, :authorization_num => original_txn.authorization_num, :reference_no => "something_new", :customer_ref => "something_old" }.merge(options).merge(@@credentials.current_gateway)) end private :tagged_update_request end