public Guid Save(PaymentResponse entity)
        {

            PaymentResponse existingEntity = _ctx.AsynchronousPaymentResponse.FirstOrDefault
                                                               (n => n.Id == entity.Id);

            if (existingEntity == null)
            {
                existingEntity = new PaymentResponse();
                existingEntity.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification;
                existingEntity.DateCreated = DateTime.Now;
                existingEntity.TimeStamp = DateTime.Now;
                existingEntity.Id = entity.Id;
                _ctx.AsynchronousPaymentResponse.Add(existingEntity);
            }

            existingEntity.DistributorCostCenterId = entity.DistributorCostCenterId;
            existingEntity.TransactionRefId = entity.TransactionRefId;
            existingEntity.AmountDue = entity.AmountDue;
            existingEntity.BusinessNumber = entity.BusinessNumber;
            existingEntity.LongDescription = entity.LongDescription;
            existingEntity.SDPReferenceId = entity.SDPReferenceId;
            existingEntity.StatusDetail = entity.StatusDetail;
            existingEntity.StatusCode = entity.StatusCode;
            existingEntity.ShortDescription = entity.ShortDescription;
            existingEntity.SDPTransactionRefId = entity.SDPTransactionRefId;
            

          //  _ctx.AsynchronousPaymentResponse.Add(existingEntity);
            _ctx.SaveChanges();
            return existingEntity.Id;
         
        }
Example #2
0
        public static ClientRequestResponseBase ThrowError(string error, ClientRequestResponseBase entity)
        {
            ClientRequestResponseBase response = new ClientRequestResponseBase();
            if (entity is PaymentNotificationRequest)
            {
                PaymentNotificationResponse apn = new PaymentNotificationResponse();
                apn.DistributorCostCenterId = entity.DistributorCostCenterId;
                apn.StatusCode = "Error";
                apn.StatusDetail = error;
                response = apn;
            }
            else if (entity is PaymentInstrumentRequest)
            {
                PaymentInstrumentResponse pi = new PaymentInstrumentResponse();
                pi.StatusCode = "Error";
                pi.StatusDetail = error;
                response = pi;
            }
            else if (entity is PaymentRequest)
            {
                PaymentResponse apr = new PaymentResponse();
                apr.StatusCode = "Error";
                apr.StatusDetail = error;
                response = apr;
            }
            else if(entity is DocSMSResponse)
            {
                DocSMSResponse sms = new DocSMSResponse();
                sms.SdpResponseCode = "Error";
                sms.SdpResponseStatus = error;
                response = sms;
            }

            return response;
        }
        public async Task<PaymentResponse> PaymentRequestAsync(PaymentRequest request)
        {

            PaymentResponse _response = new PaymentResponse();
            HttpClient httpClient = setupHttpClient();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            string url = "api/bridge/payment/paymentrequest";
            try
            {
                var response = await httpClient.PostAsJsonAsync(url, request);
                _response = await response.Content.ReadAsAsync<PaymentResponse>();
            }
            catch (Exception ex)
            {
                string error = "Failed to retrieve payment response.\n" +
                               (ex.InnerException == null ? "" : ex.InnerException.Message);
                _log.Error(error);
                _response.StatusCode = "Error";
                _response.StatusDetail = error;
            }

            return _response;
        }
