Commit d9cf30c5 authored by datdiep's avatar datdiep

fix

parent 567e6f12
Pipeline #15854 canceled with stages
......@@ -46,9 +46,6 @@ namespace UF.AssessmentProject.Controllers
[SwaggerResponse(StatusCodes.Status200OK, "Submit Transaction Message successfully", typeof(Model.Transaction.ResponseMessage))]
[SwaggerResponse(StatusCodes.Status401Unauthorized, "Unauthorized, Request")]
[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)
{
try {
......@@ -58,18 +55,22 @@ namespace UF.AssessmentProject.Controllers
results = _homeProvider.Validate(req);
_logger.LogInformation(Request.Path.ToString() + "\r\nRequest = " + JsonConvert.SerializeObject(req));
if (results.success == DataDictionary.responseResult.failed)
{
_logger.LogError(Request.Path.ToString() + "\r\nResponse =" + JsonConvert.SerializeObject(results));
}
else
{
_logger.LogInformation(Request.Path.ToString() + "\r\nResponse =" + JsonConvert.SerializeObject(results));
}
return Ok(results);
}
catch (Exception ex)
{
var error = new Model.Transaction.ResponseMessage { resultmessage = ex.Message };
return new JsonResult(new { success = false, message = "Unexpected Error" });
return BadRequest(ex.Message);
}
}
......
......@@ -13,20 +13,28 @@ namespace UF.AssessmentProject.Providers
public Model.Transaction.ResponseMessage validateField(Model.Transaction.RequestMessage req)
{
var resultmess = "";
if (req.partnerkey == null)
if (req.partnerkey == null) {
resultmess += "partnerkey is required!, ";
if (req.partnerrefno == null)
}
else if (req.partnerrefno == null) {
resultmess += "partnerrefno is required!, ";
if (req.timestamp == null)
}
else if(req.timestamp == null) {
resultmess += "timestamp is required!, ";
if (req.sig == null)
}
else if(req.sig == null) {
resultmess += "sig is required!, ";
}
if(resultmess.Length > 0)
{
return new Model.Transaction.ResponseMessage
{
success = DataDictionary.responseResult.failed,
resultmessage = resultmess.Substring(0,resultmess.Length-2),
};
}
return new Model.Transaction.ResponseMessage
{
success = DataDictionary.responseResult.success,
......@@ -39,16 +47,18 @@ namespace UF.AssessmentProject.Providers
var rs = validateField(req);
if (rs.success == DataDictionary.responseResult.failed)
{
return rs;
}
if (DateTime.Now >= DateTime.Parse(req.timestamp).AddMinutes(5))
{
return new Model.Transaction.ResponseMessage
{
success = DataDictionary.responseResult.failed,
resultmessage = "Expired!"
};
}
var rawsig = DateTime.Parse(req.timestamp).ToString("yyyyMMddHHmmss") + req.partnerkey + req.partnerrefno + req.totalamount + req.partnerpassword;
string sig = CommonUtils.EncodeBase64((CommonUtils.ComputeSha256Hash(rawsig)));
......@@ -56,49 +66,69 @@ namespace UF.AssessmentProject.Providers
string encodepass = CommonUtils.EncodeBase64(partner.partnerpassword);
if (partner == null || (partner != null && encodepass != req.partnerpassword) || sig != req.sig)
{
return new Model.Transaction.ResponseMessage
{
success = DataDictionary.responseResult.failed,
resultmessage = "Access Denied!",
};
}
long total = 0;
foreach (UF.AssessmentProject.Model.Transaction.itemdetail item in req.items)
var checkNameNull = req.items.Where(x => string.IsNullOrEmpty(x.name) == true).ToList().Count();
if (checkNameNull > 0)
{
if( item.name.Length < 0)
return new Model.Transaction.ResponseMessage
{
success = DataDictionary.responseResult.failed,
resultmessage = "item name cannot be null!",
};
}
if ( item.partneritemref.Length < 0)
var checkPartneritemrefNull = req.items.Where(x => string.IsNullOrEmpty(x.partneritemref) == true).ToList().Count();
if (checkNameNull > 0)
{
return new Model.Transaction.ResponseMessage
{
success = DataDictionary.responseResult.failed,
resultmessage = "partneritemref cannot be null!",
resultmessage = "partneritemref name cannot be null!",
};
}
if( item.unitprice < 0 )
var checkUnitPrice = req.items.Where(x => x.unitprice < 0 ).ToList().Count();
if (checkNameNull > 0)
{
return new Model.Transaction.ResponseMessage
{
success = DataDictionary.responseResult.failed,
resultmessage = "unitprice only allow positive value!",
};
}
if ( item.qty >0 && item.qty <=5)
long total = 0;
foreach (Model.Transaction.itemdetail item in req.items)
{
if (item.qty > 0 && item.qty <= 5)
{
total += item.qty * item.unitprice;
}
else
{
return new Model.Transaction.ResponseMessage
{
success = DataDictionary.responseResult.failed,
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
{
......
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