require 'test_helper' class MerchantWareTest < Test::Unit::TestCase def setup @gateway = MerchantWareGateway.new( :login => 'login', :password => 'password', :name => 'name' ) @credit_card = credit_card @amount = 100 @options = { :order_id => '1', :billing_address => address } end def test_successful_authorization @gateway.expects(:ssl_post).returns(successful_authorization_response) assert response = @gateway.authorize(@amount, @credit_card, @options) assert_instance_of Response, response assert_success response assert_equal '4706382;1', response.authorization assert_equal "APPROVED", response.message assert response.test? end def test_soap_fault_during_authorization response_500 = stub(:code => "500", :message => "Internal Server Error", :body => fault_authorization_response) @gateway.expects(:ssl_post).raises(ActiveMerchant::ResponseError.new(response_500)) assert response = @gateway.authorize(@amount, @credit_card, @options) assert_instance_of Response, response assert_failure response assert response.test? assert_nil response.authorization assert_equal "Server was unable to process request. ---> strPAN should be at least 13 to at most 19 characters in size. Parameter name: strPAN", response.message assert_equal response_500.code, response.params["http_code"] assert_equal response_500.message, response.params["http_message"] end def test_failed_authorization @gateway.expects(:ssl_post).returns(failed_authorization_response) assert response = @gateway.authorize(@amount, @credit_card, @options) assert_instance_of Response, response assert_failure response assert response.test? assert_nil response.authorization assert_equal "transaction type not supported by version", response.message assert_equal "FAILED", response.params["status"] assert_equal "1014", response.params["failure_code"] end def test_failed_void @gateway.expects(:ssl_post).returns(failed_void_response) assert response = @gateway.void("1") assert_instance_of Response, response assert_failure response assert response.test? assert_nil response.authorization assert_equal "decline", response.message assert_equal "DECLINED", response.params["status"] assert_equal "1012", response.params["failure_code"] end def test_avs_result @gateway.expects(:ssl_post).returns(successful_authorization_response) response = @gateway.authorize(@amount, @credit_card, @options) assert_equal 'N', response.avs_result['code'] end def test_cvv_result @gateway.expects(:ssl_post).returns(successful_authorization_response) response = @gateway.authorize(@amount, @credit_card, @options) assert_equal 'M', response.cvv_result['code'] end private def successful_authorization_response <<-XML 4706382 1 7/3/2009 2:05:04 AM APPROVED VI0100 Longbob Longsen 1.00 5 ************4242 0 N M 1 XML end def fault_authorization_response <<-XML soap:Server Server was unable to process request. ---> strPAN should be at least 13 to at most 19 characters in size. Parameter name: strPAN XML end def failed_authorization_response <<-XML 1 7/3/2009 3:04:33 AM FAILED;1014;transaction type not supported by version Longbob Longsen 1.00 5 *********0123 0 1 XML end def failed_void_response <<-XML 4707277 7/3/2009 3:28:38 AM DECLINED;1012;decline 3 0 0 XML end end