private UmemeApi.Transaction GetUmemeTrans(Transaction trans, UtilityCredentials creds)
        {
            UmemeApi.Transaction umemeTrans = new UmemeApi.Transaction();
            umemeTrans.CustomerName = trans.CustName;
            umemeTrans.CustomerRef  = trans.CustRef;
            umemeTrans.CustomerTel  = trans.CustomerTel;
            umemeTrans.CustomerType = trans.CustomerType;
            umemeTrans.Offline      = trans.Offline;
            umemeTrans.Password     = creds.UtilityPassword;
            string format  = "d/M/yyyy";
            string newdate = formateDate(trans.PaymentDate.Trim()).Trim();
            string payDate = newdate;//DateTime.ParseExact(newdate, format, CultureInfo.InvariantCulture).ToString();

            umemeTrans.PaymentDate       = payDate;
            umemeTrans.PaymentType       = trans.PaymentType;
            umemeTrans.Reversal          = trans.Reversal;
            umemeTrans.StatusCode        = "0";
            umemeTrans.StatusDescription = "SUCCESS";
            umemeTrans.Teller            = trans.Teller;
            umemeTrans.TranAmount        = trans.TransactionAmount;
            umemeTrans.TranIdToReverse   = trans.TranIdToReverse;
            umemeTrans.TranNarration     = trans.Narration;
            umemeTrans.TranType          = trans.TransactionType;
            umemeTrans.VendorCode        = creds.UtilityCode;
            umemeTrans.VendorTranId      = trans.BankID;
            string dataToSign = umemeTrans.CustomerRef + umemeTrans.CustomerName + umemeTrans.CustomerTel + umemeTrans.CustomerType + umemeTrans.VendorTranId + umemeTrans.VendorCode + umemeTrans.Password + umemeTrans.PaymentDate + umemeTrans.PaymentType + umemeTrans.Teller + umemeTrans.TranAmount + umemeTrans.TranNarration + umemeTrans.TranType;

            umemeTrans.DigitalSignature = GetDigitalSignature(dataToSign, trans.VendorCode);
            return(umemeTrans);
        }
        public PostResponse SendToUmeme(Transaction trans)
        {
            PostResponse    resp       = new PostResponse();
            DatabaseHandler dp         = new DatabaseHandler();
            string          vendorCode = trans.VendorCode;
            string          custref    = trans.CustRef;

            try
            {
                UtilityCredentials creds = dp.GetUtilityCreds("UMEME", trans.VendorCode);
                if (!creds.UtilityCode.Equals(""))
                {
                    System.Net.ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidation;
                    UmemeApi.EPayment umemeapi = new UmemeApi.EPayment();
                    creds.UtilityCode     = "Stanbic-Bank";
                    creds.UtilityPassword = "******";

                    UmemeApi.Transaction umemeTrans = GetUmemeTrans(trans, creds);

                    //throw new Exception("unable to connect");
                    UmemeApi.Token umemeResp = umemeapi.PostYakaPayment(umemeTrans);

                    string UmemeStatusCode = umemeResp.StatusCode.ToUpper();
                    string UmemeStatusDesc = umemeResp.StatusDescription.Trim().ToUpper();

                    if (UmemeStatusCode == "0")
                    {
                        if (trans.CustomerType.ToUpper() == "PREPAID")
                        {
                            resp.NoOfUnits         = umemeResp.Units;
                            resp.PegPayPostId      = umemeResp.PrepaidToken;
                            resp.StatusCode        = "0";
                            resp.StatusDescription = "SUCCESS";
                        }
                        else
                        {
                            resp.NoOfUnits         = umemeResp.Units;
                            resp.PegPayPostId      = umemeResp.ReceiptNumber;
                            resp.StatusCode        = "0";
                            resp.StatusDescription = "SUCCESS";
                        }
                    }
                    else if (UmemeStatusDesc.Contains("DUPLICATE VENDOR REFERENCE"))
                    {
                        UmemeApi.Response umemeResp2 = umemeapi.GetTransactionDetails(trans.BankID, creds.UtilityCode, creds.UtilityPassword);
                        if (umemeResp2.StatusCode == "0")
                        {
                            if (trans.CustomerType.ToUpper().Equals("PREPAID"))
                            {
                                resp.PegPayPostId      = umemeResp2.Token;
                                resp.StatusCode        = "0";
                                resp.StatusDescription = "SUCCESS";
                            }
                            else
                            {
                                resp.PegPayPostId      = umemeResp2.ReceiptNumber;
                                resp.StatusCode        = "0";
                                resp.StatusDescription = "SUCCESS";
                            }
                        }
                        else
                        {
                            resp.PegPayPostId      = "";
                            resp.StatusCode        = "100";
                            resp.StatusDescription = umemeResp.StatusDescription + " AT UMEME";
                        }
                    }
                    else if (UmemeStatusDesc.Contains("SUSPECTED DOUBLE POSTING"))
                    {
                        resp.PegPayPostId      = "";
                        resp.StatusCode        = "100";
                        resp.StatusDescription = UmemeStatusDesc + " AT UMEME";
                    }
                    else if (UmemeStatusDesc.Contains("GENERAL ERROR"))
                    {
                        //signal to skip this transaction
                        //resp.PegPayPostId = "";
                        //resp.StatusCode = "500";
                        //resp.StatusDescription = UmemeStatusDesc;

                        UmemeApi.Response umemeResp2 = umemeapi.GetTransactionDetails(trans.BankID, creds.UtilityCode, creds.UtilityPassword);
                        if (umemeResp2.StatusCode.Equals("35") && umemeResp2.StatusDescription.Contains("DON'T EXIST")) // Doesnt exist
                        {
                            resp.StatusCode        = "100";
                            resp.StatusDescription = UmemeStatusDesc;
                        }
                        else
                        {
                            resp.StatusCode        = "500";
                            resp.StatusDescription = UmemeStatusDesc;
                        }
                    }
                    else
                    {
                        resp.PegPayPostId      = "";
                        resp.StatusCode        = "100";
                        resp.StatusDescription = UmemeStatusDesc + " AT UMEME";
                    }
                }
                else
                {
                    //////////////////////////////// remove this part
                    resp.PegPayPostId      = "";
                    resp.StatusCode        = "100";
                    resp.StatusDescription = "UTILITY CREDENTIALS NOT SET AT PEGASUS FOR THIS REVERSAL";
                }
            }
            catch (Exception ex)
            {
                string errorMsg = ex.Message.ToUpper().Trim();

                if (errorMsg.Contains("UNABLE TO CONNECT"))
                {
                    //signal to fail this transaction
                    resp.PegPayPostId      = "";
                    resp.StatusCode        = "100";
                    resp.StatusDescription = ex.Message;
                }
                else
                {
                    //signal to skip this transaction
                    resp.PegPayPostId      = "";
                    resp.StatusCode        = "500";
                    resp.StatusDescription = ex.Message;
                }
            }
            return(resp);
        }