コード例 #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
ファイル: RemotePost.cs プロジェクト: prontoo/CaSyS
        /// <summary>
        /// Metod koj proveruva dali objektot koj se praka vo CaSyS e spored dokumentacija validen
        /// </summary>
        /// <param name="casys"></param>
        /// <returns></returns>
        public bool IsValid(Casys casys)
        {
            {
                if (string.IsNullOrEmpty(casys.CasysUrl)) return false;

                if (string.IsNullOrEmpty(casys.AmountToPay)) return false;
                if (string.IsNullOrEmpty(casys.AmountCurrency)) return false;
                //if (string.IsNullOrEmpty(casys.Details1)) return false;
                if (string.IsNullOrEmpty(casys.Details2)) return false;
                if (string.IsNullOrEmpty(casys.PayToMerchant)) return false;
                if (string.IsNullOrEmpty(casys.MerchantName)) return false;

                if (string.IsNullOrEmpty(casys.PaymentOKURL)) return false;
                if (string.IsNullOrEmpty(casys.PaymentFailURL)) return false;

                return true;
            }
        }
コード例 #3
0
ファイル: RemotePost.cs プロジェクト: prontoo/CaSyS
        public void Post(Casys casys)
        {
            _url = casys.CasysUrl;
            GenerateCheckSumHeader(PostData(casys, false), casys);
            PostData(casys, true);
            if (IsValid(casys))
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
                HttpContext.Current.Response.Write(
                    "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>");
                HttpContext.Current.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">",
                                                                 FormName));
                HttpContext.Current.Response.Write("</head><body>");
                HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >",
                                                                 FormName, Method, _url));
                const string strFilename = "C:\\Temp\\sendParms.xml";
                var doc = new XmlDocument();
                XmlNode paramsNode = null;
                if (Convert.ToBoolean(ConfigurationManager.AppSettings["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);
                    }

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

                    #endregion
                }

                for (var i = 0; i < _inputs.Keys.Count; i++)
                {
                    // TODO: na live okolina ovoj region treba da se izbrise
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["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 = _inputs.Keys[i];
                        paramNode.Attributes.Append(nameAttr);
                        var valueAttr = doc.CreateAttribute("value");
                        valueAttr.Value = _inputs[_inputs.Keys[i]];
                        paramNode.Attributes.Append(valueAttr);
                        paramsNode.AppendChild(paramNode);

                        #endregion
                    }

                    HttpContext.Current.Response.Write(
                        string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", _inputs.Keys[i],
                                      _inputs[_inputs.Keys[i]]));
                }

                // koga ce se pusti vo live okolina EnableLogging vo web.config treba da e false
                if (Convert.ToBoolean(ConfigurationManager.AppSettings["EnableLogging"]))
                {
                    doc.Save(strFilename);
                }

                HttpContext.Current.Response.Write("</form>");
                HttpContext.Current.Response.Write("</body></html>");
                HttpContext.Current.Response.End();
            }
        }
コード例 #4
0
ファイル: RemotePost.cs プロジェクト: prontoo/CaSyS
        private void GenerateCheckSumHeader(NameValueCollection inputs, Casys casys)
        {
            var headerCounter = 0;
            var headerParams = string.Empty;
            var headerParamsLength = string.Empty;
            var headerParamsValues = string.Empty;

            for (var i = 0; i < inputs.Count; i++)
            {
                if (string.IsNullOrEmpty(inputs.Get(i)))
                {
                    continue;
                }

                headerCounter += 1;
                headerParams += inputs.GetKey(i);
                headerParamsLength += inputs.Get(i).Length.ToString("000");
                headerParamsValues += inputs.Get(i);

                if (i != inputs.Count - 1)
                {
                    headerParams += ",";
                }
            }

            casys.CheckSumHeader = headerCounter.ToString("00") + headerParams + "," + headerParamsLength;
            var checkSumHeaderPass = casys.CheckSumHeader + headerParamsValues + casys.CasysPassword;
            casys.CheckSum = FormsAuthentication.HashPasswordForStoringInConfigFile(checkSumHeaderPass, "MD5");

            _inputs.Add("CheckSumHeader", casys.CheckSumHeader);
            _inputs.Add("CheckSum", casys.CheckSum);
        }
