Example #1
0
        public bool ConfirmPayment(PaymentInfo paymentInfo)
        {
            MMoneyAmount = paymentInfo.Amount;
            PaymentTransactionRefId = paymentInfo.Id;
            Confirm(paymentInfo.MMoneyPaymentType,paymentInfo.PaymentRefId);

            return MMoneyIsApproved;
        }
      public async Task<PaymentNotificationResponse> GetNotification(PaymentInfo paymentInfo)
        {
            var pnr = new PaymentNotificationRequest()
            {
                Id = Guid.NewGuid(),
                DistributorCostCenterId =_configService.Load().CostCentreId,
                ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification,
                DateCreated = DateTime.Now,
                TransactionRefId = paymentInfo.Id.ToString(),
            };

          var data = await _paymentGatewayProxy.GetPaymentNotificationAsync(pnr);
          PaymentNotificationResponse response = null; 
          if (data != null && data.StatusCode == "S1000")
          {
             _paymentNotification.Save(data);
             response = _paymentNotification.GetById(data.Id);
          }
          return response;
        }
        private static void MapPaymentInfo(tblDocument tblMainOrder, MainOrder mo)
        {
            foreach (var paymentInfo in tblMainOrder.tblOrderPaymentInfo)
            {

                var item = new PaymentInfo
                               {
                                   Amount = paymentInfo.Amount,
                                   ConfirmedAmount = paymentInfo.ConfirmedAmount,
                                   Id = paymentInfo.Id,
                                   Description = paymentInfo.Description,
                                   IsConfirmed = paymentInfo.IsConfirmed.Value,
                                   IsProcessed = paymentInfo.IsProcessed.Value,
                                   MMoneyPaymentType = paymentInfo.MMoneyPaymentType,
                                   NotificationId = paymentInfo.NotificationId,
                                   PaymentModeUsed = (PaymentMode) paymentInfo.PaymentMode,
                                   PaymentRefId = paymentInfo.PaymentRefId,
                                   Bank = paymentInfo.BankCode,
                                   BankBranch = paymentInfo.BranchCode,
                                   DueDate = paymentInfo.ChequeDueDate
                               };
                if (paymentInfo.ChequeDueDate.HasValue)
                    paymentInfo.ChequeDueDate = paymentInfo.ChequeDueDate.Value;

                mo.AddPayment(item);
            }
        }
Example #4
0
 void paymentModeModal_Closed(object sender, EventArgs e)
 {
     var pvm = _paymentModeModal.DataContext as PaymentModeViewModel;
     if (_paymentModeModal.DialogResult.Value)
     {
         if (itemEdited != null)
         {
             if (itemEdited.PaymentModeUsed == PaymentMode.Cash)
             {
                 itemEdited.Amount = pvm.CashAmount;
             }
             else if (itemEdited.PaymentModeUsed == PaymentMode.Cheque)
             {
                 itemEdited.Amount = pvm.ChequeAmount;
             }
             _vm.UpdatePaymentInfo(itemEdited.Id, itemEdited.Amount, pvm.CreditAmount);
         }
         else
         {
             if (pvm != null)
             {
                 throw new NotImplementedException();
                 //_vm.AddPaymentInfo(pvm.CashAmount,
                 //                   pvm.CreditAmount,
                 //                   pvm.MMoneyAmount,
                 //                   pvm.ChequeAmount,
                 //                   pvm.AmountPaid,
                 //                   pvm.PaymentRef,
                 //                   pvm.ChequeNumber,
                 //                   pvm.GrossAmount,
                 //                   pvm.Change,
                 //                   pvm.SelectedBank,
                 //                   pvm.SelectedBankBranch,
                 //                   pvm.SelectedMMoneyOption != null ? pvm.SelectedMMoneyOption.Name : "",
                 //                   pvm.MMoneyIsApproved,
                 //                   pvm.PaymentTransactionRefId,
                 //                   pvm.AccountNo,
                 //                   pvm.SubscriberId,
                 //                   pvm.TillNumber,
                 //                   pvm.Currency,
                 //                   pvm.PaymentNotification,
                 //                   pvm.PaymentResponse
                 //    );
             }
         }
     }
     PaymentsDataGrid.ItemsSource = null;
     PaymentsDataGrid.ItemsSource = _vm.PaymentInfoList;
     itemEdited = null;
 }
