Esempio n. 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);
            }
        }