Example #4
0
        public ClientRequestResponseBase DeserializeSDPResponse(string jsonResponse, ClientRequestResponseType responseType)
        {
            ClientRequestResponseBase crr = null;
            try
            {
                JObject jo = JObject.Parse(jsonResponse);

                string statusCode = (string) jo["statusCode"];
                if (statusCode == "E1340" || statusCode == "E1304")
                    return null;

                switch (responseType)
                {
                    case ClientRequestResponseType.PaymentInstrument:
                        SDPPaymentInstrumentResponse sdppir = null;
                        _messageValidation.CanDeserializeMessage(jsonResponse, out sdppir);
                        PaymentInstrumentResponse pir = new PaymentInstrumentResponse();

                        pir.Id = Guid.NewGuid();
                        pir.DateCreated = DateTime.Now;
                        pir.ClientRequestResponseType = ClientRequestResponseType.PaymentInstrument;
                        pir.PaymentInstrumentList = sdppir.paymentInstrumentList;
                        pir.StatusCode = sdppir.statusCode;
                        pir.StatusDetail = sdppir.statusDetail;

                        crr = pir;
                        break;

                    case ClientRequestResponseType.AsynchronousPayment:
                        SDPPaymentResponse sdppr = null;
                        PaymentResponse apr = new PaymentResponse();
                        _messageValidation.CanDeserializeMessage(jsonResponse, out sdppr);

                        apr.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPayment;
                        apr.Id = Guid.NewGuid();
                        apr.SDPTransactionRefId = sdppr.internalTrxId;
                        if (sdppr.externalTrxId != null)
                            apr.TransactionRefId = ConstructMyGuid(sdppr.externalTrxId).ToString();
                        apr.BusinessNumber = sdppr.businessNumber;
                        apr.DateCreated = sdppr.timeStamp;
                        apr.SDPReferenceId = sdppr.referenceId.ToString();
                        apr.StatusCode = sdppr.statusCode;
                        apr.StatusDetail = sdppr.statusDetail;
                        apr.ShortDescription = sdppr.statusDetail;
                        apr.LongDescription = sdppr.longDescription;
                        apr.TimeStamp = sdppr.timeStamp.ToString() == "1/1/0001 12:00:00 AM" ? DateTime.Now : sdppr.timeStamp;
                        apr.AmountDue = Convert.ToDouble(sdppr.amountDue);
                        crr = apr;
                        break;
                }
            }
            catch (Exception ex)
            {
                _auditLogRepository.AddLog(Guid.Empty, responseType.ToString(), "Client", "Error deserializing jsonResponse " + jsonResponse + " in DeserializeSDPResponse.\nException details: \n" +
                   ex.Message + ex.InnerException != null ? "\n" + ex.InnerException.Message : "");
                return null;
            }

            return crr;
        }
Example #5
0
        PaymentResponse GenerateSamplePaymentResponse(PaymentRequest request)
        {
            PaymentResponse apr = new PaymentResponse();
            Random ran = new Random();

            apr.BusinessNumber            = Guid.NewGuid().ToString();
            apr.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPayment;
            apr.DateCreated               = DateTime.Now;
            apr.TransactionRefId          = request.TransactionRefId;
            apr.Id                        = Guid.NewGuid();
            apr.SDPTransactionRefId = sampleInternalTrxId.ToString();
            apr.LongDescription           = "Long description";
            apr.SDPReferenceId            = "12345678";// ran.Next(10000000, 99999999);
            apr.ShortDescription          = "Short Desc.";
            apr.StatusDetail              = "OK";

            return apr;
        }
