Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
UFTest
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
datdiep
UFTest
Commits
d9cf30c5
Commit
d9cf30c5
authored
Jun 15, 2022
by
datdiep
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
567e6f12
Pipeline
#15854
canceled with stages
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
40 deletions
+71
-40
TransactionController.cs
UF.AssessmentProject/Controllers/TransactionController.cs
+7
-6
HomeProvider.cs
UF.AssessmentProject/Providers/HomeProvider.cs
+64
-34
No files found.
UF.AssessmentProject/Controllers/TransactionController.cs
View file @
d9cf30c5
...
@@ -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"
});
}
}
}
}
...
...
UF.AssessmentProject/Providers/HomeProvider.cs
View file @
d9cf30c5
...
@@ -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,16 +47,18 @@ namespace UF.AssessmentProject.Providers
...
@@ -39,16 +47,18 @@ 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
)));
...
@@ -56,49 +66,69 @@ namespace UF.AssessmentProject.Providers
...
@@ -56,49 +66,69 @@ namespace UF.AssessmentProject.Providers
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
();
if
(
checkNameNull
>
0
)
{
return
new
Model
.
Transaction
.
ResponseMessage
return
new
Model
.
Transaction
.
ResponseMessage
{
{
success
=
DataDictionary
.
responseResult
.
failed
,
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
return
new
Model
.
Transaction
.
ResponseMessage
{
{
success
=
DataDictionary
.
responseResult
.
failed
,
success
=
DataDictionary
.
responseResult
.
failed
,
resultmessage
=
"unitprice only allow positive value!"
,
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
;
total
+=
item
.
qty
*
item
.
unitprice
;
}
else
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
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment