示例#1
0
        //[HttpPost]
        public void MNS()
        {
            _logger.Info("MNS called by Flo2Cash");
            var       notificationUrl = ConfigurationManager.AppSettings["Flo2CashNotificationUrl"];
            WebClient wClient         = new WebClient();

            wClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            string         postData          = "";
            string         transactionNumber = String.Empty;
            string         transactionResult = String.Empty;
            IList <String> customData        = new List <String>();
            string         amount            = String.Empty;

            for (int i = 0; i < Request.Form.AllKeys.Length; i++)
            {
                string key   = Request.Form.AllKeys[i];
                string value = Request.Form[i];

                if (key == "transaction_id")
                {
                    transactionNumber = value;
                }
                else if (key == "transaction_status")
                {
                    transactionResult = value;
                }
                else if (key == "custom_data")
                {
                    customData = value.Split(new char[] { ',' });
                }
                postData += key + "=" + Server.UrlEncode(value) + "&";
            }
            postData += "cmd" + "=" + "_xverify-transaction";
            _logger.Info("Posting the following data back  to Flo2Cash:" + postData);
            byte[] postBytes      = Encoding.ASCII.GetBytes(postData);
            byte[] responseBytes  = wClient.UploadData(notificationUrl, "POST", postBytes);
            string actionResponse = Encoding.ASCII.GetString(responseBytes);

            _logger.Info("Action response: " + actionResponse);
            if (actionResponse.Trim().ToUpper() == "VERIFIED")
            {
                foreach (var infr in customData)
                {
                    int infringementNumber = int.Parse(infr);
                    var infringement       = db.infringements.FirstOrDefault(x => x.Id == infringementNumber &&
                                                                             x.StatusId == 1);
                    if (infringement == null)
                    {
                        _logger.Warn("Payment made BUT infringement not found. Infrin num:" +
                                     infr + "txn:" + transactionNumber);
                    }
                    else
                    {
                        _logger.Warn("Payment made AND infringement found. Infrin num:" +
                                     infr + "txn:" + transactionNumber);
                    }
                    if (transactionResult == "2")
                    {
                        _logger.Info("Payment successful, change infringement status");
                        infringement.StatusId = 2;
                    }

                    var infringementPayment = new infringement_payment
                    {
                        InfringementId    = infringementNumber,
                        PaymentResult     = transactionResult,
                        TransactionNumber = transactionNumber
                    };

                    _logger.Info("Infringement payment record created" + infringementPayment);

                    db.infringement_payment.Add(infringementPayment);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        _logger.Error("Payment record not saved in the database", ex);
                        throw;
                    }

                    _logger.Info("MNS completed");
                }
            }
        }
示例#2
0
        //[HttpPost]
        public void MNS()
        {
            _logger.Info("MNS called by Flo2Cash");
            var       notificationUrl = ConfigurationManager.AppSettings["Flo2CashNotificationUrl"];
            WebClient wClient         = new WebClient();

            wClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            string         postData          = "";
            string         Email             = "";
            string         transactionNumber = String.Empty;
            string         transactionResult = String.Empty;
            IList <String> customData        = new List <String>();
            string         amount            = String.Empty;

            for (int i = 0; i < Request.Form.AllKeys.Length; i++)
            {
                string key   = Request.Form.AllKeys[i];
                string value = Request.Form[i];

                if (key == "transaction_id")
                {
                    transactionNumber = value;
                }
                else if (key == "transaction_status")
                {
                    transactionResult = value;
                }
                else if (key == "custom_data")
                {
                    IList <String> customDataTemp = value.Split(new char[] { '$' });
                    customData = customDataTemp[0].Split(new char[] { ',' });
                    Email      = customDataTemp[1].ToString();
                }
                postData += key + "=" + Server.UrlEncode(value) + "&";
            }
            postData += "cmd" + "=" + "_xverify-transaction";
            _logger.Info("Posting the following data back  to Flo2Cash:" + postData);
            byte[] postBytes      = Encoding.ASCII.GetBytes(postData);
            byte[] responseBytes  = wClient.UploadData(notificationUrl, "POST", postBytes);
            string actionResponse = Encoding.ASCII.GetString(responseBytes);

            _logger.Info("Action response: " + actionResponse);
            if (actionResponse.Trim().ToUpper() == "VERIFIED")
            {
                foreach (var infr in customData)
                {
                    int infringementNumber = int.Parse(infr);
                    var infringement       = db.infringements.FirstOrDefault(x => x.Id == infringementNumber &&
                                                                             x.StatusId == 1);
                    if (infringement == null)
                    {
                        _logger.Warn("Payment made BUT infringement not found. Infrin num:" +
                                     infr + "txn:" + transactionNumber);
                    }
                    else
                    {
                        _logger.Warn("Payment made AND infringement found. Infrin num:" +
                                     infr + "txn:" + transactionNumber);
                    }
                    if (transactionResult == "2")
                    {
                        _logger.Info("Payment successful, change infringement status");
                        infringement.StatusId    = 2;
                        infringement.PaymentType = "Flow2Cash";
                    }

                    var infringementPayment = new infringement_payment
                    {
                        InfringementId    = infringementNumber,
                        PaymentResult     = transactionResult,
                        TransactionNumber = transactionNumber,
                        TransactionDate   = DateTime.Now
                    };

                    _logger.Info("Infringement payment record created" + infringementPayment);

                    db.infringement_payment.Add(infringementPayment);
                    try
                    {
                        db.SaveChanges();
                        //int[] infringementIds = Array.ConvertAll(Request.Form["custom_data"].ToString().Split(','), int.Parse);
                        string[] custom_data = Request.Form["custom_data"].ToString().Split('$');

                        int[] infringementIds = Array.ConvertAll(custom_data[0].ToString().Split(','), int.Parse);

                        List <infringement> payitems = db.infringements
                                                       .Where(x => infringementIds.Contains(x.Id)
                                                              // && x.StatusId == 1
                                                              ).ToList();

                        decimal totalamount = 0;

                        foreach (infringement info in payitems)
                        {
                            if (DateTime.Now > info.DueDate)
                            {
                                info.ActualAmountToPay = info.AfterDueDate.Value;
                                //info.DisplayDueAmount = "<b>" + info.AfterDueDate.Value + "</b>";
                                info.DisplayDueAmount = info.AfterDueDate.Value.ToString();
                                info.DisplayAmount    = info.Amount.ToString();
                            }
                            else
                            {
                                info.ActualAmountToPay = info.Amount;
                                info.DisplayDueAmount  = info.AfterDueDate.ToString();
                                //info.DisplayAmount = "<b>" + info.Amount.ToString() + "</b>";
                                info.DisplayAmount = info.Amount.ToString();
                            }

                            totalamount += info.ActualAmountToPay;
                        }

                        SendMail(payitems, transactionNumber, Email, totalamount);
                    }
                    catch (Exception ex)
                    {
                        _logger.Error("Payment record not saved in the database", ex);
                        throw;
                    }

                    _logger.Info("MNS completed");
                }
            }
        }