public static string GetSdpPaymentUri(ClientRequestResponseType type) { string sdpHost = ConfigurationSettings.AppSettings["SDPHOST"]; string sdpUri = sdpHost; switch(type) { case ClientRequestResponseType.PaymentInstrument: sdpUri = sdpHost + "caas/list/pi"; break; case ClientRequestResponseType.AsynchronousPaymentQuery: sdpUri =sdpHost + "caas/asynch/query"; break; case ClientRequestResponseType.AsynchronousPayment: sdpUri = sdpHost + "caas/direct/debit"; break; default: throw new Exception("Invalid Request Responce type"); } return sdpUri; }
public string GetPGWSUrl(ClientRequestResponseType clientRequesType) { var ulrSetting = _appSettingsService.GetByKey(SettingsKeys.PaymentGatewayWSUrl); if(ulrSetting == null) return ""; string url = ""; string urlformat = ""; if (clientRequesType == 0) urlformat = "{0}api/payment/About"; else { urlformat = "{0}Payment/SLSend?messageType=" + clientRequesType.ToString(); if (clientRequesType == ClientRequestResponseType.ExceptionReport) urlformat = "{0}Payment/PaymentReport?messageType=" + clientRequesType.ToString(); //string urlformat = "{0}Payment/SLSendSimulator?messageType=" + clientRequesType.ToString(); } url = string.Format(urlformat, pgwsUrl); return url; }
public string SerializeMessage(ClientRequestResponseBase enitity, ClientRequestResponseType entityType) { throw new NotImplementedException(); }
public ClientRequestResponseBase DeserializeSDPResponse(string jsonResponse, ClientRequestResponseType responseType) { ClientRequestResponseBase crr = null; try { JObject jo = JObject.Parse(jsonResponse); string statusCode = (string) jo["statusCode"]; if (statusCode == "E1340" || statusCode == "E1304") return null; switch (responseType) { case ClientRequestResponseType.PaymentInstrument: SDPPaymentInstrumentResponse sdppir = null; _messageValidation.CanDeserializeMessage(jsonResponse, out sdppir); PaymentInstrumentResponse pir = new PaymentInstrumentResponse(); pir.Id = Guid.NewGuid(); pir.DateCreated = DateTime.Now; pir.ClientRequestResponseType = ClientRequestResponseType.PaymentInstrument; pir.PaymentInstrumentList = sdppir.paymentInstrumentList; pir.StatusCode = sdppir.statusCode; pir.StatusDetail = sdppir.statusDetail; crr = pir; break; case ClientRequestResponseType.AsynchronousPayment: SDPPaymentResponse sdppr = null; PaymentResponse apr = new PaymentResponse(); _messageValidation.CanDeserializeMessage(jsonResponse, out sdppr); apr.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPayment; apr.Id = Guid.NewGuid(); apr.SDPTransactionRefId = sdppr.internalTrxId; if (sdppr.externalTrxId != null) apr.TransactionRefId = ConstructMyGuid(sdppr.externalTrxId).ToString(); apr.BusinessNumber = sdppr.businessNumber; apr.DateCreated = sdppr.timeStamp; apr.SDPReferenceId = sdppr.referenceId.ToString(); apr.StatusCode = sdppr.statusCode; apr.StatusDetail = sdppr.statusDetail; apr.ShortDescription = sdppr.statusDetail; apr.LongDescription = sdppr.longDescription; apr.TimeStamp = sdppr.timeStamp.ToString() == "1/1/0001 12:00:00 AM" ? DateTime.Now : sdppr.timeStamp; apr.AmountDue = Convert.ToDouble(sdppr.amountDue); crr = apr; break; } } catch (Exception ex) { _auditLogRepository.AddLog(Guid.Empty, responseType.ToString(), "Client", "Error deserializing jsonResponse " + jsonResponse + " in DeserializeSDPResponse.\nException details: \n" + ex.Message + ex.InnerException != null ? "\n" + ex.InnerException.Message : ""); return null; } return crr; }
string SendTest(ClientRequestResponseType messageType) { string mssg = ""; NameValueCollection param = new NameValueCollection(); DateTime now = DateTime.Now; #region PaymentInstrument if (messageType == ClientRequestResponseType.PaymentInstrument) { mssg = JsonConvert.SerializeObject(new PaymentInstrumentRequest { Id = Guid.NewGuid(), TransactionRefId = Guid.NewGuid().ToString(), ClientRequestResponseType = ClientRequestResponseType.PaymentInstrument, SubscriberId = "tel:254701234563", DateCreated = now, DistributorCostCenterId = new Guid("500B3503-03B0-4BE5-A397-AB617B32B038") } , new IsoDateTimeConverter()); param.Add("messageType", "PaymentInstrument"); } #endregion #region AsynchronousPayment if (messageType == ClientRequestResponseType.AsynchronousPayment) { mssg = JsonConvert.SerializeObject(new PaymentRequest { Id = Guid.NewGuid(), AccountId = "123", SubscriberId = "tel:0724556667", AllowOverPayment = true, PaymentInstrumentName = "M-Pesa", OrderNumber = "Ord_John_O003_2012.2.29.16:21_7", InvoiceNumber = "Inv_John_O003_2012.2.29.16:21_7", TransactionRefId = sampleExternalTrxId.ToString(), Currency = "KSH", ApplicationId = Guid.Parse("36EDE98E-714D-4E8E-88E1-5E96A9B2EF67").ToString(), Amount = 5, AllowPartialPayments = false, ClientRequestResponseType = ClientRequestResponseType.AsynchronousPayment, DateCreated = DateTime.Now, smsDescription = "pil", DistributorCostCenterId = new Guid("500B3503-03B0-4BE5-A397-AB617B32B038") }, new IsoDateTimeConverter()); param.Add("messageType", "AsynchronousPayment"); } #endregion #region AsynchronousPaymentNotification if (messageType == ClientRequestResponseType.AsynchronousPaymentNotification) { mssg = JsonConvert.SerializeObject(new PaymentNotificationRequest { TransactionRefId = sampleExternalTrxId.ToString(), ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification, DistributorCostCenterId = new Guid("500B3503-03B0-4BE5-A397-AB617B32B038") }, new IsoDateTimeConverter()); param.Add("messageType", "AsynchronousPaymentNotification"); } #endregion param.Add("jsonMessage", mssg); string pgBridgeUrl = ConfigurationSettings.AppSettings["PgBridgeUrl"]; WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; //string pgbridgeUrl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~")); _auditLogRepository.AddLog(Guid.Empty,messageType.ToString(),"Test PGBridge", string.Format("PGBridge Url: {0}; Json : {1}", pgBridgeUrl, mssg)); Uri uri = new Uri(pgBridgeUrl + "Payment/Msend", UriKind.Absolute); var bytes = wc.UploadValues(uri, "POST", param); string result = ByteArrayToString(bytes, EncodingType.UTF8); return result; }
private void GetPaymentNotification(string requestMsg, ClientRequestResponseType type) { _paymentNotificationCompleted = false; string url = _paymentService.GetPGWSUrl(type); Uri uri = new Uri(url, UriKind.Absolute); WebClient wc = new WebClient(); wc.UploadStringCompleted += wc_UploadGetPaymentNotificationJsonCompleted; wc.UploadStringAsync(uri, "POST", "jsonMessage=" + requestMsg); }
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; }
public void GetPaymentNotification(string requestMsg, ClientRequestResponseType type) { using (StructureMap.IContainer cont = NestedContainer) { _paymentNotificationCompleted = false; string url = Using<IPaymentService>(cont).GetPGWSUrl(type); Uri uri = new Uri(url, UriKind.Absolute); WebClient wc = new WebClient(); wc.UploadStringCompleted +=wc_UploadGetPaymentNotificationJsonCompleted; wc.UploadStringAsync(uri, "POST", "jsonMessage=" + requestMsg); } }