Commit d9cf30c5 authored by datdiep's avatar datdiep

fix

parent 567e6f12
Pipeline #15854 canceled with stages
...@@ -46,9 +46,6 @@ namespace UF.AssessmentProject.Controllers ...@@ -46,9 +46,6 @@ namespace UF.AssessmentProject.Controllers
[SwaggerResponse(StatusCodes.Status200OK, "Submit Transaction Message successfully", typeof(Model.Transaction.ResponseMessage))] [SwaggerResponse(StatusCodes.Status200OK, "Submit Transaction Message successfully", typeof(Model.Transaction.ResponseMessage))]
[SwaggerResponse(StatusCodes.Status401Unauthorized, "Unauthorized, Request")] [SwaggerResponse(StatusCodes.Status401Unauthorized, "Unauthorized, Request")]
[SwaggerResponse(StatusCodes.Status500InternalServerError, "Oops! Can't get your Post right now")] [SwaggerResponse(StatusCodes.Status500InternalServerError, "Oops! Can't get your Post right now")]
[SwaggerResponse(StatusCodes.Status400BadRequest, Type = typeof(Model.Transaction.ResponseMessage))]
[ProducesResponseType(typeof(Model.Transaction.ResponseMessage), 400)]
public ActionResult<Model.Transaction.ResponseMessage> SubmitTRansaction(Model.Transaction.RequestMessage req) public ActionResult<Model.Transaction.ResponseMessage> SubmitTRansaction(Model.Transaction.RequestMessage req)
{ {
try { try {
...@@ -58,18 +55,22 @@ namespace UF.AssessmentProject.Controllers ...@@ -58,18 +55,22 @@ namespace UF.AssessmentProject.Controllers
results = _homeProvider.Validate(req); results = _homeProvider.Validate(req);
_logger.LogInformation(Request.Path.ToString() + "\r\nRequest = " + JsonConvert.SerializeObject(req)); _logger.LogInformation(Request.Path.ToString() + "\r\nRequest = " + JsonConvert.SerializeObject(req));
if (results.success == DataDictionary.responseResult.failed) if (results.success == DataDictionary.responseResult.failed)
_logger.LogError(Request.Path.ToString() + "\r\nResponse =" + JsonConvert.SerializeObject(results)); {
_logger.LogError(Request.Path.ToString() + "\r\nResponse =" + JsonConvert.SerializeObject(results));
}
else else
{
_logger.LogInformation(Request.Path.ToString() + "\r\nResponse =" + JsonConvert.SerializeObject(results)); _logger.LogInformation(Request.Path.ToString() + "\r\nResponse =" + JsonConvert.SerializeObject(results));
}
return Ok(results); return Ok(results);
} }
catch (Exception ex) catch (Exception ex)
{ {
var error = new Model.Transaction.ResponseMessage { resultmessage = ex.Message }; return BadRequest(ex.Message);
return new JsonResult(new { success = false, message = "Unexpected Error" });
} }
} }
......
...@@ -13,20 +13,28 @@ namespace UF.AssessmentProject.Providers ...@@ -13,20 +13,28 @@ namespace UF.AssessmentProject.Providers
public Model.Transaction.ResponseMessage validateField(Model.Transaction.RequestMessage req) public Model.Transaction.ResponseMessage validateField(Model.Transaction.RequestMessage req)
{ {
var resultmess = ""; var resultmess = "";
if (req.partnerkey == null) if (req.partnerkey == null) {
resultmess += "partnerkey is required!, "; resultmess += "partnerkey is required!, ";
if (req.partnerrefno == null) }
else if (req.partnerrefno == null) {
resultmess += "partnerrefno is required!, "; resultmess += "partnerrefno is required!, ";
if (req.timestamp == null) }
else if(req.timestamp == null) {
resultmess += "timestamp is required!, "; resultmess += "timestamp is required!, ";
if (req.sig == null) }
else if(req.sig == null) {
resultmess += "sig is required!, "; resultmess += "sig is required!, ";
if(resultmess.Length > 0) }
if(resultmess.Length > 0)
{
return new Model.Transaction.ResponseMessage return new Model.Transaction.ResponseMessage
{ {
success = DataDictionary.responseResult.failed, success = DataDictionary.responseResult.failed,
resultmessage = resultmess.Substring(0,resultmess.Length-2), resultmessage = resultmess.Substring(0,resultmess.Length-2),
}; };
}
return new Model.Transaction.ResponseMessage return new Model.Transaction.ResponseMessage
{ {
success = DataDictionary.responseResult.success, success = DataDictionary.responseResult.success,
...@@ -39,66 +47,88 @@ namespace UF.AssessmentProject.Providers ...@@ -39,66 +47,88 @@ namespace UF.AssessmentProject.Providers
var rs = validateField(req); var rs = validateField(req);
if (rs.success == DataDictionary.responseResult.failed) if (rs.success == DataDictionary.responseResult.failed)
{
return rs; return rs;
}
if (DateTime.Now >= DateTime.Parse(req.timestamp).AddMinutes(5)) if (DateTime.Now >= DateTime.Parse(req.timestamp).AddMinutes(5))
{
return new Model.Transaction.ResponseMessage return new Model.Transaction.ResponseMessage
{ {
success = DataDictionary.responseResult.failed, success = DataDictionary.responseResult.failed,
resultmessage = "Expired!" resultmessage = "Expired!"
}; };
}
var rawsig = DateTime.Parse(req.timestamp).ToString("yyyyMMddHHmmss") + req.partnerkey + req.partnerrefno + req.totalamount + req.partnerpassword; var rawsig = DateTime.Parse(req.timestamp).ToString("yyyyMMddHHmmss") + req.partnerkey + req.partnerrefno + req.totalamount + req.partnerpassword;
string sig = CommonUtils.EncodeBase64((CommonUtils.ComputeSha256Hash(rawsig))); string sig = CommonUtils.EncodeBase64((CommonUtils.ComputeSha256Hash(rawsig)));
var partner = db.Partners.Where(c => c.partnerkey == req.partnerkey).FirstOrDefault(); var partner = db.Partners.Where(c => c.partnerkey == req.partnerkey).FirstOrDefault();
string encodepass = CommonUtils.EncodeBase64(partner.partnerpassword); string encodepass = CommonUtils.EncodeBase64(partner.partnerpassword);
if (partner == null || (partner != null && encodepass != req.partnerpassword) || sig != req.sig) if (partner == null || (partner != null && encodepass != req.partnerpassword) || sig != req.sig)
{
return new Model.Transaction.ResponseMessage return new Model.Transaction.ResponseMessage
{ {
success = DataDictionary.responseResult.failed, success = DataDictionary.responseResult.failed,
resultmessage = "Access Denied!", resultmessage = "Access Denied!",
}; };
}
var checkNameNull = req.items.Where(x => string.IsNullOrEmpty(x.name) == true).ToList().Count();
long total = 0; if (checkNameNull > 0)
foreach (UF.AssessmentProject.Model.Transaction.itemdetail item in req.items)
{ {
if( item.name.Length < 0) return new Model.Transaction.ResponseMessage
return new Model.Transaction.ResponseMessage {
{ success = DataDictionary.responseResult.failed,
success = DataDictionary.responseResult.failed, resultmessage = "item name cannot be null!",
resultmessage = "item name cannot be null!", };
}; }
if ( item.partneritemref.Length < 0) var checkPartneritemrefNull = req.items.Where(x => string.IsNullOrEmpty(x.partneritemref) == true).ToList().Count();
return new Model.Transaction.ResponseMessage if (checkNameNull > 0)
{ {
success = DataDictionary.responseResult.failed, return new Model.Transaction.ResponseMessage
resultmessage = "partneritemref cannot be null!", {
}; success = DataDictionary.responseResult.failed,
resultmessage = "partneritemref name cannot be null!",
};
}
if( item.unitprice < 0 ) var checkUnitPrice = req.items.Where(x => x.unitprice < 0 ).ToList().Count();
return new Model.Transaction.ResponseMessage if (checkNameNull > 0)
{ {
success = DataDictionary.responseResult.failed, return new Model.Transaction.ResponseMessage
resultmessage = "unitprice only allow positive value!", {
}; success = DataDictionary.responseResult.failed,
resultmessage = "unitprice only allow positive value!",
};
}
if ( item.qty >0 && item.qty <=5) long total = 0;
total += item.qty * item.unitprice; foreach (Model.Transaction.itemdetail item in req.items)
else {
if (item.qty > 0 && item.qty <= 5)
{
total += item.qty * item.unitprice;
}
else
{
return new Model.Transaction.ResponseMessage return new Model.Transaction.ResponseMessage
{ {
success = DataDictionary.responseResult.failed, success = DataDictionary.responseResult.failed,
resultmessage = "qty only allow positive and not exceed 5", resultmessage = "qty only allow positive and not exceed 5",
}; };
}
} }
req.totalamount = total; if ( req.totalamount != total)
{
return new Model.Transaction.ResponseMessage
{
success = DataDictionary.responseResult.failed,
resultmessage = "Invalid Total Amount.",
};
}
return new Model.Transaction.ResponseMessage return new Model.Transaction.ResponseMessage
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment