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(ClientRequestResponseBase entity) { tblPaymentResponse toSave = _ctx.tblPaymentResponse.FirstOrDefault(n => n.Id == entity.Id); string log = ""; if (toSave == null) { toSave = new tblPaymentResponse(); toSave.Id = entity.Id; toSave.DistributorCostCenterId = entity.DistributorCostCenterId; toSave.DateCreated = entity.DateCreated.ToString() == "1/1/0001 12:00:00 AM" ? DateTime.Now : entity.DateCreated; toSave.ClientRequestResponseTypeId = (int) entity.ClientRequestResponseType; } try { if (entity.ClientRequestResponseType == ClientRequestResponseType.AsynchronousPayment) { PaymentResponse ap = entity as PaymentResponse; toSave.BusinessNumber = ap.BusinessNumber; toSave.Amount = ap.AmountDue; toSave.TransactionRefId = ap.TransactionRefId; toSave.SDPTransactionRefId = ap.SDPTransactionRefId; toSave.LongDescription = ap.LongDescription; toSave.SDPReferenceId = ap.SDPReferenceId; toSave.ShortDescription = ap.ShortDescription; toSave.StatusCode = ap.StatusCode; toSave.StatusDetail = ap.StatusDetail; toSave.TimeStamp = ap.TimeStamp; toSave.SubscriberId = ap.SubscriberId; toSave.TimeStamp = ap.TimeStamp.ToString() == "1/1/0001 12:00:00 AM" ? DateTime.Now : ap.TimeStamp; log = string.Format( "New AsynchronousPaymentResponse Id: {0}; TransactionrefId: {1}; SDPTransactionRefId: {2}; BusinessNumber: {3}; Amount {4};" + " StatusCode: {5}; StatusDetail: {6}; ShortDescription: {7}; LongDescription: {8}; TimeStamp: {9};", toSave.Id, toSave.TransactionRefId, toSave.SDPTransactionRefId, toSave.BusinessNumber, toSave.Amount, toSave.StatusCode, toSave.StatusDetail, toSave.ShortDescription, toSave.LongDescription, toSave.TimeStamp); } _ctx.tblPaymentResponse.Add(toSave); _ctx.SaveChanges(); _auditLogRepository.AddLog(toSave.DistributorCostCenterId, entity.ClientRequestResponseType.ToString() + "Response", "DB", string.Format("Saved {0}", log)); } catch (Exception ex) { _auditLogRepository.AddLog(toSave.DistributorCostCenterId, entity.ClientRequestResponseType.ToString() + "Response", "DB", string.Format("Error saving {0}\nDetails: {1}", log, ex.Message + ex.InnerException != null ? "\n" + ex.InnerException.Message : "")); } return toSave.Id; }
private void Save(ClientRequestResponseBase crrMessage) { if (crrMessage.ClientRequestResponseType != ClientRequestResponseType.PaymentInstrument) _paymentRequestRepository.Save(crrMessage); }
private ClientRequestResponseBase SaveNSendSimulator(ClientRequestResponseBase crrMessage, ServerRequestBase serverMessage) { if (crrMessage.ClientRequestResponseType != ClientRequestResponseType.AsynchronousPaymentQuery) Save(crrMessage); ClientRequestResponseBase sdpResponse = null; var paymentResponse = _paymentResponseRepository.GetByTransRefId(new Guid(crrMessage.TransactionRefId)).OfType<PaymentResponse>().FirstOrDefault(); if (paymentResponse != null) { sdpResponse = paymentResponse; } return sdpResponse; }
private ClientRequestResponseBase SaveNSend(ClientRequestResponseBase crrMessage, ServerRequestBase serverMessage) { if (crrMessage.ClientRequestResponseType != ClientRequestResponseType.AsynchronousPaymentQuery) Save(crrMessage); ClientRequestResponseBase sdpResponse = null; SendToHSenid(serverMessage, crrMessage, out sdpResponse); return sdpResponse; }
SDPPaymentNotificationResponse ProcessSDPPaymentNotification(ServerRequestBase serverRequest, ClientRequestResponseBase crrRequest) { SDPPaymentNotificationResponse response = null; SDPPaymentNotificationRequest req = serverRequest as SDPPaymentNotificationRequest; try { _paymentRequestRepository.Save(crrRequest); response = new SDPPaymentNotificationResponse { statusCode = "Success", statusDetail = "Success" }; } catch(Exception ex) { //error _auditLogRepository.AddLog(Guid.Empty, crrRequest.ClientRequestResponseType.ToString(), "To/From HSenid", "Error: " + ex.Message+"\n"+ex.InnerException.Message); response = new SDPPaymentNotificationResponse { statusCode = "Failed", statusDetail = "Failed" }; } return response; }
private void SendToHSenid(ServerRequestBase requestMessage, ClientRequestResponseBase crrMessage, out ClientRequestResponseBase sdpResponse) { string hsenidUrl = ""; WebClient wc = new WebClient(); string mssg = JsonConvert.SerializeObject(requestMessage); wc.Encoding = Encoding.UTF8; hsenidUrl = SdpHost.GetSdpPaymentUri(crrMessage.ClientRequestResponseType); _auditLogRepository.AddLog(crrMessage.DistributorCostCenterId, crrMessage.ClientRequestResponseType.ToString() + "Request", "To HSenid", string.Format("Url: {0}; JsonRequest: {1}.", hsenidUrl, mssg)); Uri uri = new Uri(hsenidUrl, UriKind.Absolute); string strResponse = wc.UploadString(uri, "POST", mssg); _auditLogRepository.AddLog(crrMessage.DistributorCostCenterId, crrMessage.ClientRequestResponseType.ToString() + "Response", "From HSenid", string.Format("Url: {0}; JsonRequest: {1}.", hsenidUrl, strResponse)); sdpResponse = _messageDeserialize.DeserializeSDPResponse(strResponse, crrMessage.ClientRequestResponseType); sdpResponse.DistributorCostCenterId = crrMessage.DistributorCostCenterId; //LogThis(sdpResponse); if (sdpResponse == null) return; if (sdpResponse.ClientRequestResponseType != ClientRequestResponseType.PaymentInstrument && sdpResponse.ClientRequestResponseType != ClientRequestResponseType.AsynchronousPaymentQuery ) { _paymentResponseRepository.Save(sdpResponse); } }
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; }
private Thread StartTheSaveAndSendThread(ClientRequestResponseBase crrMessage, ServerRequestBase serverMessage) { Thread thread = new Thread(() => SaveNSend(crrMessage, serverMessage)); return thread; }
private string GetPaymentNotificationRequestJson(Guid paymentTransactionRefId, string buyGoodsTransRef, ClientRequestResponseType type) { string json = ""; string transRef = paymentTransactionRefId.ToString(); if (type == ClientRequestResponseType.BuyGoodsNotification) { transRef = buyGoodsTransRef; } var pnr = new ClientRequestResponseBase() { ClientRequestResponseType = type, DateCreated = DateTime.Now, Id = Guid.NewGuid(), DistributorCostCenterId = _configService.Load().CostCentreId, TransactionRefId = transRef }; json = JsonConvert.SerializeObject(pnr, new IsoDateTimeConverter()); _clientRequestResponses.Add(pnr); return json; }
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; } }
public Guid Save(ClientRequestResponseBase entity) { if (entity == null) { _auditLogRepository.AddLog(Guid.Empty, "Null Request", "DB", "entity == null"); } tblPaymentRequest toSave = _ctx.tblPaymentRequest.FirstOrDefault(n => n.Id == entity.Id); string log = ""; if (toSave == null) { toSave = new tblPaymentRequest(); toSave.Id = entity.Id; toSave.DistributorCostCenterId = entity.DistributorCostCenterId; toSave.DateCreated = DateTime.Now; toSave.ClientRequestResponseTypeId = (int)entity.ClientRequestResponseType; } try { if (entity is PaymentRequest) { PaymentRequest apr = entity as PaymentRequest; toSave.AccountId = apr.AccountId; toSave.Amount = apr.Amount; toSave.ApplicationId = apr.ApplicationId; toSave.SubscriberId = apr.SubscriberId; toSave.Currency = apr.Currency; toSave.Extra = apr.Extra.ToString(); toSave.InvoiceNumber = apr.InvoiceNumber; toSave.OrderNumber = apr.OrderNumber; toSave.PaymentInstrumentName = apr.PaymentInstrumentName; toSave.TransactionRefId = apr.TransactionRefId; log = string.Format( "New AsynchronousPaymentRequest Id: {0}; TransactionrefId: {1}; AccountId: {2}; Amount: {3}; ApplicationId {4};" +" SubscriberId: {5}; Currency: {6}; Extra: {7}; InvoiceNumber: {8}; OrderNumber: {9}; PaymentInstrumentName: {10};", toSave.Id, toSave.TransactionRefId, toSave.AccountId, toSave.Amount, toSave.ApplicationId, toSave.SubscriberId, toSave.Currency, toSave.Extra, toSave.InvoiceNumber, toSave.OrderNumber, toSave.PaymentInstrumentName); } if (entity is PaymentNotificationRequest) { PaymentNotificationRequest apnr = entity as PaymentNotificationRequest; toSave.TransactionRefId = apnr.TransactionRefId; toSave.SDPTransactionRefId = apnr.SDPTransactionRefId; toSave.SDPReferenceId = apnr.SDPReferenceId ?? ""; toSave.TimeStamp = apnr.SDPTimeStamp; toSave.StatusCode = apnr.SDPStatusCode ?? ""; toSave.StatusDetail = apnr.SDPStatusDetail ?? ""; toSave.Currency = apnr.SDPCurrency ?? ""; toSave.Amount = apnr.SDPPaidAmount; toSave.BalanceDue = apnr.SDPBalanceDue; toSave.TotalAmount = apnr.SDPTotalAmount; log = string.Format( "New AsynchronousPaymentNotificationRequest Id: {0}; TransactionrefId: {1}; SDPTransactionRefId: {2}; SDPReferenceId: {3}; TimeStamp {4};" + " StatusCode: {5}; StatusDetail: {6}; Currency: {7}; Amount: {8}; BalanceDue: {9}; TotalAmount: {10};", toSave.Id, toSave.TransactionRefId, toSave.SDPTransactionRefId, toSave.SDPReferenceId, toSave.TimeStamp, toSave.StatusCode, toSave.StatusDetail, toSave.Currency, toSave.Amount, toSave.BalanceDue, toSave.TotalAmount); } if (entity is BuyGoodsNotificationRequest) { BuyGoodsNotificationRequest bgr = entity as BuyGoodsNotificationRequest; toSave.TransactionRefId = bgr.TransactionRefId ?? Guid.NewGuid().ToString(); toSave.SDPTransactionRefId = bgr.SDPTransactionRefId; toSave.SubscriberName = bgr.SubscriberName ?? ""; toSave.ReceiptNumber = bgr.ReceiptNumber ?? ""; toSave.Currency = bgr.Currency; toSave.Amount = bgr.PaidAmount; toSave.MerchantBalance = bgr.MerchantBalance; toSave.Date = bgr.Date; toSave.Time = bgr.Time; toSave.StatusCode = bgr.StatusCode ?? ""; toSave.StatusDetail = bgr.StatusDetail ?? ""; log = string.Format( "New BuyGoodsNotificationRequest Id: {0}; TransactionRefId: {1}; SDPTransactionRefId: {2}; SubscriberName: {3};" + " ReceiptNumber: {4}; Currency: {5}; Amount: {6}; MerchantBalance: {7}; Date: {8};" + " Time: {9}; StatusCode: {10}; StatusDetail: {11}", toSave.Id, toSave.TransactionRefId, toSave.SDPTransactionRefId, toSave.SubscriberName, toSave.ReceiptNumber, toSave.Currency, toSave.Amount, toSave.MerchantBalance, toSave.Date, toSave.Time, toSave.StatusCode, toSave.StatusDetail); } _ctx.tblPaymentRequest.Add(toSave); _ctx.SaveChanges(); _auditLogRepository.AddLog(toSave.DistributorCostCenterId, entity.ClientRequestResponseType.ToString()+"Request", "DB", string.Format("Saved {0}", log)); } catch(Exception ex) { _auditLogRepository.AddLog(toSave.DistributorCostCenterId, entity.ClientRequestResponseType.ToString() + "Request", "DB", string.Format("Error saving {0}\nDetails: {1}", log, ex.Message + ex.InnerException != null ? "\n" + ex.InnerException.Message : "")); } return toSave.Id; }
public void ProcessClientRequest(ClientRequestResponseBase crrMessage, ServiceProvider serviceProvider, out ServerRequestBase serverReqBase) { if (crrMessage == null) { throw new Exception("Message null"); } serverReqBase = new ServerRequestBase(); string userName = ""; string password = "******"; string subscriberId = "tel:254701234563"; string applicationId = "APP_000007"; bool allowOverPayment = true, allowPartialPayment = true; string version = "1.0"; string sourcesAddress = "hewani"; string binaryHeader = "Content-Type:application/json"; if (serviceProvider != null) { applicationId = serviceProvider.SdpAppId; subscriberId = serviceProvider.SubscriberId; password = serviceProvider.SdpPassword; allowOverPayment = serviceProvider.AllowOverPayment; allowPartialPayment = serviceProvider.AllowPartialPayment; } else { throw new Exception("This service provider is not registered."); } // if (crrMessage is PaymentInstrumentRequest) { PaymentInstrumentRequest pir = crrMessage as PaymentInstrumentRequest; SDPPaymentInstrumentRequest paymentIstReq = new SDPPaymentInstrumentRequest { applicationId = applicationId, password = password, type = pir.paymentInstrumentType, //subscriberId = subscriberId subscriberId = pir.SubscriberId }; serverReqBase = paymentIstReq; } if (crrMessage is PaymentRequest) { PaymentRequest apr = crrMessage as PaymentRequest; SDPPaymentRequest sdpapr = new SDPPaymentRequest(); sdpapr.accountId = apr.AccountId.ToString(); sdpapr.allowOverPayments = allowOverPayment ? AllOverPayment.Allow.ToString() : AllOverPayment.Disallow.ToString(); sdpapr.allowPartialPayments = allowPartialPayment ? AllowPartialPayments.Allow.ToString() : AllowPartialPayments.Disallow.ToString(); sdpapr.amount = apr.Amount.ToString(); sdpapr.applicationId = applicationId; sdpapr.currency = apr.Currency; sdpapr.externalTrxId = apr.TransactionRefId.Replace("-",""); sdpapr.extra = apr.Extra; //new Dictionary<string, string>();// {new string("tilNo","66363" )}; // sdpapr.extra.Add("tillNo","66361"); sdpapr.invoiceNo = apr.InvoiceNumber; sdpapr.orderNo = apr.OrderNumber; sdpapr.password = password; sdpapr.paymentInstrumentName = apr.PaymentInstrumentName; //sdpapr.subscriberId = subscriberId; sdpapr.subscriberId = apr.SubscriberId; sdpapr.smsDescription = apr.smsDescription; serverReqBase = sdpapr; } if (crrMessage is PaymentQueryRequest) { PaymentQueryRequest apq = crrMessage as PaymentQueryRequest; SDPPaymentQueryRequest sdpapq = new SDPPaymentQueryRequest(); sdpapq.applicationId = applicationId; sdpapq.internalTrxId = apq.TransactionRefId.ToString(); sdpapq.password = password; serverReqBase = sdpapq; } if(crrMessage is DocSMS) { DocSMS sms = crrMessage as DocSMS; SDPSMSRequest reqSMS = new SDPSMSRequest { applicationId = applicationId, password = password, destinationAddresses = sms.Recipitents.Select(n => "tel:" + n).ToList(), deliveryStatusRequest = 1, encoding = SDPSmsEncoding.Text, message = sms.SmsBody, }; } }
string LogThis(ClientRequestResponseBase response) { string log = ""; if (response is PaymentInstrumentResponse) { var res = response as PaymentInstrumentResponse; string pi = res.PaymentInstrumentList.Aggregate("", (current, item) => current + ("Name: " + item.name + "Type: " + item.type + (item.accountId != null ? "Account: " + item.accountId : ""))); log = string.Format("From HSenid; PaymentInstrumentResponse; PaymentInstrumentList: {0}; Status Detail: {1}", pi, res.StatusDetail); } return log; }
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; } }
ClientRequestResponseBase GenerateSampleResponce(ClientRequestResponseBase crrMessage) { ClientRequestResponseType messageType = crrMessage.ClientRequestResponseType; switch(messageType) { case ClientRequestResponseType.PaymentInstrument: return GetSamplePaymentList(); case ClientRequestResponseType.AsynchronousPayment: return GenerateSamplePaymentResponse(crrMessage as PaymentRequest); } return null; }
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 string SerializeMessage(ClientRequestResponseBase enitity, ClientRequestResponseType entityType) { throw new NotImplementedException(); }
public void ProcessSDPRequest(ServerRequestBase sdpRequest, out ClientRequestResponseBase crrRequest, out string subcriberid, out Guid sip) { subcriberid = ""; sip = Guid.Empty; ClientRequestResponseBase paymentRequest = null; Guid serviceProviderId = Guid.Empty; crrRequest = new ClientRequestResponseBase(); if (sdpRequest is SDPPaymentNotificationRequest) { paymentRequest = _paymentResponseRepository.GetByTransRefId( new Guid(((SDPPaymentNotificationRequest)sdpRequest) .externalTrxId)) .OfType<PaymentResponse>().FirstOrDefault(); if (paymentRequest != null) { serviceProviderId = paymentRequest.DistributorCostCenterId; } if (paymentRequest is PaymentResponse) { var respo = ((PaymentResponse) paymentRequest); subcriberid = respo.SubscriberId; sip = respo.DistributorCostCenterId; } SDPPaymentNotificationRequest sdpapn = sdpRequest as SDPPaymentNotificationRequest; PaymentNotificationRequest apn = new PaymentNotificationRequest(); apn.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification; apn.DateCreated = sdpapn.timestamp; apn.Id = Guid.NewGuid(); apn.TransactionRefId =ConstructMyGuid(sdpapn.externalTrxId).ToString(); apn.SDPStatusCode = sdpapn.statusCode; apn.SDPStatusDetail = sdpapn.statusDetail; apn.SDPTimeStamp = sdpapn.timestamp; apn.SDPTransactionRefId = sdpapn.internalTrxId; apn.SDPPaidAmount = Convert.ToDouble(sdpapn.paidAmount); apn.SDPTotalAmount = Convert.ToDouble(sdpapn.totalAmount); apn.SDPBalanceDue = Convert.ToDouble(sdpapn.balanceDue); apn.SDPCurrency = sdpapn.currency; apn.SDPReferenceId = sdpapn.referenceId; apn.DistributorCostCenterId = serviceProviderId; crrRequest = apn; } else if (sdpRequest is SDPBuyGoodsNotificationRequest) { throw new Exception("Buy goods not in use"); SDPBuyGoodsNotificationRequest sdpBg = sdpRequest as SDPBuyGoodsNotificationRequest; BuyGoodsNotificationRequest bgNotif = new BuyGoodsNotificationRequest(); bgNotif.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification; bgNotif.Currency = sdpBg.currency; bgNotif.Date = sdpBg.date; bgNotif.DateCreated = DateTime.Now; bgNotif.Id = Guid.NewGuid(); bgNotif.MerchantBalance = Convert.ToDouble(sdpBg.merchantBalance); bgNotif.PaidAmount = Convert.ToDouble(sdpBg.paidAmount); bgNotif.ReceiptNumber = sdpBg.receiptNumber; bgNotif.SDPTransactionRefId = sdpBg.internalTrxId; bgNotif.StatusCode = sdpBg.statusCode; bgNotif.StatusDetail = sdpBg.statusDetail; bgNotif.SubscriberName = sdpBg.subscriberName; bgNotif.Time = sdpBg.time; crrRequest = bgNotif; } }