Example #6
0
        ClientRequestResponseBase ThrowError(string error, ClientRequestResponseBase enitity)
        {
            ClientRequestResponseBase response = new ClientRequestResponseBase();
            if (enitity is PaymentNotificationRequest)
            {
                PaymentNotificationResponse apn = new PaymentNotificationResponse();
                apn.DistributorCostCenterId = enitity.DistributorCostCenterId;
                apn.StatusCode = "Failed";
                apn.StatusDetail = error;
                response = apn;
            }
            else if (enitity is PaymentInstrumentRequest)
            {
                PaymentInstrumentResponse pi = new PaymentInstrumentResponse();
                pi.StatusDetail = "Failed: " + error;
                response = pi;
            }
            else if (enitity is PaymentRequest)
            {
                PaymentResponse apr = new PaymentResponse();
                apr.StatusCode = "Failed";
                apr.StatusDetail = error;
                response = apr;
            }

            return response;
        }
        public void AddPaymentInfo(decimal cashAmnt, decimal creditAmnt, decimal mMoneyAmnt, decimal chequeAmnt,
                                   decimal amountPaid, string mMoneyReferenceNo, string chequeNo, decimal grossAmount,
                                   decimal change, Bank bank, BankBranch bBranch, string mMoneyOption,
                                   bool mMoneyIsApproved, Guid mMoneyTransactionRefId, string mMoneyAccountId,
                                   string mMoneySubscriberId, string mMoneyTillNumber, string currency,
                                   PaymentNotificationResponse paymentNotif,
                                   PaymentResponse paymentResponse)
        {
            using (StructureMap.IContainer cont = NestedContainer)
            {
                CashAmount = cashAmnt - change;
                bankBranch = bBranch;
                TotalGross = grossAmount + AmountPaid;

                CreditAmount = creditAmnt;
                MMoneyAmount = mMoneyAmnt;
                ChequeAmount = chequeAmnt;
                MMoneyRefNo = mMoneyReferenceNo;
                ChequeNo = chequeNo + " - " + (bank != null ? bank.Name : "");
                AmountPaid = amountPaid + AmountPaid;
                MMoneyOption = mMoneyOption;

                string desc = "";
              
                #region Cash

                if (cashAmnt > 0)
                {
                    var existing = PaymentInfoList.FirstOrDefault(n => n.PaymentModeUsed == PaymentMode.Cash && n.IsNew);
                    if (existing == null)
                    {
                        existing = new PaymentInfo
                                       {
                                           Id = Guid.NewGuid(),
                                           Amount = cashAmnt - change, //??
                                           PaymentModeUsed = PaymentMode.Cash,
                                           IsNew = true,
                                           IsConfirmed = true,
                                           PaymentRefId = "Cash",
                                           MMoneyPaymentType = "",
                                           PaymentTypeDisplayer = "Cash",
                                           Description = "", 
                                       };
                        PaymentInfoList.Add(existing);
                    }
                    else
                        existing.Amount += cashAmnt;

                    desc = GetLocalText("sl.payment.notifitcation.desc.inpaymentof") /*"In payment of" */
                           + " " + currency + " " + existing.Amount + ".";
                    existing.Description = desc;
                }

                #endregion

                #region Cheq

                if (chequeAmnt > 0)
                {
                    var existing =
                        PaymentInfoList.FirstOrDefault(n => n.PaymentModeUsed == PaymentMode.Cheque && n.IsNew);
                    if (existing == null)
                    {
                        existing = new PaymentInfo
                                       {
                                           Id = Guid.NewGuid(),
                                           Amount = chequeAmnt,
                                           PaymentModeUsed = PaymentMode.Cheque,
                                           PaymentRefId = chequeNo + " - " + (bank != null ? bank.Name : ""),
                                           IsNew = true,
                                           IsConfirmed = true,
                                           MMoneyPaymentType = "",
                                           PaymentTypeDisplayer =
                                               "Cheque " + chequeNo + " - " + (bank != null ? bank.Name : ""),
                                           Description = ""
                                       };
                        PaymentInfoList.Add(existing);
                    }
                    else
                        existing.Amount += chequeAmnt;

                    desc = GetLocalText("sl.payment.notifitcation.desc.inpaymentof") /*"I payment of"*/
                           + " " + currency + " " + existing.Amount + " "
                           + GetLocalText("sl.payment.notifitcation.desc.tobank") /*"to bank"*/
                           + " " + (bank != null ? bank.Name : "") + " "
                           + GetLocalText("sl.payment.notifitcation.desc.chequenumber") /*"cheque number"*/
                           + " " + chequeNo + ".";
                    existing.Description = desc;
                }

                #endregion

                #region M-Money

                if (mMoneyAmnt > 0)
                {
                    if (mMoneyTransactionRefId == Guid.Empty)
                        throw new Exception("Transaction reference id not set.\nAddPaymentInfo()");

                    //cn: Add or replace a notification.
                    var existingNotif = _paymentNotifs.FirstOrDefault(n => n.Id == paymentNotif.Id);
                    if (existingNotif != null)
                        _paymentNotifs.Remove(existingNotif);

                    if (paymentNotif != null)
                        _paymentNotifs.Add(paymentNotif);

                    var mmPayment = new PaymentInfo
                                        {
                                            Id = mMoneyTransactionRefId,
                                            Amount = mMoneyAmnt,
                                            PaymentModeUsed = PaymentMode.MMoney,
                                            MMoneyPaymentType = mMoneyOption,
                                            IsNew = true,
                                            IsConfirmed = mMoneyIsApproved,
                                            PaymentRefId = mMoneyReferenceNo,
                                            PaymentTypeDisplayer = mMoneyOption,
                                            Description = desc
                                        };
                    PaymentInfoList.Add(mmPayment);

                    if (mmPayment.IsConfirmed)
                        desc = MMoneyDescription(mmPayment.Amount, currency, mMoneySubscriberId, mMoneyAccountId,
                                                 mMoneyTillNumber, MMoneyRefNo);
                    else
                        desc = paymentResponse.LongDescription != ""
                                   ? paymentResponse.LongDescription
                                   : paymentResponse.ShortDescription;

                    mmPayment.Description = desc;
                }

                #endregion

                #region Credit

                var credit = PaymentInfoList.FirstOrDefault(n => n.PaymentModeUsed == PaymentMode.Credit && n.IsNew);
                if (credit == null)
                {
                    credit = new PaymentInfo
                                 {
                                     Id = Guid.NewGuid(),
                                     Amount = creditAmnt,
                                     PaymentModeUsed = PaymentMode.Credit,
                                     IsNew = true,
                                     IsConfirmed = true,
                                     MMoneyPaymentType = "",
                                     PaymentRefId = "",
                                     PaymentTypeDisplayer = "Credit"
                                 };

                    PaymentInfoList.Add(credit);
                }
                else
                    credit.Amount = creditAmnt;

                if (credit.Amount == 0)
                    PaymentInfoList.Remove(credit);

                #endregion

                RecalcAmountPaid();
                CanSaveToContinue = false;
            }
        }
