示例#1
0
文件: Pay.cs 项目: prontoo/CaSyS
        public void PayInvoicesCaSyS(Collection<InvoiceDetails> invoices, LoginInfo info, string lang, string email)
        {
            var _invoicesNumbers = string.Empty;
            var amount = 0m;
            foreach (var item in invoices)
            {
                amount += item.Invoice_Unbilled_Amount;
                _invoicesNumbers += item.Invoice_Ref_Number + "; ";
            }

            _invoicesNumbers = _invoicesNumbers.Trim().TrimEnd(';');
            try
            {
                var invoiceCount = invoices.Count;
                var tmName1 = string.Empty;
                var tmName2 = string.Empty;

                //ToDo Da se sredi
                var myOracle = new MyOracle(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
                var ePaymentSessionId = myOracle.GenerateOrderId();

                var casys = new Casys
                {
                    PaymentOKURL = EnvironmentHelper.PaymentOkurlInvoices + "?orderId=" + ePaymentSessionId + "&lang=" + lang,
                    PaymentFailURL = EnvironmentHelper.PaymentFailurlInvoices + "?orderId=" + ePaymentSessionId + "&lang=" + lang,
                    PayToMerchant = Settings.Default.MerchantIdInvoices,

                    AmountToPay = InvoicesAmountForCaSyS(amount),
                    AmountCurrency = "MKD",
                    Details1 = info.MSISDN,
                    Details2 = ePaymentSessionId,
                    Details3 = lang,
                    Telephone = info.MSISDN,
                    MerchantName = Settings.Default.MerchantName,
                    Email = email,
                    CasysPassword = EnvironmentHelper.CasysPasswordInvoices,
                    CasysUrl = EnvironmentHelper.ReturnCasysURL(lang)
                };

                if (SaveToDB(ePaymentSessionId, info, invoices, email))
                {
                    var rp = new RemotePost();
                    rp.Post(casys); // -------->>>> Kon CaSyS
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (ThreadAbortException)
            {
                return;
            }
            catch (Exception ex)
            {
                //Utils.LogError(ex);
                throw;
            }
        }
示例#2
0
文件: Pay.cs 项目: prontoo/CaSyS
        private bool SaveToDB(string ePaymentSessionId, LoginInfo info, Collection<InvoiceDetails> invoicesCurent, string email)
        {
            try
            {
                var myOracle = new MyOracle(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
                var isSuccess = myOracle.CreateEPayment(ePaymentSessionId, email, info.MSISDN);
                if (!isSuccess)
                {
                    return false;
                }

                foreach (var inv in invoicesCurent)
                {
                    myOracle = new MyOracle(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
                    var orderId = myOracle.GenerateOrderId();
                    myOracle = new MyOracle(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
                    isSuccess = myOracle.CreateEPaymentDetails(
                                    orderId,
                                    ePaymentSessionId,
                                    inv.Invoice_Ref_Number,
                                    Convert.ToDecimal(inv.Invoice_Unbilled_Amount));
                    if (!isSuccess)
                    {
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                //Utils.LogError(ex);
                return false;
            }

            return true;
        }
示例#3
0
        /// <summary>
        /// Zima Naracka za Vaucer od baza koja nema trasaction ID
        /// </summary>
        /// <param name="sessionId">
        /// sessionId na narackata za eTopUp
        /// </param>
        /// <param name="casysTransactionId">
        /// Vraka Id na transakcijata vo CaSyS
        /// </param>
        /// <param name="language">
        /// Jazik na koj se vrsi celata transakcija
        /// </param>
        /// <param name="alredyPayed">
        /// The alredy Payed.
        /// </param>
        /// <returns>
        /// Vraka objekt Casys za narackata
        /// </returns>
        private Casys GetEPaymentFromDb(string sessionId, string casysTransactionId, string language, out string alredyPayed)
        {
            alredyPayed = null;
            var c = new Casys();
            var p = new MyOracle(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
            var o = p.GetEPaymentById(sessionId);
            if (o != null)
            {
                c.Email = o.ConfirmationEmail;
                c.Telephone = o.ConfirmationTelephone;
                c.Details1 = o.ConfirmationTelephone;
                c.Details2 = o.SessionID;
                c.Details3 = language;

                decimal totalamount = 0;
                foreach (var amount in o.InvoiceDetais)
                {
                    totalamount += amount.Amount;
                }

                c.AmountToPay = InvoicesAmountForCaSyS(totalamount);
                c.CPayPaymentRef = casysTransactionId;

                // Some default values
                c.PaymentOKURL = EnvironmentHelper.PaymentOkurlInvoices + "?orderId=" + o.SessionID + "&lang=" + language;
                c.PaymentFailURL = EnvironmentHelper.PaymentFailurlInvoices + "?orderId=" + o.SessionID + "&lang=" + language;
                c.PayToMerchant = ConfigurationManager.AppSettings["MerchantId"];
                c.AmountCurrency = "MKD";
                c.MerchantName = ConfigurationManager.AppSettings["MerchantName"];
                c.CasysPassword = EnvironmentHelper.CasysPasswordInvoices;

                alredyPayed = o.PaymentSuccess;
            }

            return c;
        }
示例#4
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);
            }
        }
示例#5
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);

            }
        }