Example #5
0
        void SelectPaymentMode(PaymentInfo itemToEdit)
        {
            _paymentModeModal = new PaymentModeModal();
            _paymentModeModal.Closed += new EventHandler(paymentModeModal_Closed);
            var pvm = _paymentModeModal.DataContext as PaymentModeViewModel;
            pvm.RunClearAndSetup();
            pvm.AmountPaid = _vm.AmountPaid;//carry this accross
            pvm.GrossAmount = _vm.TotalGross - _vm.AmountPaid;

            if (itemToEdit != null)
            {
                PaymentMode itemMode = itemToEdit.PaymentModeUsed;
                switch (itemMode)
                {
                    case PaymentMode.Cash:
                        pvm.CashAmount = itemToEdit.Amount;
                        pvm.GrossAmount += itemToEdit.Amount;
                        break;
                    case PaymentMode.Cheque:
                        pvm.ChequeAmount = itemToEdit.Amount;
                        pvm.GrossAmount += itemToEdit.Amount;
                        break;
                    //should not edit MMoney payment mode
                    //should not edit Credit
                }
            }
            //added to keep track of payments if someone goes back to the payments screen
            //pvm.CashAmount = _vm.CashAmount;
            //pvm.ChequeAmount = _vm.ChequeAmount;
            //pvm.ChequeNumber = _vm.ChequeNo;
            //pvm.MMoneyAmount = _vm.MMoneyAmount;
            //pvm.PaymentRef = _vm.MMoneyRefNo;

            pvm.TheOrder = _vm.OrderDocument;
            pvm.OrderOutletId = _vm.SelectedOutlet.Id;
            pvm.OrderDocReference = _vm.OrderId;
            pvm.InvoiceDocReference = _vm.InvoiceDocument.DocumentReference;
            pvm.SetUpSubscriber();
            pvm.CalcAmountPaid();

            if (_vm.bankBranch != null)
            {
                pvm.LoadForEditing(_vm.bankBranch);
            }

            _paymentModeModal.ShowDialog();
        }
        PaymentInfo Map(PaymentNotificationListItem detail, ReceiptLineItem item, PaymentNotificationResponse paymentNotif)
        {
            var info = new PaymentInfo
                           {
                               Amount = (decimal) detail.PaidAmount,
                               Id = Guid.NewGuid(),
                               PaymentModeUsed = PaymentMode.MMoney,
                               IsConfirmed = true,
                               IsNew = true,
                               MMoneyPaymentType = item.MMoneyPaymentType,
                               PaymentRefId = item.PaymentRefId,
                               PaymentTypeDisplayer = item.MMoneyPaymentType,
                               NotificationId = detail.Id + ";",
                               Description = MMoneyDescription((decimal) detail.PaidAmount,
                                                               paymentNotif.Currency,
                                                               paymentNotif.SubscriberId,
                                                               paymentNotif.AccountId, "",
                                                               paymentNotif.SDPReferenceId)
                           };

            return info;
        }
        private void SubmitUnConfirmedMMoneyPayments(Order order, Receipt paymentDoc,
                                                     IEnumerable<PaymentInfo> mmPayments, Guid invoiceId,
                                                     string invoiceRef)
        {
            using (StructureMap.IContainer cont = NestedContainer)
            {
                foreach (var mmPayment in mmPayments)
                {
                    var newPaymentInfos = new List<PaymentInfo>();
                    //cn: if payment was made in partial check confirmation
                    if (!mmPayment.IsConfirmed) //cn: means sum of paymentNotif.PaidAmount < mmPayment.Amount
                    {
                        var paymentNotifs =
                            _paymentNotifs.Where(n => n.TransactionRefId == mmPayment.Id.ToString()).ToList();
                        if (paymentNotifs.Count > 0)
                        {
                            //cn: for each notification with a payment greater than 0, create line item
                            foreach (var paymentNotif in paymentNotifs)
                            {
                                foreach (
                                    var item in paymentNotif.PaymentNotificationDetails.Where(n => n.PaidAmount > 0))
                                {
                                    PaymentInfo info = new PaymentInfo
                                                           {
                                                               Amount = (decimal) item.PaidAmount,
                                                               Id = Guid.NewGuid(),
                                                               PaymentModeUsed = PaymentMode.MMoney,
                                                               IsConfirmed = true,
                                                               IsNew = true,
                                                               MMoneyPaymentType = mmPayment.MMoneyPaymentType,
                                                               PaymentRefId = mmPayment.PaymentRefId,
                                                               PaymentTypeDisplayer = mmPayment.PaymentTypeDisplayer,
                                                               NotificationId = item.Id + ";",
                                                               Description =
                                                                   MMoneyDescription((decimal) item.PaidAmount,
                                                                                     paymentNotif.Currency,
                                                                                     paymentNotif.SubscriberId,
                                                                                     paymentNotif.AccountId, "",
                                                                                     paymentNotif.SDPReferenceId)
                                                           };
                                    newPaymentInfos.Add(info);
                                }
                            }

                            Using<IPOSSalesWFManager>(cont).SubmitSecondarymMoneyPayment(order, paymentDoc, newPaymentInfos,
                                                                            invoiceId, invoiceRef);
                        }
                    }
                }
                _paymentNotifs.Clear();
            }
        }
        public void RemovePaymentIfo(Guid Id)
        {
            var existing = PaymentInfoList.FirstOrDefault(n => n.Id == Id);
            if (existing != null)
            {
                PaymentInfoList.Remove(existing);
                AmountPaid -= existing.Amount;

                var credit = PaymentInfoList.FirstOrDefault(n => n.PaymentModeUsed == PaymentMode.Credit);
                if (credit != null)
                {
                    credit.Amount += existing.Amount;
                }
                else
                {
                    var newItem = new PaymentInfo
                                      {
                                          Id = Guid.NewGuid(),
                                          Amount = existing.Amount,
                                          PaymentModeUsed = PaymentMode.Credit,
                                          IsNew = true,
                                          IsConfirmed = true,
                                          MMoneyPaymentType = "",
                                          PaymentRefId = ""
                                      };
                    PaymentInfoList.Add(newItem);
                }

                if (_paymentNotifs != null && _paymentNotifs.Count > 0)
                {
                    var myNotif = _paymentNotifs.FirstOrDefault(n => n.TransactionRefId == Id.ToString());
                    if (myNotif != null)
                        _paymentNotifs.Remove(myNotif);
                }
            }

            //????????????????????????????????????????????????????????????????????????????????????????????????????????????
            if (PaymentInfoList.Count == 1 && PaymentInfoList.First().PaymentModeUsed == PaymentMode.Credit)
            {
                var rem = PaymentInfoList.First();
                PaymentInfoList.Remove(rem);
            }
            RecalcAmountPaid();
            if (PaymentInfoList.Count == 0)
                CanSaveToContinue = true;
        }
 public void UpdatePaymentInfo(Guid itemId, decimal amount, decimal creditAmnt)
 {
     var credit = PaymentInfoList.FirstOrDefault(n => n.PaymentModeUsed == PaymentMode.Credit);
     if (credit != null)
     {
         if (creditAmnt == 0)
             PaymentInfoList.Remove(credit);
         else
             credit.Amount = creditAmnt;
     }
     else
     {
         if (creditAmnt > 0)
         {
             var newItem = new PaymentInfo
                               {
                                   Id                = Guid.NewGuid(),
                                   Amount            = creditAmnt,
                                   PaymentModeUsed   = PaymentMode.Credit,
                                   IsNew             = true,
                                   IsConfirmed        = true,
                                   MMoneyPaymentType = "",
                                   PaymentRefId      = ""
                               };
             PaymentInfoList.Add(newItem);
         }
     }
     RecalcAmountPaid();
 }
        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;
            }
        }
        public void LoadPayments()
        {
            using (StructureMap.IContainer container = NestedContainer)
            {
                Receipts = new List<Receipt>();
               
                DateTime start = DateTime.Now;
                InvoiceDocument = Using<IInvoiceRepository>(container).GetInvoiceByOrderId(OrderIdLookup);
                if (InvoiceDocument == null) return;
                InvoiceIdLookUp = InvoiceDocument.Id;
                start = DateTime.Now;

                var receipts = Using<IReceiptRepository>(container).GetByInvoiceId(InvoiceDocument.Id);

                receipts.ForEach(Receipts.Add); //cache

                InvoiceReceipts.Clear();
                var rec = new Receipt(Guid.Empty) {DocumentReference = "--Select A Receipt to View--"};
                SelectedReceipt = rec;
                InvoiceReceipts.Add(rec);
                receipts.Where(n => n.Total > 0).ToList().ForEach(n => InvoiceReceipts.Add(n));
                start = DateTime.Now;
                var paymentInfo = new List<PaymentInfo>();
                receipts.ToList()
                        .ForEach(n => n.LineItems
                                       .ForEach(x =>
                                                    {
                                                        decimal unconfirmedAmnt = 0m;
                                                        bool isConfirmed = Using<ITransactionalViewmodelRefactoring>(container).LineItemIsConfirmed(n, x.Id,out unconfirmedAmnt);
                                                        if (isConfirmed &&
                                                            x.LineItemType == OrderLineItemType.DuringConfirmation)
                                                            //cn: a fully confirmed payment
                                                            return;
                                                        var info = new PaymentInfo
                                                                       {
                                                                           Id = x.Id,
                                                                           Amount =
                                                                               x.LineItemType ==
                                                                               OrderLineItemType.DuringConfirmation
                                                                                   ? unconfirmedAmnt
                                                                                   : x.Value,
                                                                           PaymentModeUsed = (PaymentMode) x.PaymentType,
                                                                           IsNew = false,
                                                                           IsConfirmed = isConfirmed,
                                                                           PaymentRefId = x.PaymentRefId,
                                                                           MMoneyPaymentType = x.MMoneyPaymentType,
                                                                           PaymentTypeDisplayer =
                                                                               x.PaymentType == PaymentMode.MMoney
                                                                                   ? x.MMoneyPaymentType
                                                                                   : x.PaymentType.ToString()
                                                                       };
                                                        paymentInfo.Add(info);
                                                    }
                                          ));

                paymentInfo.ForEach(PaymentInfoList.Add);

                RecalcAmountPaid();
            }
        }
        private async void ConfirmPayment(UnconfirmedPaymentItem paymentInfoItem)
        {
            using (var c = NestedContainer)
            {
                var order = Using<IMainOrderRepository>(c).GetById(paymentInfoItem.OrderId);
                var paymentbridgeService = Using<IPaymentGateWayBridge>(c);

                if (order != null && order.GetPayments.Count>0)
                {
                    var payments=order.GetPayments;
                    if (payments.Any(p => p.Id == paymentInfoItem.LineItemId && p.IsConfirmed))
                    {
                        MessageBox.Show("This payment has already been confirmed.", "Distributr: Payment Module",
                                        MessageBoxButton.OK);
                        return;
                    }
                    try
                    {
                        var paymentInfo = payments.FirstOrDefault(p => p.Id == paymentInfoItem.LineItemId);
                        var responce = await paymentbridgeService.GetNotification(paymentInfo);
                        if (responce !=null  && responce.PaymentNotificationDetails.Any(s=>!s.IsUsed) )
                        {
                            foreach (var notItem in responce.PaymentNotificationDetails)
                            {
                                var payment = new PaymentInfo()
                                {
                                    Id = new Guid(responce.TransactionRefId),
                                    Amount = (decimal)notItem.PaidAmount,
                                    ConfirmedAmount = (decimal) notItem.PaidAmount,
                                    PaymentRefId = responce.SDPReferenceId,
                                    MMoneyPaymentType = paymentInfo.MMoneyPaymentType,
                                    NotificationId = notItem.Id.ToString(),
                                    PaymentModeUsed = paymentInfo.PaymentModeUsed,
                                    IsConfirmed = true,
                                    IsProcessed = false

                                };
                                paymentbridgeService.ConfirmNotification(notItem.Id);
                                order.AddOrderPaymentInfoLineItem(payment);
                                    
                            }
                            Config config = Using<IConfigService>(c).Load();
                            if (order.OrderType==OrderType.DistributorPOS)
                                Using<IOrderPosWorkflow>(c).Submit(order,config);

                            else
                            {
                                
                 
                                Using<IOrderWorkflow>(c).Submit(order,config);
                            }
                            Load();

                            MessageBox.Show("This payment confirmed.", "Distributr: Payment Module",
                                       MessageBoxButton.OK);
                        }
                        //if(Using<IPaymentUtils>(c).ConfirmPayment(paymentInfo))
                        //{
                        //    order.AddOrderPaymentInfoLineItem(paymentInfo);

                        //    if (order.DocumentReference.ToLower().StartsWith("sale"))
                        //        Using<IOrderPosWorkflow>(c).Submit(order);

                        //    else
                        //    {
                        //        Using<IOrderWorkflow>(c).Submit(order);
                        //    }
                        //    Load();

                        //    MessageBox.Show("This payment confirmed.", "Distributr: Payment Module",
                        //               MessageBoxButton.OK);
                     
                        //}

                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
               
            }
        }
        private async void GetPaymntNotification()
        {
            if (SelectedMMoneyOption != null)
            {
                if (SelectedMMoneyOption.Name == "Buy Goods")
                {
                    if (PaymentRef == "")
                    {
                        MessageBox.Show(
                            /*"You must enter the Transaction Reference No. from the SMS received by the subscriber after paying."*/
                            GetLocalText("sl.payment.validate.referenceNoEmpty")
                            , GetLocalText("sl.payment.title") /*"Distributr: Payment Module"*/,
                            MessageBoxButton.OK);
                        return;
                    }

                    if (!IsValid())
                        return;
                }
            }
            using (var c = NestedContainer)
            {
                var paymentinfo =new PaymentInfo()
                                {
                                    Id = PaymentTransactionRefId,
                                    Amount = MMoneyAmount,
                                    ConfirmedAmount = MMoneyAmount,
                                    
                                };

                var notification = await Using<IPaymentGateWayBridge>(c).GetNotification(paymentinfo);
                if (notification !=null)
                {
                    MMoneyConfirmedAmount =(decimal)notification.PaymentNotificationDetails.Where(s => s.IsUsed == false).Sum(s => s.PaidAmount);
                }
                ProcessPaymentNotification(notification);
                
            }
           
            //GetPaymentNotification();

           

        }
        private void CompletePayment()
        {
            

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

                desc = GetLocalText("sl.payment.notifitcation.desc.inpaymentof") /*"In payment of" */
                       + " " + Currency + " " + existing.Amount.ToString("0.00") + ".";
                existing.Description = desc;
                TotalBilledAmount += CashAmount;
            }

            #endregion

            #region Cheq
            if (!string.IsNullOrEmpty(ChequeNumber) && ChequeAmount <= 0m)
            {
                MessageBox.Show("Check amount ????", "Distributr Warning", MessageBoxButton.OK);
                return;
            }
            if (ChequeAmount > 0)
            {

                if (string.IsNullOrEmpty(ChequeNumber))
                {
                    MessageBox.Show("Kindly enter the cheque number", "Distributr Warning");
                    return;
                }
                if (SelectedBank == null)
                {
                    MessageBox.Show("Kindly select bank", "Distributr Warning");
                    return;
                }
                if (SelectedBankBranch == null)
                {
                    MessageBox.Show("Kindly select bank branch", "Distributr Warning");
                    return;
                }
                var existing =
                    PaymentInfoList.FirstOrDefault(n => n.PaymentModeUsed == PaymentMode.Cheque && n.IsNew);
                if (existing == null)
                {
                    existing = new PaymentInfo
                    {
                        Id = Guid.NewGuid(),
                        ConfirmedAmount = ChequeAmount,
                        Amount = MMoneyAmount,
                        PaymentModeUsed = PaymentMode.Cheque,
                        PaymentRefId = ChequeNumber,
                        Bank = SelectedBank.Code,
                        BankBranch = SelectedBankBranch.Code,
                        IsNew = true,
                        IsConfirmed = true,
                        MMoneyPaymentType = "",
                        PaymentTypeDisplayer =
                            "Cheque " + ChequeNumber + " - " + (SelectedBank != null ? SelectedBank.Name : ""),
                        Description = "",
                        DueDate = ChequeDueDate
                    };
                    PaymentInfoList.Add(existing);
                }
                else
                    existing.ConfirmedAmount += ChequeAmount;
                TotalBilledAmount += ChequeAmount;

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

            #endregion

            #region M-Money

            if (MMoneyAmount > 0)
            {
                if (PaymentTransactionRefId == Guid.Empty)
                {
                    MessageBox.Show("Transaction reference id not set.,Have you requested for M-Money payment?");
                    return;
                }


                //cn: Add or replace a notification.
                PaymentNotificationResponse existingNotif = null;
                foreach (PaymentNotificationResponse n in NotificationResponses)
                {
                    if (PaymentNotification != null && n.Id == PaymentNotification.Id)
                    {
                        existingNotif = n;
                        break;
                    }
                }
                if (existingNotif != null)
                    NotificationResponses.Remove(existingNotif);

                if (PaymentNotification != null)
                    NotificationResponses.Add(PaymentNotification);

                var mmPayment = new PaymentInfo
                {
                    Id = PaymentTransactionRefId,
                    ConfirmedAmount = MMoneyConfirmedAmount,
                    Amount = MMoneyAmount,
                    PaymentModeUsed = PaymentMode.MMoney,
                    MMoneyPaymentType = SelectedMMoneyOption.Type,
                    IsNew = true,
                    IsConfirmed = MMoneyConfirmedAmount>0,
                    PaymentRefId = PaymentRef,
                    PaymentTypeDisplayer = SelectedMMoneyOption.Type,
                    Description = desc
                };
                PaymentInfoList.Add(mmPayment);

                if (mmPayment.IsConfirmed)
                    desc = MMoneyDescription();
                else
                    desc = PaymentResponse.LongDescription != ""
                               ? PaymentResponse.LongDescription
                               : PaymentResponse.ShortDescription;

                mmPayment.Description = desc;
                TotalBilledAmount += mmPayment.ConfirmedAmount;
            }

            #endregion

            #region Credit

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

                PaymentInfoList.Add(credit);
            }
            else
                credit.ConfirmedAmount = CreditAmount;

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

            #endregion

            RecalcAmountPaid();
            this.RequestClose(this, EventArgs.Empty);

        }