Example #8
0
        void ProcessPaymentRequestResponse(PaymentResponse apr)
        {
            if (apr.StatusCode.StartsWith("E") || apr.StatusCode.ToLower() == "error")//error codes from SDP{
            {
                string errorMsg = "\n\nStatusCode:  " + apr.StatusCode + "\nStatusDetail: " + apr.StatusDetail;
                ReportPaymentRequestError(errorMsg);
                return;
            }

            string token = "";
            string msg = "Please pay this amount\t" + apr.AmountDue + " " + Currency;
            string option = SelectedMMoneyOption.Name.ToLower();

            if (option == "pay-bill" || option == "paybill" || option == "pay bill")
            {
                string payBillMsg =
                    "Please access Pay Bill in M-PESA menu and enter the following when prompted:\n" +
                    "   - Business No:\t" + apr.BusinessNumber + ",\n" +
                    "   - Account No:\t" + apr.SDPReferenceId + ",\n" +
                    "   - Amount:\t" + Currency + " " + apr.AmountDue + ".";
                msg = payBillMsg;
            }
            else if (option == "buy-goods" || option == "buygoods" || option == "buy goods")
            {
                if (!string.IsNullOrEmpty(TheOrder.DocumentIssuerUser.TillNumber))
                    token = "and specify the till number: " + TheOrder.DocumentIssuerUser.TillNumber;
                string buyGoodsMsg =
                    "Please access Buy Goods in M-PESA menu and pay " + Currency + " " + apr.AmountDue + "" +
                    token + "\n" +
                    "Please make sure the Till Number of the merchant and the amount is correctly entered.";
                msg = buyGoodsMsg;
            }
            else if (option == "equity")
            {
                string equityMsg =
                    "Please access Equity Bank Easy Pay menu and enter the following when prompted:\n" +
                    "   - Business no:\t" + apr.BusinessNumber + ",\n" +
                    "   - Reference ID:\t" + apr.SDPReferenceId + ",\n" +
                    "   - Amount:\t" + Currency + " " + apr.AmountDue + ".";
                msg = equityMsg;
            }
            else if (option == "m-pesa" || option == "mpesa" || option == "m pesa")
            {
                string m_pesaMsg = "Please access M-Pesa menu and pay " + Currency + " to the phone number " +
                                   AccountNo;
                msg = m_pesaMsg;
            }
            try
            {
                PaymentRef = apr.SDPReferenceId;
            }
            catch { }
            if (apr.StatusCode == "S1000")
            {
                MessageBox.Show(apr.LongDescription ?? msg, "Distributr: Payment Module",
                                MessageBoxButton.OK);
            }
            else
            {
                string longMsg = "Status Code: " + apr.StatusCode
                                 + "\nStatus Detail: " + apr.StatusDetail;
                longMsg += "\n" + apr.LongDescription ?? msg;

                MessageBox.Show(longMsg, "Distributr: Payment Module", MessageBoxButton.OK);
            }

            _clientRequestResponses.Add(apr);
            //_asynchronousPaymentResponseService.Save(apr);
            PaymentResponse = apr;

            CanMakePaymentRequest = false;
            CanGetPaymentNotification = true;
            CanSeePaymentResponse = true;
            CanChangePaymentOption = false;
            CanEditMMoneyAmount = false;
            CanEditAccountNo = false;
            CanClearMMoneyFields = false;
            CanEditSubscriberNo = false;
        }
        ClientRequestResponseBase Map(tblPaymentResponse tblApn)
        {
            ClientRequestResponseBase crr = null;
            ClientRequestResponseType type = (ClientRequestResponseType) tblApn.ClientRequestResponseTypeId;
            switch(type)
            {
                case ClientRequestResponseType.AsynchronousPayment:
                    crr = new PaymentResponse();
                    break;
                case ClientRequestResponseType.AsynchronousPaymentNotification:
                    crr = new PaymentNotificationResponse();
                    break;
            }

            if (crr != null)
            {
                crr.Id = tblApn.Id;
                crr.DistributorCostCenterId = tblApn.DistributorCostCenterId;
                crr.ClientRequestResponseType = (ClientRequestResponseType) tblApn.ClientRequestResponseTypeId;
                crr.DateCreated = tblApn.DateCreated.Value;
            }

            //if (crr.ClientRequestResponseType == ClientRequestResponseType.AsynchronousPaymentNotification)
            //{
            //    AsynchronousPaymentNotificationResponse apn = crr as AsynchronousPaymentNotificationResponse;
            //    apn.PaidAmount                                  = tblApn.Amount.Value;
            //    apn.Currency                                = tblApn.Currency.Trim();
            //    apn.TransactionRefId                        = tblApn.TransactionRefId;
            //    apn.SDPTransactionRefId                     = tblApn.SDPTransactionRefId;
            //    apn.SDPReferenceId                          = tblApn.SDPReferenceId;
            //    apn.StatusCode                              = tblApn.StatusCode.Trim();
            //    apn.StatusDetail                            = tblApn.StatusDetail.Trim();
            //    apn.TimeStamp                               = tblApn.TimeStamp.Value;
            //}

            if (crr.ClientRequestResponseType == ClientRequestResponseType.AsynchronousPayment)
            {
                PaymentResponse apr = crr as PaymentResponse;
                apr.BusinessNumber              = tblApn.BusinessNumber;
                apr.AmountDue                   = tblApn.Amount.Value;
                apr.TransactionRefId            = tblApn.TransactionRefId;
                apr.SDPTransactionRefId         = tblApn.SDPTransactionRefId;
                apr.LongDescription             = tblApn.LongDescription.Trim();
                apr.SDPReferenceId              = tblApn.SDPReferenceId;
                apr.ShortDescription            = tblApn.ShortDescription.Trim();
                apr.StatusDetail                = tblApn.StatusDetail.Trim();
                apr.StatusCode                  = tblApn.StatusCode.Trim();
                apr.TimeStamp                   = tblApn.TimeStamp.Value;
                apr.SubscriberId = tblApn.SubscriberId;
            }

            return crr;
        }