コード例 #5
0
ファイル: RemotePost.cs プロジェクト: prontoo/CaSyS
        public NameValueCollection PostData(Casys casys, bool isFormParams)
        {
            if (_inputs != null)
            {
                if (!isFormParams)
                {
                    _inputs.Add("AmountToPay", casys.AmountToPay);
                    _inputs.Add("AmountCurrency", casys.AmountCurrency);
                    _inputs.Add("Details1", casys.Details1);
                    _inputs.Add("Details2", casys.Details2);
                    _inputs.Add("Details3", casys.Details3);
                    _inputs.Add("PayToMerchant", casys.PayToMerchant);
                    _inputs.Add("MerchantName", casys.MerchantName);
                    _inputs.Add("PaymentOKURL", HttpContext.Current.Server.HtmlDecode(casys.PaymentOKURL));
                    _inputs.Add("PaymentFailURL", casys.PaymentFailURL);
                    _inputs.Add("FirstName", casys.FirstName);
                    _inputs.Add("LastName", casys.LastName);
                    _inputs.Add("Address", casys.Address);
                    _inputs.Add("City", casys.City);
                    _inputs.Add("Zip", casys.Zip);
                    _inputs.Add("Country", casys.Country);
                    _inputs.Add("Telephone", casys.Telephone);
                    _inputs.Add("Email", casys.Email);
                }
            }

            return _inputs;
        }
コード例 #6
0
ファイル: Utilities.cs プロジェクト: prontoo/CaSyS
 /// <summary>
 /// Za dva objekti CaSys go spoerduva nivniot MD5 checkSum
 /// </summary>
 /// <param name="md5Send">Prviot Casys objekt</param>
 /// <param name="receive">return CheckSumHeader</param>
 /// <returns>Vraka true dokolku se isti checkSum-te</returns>
 public static bool IsValidMd5Invoices(Casys md5Send, string receive)
 {
     var send = GenerateCheckSumHeader(md5Send);
     //return true;
     return send == receive;
 }
コード例 #7
0
ファイル: Utilities.cs プロジェクト: prontoo/CaSyS
        /// <summary>
        /// Pomosna klasa za MD5 redenje na polinja
        /// </summary>
        /// <param name="casys">Cassys objektot koj se redi</param>
        /// <returns>Sreden Casys objekt za MD5 redenje</returns>
        private static NameValueCollection PostData(Casys casys)
        {
            var valueWithDdv = casys.AmountToPay;
            if (casys.AmountToPay.EndsWith(".0") || casys.AmountToPay.EndsWith(",0"))
            {
                valueWithDdv = valueWithDdv.Substring(0, valueWithDdv.Length - 2);
            }

            var inputs = new NameValueCollection
             {
                 {"AmountCurrency", casys.AmountCurrency},
                 {"AmountToPay", valueWithDdv},
                 {"Details1", casys.Details1},
                 {"Details2", casys.Details2},
                 {"Details3", casys.Details3},
                 {"PayToMerchant", casys.PayToMerchant},
                 {"MerchantName", casys.MerchantName},
                 {"PaymentOKURL", casys.PaymentOKURL},
                 {"PaymentFailURL", casys.PaymentFailURL},
                 {"FirstName", casys.FirstName},
                 {"LastName", casys.LastName},
                 {"Address", casys.Address},
                 {"City", casys.City},
                 {"Zip", casys.Zip},
                 {"Country", casys.Country},
                 {"Telephone", casys.Telephone},
                 {"Email", casys.Email},
                 {"cPayPaymentRef", casys.CPayPaymentRef}
             };
            return inputs;
        }
