Пример #1
0
        private TransactionRequestResult ParseRequestResults(string xml)
        {
            var sr  = new StringReader(xml);
            var xtr = new XmlTextReader(sr)
            {
                XmlResolver        = null,
                WhitespaceHandling = WhitespaceHandling.None
            };

            // get the root node
            xtr.Read();

            var res = new TransactionRequestResult();

            if ((xtr.NodeType != XmlNodeType.Element) || (xtr.Name != "TransactionRequest"))
            {
                return(res);
            }

            while (xtr.Read())
            {
                if ((xtr.NodeType != XmlNodeType.Element) || xtr.IsEmptyElement)
                {
                    continue;
                }

                var currentNode = xtr.Name;
                xtr.Read();
                if (xtr.NodeType != XmlNodeType.Text)
                {
                    continue;
                }

                switch (currentNode)
                {
                case "Result":
                    res.Result = bool.Parse(xtr.Value);
                    break;

                case "URI":
                    res.Uri = xtr.Value;
                    break;

                case "Error":
                    res.Error = xtr.Value;
                    break;
                }
            }

            return(res);
        }
        /// <summary>
        /// Parse the result of the transaction request and save the appropriate fields in an object to be used later
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        private TransactionRequestResult ParseResults(string xml)
        {
            string        _currentNode;
            StringReader  _sr  = new StringReader(xml);
            XmlTextReader _xtr = new XmlTextReader(_sr);

            _xtr.XmlResolver        = null;
            _xtr.WhitespaceHandling = WhitespaceHandling.None;

            // get the root node
            _xtr.Read();

            TransactionRequestResult res = new TransactionRequestResult();

            if ((_xtr.NodeType == XmlNodeType.Element) && (_xtr.Name == "TransactionRequest"))
            {
                while (_xtr.Read())
                {
                    if ((_xtr.NodeType == XmlNodeType.Element) && (!_xtr.IsEmptyElement))
                    {
                        _currentNode = _xtr.Name;
                        _xtr.Read();
                        if (_xtr.NodeType == XmlNodeType.Text)
                        {
                            switch (_currentNode)
                            {
                            case "Result":
                                res.Result = bool.Parse(_xtr.Value);
                                break;

                            case "URI":
                                res.URI = _xtr.Value;
                                break;

                            case "Error":
                                res.Error = _xtr.Value;
                                break;
                            }
                        }
                    }
                }
            }

            return(res);
        }
        /// <summary>
        /// Post process payment (payment gateways that require redirecting)
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>The error status, or String.Empty if no errors</returns>
        public string PostProcessPayment(Order order)
        {
            InitSettings();

            string resultXML = string.Empty;

            string strPost = "CustomerID=" + customerID;

            strPost += Format("UserName", username);
            //send amounts to the generator in DOLLAR FORM. ie 10.05
            strPost += Format("Amount", order.OrderTotal.ToString("####.00", new CultureInfo("en-US", false).NumberFormat));
            strPost += Format("Currency", CurrencyManager.PrimaryStoreCurrency.CurrencyCode);


            // supported languages:
            // "EN" - English
            // "FR" - French
            // "DE" - German
            // "ES" - Spanish
            // "NL" - Dutch
            strPost += Format("Language", "EN");
            strPost += Format("CustomerFirstName", order.BillingFirstName);
            strPost += Format("CustomerLastName", order.BillingLastName);
            strPost += Format("CustomerAddress", order.BillingAddress1);
            strPost += Format("CustomerCity", order.BillingCity);
            strPost += Format("CustomerState", order.BillingStateProvince);
            strPost += Format("CustomerPostCode", order.BillingZipPostalCode);
            strPost += Format("CustomerCountry", order.BillingCountry);
            strPost += Format("CustomerEmail", order.BillingEmail);
            strPost += Format("CustomerPhone", order.BillingPhoneNumber);
            strPost += Format("InvoiceDescription", order.OrderID.ToString());
            strPost += Format("CancelURL", CommonHelper.GetStoreLocation(false) + "eWayMerchantReturn.aspx");
            strPost += Format("ReturnUrl", CommonHelper.GetStoreLocation(false) + "eWayMerchantReturn.aspx");

            strPost += Format("MerchantReference", order.OrderID.ToString());
            strPost += Format("MerchantInvoice", order.OrderID.ToString());
            strPost += Format("MerchantOption1", order.OrderID.ToString());

            string url = paymentPage + "Request?" + strPost;

            HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);

            objRequest.Method = WebRequestMethods.Http.Get;

            HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();

            //get the response from the transaction generate page
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            {
                resultXML = sr.ReadToEnd();
                // Close and clean up the StreamReader
                sr.Close();
            }

            //parse the result message
            TransactionRequestResult resultObj = ParseResults(resultXML);

            if (resultObj.Result)
            {
                //redirect the user to the payment page
                HttpContext.Current.Response.Redirect(resultObj.URI);
            }
            else
            {
                throw new NopException(resultObj.Error);
            }
            return(string.Empty);
        }
        /// <summary>
        /// Parse the result of the transaction request and save the appropriate fields in an object to be used later
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        private TransactionRequestResult ParseResults(string xml)
        {
            string _currentNode;
            StringReader _sr = new StringReader(xml);
            XmlTextReader _xtr = new XmlTextReader(_sr);
            _xtr.XmlResolver = null;
            _xtr.WhitespaceHandling = WhitespaceHandling.None;

            // get the root node
            _xtr.Read();

            TransactionRequestResult res = new TransactionRequestResult();

            if ((_xtr.NodeType == XmlNodeType.Element) && (_xtr.Name == "TransactionRequest"))
            {
                while (_xtr.Read())
                {
                    if ((_xtr.NodeType == XmlNodeType.Element) && (!_xtr.IsEmptyElement))
                    {
                        _currentNode = _xtr.Name;
                        _xtr.Read();
                        if (_xtr.NodeType == XmlNodeType.Text)
                        {
                            switch (_currentNode)
                            {
                                case "Result":
                                    res.Result = bool.Parse(_xtr.Value);
                                    break;

                                case "URI":
                                    res.URI = _xtr.Value;
                                    break;

                                case "Error":
                                    res.Error = _xtr.Value;
                                    break;
                            }
                        }
                    }
                }
            }

            return res;
        }