SermepaReturn.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 » SermepaReturn.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NopSolutions.NopCommerce.BusinessLogic;
using NopSolutions.NopCommerce.BusinessLogic.Audit;
using NopSolutions.NopCommerce.BusinessLogic.Configuration.Settings;
using NopSolutions.NopCommerce.BusinessLogic.Orders;
using NopSolutions.NopCommerce.BusinessLogic.SEO;
using NopSolutions.NopCommerce.Common;
using NopSolutions.NopCommerce.Common.Utils;
using NopSolutions.NopCommerce.Payment.Methods.PayPoint;

namespace NopSolutions.NopCommerce.Web{
    public partial class SermepaReturnPage : BaseNopPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CommonHelper.SetResponseNoCache(Response);

            if (!Page.IsPostBack)
            {
                string HostName = Request.UserHostName;
                LogManager.InsertLog(LogTypeEnum.OrderError, "TPV SERMEPA: Host " + HostName, "Host: " + HostName);

                //ID de Pedido
                string orderId = Request["Ds_Order"];
                string strDs_Merchant_Order = Request["Ds_Order"];

                string strDs_Merchant_Amount = Request["Ds_Amount"];
                string strDs_Merchant_MerchantCode = Request["Ds_MerchantCode"];
                string strDs_Merchant_Currency = Request["Ds_Currency"];

                //Respuesta del TPV
                string str_Merchant_Response = Request["Ds_Response"];
                int Ds_Response = Convert.ToInt32(Request["Ds_Response"]);

                //Clave
                bool pruebas = SettingManager.GetSettingValueBoolean("PaymentMethod.Sermepa.Pruebas");
                string clave = "";
                if (pruebas) { clave = SettingManager.GetSettingValue("PaymentMethod.Sermepa.ClavePruebas"); }
                else { clave = SettingManager.GetSettingValue("PaymentMethod.Sermepa.ClaveReal"); };

                //Calculo de la firma
                string SHA = string.Format("{0}{1}{2}{3}{4}{5}",
                    strDs_Merchant_Amount,
                    strDs_Merchant_Order,
                    strDs_Merchant_MerchantCode,
                    strDs_Merchant_Currency,
                    str_Merchant_Response,
                    clave);

                byte[] SHAresult;
                SHA1 shaM = new SHA1Managed();
                SHAresult = shaM.ComputeHash(Encoding.Default.GetBytes(SHA));
                string SHAresultStr = BitConverter.ToString(SHAresult).Replace("-", "");

                //Firma enviada
                string signature = Request["Ds_Signature"];

                //Comprobamos la integridad de las comunicaciones con las claves
                //LogManager.InsertLog(LogTypeEnum.OrderError, "TPV SERMEPA: Clave generada", "CLAVE GENERADA: " + SHAresultStr);
                //LogManager.InsertLog(LogTypeEnum.OrderError, "TPV SERMEPA: Clave obtenida", "CLAVE OBTENIDA: " + signature);
                if (!signature.Equals(SHAresultStr))
                {
                    LogManager.InsertLog(LogTypeEnum.OrderError, "TPV SERMEPA: Clave incorrecta", "Las claves enviada y generada no coinciden: " + SHAresultStr + " != " + signature);
                    return;
                }

                //Pedido
                Order order = OrderManager.GetOrderById(Convert.ToInt32(orderId));
                if (order == null)
                    throw new NopException(string.Format("El pedido de ID {0} no existe", orderId));

                //Actualizamos el pedido
                if (Ds_Response > -1 && Ds_Response < 100)
                {
                    //Lo marcamos como pagado
                    if (OrderManager.CanMarkOrderAsPaid(order))
                    {
                        OrderManager.MarkOrderAsPaid(order.OrderId);
                    }
                    //OrderManager.InsertOrderNote(order.OrderId, "Informacin del pago: " + Request.Form.ToString(), DateTime.Now);
                }
                else
                {
                    LogManager.InsertLog(LogTypeEnum.OrderError, "TPV SERMEPA: Pago no autorizado", "Pago no autorizado con ERROR: " + Ds_Response);
                    //OrderManager.InsertOrderNote(order.OrderId, "!!! PAGO DENEGADO !!! " + Request.Form.ToString(), DateTime.Now);
                }

            }
        }

        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.