Exemplo n.º 1
0
 /// <summary>
 /// Adds authentication information to the request.
 /// </summary>
 /// <param name="request">The request.</param>
 void AuthenticateRequest(ANetApiRequest request)
 {
     request.merchantAuthentication                 = new merchantAuthenticationType();
     request.merchantAuthentication.name            = _apiLogin;
     request.merchantAuthentication.Item            = _transactionKey;
     request.merchantAuthentication.ItemElementName = ItemChoiceType.transactionKey;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Sends the specified API request.
        /// </summary>
        /// <param name="apiRequest">The API request.</param>
        /// <returns></returns>
        public ANetApiResponse Send(ANetApiRequest apiRequest)
        {
            //Authenticate it
            AuthenticateRequest(apiRequest);

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_serviceUrl);

            webRequest.Method      = "POST";
            webRequest.ContentType = "text/xml";
            webRequest.KeepAlive   = true;

            // Serialize the request
            var       type       = apiRequest.GetType();
            var       serializer = new XmlSerializer(type);
            XmlWriter writer     = new XmlTextWriter(webRequest.GetRequestStream(), Encoding.UTF8);

            serializer.Serialize(writer, apiRequest);
            writer.Close();


            // Get the response
            WebResponse webResponse = webRequest.GetResponse();

            // Load the response from the API server into an XmlDocument.
            _xmlDoc = new XmlDocument();
            _xmlDoc.Load(XmlReader.Create(webResponse.GetResponseStream()));


            var response = DecideResponse(_xmlDoc);

            CheckForErrors(response);
            return(response);
        }
        /// <summary>
        /// Sends the specified API request.
        /// </summary>
        /// <param name="apiRequest">The API request.</param>
        /// <returns></returns>
        public ANetApiResponse Send(ANetApiRequest apiRequest)
        {
            //Authenticate it
            AuthenticateRequest(apiRequest);

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_serviceUrl);

            webRequest.Method      = "POST";
            webRequest.ContentType = "text/xml";
            webRequest.KeepAlive   = true;

            //set the http connection timeout
            var httpConnectionTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpConnectionTimeout);

            webRequest.Timeout = (httpConnectionTimeout != 0 ? httpConnectionTimeout : Constants.HttpConnectionDefaultTimeout);

            //set the time out to read/write from stream
            var httpReadWriteTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpReadWriteTimeout);

            webRequest.ReadWriteTimeout = (httpReadWriteTimeout != 0 ? httpReadWriteTimeout : Constants.HttpReadWriteDefaultTimeout);

            // Serialize the request
            var       type       = apiRequest.GetType();
            var       serializer = new XmlSerializer(type);
            XmlWriter writer     = new XmlTextWriter(webRequest.GetRequestStream(), Encoding.UTF8);

            serializer.Serialize(writer, apiRequest);
            writer.Close();

            // Set Tls to Tls1.2
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            // Get the response
            WebResponse webResponse = webRequest.GetResponse();

            // Load the response from the API server into an XmlDocument.
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(XmlReader.Create(webResponse.GetResponseStream(), new XmlReaderSettings()));


            var response = DecideResponse(xmlDoc);

            CheckForErrors(response, xmlDoc);
            return(response);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sends the specified API request.
        /// </summary>
        /// <param name="apiRequest">The API request.</param>
        /// <returns></returns>
        public ANetApiResponse Send(ANetApiRequest apiRequest)
        {
            //Authenticate it
            AuthenticateRequest(apiRequest);

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_serviceUrl);

            webRequest.Method                = "POST";
            webRequest.ContentType           = "text/xml";
            webRequest.Headers["Connection"] = "keep-alive";

            /* HACK: No timeout properties are available on WebRequest in .NET Core
             * //set the http connection timeout
             * var httpConnectionTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpConnectionTimeout);
             * webRequest.Timeout = (httpConnectionTimeout != 0 ? httpConnectionTimeout : Constants.HttpConnectionDefaultTimeout);
             *
             * //set the time out to read/write from stream
             * var httpReadWriteTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpReadWriteTimeout);
             * webRequest.ReadWriteTimeout = (httpReadWriteTimeout != 0 ? httpReadWriteTimeout : Constants.HttpReadWriteDefaultTimeout);
             */

            // Serialize the request
            var type       = apiRequest.GetType();
            var serializer = new XmlSerializer(type);

            using (XmlWriter writer = XmlWriter.Create(HttpUtility.GetRequestStreamAsync(webRequest).Result, new XmlWriterSettings {
                Encoding = Encoding.UTF8
            }))
            {
                serializer.Serialize(writer, apiRequest);
            }

            // Get the response
            WebResponse webResponse = HttpUtility.GetResponseAsync(webRequest).Result;

            // Load the response from the API server into an XmlDocument.
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(XmlReader.Create(webResponse.GetResponseStream(), new XmlReaderSettings()));

            var response = DecideResponse(xmlDoc);

            CheckForErrors(response, xmlDoc);
            return(response);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Adds authentication information to the request.
 /// </summary>
 /// <param name="request">The request.</param>
 void AuthenticateRequest(ANetApiRequest request)
 {
     request.merchantAuthentication                = new merchantAuthenticationType();
     request.merchantAuthentication.name           = _apiLogin;
     request.merchantAuthentication.transactionKey = _transactionKey;
 }