public string GetMerchantChargeDetailsApi(Request vmRequest) { ListenerResponse resp = new ListenerResponse(); MerchantChargeResponse chargeResp = new MerchantChargeResponse(); string xmlResponse = ""; resp = GetVendorCredentials(vmRequest.Username, vmRequest.Password); if (resp.StatusCode.Equals("0") && resp.StatusDescription.Equals("ValidVendor")) { if (IsValidDigitalSignature(vmRequest)) { mapiRequest.ReferenceId = vmRequest.MerchantCode; mapiRequest.MerchantId = vmRequest.MerchantCode; mapiRequest.RequestAgent = "1"; mapiRequest.ApiUsername = apiUsername; mapiRequest.ApiPassword = apiPassword; mapiRequest.Channel = vmRequest.Channel; apiResp = mapi.GetMerchantDetails(mapiRequest); if (apiResp.Status.Equals("0")) { mapiRequest.Amount = vmRequest.Amount; mapiRequest.ReferenceId = apiResp.Customer.AccountNumber; chargeResp = mapi.GetCharges(mapiRequest); if (chargeResp.StatusCode.Equals("0")) { xmlResponse = GetMerchantChargeXmlResponse(chargeResp); } else { apiResp.Status = chargeResp.StatusCode; apiResp.StatusDescription = chargeResp.StatusDesc; xmlResponse = GetMerchantChargeXmlResponse(chargeResp); } } else { chargeResp.Status = apiResp.Status; chargeResp.StatusDesc = apiResp.StatusDescription; xmlResponse = GetMerchantChargeXmlResponse(chargeResp); } } else { chargeResp.Status = "30"; chargeResp.StatusDesc = "Invalid Digital Signature"; xmlResponse = GetMerchantChargeXmlResponse(chargeResp); } } else { chargeResp.Status = "100"; chargeResp.StatusDesc = "Invalid Vendor Credentials"; xmlResponse = GetMerchantChargeXmlResponse(chargeResp); } return(xmlResponse); }
public string GetMerchantTransactionDetailsApi(Request vmRequest) { ListenerResponse resp = new ListenerResponse(); MerchantChargeResponse chargeResp = new MerchantChargeResponse(); string xmlResponse = ""; resp = GetVendorCredentials(vmRequest.Username, vmRequest.Password); if (resp.StatusCode.Equals("0") && resp.StatusDescription.Equals("ValidVendor")) { if (IsValidDigitalSignature(vmRequest)) { mapiRequest.ReferenceId = vmRequest.TransactionId; mapiRequest.MerchantId = vmRequest.MerchantCode; mapiRequest.RequestAgent = "1"; mapiRequest.ApiUsername = apiUsername; mapiRequest.ApiPassword = apiPassword; mapiRequest.Channel = vmRequest.Channel; mtran = mapi.GetTransactionDetails(mapiRequest); if (!string.IsNullOrEmpty(mtran.Status.ToString())) { if (!(string.IsNullOrEmpty(mtran.Status.ToString()))) { xmlResponse = GetMerchantTranStatusXmlResponse(mtran); } else { mtran.Status = "201"; mtran.StatusDescription = "Transaction Not Found"; xmlResponse = GetMerchantTranStatusXmlResponse(mtran); } } else { mtran.Status = mtran.Status; mtran.StatusDescription = mtran.StatusDescription; xmlResponse = GetMerchantTranStatusXmlResponse(mtran); } } else { apiResp.Status = "30"; apiResp.StatusDescription = "Invalid Digital Signature"; xmlResponse = GetMerchantPaymentXmlResponse(apiResp); } } else { apiResp.Status = "100"; apiResp.StatusDescription = "Invalid Vendor Credentials"; xmlResponse = GetMerchantPaymentXmlResponse(apiResp); } return(xmlResponse); }
public void ProcessThread(object httpContext) { BusinessLogic bl = new BusinessLogic(); ListenerResponse resp = new ListenerResponse(); string xmlResponse = ""; byte[] buf; string SourceIp = ""; string ServerIp = ""; HttpListenerContext context = (HttpListenerContext)httpContext; try { SourceIp = bl.GetRequestIp(); ServerIp = bl.GetServerIpIpValue(); string request = (new StreamReader(context.Request.InputStream).ReadToEnd()); Console.WriteLine("------------Request Made---------"); Console.WriteLine(request + " " + DateTime.Now.ToString()); string startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"); string StartTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"); Log.Info("----------------------------Request Made------------------------------\n" + StartTime + Environment.NewLine + request); System.Net.ServicePointManager.ServerCertificateValidationCallback = bl.RemoteCertificateValidation; xmlResponse = bl.ProcessRequest(request, SourceIp, ServerIp); string endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"); Log.Info(".........................Response to Request......................\n" + endTime + Environment.NewLine + xmlResponse + Environment.NewLine); Console.WriteLine(".........................Response to Request......................"); Console.WriteLine(xmlResponse + " " + DateTime.Now.ToString()); buf = Encoding.ASCII.GetBytes(xmlResponse); context.Response.ContentLength64 = buf.Length; context.Response.OutputStream.Write(buf, 0, buf.Length); Console.WriteLine(".........................Response to Request......................"); Console.WriteLine(xmlResponse + " " + DateTime.Now.ToString()); } catch (Exception ex) { MethodBase methodBase = MethodBase.GetCurrentMethod(); string method = methodBase.DeclaringType.Name + "." + methodBase.Name; bl.LogError("", method, "", "Exception", ex.Message, ""); string errorResponse = "The request could not be processed at this time.Please try again later..."; buf = Encoding.ASCII.GetBytes(errorResponse); context.Response.ContentLength64 = buf.Length; context.Response.OutputStream.Write(buf, 0, buf.Length); Console.WriteLine(".........................Response to Request......................"); Console.WriteLine(errorResponse + " " + DateTime.Now.ToString()); } }
public virtual void ProcessRequest(HttpListenerContext RequestContext) { try { IHttpRequest req = new ListenerRequest(RequestContext.Request); IHttpResponse resp = new ListenerResponse(RequestContext.Response); HandleHttpRequest(req, resp); RequestContext.Response.OutputStream.Close(); } catch (Exception ex) { // "Internal server error" RequestContext.Response.StatusCode = 500; RequestContext.Response.StatusDescription = ex.Message; } }
public ListenerResponse GetVendorCredentials(string vendorcode, string password) { ListenerResponse resp = new ListenerResponse(); DataTable vendordetails = dbh.GetVendorDetails(vendorcode, HashPassword(password)); if (vendordetails.Rows.Count > 0) { resp.StatusCode = "0"; resp.StatusDescription = "ValidVendor"; } else { resp.StatusCode = "100"; resp.StatusDescription = "InValidVendor VendorCredentials"; } return(resp); }
private static void L_ProductionReceived(object sender, ProductionEventArgs e) { e.ResponseArray[18] = e.ProcessIndicator; e.ResponseArray[19] = e.SuccessIndicator; e.ResponseArray[20] = e.FaultCode; e.ResponseArray[21] = 308; e.ResponseArray[22] = e.P_Val_1; e.ResponseArray[23] = e.P_Val_2; e.ResponseArray[24] = e.P_Val_3; e.ResponseArray[25] = e.P_Val_4; e.ResponseArray[26] = e.P_Val_5; e.ResponseArray[27] = e.P_Val_6; e.ResponseArray[28] = e.P_Val_7; e.ResponseArray[29] = e.P_Val_8; e.ResponseArray[30] = e.P_Val_9; e.ResponseArray[31] = e.P_Val_10; e.ResponseArray[32] = e.P_Val_11; e.ResponseArray[33] = e.P_Val_12; e.ResponseArray[34] = e.P_Val_13; e.ResponseArray[35] = e.P_Val_14; e.ResponseArray[36] = e.P_Val_15; e.ResponseArray[37] = e.P_Val_16; e.ResponseArray[38] = e.P_Val_17; e.ResponseArray[39] = e.P_Val_18; e.ResponseArray[40] = e.P_Val_19; e.ResponseArray[41] = e.P_Val_20; e.ResponseArray[42] = e.P_Val_21; e.ResponseArray[43] = e.P_Val_22; e.ResponseArray[44] = e.P_Val_23; e.ResponseArray[45] = e.P_Val_24; e.ResponseArray[46] = e.P_Val_25; e.ResponseArray[47] = e.P_Val_26; e.ResponseArray[48] = e.P_Val_27; e.ResponseArray[49] = e.P_Val_28; var r = new ListenerResponse(); r.ProductionResponse(e); }
public string GetMerchantTranStatusApi(Request vmRequest) { ListenerResponse resp = new ListenerResponse(); MerchantChargeResponse chargeResp = new MerchantChargeResponse(); string xmlResponse = ""; mapiRequest.ReferenceId = vmRequest.RequestId; mapiRequest.MerchantId = vmRequest.MerchantCode; mapiRequest.RequestAgent = "1"; mapiRequest.ApiUsername = apiUsername; mapiRequest.ApiPassword = apiPassword; mapiRequest.Channel = vmRequest.Channel; apiResp = mapi.GetMerchantDetails(mapiRequest); if (apiResp.Status.Equals("0")) { mapiRequest.Amount = vmRequest.Amount; mapiRequest.ReferenceId = apiResp.Customer.AccountNumber; chargeResp = mapi.GetCharges(mapiRequest); if (chargeResp.StatusCode.Equals("0")) { xmlResponse = GetMerchantChargeXmlResponse(chargeResp); } else { apiResp.Status = chargeResp.StatusCode; apiResp.StatusDescription = chargeResp.StatusDesc; xmlResponse = GetMerchantChargeXmlResponse(chargeResp); } } else { chargeResp.Status = apiResp.Status; chargeResp.StatusDesc = apiResp.StatusDescription; xmlResponse = GetMerchantChargeXmlResponse(chargeResp); } return(xmlResponse); }
public string GetMerchantDetailsApi(Request vmRequest) { ListenerResponse resp = new ListenerResponse(); string xmlResponse = ""; mapiRequest.ReferenceId = vmRequest.MerchantCode; mapiRequest.MerchantId = vmRequest.MerchantCode; mapiRequest.RequestAgent = "1"; mapiRequest.Channel = vmRequest.Channel; mapiRequest.ApiPassword = apiPassword; mapiRequest.ApiUsername = apiUsername; resp = GetVendorCredentials(vmRequest.Username, vmRequest.Password); if (resp.StatusCode.Equals("0") && resp.StatusDescription.Equals("ValidVendor")) { if (IsValidDigitalSignature(vmRequest)) { apiResp = mapi.GetMerchantDetails(mapiRequest); xmlResponse = GetValidationXmlResponse(apiResp); } else { apiResp.Status = "30"; apiResp.StatusDescription = "Invalid Digital Signature"; xmlResponse = GetValidationXmlResponse(apiResp); } } else { apiResp.Status = "100"; apiResp.StatusDescription = "Invalid Vendor Credentials"; xmlResponse = GetValidationXmlResponse(apiResp); } return(xmlResponse); }
public string ProcessRequest(string request, string sourceip, string serverip) { ListenerResponse valResponse = new ListenerResponse(); string xmlResponse = ""; try { string RequestType = GetTranRequestType(request); if (RequestType.Equals("ValidateMerchant")) { Request vmreq = GetValidateMerchantRequestDetails(request); if (vmreq.StatusCode.Equals("0")) { xmlResponse = GetMerchantDetailsApi(vmreq); } else { LogError(vmreq.Username, "ProcessThread->GetMerchantDetailsApi", vmreq.MerchantCode, "Logical", vmreq.StatusDescription, vmreq.RequestId); } LogRequestResponse(request, xmlResponse, vmreq.RequestId, "ValidateMerchant", vmreq.Username, sourceip, serverip); } else if (RequestType.Equals("MakeMerchantPayment")) { Request vmreq = GetMerchantPaymentDetails(request); if (vmreq.StatusCode.Equals("0")) { xmlResponse = GetMerchantPaymentDetailsApi(vmreq); } else { LogError(vmreq.Username, "ProcessThread->GetMerchantPaymentDetailsApi", vmreq.MerchantCode, "Logical", vmreq.StatusDescription, vmreq.RequestId); } LogRequestResponse(request, xmlResponse, vmreq.RequestId, "MakeMerchantPayment", vmreq.Username, sourceip, serverip); } else if (RequestType.Equals("GetMerchantCharge")) { Request vmreq = GetMerchantChargeRequestDetails(request); if (vmreq.StatusCode.Equals("0")) { xmlResponse = GetMerchantChargeDetailsApi(vmreq); } else { LogError(vmreq.Username, "ProcessThread->GetMerchantChargeDetailsApi", vmreq.MerchantCode, "Logical", vmreq.StatusDescription, vmreq.RequestId); } LogRequestResponse(request, xmlResponse, vmreq.RequestId, "GetMerchantCharge", vmreq.Username, sourceip, serverip); } else if (RequestType.Equals("GetTransactionStatus")) { Request vmreq = GetMerchantTranStatusDetails(request); if (vmreq.StatusCode.Equals("0")) { xmlResponse = GetMerchantTransactionDetailsApi(vmreq); } else { LogError(vmreq.Username, "ProcessThread->GetMerchantTransactionDetailsApi", vmreq.MerchantCode, "Logical", vmreq.StatusDescription, vmreq.RequestId); } LogRequestResponse(request, xmlResponse, vmreq.RequestId, "GetTransactionStatus", vmreq.Username, sourceip, serverip); } else if (RequestType.Equals("ValidateCustomerRef")) { Request vmreq = GetValidateCustRefDetails(request); if (vmreq.StatusCode.Equals("0")) { xmlResponse = GetValidateCustRefDetailsApi(vmreq); } else { LogError(vmreq.Username, "ProcessThread->GetValidateCustRefDetailsApi", vmreq.MerchantCode, "Logical", vmreq.StatusDescription, vmreq.RequestId); } LogRequestResponse(request, xmlResponse, vmreq.RequestId, "ValidateCustomerRef", vmreq.Username, sourceip, serverip); } } catch (Exception ex) { valResponse.StatusCode = "200"; valResponse.StatusDescription = ex.Message; LogError("", "ProcessThread", "", "Exception", ex.Message, ""); } return(xmlResponse); }
public string GetMerchantPaymentDetailsApi(Request vmRequest) { ListenerResponse resp = new ListenerResponse(); string xmlResponse = ""; resp = GetVendorCredentials(vmRequest.Username, vmRequest.Password); if (resp.StatusCode.Equals("0") && resp.StatusDescription.Equals("ValidVendor")) { if (IsValidDigitalSignature(vmRequest)) { mapiRequest.ReferenceId = vmRequest.MerchantCode; mapiRequest.MerchantId = vmRequest.MerchantCode; mapiRequest.RequestAgent = vmRequest.CustomerTel; mapiRequest.ApiUsername = apiUsername; mapiRequest.ApiPassword = apiPassword; mapiRequest.Channel = vmRequest.Channel; apiResp = mapi.GetMerchantDetails(mapiRequest); if (apiResp.Status.Equals("0")) { mapiRequest.Amount = vmRequest.Amount; mapiRequest.ReferenceId = apiResp.Customer.AccountNumber; MerchantChargeResponse chargeResp = mapi.GetCharges(mapiRequest); if (chargeResp.StatusCode.Equals("0")) { mtran.DigitalSignature = "1234"; mtran.ApiUsername = apiUsername; mtran.ApiPassword = apiPassword; mtran.Channel = vmRequest.Channel; mtran.CustTel = vmRequest.CustomerTel;//bll.DecryptPhone(phone); mtran.AccountTo = apiResp.Customer.AccountNumber; mtran.AccountFrom = vmRequest.CustomerTel; mtran.Amount = vmRequest.Amount; mtran.TranType = "TOPUP"; mtran.PaymentType = "MTN MOBILE MONEY"; mtran.PaymentDate = DateTime.Now.ToString("dd/MM/yyyy"); mtran.TranId = vmRequest.RequestId; mtran.MerchantId = vmRequest.MerchantCode; mtran.CustRef = vmRequest.CustomerRef; mtran.CustName = vmRequest.MerchantCode; mtran.CreatedBy = "108633"; mtran.CustomerType = "PUBLIC"; mtran.Utility = ""; mtran.Area = vmRequest.MerchantCode; mtran.Field1 = ""; mtran.Narration = vmRequest.Narration; mtran.Charge = chargeResp.CalculatedChargeAmount; payResp = mapi.MakePegPayTopUp(mtran); payResp.RequestId = vmRequest.RequestId; xmlResponse = GetMerchantPaymentXmlResponse(payResp); } else { apiResp.Status = chargeResp.StatusCode; apiResp.StatusDescription = chargeResp.StatusDesc; xmlResponse = GetMerchantPaymentXmlResponse(apiResp); } } else { apiResp.Status = apiResp.Status; apiResp.StatusDescription = apiResp.StatusDescription; xmlResponse = GetMerchantPaymentXmlResponse(apiResp); } } else { apiResp.Status = "30"; apiResp.StatusDescription = "Invalid Digital Signature"; xmlResponse = GetMerchantPaymentXmlResponse(apiResp); } } else { apiResp.Status = "100"; apiResp.StatusDescription = "Invalid Vendor Credentials"; xmlResponse = GetMerchantPaymentXmlResponse(apiResp); } return(xmlResponse); }
public string GetValidateCustRefDetailsApi(Request vmRequest) { ListenerResponse resp = new ListenerResponse(); ValidateCustomerRefResponse apiresponse = new ValidateCustomerRefResponse(); string xmlResponse = ""; resp = GetVendorCredentials(vmRequest.Username, vmRequest.Password); if (resp.StatusCode.Equals("0") && resp.StatusDescription.Equals("ValidVendor")) { if (IsValidDigitalSignature(vmRequest)) { mapiRequest.ReferenceId = vmRequest.MerchantCode; mapiRequest.MerchantId = vmRequest.MerchantCode; mapiRequest.RequestAgent = "1"; mapiRequest.ApiUsername = apiUsername; mapiRequest.ApiPassword = apiPassword; mapiRequest.Channel = vmRequest.Channel; Response apiResp2 = mapi.GetMerchantDetails(mapiRequest); bool NotReferenced = false; bool IsReferenced = bool.TryParse(apiResp2.Customer.CustomerType, out NotReferenced); if (IsReferenced) { if (apiResp2.Status.Equals("0")) { if (vmRequest.MerchantCode.Equals("108633")) { TotalLogic total = new TotalLogic(); CardValidationResponse rr = new CardValidationResponse(); rr = total.CallWebService(vmRequest.CustomerRef); apiresponse.CustomerName = rr.HolderName; apiresponse.MerchantName = apiResp2.Customer.FullName; apiresponse.StatusCode = rr.StatusCode; apiresponse.StatusDescription = rr.StatusDescription; apiresponse.MerchantCode = vmRequest.MerchantCode; apiresponse.OutstandingBalance = "0"; apiresponse.MinimumBalance = "0"; xmlResponse = GetValidateCustRefXmlResponse(apiresponse); } else { mapiRequest.ReferenceId = vmRequest.CustomerRef; apiResp2 = mapi.GetMerchantCustomer(mapiRequest); apiresponse.MerchantName = apiResp2.Customer.FullName; apiresponse.CustomerName = apiResp2.Customer.FullName; apiresponse.MerchantCode = vmRequest.MerchantCode; apiresponse.OutstandingBalance = apiResp2.Customer.RunningBalance; apiresponse.StatusCode = apiResp2.Status; apiresponse.StatusDescription = apiResp2.StatusDescription; xmlResponse = GetValidateCustRefXmlResponse(apiresponse); } } else { apiresponse.StatusCode = "29"; apiresponse.StatusDescription = "Invalid Merchant Code"; xmlResponse = GetValidateCustRefXmlResponse(apiresponse); } } else { apiresponse.StatusCode = "29"; apiresponse.StatusDescription = "Merchant Customer Not Referenced"; xmlResponse = GetValidateCustRefXmlResponse(apiresponse); } } else { apiresponse.StatusCode = "30"; apiresponse.StatusDescription = "Invalid Digital Signature"; xmlResponse = GetValidateCustRefXmlResponse(apiresponse); } } else { apiresponse.StatusCode = "100"; apiresponse.StatusDescription = "Invalid Vendor Credentials"; xmlResponse = GetValidateCustRefXmlResponse(apiresponse); } return(xmlResponse); }