eWayMerchantReturn.aspx.cs :  » Web-Frameworks » nopCommerce » NopSolutions » NopCommerce » Web » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Web Frameworks » nopCommerce 
nopCommerce » NopSolutions » NopCommerce » Web » eWayMerchantReturn.aspx.cs
//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using NopSolutions.NopCommerce.BusinessLogic;
using NopSolutions.NopCommerce.BusinessLogic.Configuration.Settings;
using NopSolutions.NopCommerce.BusinessLogic.CustomerManagement;
using NopSolutions.NopCommerce.BusinessLogic.Orders;
using NopSolutions.NopCommerce.BusinessLogic.Payment;
using NopSolutions.NopCommerce.Common.Utils;

namespace NopSolutions.NopCommerce.Web{
    public partial class eWayMerchantReturnPage : BaseNopPage
    {
        public string _AuthCode = string.Empty;
        public string _ResponseCode = string.Empty;
        public string _ReturnAmount = string.Empty;
        public string _TrxnNumber = string.Empty;
        public string _TrxnStatus = string.Empty;
        public string _MerchnatOption1 = string.Empty;
        public string _MerchnatOption2 = string.Empty;
        public string _MerchnatOption3 = string.Empty;
        public string _ReferenceNumber = string.Empty;
        public string _ReferenceInvoice = string.Empty;
        public string _TrxnResponseMessage = string.Empty;
        public string _ErrorMessage = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            CommonHelper.SetResponseNoCache(Response);

            string AccessPaymentCode = string.Empty;

            if (!Page.IsPostBack)
            {
                if (Request.Form["AccessPaymentCode"] != null)
                    AccessPaymentCode = Request.Form["AccessPaymentCode"].ToString();

                //get the result of the transaction based on the unique payment code
                if (CheckAccessCode(AccessPaymentCode))
                {
                    if (_TrxnStatus.ToLower().Equals("true"))
                    {
                        divAuthorised.Style["display"] = "block";
                    }
                    else
                    {
                        divFailed.Style["display"] = "block";
                        Response.Redirect(CommonHelper.GetStoreLocation());
                    }

                    //display the saved values
                    lblStatus.Text = _TrxnStatus;
                    lblAuthCode.Text = _AuthCode;
                    lblResponseCode.Text = _ResponseCode;
                    lblReturnAmount.Text = _ReturnAmount;
                    lblMerchantInvoice.Text = _ReferenceInvoice;
                    lblTrxnNumber.Text = _TrxnNumber;
                    lblMerchantOption1.Text = _MerchnatOption1;
                    lblMerchantOption2.Text = _MerchnatOption2;
                    lblMerchantOption3.Text = _MerchnatOption3;
                    lblMerchantReference.Text = _ReferenceNumber;
                    lblTrxnResponseMessage.Text = _TrxnResponseMessage;
                    lblErrorMessage.Text = _ErrorMessage;


                    int orderId = Convert.ToInt32(_MerchnatOption1);
                    Order order = OrderManager.GetOrderById(orderId);
                    if (String.IsNullOrEmpty(_ErrorMessage) && order != null)
                    {
                        if (OrderManager.CanMarkOrderAsPaid(order))
                        {
                            OrderManager.MarkOrderAsPaid(order.OrderId);
                        }
                        Response.Redirect("~/checkoutcompleted.aspx");
                    }
                    else
                    {
                        Response.Redirect(CommonHelper.GetStoreLocation());
                    }

                }
                else
                {
                    // unable to check the transaction amount
                    divFraud.Style["display"] = "block";
                    Response.Redirect(CommonHelper.GetStoreLocation());
                }
            }
        }

        /// <summary>
        /// Procedure to check the 64 character access payment code
        /// for security
        /// </summary>
        /// <param name="AccessPaymentCode">64 char code</param>
        /// <returns>true if found; false if not found</returns>
        protected bool CheckAccessCode(string AccessPaymentCode)
        {
            //POST to Payment gateway the access code returned
            string strPost = "CustomerID=" + SettingManager.GetSettingValue("PaymentMethod.eWayUK.CustomerId");
            strPost += Format("AccessPaymentCode", AccessPaymentCode);
            strPost += Format("UserName", SettingManager.GetSettingValue("PaymentMethod.eWayUK.Username"));

            string url = SettingManager.GetSettingValue("PaymentMethod.eWayUK.PaymentPage") + "Result?" + strPost;

            HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
            objRequest.Method = WebRequestMethods.Http.Get;
            string resultXML = string.Empty;

            try
            {
                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();
                }
            }
            catch (Exception)
            {
                return false;
            }

            //parse the results save the values
            ParseAndSaveXMLResult(resultXML);

            return true;
        }

        /// <summary>
        /// Parse the XML Returned and save all the values to be displayed to user
        /// </summary>
        /// <param name="resultXML">XML of the transaction result</param>
        private void ParseAndSaveXMLResult(string resultXML)
        {
            string _currentNode;
            StringReader _sr = new StringReader(resultXML);
            XmlTextReader _xtr = new XmlTextReader(_sr);
            _xtr.XmlResolver = null;
            _xtr.WhitespaceHandling = WhitespaceHandling.None;

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

            if ((_xtr.NodeType == XmlNodeType.Element) && (_xtr.Name == "TransactionResponse"))
            {
                while (_xtr.Read())
                {
                    if ((_xtr.NodeType == XmlNodeType.Element) && (!_xtr.IsEmptyElement))
                    {
                        _currentNode = _xtr.Name;
                        _xtr.Read();
                        if (_xtr.NodeType == XmlNodeType.Text)
                        {
                            switch (_currentNode)
                            {

                                case "AuthCode":
                                    _AuthCode = _xtr.Value;
                                    break;
                                case "ResponseCode":
                                    _ResponseCode = _xtr.Value;
                                    break;
                                case "ReturnAmount":
                                    _ReturnAmount = _xtr.Value;
                                    break;
                                case "TrxnStatus":
                                    _TrxnStatus = _xtr.Value;
                                    break;
                                case "TrxnNumber":
                                    _TrxnNumber = _xtr.Value;
                                    break;
                                case "MerchantOption1":
                                    _MerchnatOption1 = _xtr.Value;
                                    break;
                                case "MerchantOption2":
                                    _MerchnatOption2 = _xtr.Value;
                                    break;
                                case "MerchantOption3":
                                    _MerchnatOption3 = _xtr.Value;
                                    break;
                                case "MerchantInvoice":
                                    _ReferenceInvoice = _xtr.Value;
                                    break;
                                case "MerchantReference":
                                    _ReferenceNumber = _xtr.Value;
                                    break;

                                case "TrxnResponseMessage":
                                    _TrxnResponseMessage = _xtr.Value;
                                    break;
                                case "ErrorMessage":
                                    _ErrorMessage = _xtr.Value;
                                    break;

                            }
                        }
                    }
                }
            }
        }
        
        /// <summary>
        /// Format the string needed to post to the Generate page
        /// </summary>
        /// <param name="fieldName">eWAY Parameter Name</param>
        /// <param name="value">Value of Parameter</param>
        /// <returns>Formated value for the URL</returns>
        private string Format(string fieldName, string value)
        {
            if (!string.IsNullOrEmpty(value))
                return "&" + fieldName + "=" + value;
            else
                return "";
        }

        public override bool AllowGuestNavigation
        {
            get
            {
                return true;
            }
        }
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.