コード例 #8
0
ファイル: Utilities.cs プロジェクト: prontoo/CaSyS
        /// <summary>
        /// Generira checkSum za objekt
        /// </summary>
        /// <param name="casys">Objek za koj se generira checkSum</param>
        /// <returns>checkSum string</returns>
        private static string GenerateCheckSumHeader(Casys casys)
        {
            var inputs = PostData(casys);
            var headerCounter = 0;
            var headerParams = string.Empty;
            var headerParamsLength = string.Empty;
            var headerParamsValues = string.Empty;

            // TODO: na live okolina ovoj region treba da se izbrise
            #region [Kreira XML kade sto gi zapisuva return parametrite - koga ce se pusti vo live okolina ovoj xml treba da se izbrise ]
            const string strFilename = "C:\\Temp\\parmsForCheck.xml";
            if (File.Exists(strFilename))
            {
                File.Delete(strFilename);
            }

            var xdoc = new XmlDocument();
            XmlNode docNode = xdoc.CreateXmlDeclaration("1.0", "UTF-8", null);
            xdoc.AppendChild(docNode);
            XmlNode paramsNode = xdoc.CreateElement("Parameters");
            xdoc.AppendChild(paramsNode);
            #endregion

            for (var i = 0; i < inputs.Count; i++)
            {
                if (!string.IsNullOrEmpty(inputs.Get(i)))
                {
                    // TODO: na live okolina ovoj region treba da se izbrise
                    #region [Kreira XML kade sto gi zapisuva return parametrite - koga ce se pusti vo live okolina ovoj xml treba da se izbrise ]
                    XmlNode paramNode = xdoc.CreateElement("parameter");
                    var nameAttr = xdoc.CreateAttribute("name");
                    nameAttr.Value = inputs.GetKey(i);
                    if (paramNode.Attributes != null)
                    {
                        paramNode.Attributes.Append(nameAttr);
                    }

                    var valueAttr = xdoc.CreateAttribute("value");
                    valueAttr.Value = inputs.Get(i);
                    if (paramNode.Attributes != null)
                    {
                        paramNode.Attributes.Append(valueAttr);
                    }

                    paramsNode.AppendChild(paramNode);
                    #endregion

                    headerCounter += 1;
                    headerParams += inputs.GetKey(i);
                    headerParamsLength += inputs.Get(i).Length.ToString("000");
                    headerParamsValues += inputs.Get(i);

                    if (i != inputs.Count - 1)
                    {
                        headerParams += ",";
                    }
                }
            }

            casys.CheckSumHeader = headerCounter.ToString("00") + headerParams + "," + headerParamsLength;
            var checkSumHeaderPass = casys.CheckSumHeader + headerParamsValues + casys.CasysPassword;

            // TODO: na live okolina ovoj region treba da se izbrise
            #region [Kreira XML kade sto gi zapisuva return parametrite - koga ce se pusti vo live okolina ovoj xml treba da se izbrise ]
            XmlNode paramNodeE = xdoc.CreateElement("parameter");
            var nameAttrN = xdoc.CreateAttribute("name");
            nameAttrN.Value = "CheckSumHeader";
            if (paramNodeE.Attributes != null)
            {
                paramNodeE.Attributes.Append(nameAttrN);
            }

            var valueAttrV = xdoc.CreateAttribute("value");
            valueAttrV.Value = casys.CheckSumHeader;
            if (paramNodeE.Attributes != null)
            {
                paramNodeE.Attributes.Append(valueAttrV);
            }

            paramsNode.AppendChild(paramNodeE);
            #endregion

            // TODO: na live okolina ovoj region treba da se izbrise
            #region [Kreira XML kade sto gi zapisuva return parametrite - koga ce se pusti vo live okolina ovoj xml treba da se izbrise ]
            XmlNode paramNodeE1 = xdoc.CreateElement("parameter");
            var nameAttrN1 = xdoc.CreateAttribute("name");
            nameAttrN1.Value = "CheckSumHeaderPass";
            if (paramNodeE1.Attributes != null)
            {
                paramNodeE1.Attributes.Append(nameAttrN1);
            }

            var valueAttrV1 = xdoc.CreateAttribute("value");
            valueAttrV1.Value = checkSumHeaderPass;
            if (paramNodeE1.Attributes != null)
            {
                paramNodeE1.Attributes.Append(valueAttrV1);
            }

            paramsNode.AppendChild(paramNodeE1);
            #endregion

            var checkSumHeader = FormsAuthentication.HashPasswordForStoringInConfigFile(checkSumHeaderPass, "MD5");

            // TODO: na live okolina ovoj region treba da se izbrise
            #region [Kreira XML kade sto gi zapisuva checkSumHeader - koga ce se pusti vo live okolina ovoj xml treba da se izbrise ]
            XmlNode paramNodeE2 = xdoc.CreateElement("parameter");
            var nameAttrN2 = xdoc.CreateAttribute("name");
            nameAttrN2.Value = "checkSumHeader";
            if (paramNodeE2.Attributes != null)
            {
                paramNodeE2.Attributes.Append(nameAttrN2);
            }

            var valueAttrV2 = xdoc.CreateAttribute("value");
            valueAttrV2.Value = checkSumHeader;
            if (paramNodeE2.Attributes != null)
            {
                paramNodeE2.Attributes.Append(valueAttrV2);
            }

            paramsNode.AppendChild(paramNodeE2);
            #endregion

            // TODO: na live okolina ovoj red treba da se izbrise
            xdoc.Save(strFilename);
            return checkSumHeader;
        }
コード例 #9
0
ファイル: PaySuccess.aspx.cs プロジェクト: prontoo/CaSyS
        /// <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;
        }