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 Guid Save(PaymentNotificationResponse entity) { PaymentNotificationResponse existingEntity = _ctx.AsynchronousPaymentNotificationResponse.FirstOrDefault (n => n.Id == entity.Id); if (existingEntity == null) { existingEntity = new PaymentNotificationResponse(); existingEntity.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification; existingEntity.DateCreated = DateTime.Now; existingEntity.TimeStamp = DateTime.Now; existingEntity.Id = entity.Id; _ctx.AsynchronousPaymentNotificationResponse.Add(existingEntity); } // existingEntity.PaymentNotificationDetails foreach (var item in entity.PaymentNotificationDetails) { var i =_ctx.PaymentNotificationListItems.FirstOrDefault(s => s.Id == item.Id); if (i == null) { i= new PaymentNotificationListItem(); i.Id = item.Id; _ctx.PaymentNotificationListItems.Add(i); } i.BalanceDue = item.BalanceDue; i.PaidAmount = item.PaidAmount; i.Status = item.Status; i.TimeStamp = item.TimeStamp; i.TotalAmount = item.TotalAmount; i.ResponseId = existingEntity.Id; } existingEntity.DistributorCostCenterId = entity.DistributorCostCenterId; existingEntity.TransactionRefId = entity.TransactionRefId; existingEntity.BalanceDue = entity.BalanceDue; existingEntity.Currency = entity.Currency; existingEntity.PaidAmount = entity.PaidAmount; existingEntity.SDPReferenceId = entity.SDPReferenceId; //_ctx.AsynchronousPaymentNotificationResponse.Add(existingEntity); _ctx.SaveChanges(); return existingEntity.Id; }
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; }
private void wc_UploadGetPaymentNotificationJsonCompleted(object sender, UploadStringCompletedEventArgs e) { Thread.Sleep(1000); try { if (e.Error == null) { if (_paymentNotificationCompleted) { //if (isBusyWindow != null) // isBusyWindow.OKButton_Click(this, null); return; } MMoneyIsApproved = false; string jsonResult = e.Result; if (!ValidateResponse(jsonResult)) { ReportPaymentNotificationError(""); return; } PaymentNotificationResponse sapr = null; BuyGoodsNotificationResponse bgr = null; string msg = ""; string desc = ""; string reference = ""; JObject jo = JObject.Parse(jsonResult); double totalPaid = 0; double balance = Convert.ToDouble(MMoneyAmount); string currency = "KES"; #region AsynchronousPaymentNotificationResponse if ((int) (jo["ClientRequestResponseType"]) == 3) { MessageSerializer.CanDeserializeMessage(jsonResult, out sapr); if (sapr == null) { msg = GetLocalText("sl.payment.notifitcation.pending"); } else if ((sapr.PaymentNotificationDetails != null && sapr.PaymentNotificationDetails.Count == 0) || sapr.StatusDetail == "Pending") { msg = GetLocalText("sl.payment.notifitcation.pending"); /*"Specified payment is still pending. Please check again later.";*/ } else { var existingNotif = _paymentNotifs.FirstOrDefault(n => n.TransactionRefId == sapr.TransactionRefId); if (existingNotif != null) _paymentNotifs.Remove(existingNotif); _paymentNotifs.Add(sapr); int i = 1; totalPaid = sapr.PaymentNotificationDetails.Sum(n => n.PaidAmount); MMoneyIsApproved = totalPaid >= Convert.ToDouble(MMoneyAmount); balance = sapr.PaymentNotificationDetails.OrderByDescending(n => n.TimeStamp) .FirstOrDefault() .BalanceDue; currency = sapr.Currency; msg = GetLocalText("sl.payment.notifitcation.response.paymentDetails") /*"Payment Details:"*/ + "\tCount = " + sapr.PaymentNotificationDetails.Count + "\n\n"; msg += GetLocalText("sl.payment.notifitcation.response.paymentStatus") /*"Payment Status:"*/+ " \t" + sapr.StatusDetail + ",\n" + GetLocalText("sl.payment.notifitcation.response.currency") /*"Currency:"*/+ " \t\t" + sapr.Currency + ",\n" + GetLocalText("sl.payment.notifitcation.response.reference") /*"Reference Id:"*/+ " \t" + sapr.SDPReferenceId + "\n"; double cumTotalPaid = 0; foreach (var pnr in sapr.PaymentNotificationDetails.OrderBy(n => n.TimeStamp)) { cumTotalPaid += pnr.PaidAmount; var notif = new PaymentNotificationResponse { Id = Guid.NewGuid(), TransactionRefId = sapr.TransactionRefId, SDPTransactionRefId = sapr.SDPTransactionRefId, SDPReferenceId = sapr.SDPReferenceId, StatusCode = sapr.StatusCode, StatusDetail = sapr.StatusDetail, DateCreated = sapr.DateCreated, Currency = sapr.Currency, ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification, DistributorCostCenterId = sapr.DistributorCostCenterId, BalanceDue = pnr.BalanceDue, PaidAmount = pnr.PaidAmount, TimeStamp = pnr.TimeStamp, TotalAmount = cumTotalPaid //pnr.TotalAmount }; msg += "# " + i + ":\n"; msg += GetLocalText("sl.payment.notifitcation.response.amountPaid") /*"Amount Paid:"*/+ " \t" + pnr.PaidAmount + ",\n" + GetLocalText("sl.payment.notifitcation.response.balanceDue") /*"Balance Due:"*/+ " \t" + pnr.BalanceDue + ",\n" + GetLocalText("sl.payment.notifitcation.response.totalAmount") /*"Total Amount:"*/+ " \t" + cumTotalPaid /*pnr.TotalAmount*/+ ",\n" + GetLocalText("sl.payment.notifitcation.response.timeStamp") /*"Time Stamp:"*/+ " \t" + pnr.TimeStamp + "\n\n" + "Status:" + " \t" + pnr.Status + "\n\n" ; //_asynchronousPaymentNotificationResponseService.Save(notif); _clientRequestResponses.Add(notif); i++; } var p = sapr.PaymentNotificationDetails.First(); desc = GetLocalText("sl.payment.notifitcation.desc.inpaymentof") /*"In payment of"*/ + " " + sapr.Currency + " " + p.PaidAmount + " " + GetLocalText("sl.payment.notifitcation.desc.bysubscriber") /*"by subscriber"*/ + " " + sapr.SubscriberId + " " + GetLocalText("sl.payment.notifitcation.desc.toaccount") /*"to account"*/+ " " + sapr.AccountId + " " + GetLocalText("sl.payment.notifitcation.desc.paymentreference") /*"Payment reference:"*/ + " " + sapr.SDPReferenceId; } } #endregion #region BuyGoodsNotificationResponse else if ((int) (jo["ClientRequestResponseType"]) == 5) { MessageSerializer.CanDeserializeMessage(jsonResult, out bgr); if (bgr == null || bgr.StatusDetail == "Pending") { msg = GetLocalText("sl.payment.notifitcation.pending"); /*"Specified payment is still pending. Please check again later.";*/ } else { totalPaid = bgr.PaidAmount; balance = Convert.ToDouble(MMoneyAmount) - bgr.PaidAmount; currency = bgr.Currency; MMoneyIsApproved = totalPaid >= Convert.ToDouble(MMoneyAmount); msg = GetLocalText("sl.payment.notifitcation.response.paymentDetails") /*"Payment Details:"*/ + "\n\n"; PaymentRequest apr = _asynchronousPaymentRequestRepository.GetByTransactionRefId( bgr.TransactionRefId). LastOrDefault(); msg += GetLocalText("sl.payment.bgnotifitcation.response.paymentStatus") /*"Payment Status:"*/+ " \t" + bgr.StatusDetail + ",\n" + GetLocalText("sl.payment.bgnotifitcation.response.amountPaid") /*"Amount Paid:"*/+ " \t" + bgr.PaidAmount + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.receiptNumber") /*"Receipt Number:"*/+ " \t" + bgr.ReceiptNumber + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.date") /*"Date:"*/+ " \t" + bgr.Date.ToShortDateString() + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.time") /*"Time:"*/+ " \t" + bgr.Time.ToShortTimeString() + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.currency") /*"Currency:"*/+ " \t" + bgr.Currency + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.paidTo") /*"Paid To Subscriber:"*/+ " \t" + bgr.SubscriberName + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.merchantBal") /*"Merchant Balance:"*/+ " \t" + bgr.MerchantBalance + "\n\n" ; //_buyGoodsNotificationResponseRepository.Save(bgr); _clientRequestResponses.Add(bgr); reference = bgr.ReceiptNumber; desc = GetLocalText("sl.payment.notifitcation.desc.inpaymentof") /*"In payment of"*/+ " " + bgr.Currency + " " + bgr.PaidAmount + " " + GetLocalText("sl.payment.notifitcation.desc.bysubscriber") /*"by subscriber"*/ + " " + (apr != null ? apr.SubscriberId : "") + " " + GetLocalText("sl.payment.notifitcation.desc.toaccount") /*"to account"*/+ " " + (apr != null ? apr.AccountId : "") + " " + GetLocalText("sl.payment.notifitcation.desc.paymentreference") /*"Payment reference:"*/ + " " + bgr.ReceiptNumber; } } #endregion else { ReportPaymentNotificationError(""); return; } MessageBox.Show(msg, GetLocalText("sl.payment.title") /*"Distributr: Payment Module"*/, MessageBoxButton.OK); if (!MMoneyIsApproved) { MessageBox.Show( GetLocalText("sl.payment.notification.notconfirmed") /*"Payment not confirmed due to outstanding balance of"*/ + " " + currency + " " + balance /*(Convert.ToDouble(MMoneyAmount) - totalPaid)*/, GetLocalText("sl.payment.title") /*"Distributr: Payment Module"*/, MessageBoxButton.OK); } _paymentNotificationCompleted = true; } else { ReportPaymentNotificationError(e.Error.Message); } } catch (Exception ex) { ReportPaymentNotificationError(ex.Message); } }
void ProcessPaymentNotification(ClientRequestResponseBase response) { using (var c = NestedContainer) { string msg = ""; string desc = ""; string reference = ""; double totalPaid = 0.0; double balance = Convert.ToDouble(MMoneyAmount); string currency = "KES"; if (response == null) { msg = GetLocalText("sl.payment.notifitcation.pending"); } else if (response is PaymentNotificationResponse) { PaymentNotificationResponse sapr = response as PaymentNotificationResponse; if ((sapr.PaymentNotificationDetails != null && sapr.PaymentNotificationDetails.Count == 0) || sapr.StatusDetail == "Pending") { msg = GetLocalText("sl.payment.notifitcation.pending"); /*"Specified payment is still pending. Please check again later.";*/ } else { int i = 1; if (sapr.PaymentNotificationDetails != null) { var existingNotif = _paymentNotifs.FirstOrDefault(n => n.TransactionRefId == sapr.TransactionRefId); if(existingNotif != null) { _paymentNotifs.Remove(existingNotif); _paymentNotifs.Add(sapr); } totalPaid = sapr.PaymentNotificationDetails.Sum(n => n.PaidAmount); MMoneyIsApproved = totalPaid >= Convert.ToDouble(MMoneyAmount); var paymentNotificationListItem = sapr.PaymentNotificationDetails.OrderByDescending(n => n.TimeStamp).FirstOrDefault(); if (paymentNotificationListItem != null) balance = sapr.PaymentNotificationDetails.OrderByDescending(n => n.TimeStamp) .FirstOrDefault() .BalanceDue; currency = sapr.Currency; msg = GetLocalText("sl.payment.notifitcation.response.paymentDetails") /*"Payment Details:"*/ + "\tCount = " + sapr.PaymentNotificationDetails.Count + "\n\n"; msg += GetLocalText("sl.payment.notifitcation.response.paymentStatus") /*"Payment Status:"*/+ " \t" + sapr.StatusDetail + ",\n" + GetLocalText("sl.payment.notifitcation.response.currency") /*"Currency:"*/+ " \t\t" + sapr.Currency + ",\n" + GetLocalText("sl.payment.notifitcation.response.reference") /*"Reference Id:"*/+ " \t" + sapr.SDPReferenceId + "\n"; double cumTotalPaid = 0; foreach (var pnr in sapr.PaymentNotificationDetails.OrderBy(n => n.TimeStamp)) { cumTotalPaid += pnr.PaidAmount; var notif = new PaymentNotificationResponse { Id = Guid.NewGuid(), TransactionRefId = sapr.TransactionRefId, SDPTransactionRefId = sapr.SDPTransactionRefId, SDPReferenceId = sapr.SDPReferenceId, StatusCode = sapr.StatusCode, StatusDetail = sapr.StatusDetail, DateCreated = sapr.DateCreated, Currency = sapr.Currency, ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification, DistributorCostCenterId = sapr.DistributorCostCenterId, BalanceDue = pnr.BalanceDue, PaidAmount = pnr.PaidAmount, TimeStamp = pnr.TimeStamp, TotalAmount = cumTotalPaid //pnr.TotalAmount }; msg += "# " + i + ":\n"; msg += GetLocalText("sl.payment.notifitcation.response.amountPaid") /*"Amount Paid:"*/+ " \t" + pnr.PaidAmount + ",\n" + GetLocalText("sl.payment.notifitcation.response.balanceDue") /*"Balance Due:"*/+ " \t" + pnr.BalanceDue + ",\n" + GetLocalText("sl.payment.notifitcation.response.totalAmount") /*"Total Amount:"*/+ " \t" + cumTotalPaid /*pnr.TotalAmount*/+ ",\n" + GetLocalText("sl.payment.notifitcation.response.timeStamp") /*"Time Stamp:"*/+ " \t" + pnr.TimeStamp + "\n\n" + "Status:" + " \t" + pnr.Status + "\n\n" ; //_asynchronousPaymentNotificationResponseService.Save(notif); _clientRequestResponses.Add(notif); i++; } var p = sapr.PaymentNotificationDetails.First(); desc = GetLocalText("sl.payment.notifitcation.desc.inpaymentof") /*"In payment of"*/ + " " + sapr.Currency + " " + p.PaidAmount + " " + GetLocalText("sl.payment.notifitcation.desc.bysubscriber") /*"by subscriber"*/ + " " + sapr.SubscriberId + " " + GetLocalText("sl.payment.notifitcation.desc.toaccount") /*"to account"*/+ " " + sapr.AccountId + " " + GetLocalText("sl.payment.notifitcation.desc.paymentreference") /*"Payment reference:"*/ + " " + sapr.SDPReferenceId; } } } else if (response is BuyGoodsNotificationResponse) { var bgr = response as BuyGoodsNotificationResponse; if (bgr.StatusDetail == "Pending") { msg = GetLocalText("sl.payment.notifitcation.pending"); /*"Specified payment is still pending. Please check again later.";*/ } else { totalPaid = bgr.PaidAmount; balance = Convert.ToDouble(MMoneyAmount) - bgr.PaidAmount; MMoneyIsApproved = totalPaid >= Convert.ToDouble(MMoneyAmount); msg = GetLocalText("sl.payment.notifitcation.response.paymentDetails") /*"Payment Details:"*/ + "\n\n"; PaymentRequest apr = _asynchronousPaymentRequestRepository.GetByTransactionRefId( bgr.TransactionRefId). LastOrDefault(); msg += GetLocalText("sl.payment.bgnotifitcation.response.paymentStatus") /*"Payment Status:"*/+ " \t" + bgr.StatusDetail + ",\n" + GetLocalText("sl.payment.bgnotifitcation.response.amountPaid") /*"Amount Paid:"*/+ " \t" + bgr.PaidAmount + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.receiptNumber") /*"Receipt Number:"*/+ " \t" + bgr.ReceiptNumber + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.date") /*"Date:"*/+ " \t" + bgr.Date.ToShortDateString() + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.time") /*"Time:"*/+ " \t" + bgr.Time.ToShortTimeString() + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.currency") /*"Currency:"*/+ " \t" + bgr.Currency + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.paidTo") /*"Paid To Subscriber:"*/+ " \t" + bgr.SubscriberName + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.merchantBal") /*"Merchant Balance:"*/+ " \t" + bgr.MerchantBalance + "\n\n" ; //Using<IBuyGoodsNotificationResponseRepository>(c).Save(bgr); _clientRequestResponses.Add(bgr); reference = bgr.ReceiptNumber; desc = GetLocalText("sl.payment.notifitcation.desc.inpaymentof") /*"In payment of"*/+ " " + bgr.Currency + " " + bgr.PaidAmount + " " + GetLocalText("sl.payment.notifitcation.desc.bysubscriber") /*"by subscriber"*/ + " " + (apr != null ? apr.SubscriberId : "") + " " + GetLocalText("sl.payment.notifitcation.desc.toaccount") /*"to account"*/+ " " + (apr != null ? apr.AccountId : "") + " " + GetLocalText("sl.payment.notifitcation.desc.paymentreference") /*"Payment reference:"*/ + " " + bgr.ReceiptNumber; } } MessageBox.Show(msg, GetLocalText("sl.payment.title") /*"Distributr: Payment Module"*/, MessageBoxButton.OK); if (!MMoneyIsApproved) { MessageBox.Show( GetLocalText("sl.payment.notification.notconfirmed") /*"Payment not confirmed due to outstanding balance of"*/ + " " + currency + " " + balance /*(Convert.ToDouble(MMoneyAmount) - totalPaid)*/, GetLocalText("sl.payment.title") /*"Distributr: Payment Module"*/, MessageBoxButton.OK); } _paymentNotificationCompleted = true; } }
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; }
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; } }
void ProcessPaymentNotification(ClientRequestResponseBase response) { using (var c = NestedContainer) { string msg = ""; double totalPaid = 0.0; double balance = Convert.ToDouble(MMoneyAmount); if (response == null) { msg = GetLocalText("sl.payment.notifitcation.pending"); } else if (response is PaymentNotificationResponse) { PaymentNotificationResponse sapr = response as PaymentNotificationResponse; if ((sapr.PaymentNotificationDetails != null && sapr.PaymentNotificationDetails.Count == 0) || sapr.StatusDetail == "Pending") { msg = GetLocalText("sl.payment.notifitcation.pending"); /*"Specified payment is still pending. Please check again later.";*/ } else { PaymentNotification = sapr; int i = 1; if (sapr.PaymentNotificationDetails != null) { totalPaid = sapr.PaymentNotificationDetails.Sum(n => n.PaidAmount); MMoneyIsApproved = totalPaid >= Convert.ToDouble(MMoneyAmount); var paymentNotificationListItem = sapr.PaymentNotificationDetails.OrderByDescending(n => n.TimeStamp).FirstOrDefault(); if (paymentNotificationListItem != null) balance = paymentNotificationListItem.BalanceDue; msg = GetLocalText("sl.payment.notifitcation.response.paymentDetails") /*"Payment Details:"*/ + "\tCount = " + sapr.PaymentNotificationDetails.Count + "\n\n"; msg += GetLocalText("sl.payment.notifitcation.response.paymentStatus") /*"Payment Status:"*/+ " \t" + sapr.StatusDetail + ",\n" + GetLocalText("sl.payment.notifitcation.response.currency") /*"Currency:"*/+ " \t\t" + sapr.Currency + ",\n" + GetLocalText("sl.payment.notifitcation.response.reference") /*"Reference Id:"*/+ " \t" + sapr.SDPReferenceId + "\n"; double cumTotalPaid = 0; foreach (var pnr in sapr.PaymentNotificationDetails.Where(s=>!s.IsUsed).OrderBy(n => n.TimeStamp)) { cumTotalPaid += pnr.PaidAmount; var notif = new PaymentNotificationResponse { Id = pnr.Id, TransactionRefId = sapr.TransactionRefId, SDPTransactionRefId = sapr.SDPTransactionRefId, SDPReferenceId = sapr.SDPReferenceId, StatusCode = sapr.StatusCode, StatusDetail = sapr.StatusDetail, DateCreated = sapr.DateCreated, Currency = sapr.Currency, ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification, DistributorCostCenterId = sapr.DistributorCostCenterId, BalanceDue = pnr.BalanceDue, PaidAmount = pnr.PaidAmount, TimeStamp = pnr.TimeStamp, TotalAmount = cumTotalPaid //pnr.TotalAmount }; msg += "# " + i + ":\n"; msg += GetLocalText("sl.payment.notifitcation.response.amountPaid") /*"Amount Paid:"*/+ " \t" + pnr.PaidAmount + ",\n" + GetLocalText("sl.payment.notifitcation.response.balanceDue") /*"Balance Due:"*/+ " \t" + pnr.BalanceDue + ",\n" + GetLocalText("sl.payment.notifitcation.response.totalAmount") /*"Total Amount:"*/+ " \t" + cumTotalPaid /*pnr.TotalAmount*/+ ",\n" + GetLocalText("sl.payment.notifitcation.response.timeStamp") /*"Time Stamp:"*/+ " \t" + pnr.TimeStamp + "\n\n" + "Status:" + " \t" + pnr.Status + "\n\n" ; Using<IAsynchronousPaymentNotificationResponseRepository>(c).Save(notif); i++; } } } } else if (response is BuyGoodsNotificationResponse) { var bgr = response as BuyGoodsNotificationResponse; if (bgr.StatusDetail == "Pending") { msg = GetLocalText("sl.payment.notifitcation.pending"); /*"Specified payment is still pending. Please check again later.";*/ } else { totalPaid = bgr.PaidAmount; balance = Convert.ToDouble(MMoneyAmount) - bgr.PaidAmount; MMoneyIsApproved = totalPaid >= Convert.ToDouble(MMoneyAmount); msg = GetLocalText("sl.payment.notifitcation.response.paymentDetails") /*"Payment Details:"*/ + "\n\n"; msg += GetLocalText("sl.payment.bgnotifitcation.response.paymentStatus") /*"Payment Status:"*/+ " \t" + bgr.StatusDetail + ",\n" + GetLocalText("sl.payment.bgnotifitcation.response.amountPaid") /*"Amount Paid:"*/+ " \t" + bgr.PaidAmount + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.receiptNumber") /*"Receipt Number:"*/+ " \t" + bgr.ReceiptNumber + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.date") /*"Date:"*/+ " \t" + bgr.Date.ToShortDateString() + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.time") /*"Time:"*/+ " \t" + bgr.Time.ToShortTimeString() + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.currency") /*"Currency:"*/+ " \t" + bgr.Currency + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.paidTo") /*"Paid To Subscriber:"*/+ " \t" + bgr.SubscriberName + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.merchantBal") /*"Merchant Balance:"*/+ " \t" + bgr.MerchantBalance + "\n\n" ; Using<IBuyGoodsNotificationResponseRepository>(c).Save(bgr); } } MessageBox.Show(msg, GetLocalText("sl.payment.title") /*"Distributr: Payment Module"*/, MessageBoxButton.OK); if (!MMoneyIsApproved) { MessageBox.Show( GetLocalText("sl.payment.notification.notconfirmed") /*"Payment not confirmed due to outstanding balance of"*/ + " " + Currency + " " + balance /*(Convert.ToDouble(MMoneyAmount) - totalPaid)*/, GetLocalText("sl.payment.title") /*"Distributr: Payment Module"*/, MessageBoxButton.OK); } if (MMoneyIsApproved) { CanGetPaymentNotification = false; CanSeePaymentNotification = true; CanClearMMoneyFields = false; CanChangePaymentOption = false; CanEditMMoneyAmount = false; CanEditAccountNo = false; CanClearMMoneyFields = false; CanEditSubscriberNo = false; } _paymentNotificationCompleted = true; } }
private void wc_UploadGetPaymentNotificationJsonCompleted(object sender, UploadStringCompletedEventArgs e) { using (StructureMap.IContainer cont = NestedContainer) { try { if (e.Error == null) { if (_paymentNotificationCompleted) return; MMoneyIsApproved = false; string jsonResult = e.Result; if (!ValidateResponse(jsonResult)) { ReportPaymentNotificationError(); return; } PaymentNotificationResponse sapr = null; BuyGoodsNotificationResponse bgr = null; JObject jo = JObject.Parse(jsonResult); string msg = ""; double totalPaid = 0.0; double balance = Convert.ToDouble(MMoneyAmount); if ((int)(jo["ClientRequestResponseType"]) == 3) { MessageSerializer.CanDeserializeMessage(jsonResult, out sapr); if (sapr == null) { msg = GetLocalText("sl.payment.notifitcation.pending"); } else if ((sapr.PaymentNotificationDetails != null && sapr.PaymentNotificationDetails.Count == 0) || sapr.StatusDetail == "Pending") { msg = GetLocalText("sl.payment.notifitcation.pending"); /*"Specified payment is still pending. Please check again later.";*/ } else { PaymentNotification = sapr; int i = 1; totalPaid = sapr.PaymentNotificationDetails.Sum(n => n.PaidAmount); MMoneyIsApproved = totalPaid >= Convert.ToDouble(MMoneyAmount); balance = sapr.PaymentNotificationDetails.OrderByDescending(n => n.TimeStamp) .FirstOrDefault() .BalanceDue; msg = GetLocalText("sl.payment.notifitcation.response.paymentDetails") /*"Payment Details:"*/ + "\tCount = " + sapr.PaymentNotificationDetails.Count + "\n\n"; msg += GetLocalText("sl.payment.notifitcation.response.paymentStatus") /*"Payment Status:"*/+ " \t" + sapr.StatusDetail + ",\n" + GetLocalText("sl.payment.notifitcation.response.currency") /*"Currency:"*/+ " \t\t" + sapr.Currency + ",\n" + GetLocalText("sl.payment.notifitcation.response.reference") /*"Reference Id:"*/+ " \t" + sapr.SDPReferenceId + "\n"; double cumTotalPaid = 0; foreach (var pnr in sapr.PaymentNotificationDetails.OrderBy(n => n.TimeStamp)) { cumTotalPaid += pnr.PaidAmount; var notif = new PaymentNotificationResponse { Id = pnr.Id, TransactionRefId = sapr.TransactionRefId, SDPTransactionRefId = sapr.SDPTransactionRefId, SDPReferenceId = sapr.SDPReferenceId, StatusCode = sapr.StatusCode, StatusDetail = sapr.StatusDetail, DateCreated = sapr.DateCreated, Currency = sapr.Currency, ClientRequestResponseType = ClientRequestResponseType .AsynchronousPaymentNotification, DistributorCostCenterId = sapr.DistributorCostCenterId, BalanceDue = pnr.BalanceDue, PaidAmount = pnr.PaidAmount, TimeStamp = pnr.TimeStamp, TotalAmount = cumTotalPaid //pnr.TotalAmount }; msg += "# " + i + ":\n"; msg += GetLocalText("sl.payment.notifitcation.response.amountPaid") /*"Amount Paid:"*/+ " \t" + pnr.PaidAmount + ",\n" + GetLocalText("sl.payment.notifitcation.response.balanceDue") /*"Balance Due:"*/+ " \t" + pnr.BalanceDue + ",\n" + GetLocalText("sl.payment.notifitcation.response.totalAmount") /*"Total Amount:"*/+ " \t" + cumTotalPaid /*pnr.TotalAmount*/+ ",\n" + GetLocalText("sl.payment.notifitcation.response.timeStamp") /*"Time Stamp:"*/+ " \t" + pnr.TimeStamp + "\n\n" + "Status:" + " \t" + pnr.Status + "\n\n" ; Using<IAsynchronousPaymentNotificationResponseRepository>(cont).Save(notif); i++; } } } #region BuyGoodsNotificationResponse else if ((int)(jo["ClientRequestResponseType"]) == 5) { MessageSerializer.CanDeserializeMessage(jsonResult, out bgr); if (bgr == null || bgr.StatusDetail == "Pending") { msg = GetLocalText("sl.payment.notifitcation.pending"); /*"Specified payment is still pending. Please check again later.";*/ } else { totalPaid = bgr.PaidAmount; balance = Convert.ToDouble(MMoneyAmount) - bgr.PaidAmount; MMoneyIsApproved = totalPaid >= Convert.ToDouble(MMoneyAmount); msg = GetLocalText("sl.payment.notifitcation.response.paymentDetails") /*"Payment Details:"*/ + "\n\n"; msg += GetLocalText("sl.payment.bgnotifitcation.response.paymentStatus") /*"Payment Status:"*/+ " \t" + bgr.StatusDetail + ",\n" + GetLocalText("sl.payment.bgnotifitcation.response.amountPaid") /*"Amount Paid:"*/+ " \t" + bgr.PaidAmount + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.receiptNumber") /*"Receipt Number:"*/+ " \t" + bgr.ReceiptNumber + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.date") /*"Date:"*/+ " \t" + bgr.Date.ToShortDateString() + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.time") /*"Time:"*/+ " \t" + bgr.Time.ToShortTimeString() + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.currency") /*"Currency:"*/+ " \t" + bgr.Currency + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.paidTo") /*"Paid To Subscriber:"*/+ " \t" + bgr.SubscriberName + "\n" + GetLocalText("sl.payment.bgnotifitcation.response.merchantBal") /*"Merchant Balance:"*/+ " \t" + bgr.MerchantBalance + "\n\n" ; Using<IBuyGoodsNotificationResponseRepository>(cont).Save(bgr); } } #endregion else { ReportPaymentNotificationError(); return; } MessageBox.Show(msg, GetLocalText("sl.payment.title") /*"Distributr: Payment Module"*/, MessageBoxButton.OK); if (!MMoneyIsApproved) { MessageBox.Show( GetLocalText("sl.payment.notification.notconfirmed") /*"Payment not confirmed due to outstanding balance of"*/ + " " + Currency + " " + balance /*(Convert.ToDouble(MMoneyAmount) - totalPaid)*/, GetLocalText("sl.payment.title") /*"Distributr: Payment Module"*/, MessageBoxButton.OK); } if (MMoneyIsApproved) { CanGetPaymentNotification = false; CanSeePaymentNotification = true; CanClearMMoneyFields = false; CanChangePaymentOption = false; CanEditMMoneyAmount = false; CanEditAccountNo = false; CanClearMMoneyFields = false; CanEditSubscriberNo = false; } _paymentNotificationCompleted = true; } else { ReportPaymentNotificationError(); } } catch { ReportPaymentNotificationError(); } } }
public async Task<PaymentNotificationResponse> GetPaymentNotificationAsync(PaymentNotificationRequest request) { PaymentNotificationResponse _response = new PaymentNotificationResponse(); HttpClient httpClient = setupHttpClient(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string url = "api/bridge/payment/getpaymentnotification"; try { var response = await httpClient.PostAsJsonAsync(url, request); string data = await response.Content.ReadAsStringAsync(); JObject jo =JsonConvert.DeserializeObject<JObject>(data); var respodata = jo["Response"]; _response = respodata.ToObject<PaymentNotificationResponse>(); var datelastsyncInfo = jo["Response"]["PaymentNotificationDetails"]; var items = datelastsyncInfo.ToObject <List<PaymentNotificationListItem>>();// JsonConvert.DeserializeObject<List<PaymentNotificationListItem>>(); _response.PaymentNotificationDetails = items; } catch (Exception ex) { string error = "Failed to retrieve payment notification.\n" + (ex.InnerException == null ? "" : ex.InnerException.Message); _log.Error(error); _response.StatusCode = "Error"; _response.StatusDetail = error; } return _response; }
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; }
public ClientRequestResponseBase ProcessClientPaymentNotificationRequest(ClientRequestResponseBase crrReqMsg) { ClientRequestResponseBase response = new ClientRequestResponseBase(); try { IEnumerable<ClientRequestResponseBase> sdpRequests = new List<ClientRequestResponseBase>(); if (crrReqMsg is PaymentNotificationRequest) { sdpRequests = _paymentRequestRepository.GetByTransactionRefId(crrReqMsg.TransactionRefId).OfType <PaymentNotificationRequest>().ToList();//.FirstOrDefault(); if (sdpRequests.Count() > 0) { var any = sdpRequests.OrderBy(n => ((PaymentNotificationRequest)n).SDPTimeStamp).FirstOrDefault(s=>!string.IsNullOrEmpty(s.TransactionRefId)) as PaymentNotificationRequest; var paymentResp = _paymentRequestRepository.GetByTransactionRefId(crrReqMsg.TransactionRefId).OfType <PaymentRequest>().FirstOrDefault(); var paymentInfoDetails = new List<PaymentNotificationListItem>(); foreach (var re in sdpRequests) { var apnr = re as PaymentNotificationRequest; var detail = new PaymentNotificationListItem { Id = apnr.Id, PaidAmount = apnr.SDPPaidAmount, TotalAmount = apnr.SDPTotalAmount, BalanceDue = apnr.SDPBalanceDue, TimeStamp = apnr.SDPTimeStamp, Status = apnr.SDPStatusCode +"; "+apnr.SDPStatusDetail, ResponseId = apnr.Id }; paymentInfoDetails.Add(detail); } response = new PaymentNotificationResponse { Id = any.Id, TransactionRefId = any.TransactionRefId, DistributorCostCenterId = any.DistributorCostCenterId, ClientRequestResponseType = any.ClientRequestResponseType, SDPReferenceId = any.SDPReferenceId, SDPTransactionRefId = any.SDPTransactionRefId, Currency = any.SDPCurrency, StatusCode = any.SDPStatusCode, StatusDetail = any.SDPStatusDetail, DateCreated = any.DateCreated, PaymentNotificationDetails = paymentInfoDetails, AccountId = paymentResp.AccountId, SubscriberId = paymentResp.SubscriberId, Items = paymentInfoDetails, }; return response; } goto pending; } #region BuyGoodsNotificationRequest if (crrReqMsg is BuyGoodsNotificationRequest) { var sdpBgRequests = _paymentRequestRepository.GetByReceiptNumber(crrReqMsg.TransactionRefId).OfType <BuyGoodsNotificationRequest>().LastOrDefault(); if (sdpBgRequests == null) goto pending; BuyGoodsNotificationRequest bgnr = sdpBgRequests as BuyGoodsNotificationRequest; response = new BuyGoodsNotificationResponse { Id = bgnr.Id, ClientRequestResponseType = ClientRequestResponseType.BuyGoodsNotification, Currency = bgnr.Currency, Date = bgnr.Date, DateCreated = bgnr.DateCreated, DistributorCostCenterId = crrReqMsg.DistributorCostCenterId, MerchantBalance = bgnr.MerchantBalance, PaidAmount = bgnr.PaidAmount, ReceiptNumber = bgnr.ReceiptNumber, SDPTransactionRefId = bgnr.SDPTransactionRefId, StatusCode = bgnr.StatusCode, StatusDetail = bgnr.StatusDetail, SubscriberName = bgnr.SubscriberName ?? "", Time = bgnr.Time, TransactionRefId = bgnr.TransactionRefId }; return response; } #endregion } catch (Exception ex) { string msg = string.Format("Notification; Id: {0}; TransactionRefId: " + crrReqMsg.Id, crrReqMsg.TransactionRefId); _auditLogRepository.AddLog(crrReqMsg.DistributorCostCenterId, crrReqMsg.ClientRequestResponseType.ToString(), "To Mobile", "Error in ProcessClientPaymentNotificationRequest \n" + msg + "\nException details: \n" + ex.Message + ex.InnerException != null ? "\n" + ex.InnerException.Message : ""); goto pending; } pending: response = new PaymentNotificationResponse { Id = Guid.NewGuid(), ClientRequestResponseType = crrReqMsg.ClientRequestResponseType, TransactionRefId = crrReqMsg.TransactionRefId, StatusDetail = "Pending", }; return response; }