public async Task <object> RequestReconciliationReportAsync(int daysAgo, String productSPCode) { daysAgo = -1 * daysAgo; GepgUtility gepg = new GepgUtility(_hostingEnvironment, config, _loggerFactory); ReconcRequest Reconciliation = new ReconcRequest(); gepgSpReconcReq request = new gepgSpReconcReq(); request.SpReconcReqId = Math.Abs(Guid.NewGuid().GetHashCode());//Convert.ToInt32(DateTime.UtcNow.Year.ToString() + DateTime.UtcNow.Month.ToString() + DateTime.UtcNow.Day.ToString()); request.SpCode = productSPCode; request.SpSysId = Configuration["PaymentGateWay:GePG:SystemId"]; request.TnxDt = DateTime.Now.AddDays(daysAgo).ToString("yyyy-MM-dd"); request.ReconcOpt = 1; var requestString = gepg.SerializeClean(request, typeof(gepgSpReconcReq)); string signature = gepg.GenerateSignature(requestString); var signedRequest = gepg.FinaliseSignedMsg(new ReconcRequest() { gepgSpReconcReq = request, gepgSignature = signature }, typeof(ReconcRequest)); var result = await gepg.SendHttpRequest("/api/reconciliations/sig_sp_qrequest", signedRequest, productSPCode, "default.sp.in"); var content = signedRequest + "********************" + result; _gepgFileLogger.Log(productSPCode + "_GepGReconRequest", content); return(new { reconcId = request.SpReconcReqId, resp = result }); }
public async Task <IActionResult> GePGReceiveControlNumber([FromBody] gepgBillSubResp model) { int billId; if (model.HasValidSignature) { if (!ModelState.IsValid) { return(BadRequest(imisPayment.ControlNumberResp(GepgCodeResponses.GepgResponseCodes["Invalid Request Data"]))); } ControlNumberResp ControlNumberResponse; foreach (var bill in model.BillTrxInf) { ControlNumberResponse = new ControlNumberResp() { internal_identifier = bill.BillId, control_number = bill.PayCntrNum, error_occured = bill.TrxStsCode == GepgCodeResponses.GepgResponseCodes["Successful"].ToString()?false:true, error_message = bill.TrxStsCode }; billId = bill.BillId; string reconc = JsonConvert.SerializeObject(ControlNumberResponse); _gepgFileLogger.Log(billId, "CN_Response", reconc); try { var response = base.GetReqControlNumber(ControlNumberResponse); if (ControlNumberResponse.error_occured == true) { var rejectedReason = imisPayment.PrepareRejectedReason(billId, bill.TrxStsCode); imisPayment.setRejectedReason(billId, rejectedReason); } } catch (Exception e) { _logger.LogError(e, "Error in GePGReceiveControlNumber"); throw; } } return(Ok(imisPayment.ControlNumberResp(GepgCodeResponses.GepgResponseCodes["Successful"]))); } else { foreach (var bill in model.BillTrxInf) { billId = bill.BillId; string reconc = JsonConvert.SerializeObject(model); _gepgFileLogger.Log(billId, "CN_Response_InvalidSignature", reconc); imisPayment.setRejectedReason(billId, GepgCodeResponses.GepgResponseCodes["Invalid Signature"] + ":Invalid Signature"); } return(Ok(imisPayment.ControlNumberResp(GepgCodeResponses.GepgResponseCodes["Invalid Signature"]))); } }
public override async Task <InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding effectiveEncoding) { string content; string signature; bool hasValidSignature = true; if (context == null) { throw new ArgumentNullException(nameof(context)); } if (effectiveEncoding == null) { throw new ArgumentNullException(nameof(effectiveEncoding)); } var Request = context.HttpContext.Request; var buffer = new byte[Convert.ToInt32(Request.ContentLength)]; string body = string.Empty; using (var reader = new StreamReader( Request.Body, encoding: effectiveEncoding, detectEncodingFromByteOrderMarks: false, bufferSize: buffer.Length, leaveOpen: true )) { body = await reader.ReadToEndAsync(); // stream = reader;// Do something } GePGSignatureValidator signatureValidator = new GePGSignatureValidator(hostingEnvironment, configuration); content = this.getContent(body, this.type.Name); signature = this.getSignature(body, "gepgSignature"); hasValidSignature = signatureValidator.VerifyData(content, signature); //get the billId/paymentId from request body - from <BillId> node if (this.type.Name != "gepgSpReconcResp") { string billId = body.Between("<BillId>", "</BillId>"); if (!String.IsNullOrEmpty(billId)) { _gepgFileLogger.Log(billId + "_" + type.Name, body); } else { _gepgFileLogger.LogRequestBody(type.Name, body); } } else { _gepgFileLogger.Log(type.Name, body); } TextReader writer = new StringReader(content); try { var serializer = new XmlSerializer(type); dynamic model = Convert.ChangeType(serializer.Deserialize(writer), type); model.HasValidSignature = hasValidSignature; return(await InputFormatterResult.SuccessAsync(Convert.ChangeType(model, type))); } catch { return(await InputFormatterResult.FailureAsync()); } }