require 'test_helper' class ModernPaymentsCimTest < Test::Unit::TestCase def setup Base.mode = :test @gateway = ModernPaymentsCimGateway.new( :login => 'login', :password => 'password' ) @credit_card = credit_card @amount = 100 @options = { :order_id => '1', :billing_address => address, :description => 'Store Purchase' } end def test_create_customer @gateway.expects(:ssl_post).returns(successful_create_customer_response) assert response = @gateway.create_customer(@options) assert_instance_of Response, response assert response.test? assert_success response assert_equal "6677348", response.params["create_customer_result"] end def test_modify_customer_credit_card @gateway.expects(:ssl_post).returns(successful_modify_customer_credit_card_response) assert response = @gateway.modify_customer_credit_card("10001", @credit_card) assert_instance_of Response, response assert response.test? assert_success response assert_equal "6677757", response.params["modify_customer_credit_card_result"] end def test_successful_credit_card_authorization @gateway.expects(:ssl_post).returns(successful_authorization_response) assert response = @gateway.authorize_credit_card_payment("10001", @amount) assert_instance_of Response, response assert response.test? assert_success response assert_equal "18713505", response.params["trans_id"] assert_equal "RESPONSECODE=A\nAUTHCODE=020411\nDECLINEREASON=\nAVSDATA=Z\nTRANSID=C00 17093294", response.params["auth_string"] assert_equal "Approved", response.params["message_text"] assert_equal "true", response.params["approved"] assert_equal "Z", response.params["avs_code"] assert_equal "020411", response.params["auth_code"] assert_equal "C00 17093294", response.params["trans_code"] assert_equal "18713505", response.authorization assert_equal ModernPaymentsCimGateway::SUCCESS_MESSAGE, response.message assert_equal 'Z', response.avs_result['code'] end def test_unsuccessful_credit_card_authorization @gateway.expects(:ssl_post).returns(unsuccessful_credit_card_authorization_response) assert response = @gateway.authorize_credit_card_payment("10001", @amount) assert_instance_of Response, response assert response.test? assert_failure response assert_equal "999", response.authorization assert_match /RESPONSECODE=D/, response.params["message_text"] end def test_soap_fault_response @gateway.expects(:ssl_post).returns(soap_fault_response) assert response = @gateway.create_customer(@options) assert_instance_of Response, response assert response.test? assert_failure response assert_equal "soap:Client", response.params["faultcode"] end private def successful_create_customer_response <<-XML 6677348 XML end def successful_modify_customer_credit_card_response <<-XML 6677757 XML end def unsuccessful_credit_card_authorization_response <<-XML 999 RESPONSECODE=D,AUTHCODE=,DECLINEREASON.1.TAG=,DECLINEREASON.1.ERRORCLASS=card declined,DECLINEREASON.1.PARAM1=05:DECLINE,DECLINEREASON.1.PARAM2=The authorization is declined,DECLINEREASON.1.MESSAGE=Card was declined: The authorization is declined,AVSDATA RESPONSECODE=D,AUTHCODE=,DECLINEREASON.1.TAG=,DECLINEREASON.1.ERRORCLASS=card declined,DECLINEREASON.1.PARAM1=05:DECLINE,DECLINEREASON.1.PARAM2=The authorization is declined,DECLINEREASON.1.MESSAGE=Card was declined: The authorization is declined,AVSDATA false XML end def soap_fault_response <<-XML soap:Client System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: h heheheh http://secure.modpay.com:81/ws/CreateCustomer. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) XML end def successful_authorization_response <<-XML 18713505020411ZC00 17093294 RESPONSECODE=A AUTHCODE=020411 DECLINEREASON= AVSDATA=Z TRANSID=C00 17093294 Approvedtrue XML end end