Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var sessionId = string.Empty;
            var casysTransactionId = string.Empty;
            var requestResponse = new RequestResponse();
            var returnedParams = GetFormParams();
            var infoLog = new StringBuilder();
            var doc = new XmlDocument();
            XmlNode paramsNode = null;
            const string strFilename = "C:\\Temp\\returnParms.xml";
            var lang = "MK";
            var tmisIssuedByAcquirer = string.Empty;

            if (!IsPostBack)
            {
                Translate();
            }

            if (CheckForm() == "get")
            {
                if (!string.IsNullOrEmpty(Request.QueryString["orderId"]))
                {
                    MyOracle p = new MyOracle(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
                    var invoiceForGet = p.GetEPaymentByIdForGet(Request.QueryString["orderId"]);
                    if (invoiceForGet != null)
                    {
                        if (invoiceForGet.Count > 0)
                        {
                            lang = Request.QueryString["lang"];
                            FillRequestInvoices(invoiceForGet, lang, true);
                            return;
                        }

                        return;
                    }
                }

                return;
            }

            if (returnedParams.Count > 0)
            {
                if (EnvironmentHelper.EnableLogging)
                {
                    #region [Kreira XML kade sto gi zapisuva return parametrite - koga ce se pusti vo live okolina EnableLogging vo web.config treba da e false ]

                    if (File.Exists(strFilename))
                    {
                        File.Delete(strFilename);
                    }

                    XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
                    doc.AppendChild(docNode);
                    paramsNode = doc.CreateElement("Parameters");
                    doc.AppendChild(paramsNode);
                    #endregion
                }

                if (EnvironmentHelper.EnableLogging)
                {
                    infoLog.AppendLine("Return parametars from CaSyS ... started ... Date nad Time: " + DateTime.Now);
                }

                foreach (var rtp in returnedParams)
                {
                    if (EnvironmentHelper.EnableLogging)
                    {
                        #region [Kreira XML kade sto gi zapisuva return parametrite - koga ce se pusti vo live okolina EnableLogging vo web.config treba da e false ]

                        XmlNode paramNode = doc.CreateElement("parameter");
                        var nameAttr = doc.CreateAttribute("name");
                        nameAttr.Value = rtp.ParameterName;

                        // koga ce se pusti vo live okolina EnableLogging vo web.config treba da e false
                        if (EnvironmentHelper.EnableLogging)
                        {
                            infoLog.AppendLine(rtp.ParameterName + ": " + rtp.ParameterValue);
                        }

                        if (paramNode.Attributes != null)
                        {
                            paramNode.Attributes.Append(nameAttr);
                        }

                        var valueAttr = doc.CreateAttribute("value");
                        valueAttr.Value = rtp.ParameterValue;
                        if (paramNode.Attributes != null)
                        {
                            paramNode.Attributes.Append(valueAttr);
                        }

                        if (paramsNode != null)
                        {
                            paramsNode.AppendChild(paramNode);
                        }

                        #endregion
                    }

                    for (var y = 0; y < requestResponse.RequestResponseProperties().Count; y++)
                    {
                        var propName = requestResponse.RequestResponseProperties().GetKey(y);
                        if (propName != rtp.ParameterName)
                        {
                            continue;
                        }

                        var propertyInfo = typeof(RequestResponse).GetProperty(propName);
                        if (propertyInfo.GetSetMethod() != null)
                        {
                            propertyInfo.SetValue(requestResponse, rtp.ParameterValue, null);
                        }
                    }
                }

                // koga ce se pusti vo live okolina EnableLogging vo web.config treba da e false
                if (EnvironmentHelper.EnableLogging)
                {
                    infoLog.AppendLine("Return parametars from CaSyS ... end ...");
                    Utils.LogError(infoLog.ToString());
                    doc.Save(strFilename);
                }

                sessionId = requestResponse.Details2;
                lang = requestResponse.Details3;

                requestResponse.CasysPassword = EnvironmentHelper.CasysPasswordInvoices;
                requestResponse.CasysUrl = EnvironmentHelper.ReturnCasysUrl(lang);
                casysTransactionId = requestResponse.CPayPaymentRef;
                tmisIssuedByAcquirer = requestResponse.TMisIssuedByAcquirer;
            }

            try
            {
                info.SessionId = sessionId;
                MyOracle p = new MyOracle(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
                var o = p.GetEPaymentById(sessionId);

                string alredyPayed;
                var oFromDb = GetEPaymentFromDb(sessionId, casysTransactionId, lang, out alredyPayed);
                if (o != null)
                {
                    if (string.IsNullOrEmpty(alredyPayed))
                    {
                        if (o.Count > 0)
                        {
                            if (Utilities.IsValidMd5Invoices(oFromDb, requestResponse.ReturnCheckSum))
                            {
                                p = new MyOracle(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
                                var succesUpdate = p.UpdateEPayment(sessionId, casysTransactionId,
                                                                           tmisIssuedByAcquirer, string.Empty);
                                if (succesUpdate)
                                {
                                    var ob = p.GetEPaymentById(sessionId);
                                    var ePaymentSerialNumber = FillRequestInvoices(ob, lang, false);

                                    if (!string.IsNullOrEmpty(ePaymentSerialNumber))
                                    {
                                        p = new MyOracle(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
                                        p.UpdateEPaymentSuccess(ob.SessionID, ePaymentSerialNumber);
                                    }
                                    else
                                    {
                                        //Auditing.LogAction(AuditAction.InvoiceNoSerial, false, "0", info, DateTime.Now);
                                        throw new ArgumentException("InvoiceNoSerial");
                                    }

                                    //Auditing.LogAction(AuditAction.InvoiceSuccess, true, "0", info, DateTime.Now);
                                }
                                else
                                {
                                    //Auditing.LogAction(AuditAction.InvoiceUpdateinDatabaseFailed, false, "0", info, DateTime.Now);
                                    throw new ArgumentException("InvoiceUpdateinDatabaseFailed");
                                }
                            }
                            else
                            {
                                //Auditing.LogAction(AuditAction.InvoiceWrongMD5, false, "0", info, DateTime.Now);
                                throw new ArgumentException("InvoiceWrongMD5");
                            }
                        }
                        else
                        {
                            //Auditing.LogAction(AuditAction.InvoiceNotExistInDataBase1, false, "0", info, DateTime.Now);
                            throw new ArgumentException("InvoiceNotExistInDataBase1");
                        }
                    }
                    else
                    {
                        //Auditing.LogAction(AuditAction.InvoiceAllreadyPayed, false, "0", info, DateTime.Now);
                        throw new ArgumentException("InvoiceAllreadyPayed");
                    }
                }
                else
                {
                    //Auditing.LogAction(AuditAction.InvoiceNotExistInDataBase, false, "0", info, DateTime.Now);
                    throw new ArgumentException("InvoiceNotExistInDataBase");
                }
            }
            catch (Exception ex)
            {
                // ErrorSignal.FromCurrentContext().Raise(ex);
                Log(ex);
                //Auditing.LogAction(AuditAction.InvoiceGeneralError, false, "0", info, DateTime.Now);
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Utilities utilities = new Utilities();
            var lang = utilities.LanguageSetAndReturn(Request.QueryString["lang"] ?? string.Empty);
            //if (!string.IsNullOrEmpty(Request.QueryString["lang"]))
            //{
            //    lang = Request.QueryString["lang"].ToUpper();
            switch (lang)
            {
                case "MK":
                    LiteralInfo.Text = MyTranslation.GetResourceString("UnsuccessfulTransaction");
                    invoiceсWithPay.InnerText = MyTranslation.GetResourceString("MENU_INVOICES");
                    break;
                case "EN":
                    LiteralInfo.Text = MyTranslation.GetResourceString("UnsuccessfulTransaction");
                    invoiceсWithPay.InnerText = MyTranslation.GetResourceString("MENU_INVOICES");
                    break;
                case "AL":
                    LiteralInfo.Text = MyTranslation.GetResourceString("UnsuccessfulTransaction");
                    invoiceсWithPay.InnerText = MyTranslation.GetResourceString("MENU_INVOICES");
                    break;
                default:
                    LiteralInfo.Text = MyTranslation.GetResourceString("UnsuccessfulTransaction");
                    invoiceсWithPay.InnerText = MyTranslation.GetResourceString("MENU_INVOICES");
                    break;
            }
            //}

            var sessionId = string.Empty;
            var casysTransactionId = string.Empty;
            var requestResponse = new RequestResponse();
            var returnedParams = GetFormParams();
            var infoLog = new StringBuilder();
            var doc = new XmlDocument();
            XmlNode paramsNode = null;
            const string strFilename = "C:\\Temp\\returnParms.xml";
            var tmisIssuedByAcquirer = string.Empty;
            var tmPmtReasonOfDecline = string.Empty;

            if (CheckForm() == "get")
            {
                if (!string.IsNullOrEmpty(Request.QueryString["orderId"]))
                {
                    MyOracle p = new MyOracle(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
                    if (p.GetEPaymentById(Request.QueryString["orderId"]) != null)
                    {
                        var o = p.GetEPaymentById(Request.QueryString["orderId"]);
                        if (o.Count > 0)
                        {
                            LiteralReasonOfDecline.Text = MyTranslation.GetResourceString("error_casys_Invoices" + o.TmPmtReasonOfDecline);
                            return;
                        }

                        return;
                    }
                }

                return;
            }

            if (returnedParams.Count > 0)
            {
                if (EnvironmentHelper.EnableLogging)
                {
                    #region [Kreira XML kade sto gi zapisuva return parametrite - koga ce se pusti vo live okolina EnableLogging vo web.config treba da e false ]

                    if (File.Exists(strFilename))
                    {
                        File.Delete(strFilename);
                    }

                    XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
                    doc.AppendChild(docNode);
                    paramsNode = doc.CreateElement("Parameters");
                    doc.AppendChild(paramsNode);
                    #endregion
                }

                if (EnvironmentHelper.EnableLogging)
                {
                    infoLog.AppendLine("Return parametars from CaSyS ... started ... Date nad Time: " + DateTime.Now);
                }

                foreach (var rtp in returnedParams)
                {
                    if (EnvironmentHelper.EnableLogging)
                    {
                        #region [Kreira XML kade sto gi zapisuva return parametrite - koga ce se pusti vo live okolina EnableLogging vo web.config treba da e false ]

                        XmlNode paramNode = doc.CreateElement("parameter");
                        var nameAttr = doc.CreateAttribute("name");
                        nameAttr.Value = rtp.ParameterName;

                        // koga ce se pusti vo live okolina EnableLogging vo web.config treba da e false
                        if (EnvironmentHelper.EnableLogging)
                        {
                            infoLog.AppendLine(rtp.ParameterName + ": " + rtp.ParameterValue);
                        }

                        if (paramNode.Attributes != null)
                        {
                            paramNode.Attributes.Append(nameAttr);
                        }

                        var valueAttr = doc.CreateAttribute("value");
                        valueAttr.Value = rtp.ParameterValue;
                        if (paramNode.Attributes != null)
                        {
                            paramNode.Attributes.Append(valueAttr);
                        }

                        if (paramsNode != null)
                        {
                            paramsNode.AppendChild(paramNode);
                        }

                        #endregion
                    }

                    for (var y = 0; y < requestResponse.RequestResponseProperties().Count; y++)
                    {
                        var propName = requestResponse.RequestResponseProperties().GetKey(y);
                        if (propName != rtp.ParameterName)
                        {
                            continue;
                        }

                        var propertyInfo = typeof(RequestResponse).GetProperty(propName);
                        if (propertyInfo.GetSetMethod() != null)
                        {
                            propertyInfo.SetValue(requestResponse, rtp.ParameterValue, null);
                        }
                    }
                }

                // koga ce se pusti vo live okolina EnableLogging vo web.config treba da e false
                if (EnvironmentHelper.EnableLogging)
                {
                    infoLog.AppendLine("Return parametars from CaSyS ... end ...");
                    doc.Save(strFilename);
                }

                sessionId = requestResponse.Details2;
                lang = requestResponse.Details3;

                requestResponse.CasysPassword = EnvironmentHelper.CasysPasswordInvoices;
                requestResponse.CasysUrl = EnvironmentHelper.ReturnCasysUrl(lang);
                casysTransactionId = requestResponse.CPayPaymentRef;
                tmisIssuedByAcquirer = requestResponse.TMisIssuedByAcquirer;
                tmPmtReasonOfDecline = requestResponse.TMPmtReasonOfDecline;
            }

            try
            {
                info.SessionId = sessionId;
                MyOracle p = new MyOracle(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
                var succesUpdate = p.UpdateEPayment(sessionId, casysTransactionId,
                                           tmisIssuedByAcquirer, tmPmtReasonOfDecline);
            }
            catch (Exception ex)
            {
                Utils.LogError(ex);

            }
        }