Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haiyen-payment
Overview
Overview
Details
Activity
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
Giang Tran
haiyen-payment
Commits
8dcdfabb
Commit
8dcdfabb
authored
Aug 28, 2026
by
tdgiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add admin return/IPN handlers with signature verification
parent
6dffeac6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
0 deletions
+106
-0
admin.server.controller.js
app/controllers/admin.server.controller.js
+88
-0
pay-result.server.view.html
app/views/admin/pay-result.server.view.html
+18
-0
No files found.
app/controllers/admin.server.controller.js
View file @
8dcdfabb
...
...
@@ -71,3 +71,91 @@ exports.payPage = function (req, res) {
});
});
};
exports
.
epayReturn
=
function
(
req
,
res
)
{
var
q
=
req
.
query
;
var
resultCd
=
q
.
resultCd
;
var
merTrxId
=
q
.
merTrxId
;
if
(
resultCd
!==
"00_000"
)
{
return
res
.
render
(
"admin/pay-result"
,
{
success
:
false
,
message
:
q
.
resultMsg
||
"Giao dịch không thành công"
,
});
}
AdminTransaction
.
findOne
({
merTrxId
:
merTrxId
},
function
(
err
,
tx
)
{
if
(
err
||
!
tx
)
{
return
res
.
render
(
"admin/pay-result"
,
{
success
:
false
,
message
:
"Không tìm thấy giao dịch"
,
});
}
var
expected
=
epaySign
.
signResponse
(
resultCd
,
tx
.
timeStamp
,
tx
.
merTrxId
,
q
.
trxId
,
config
.
epay
.
merchant_id
,
tx
.
amount
,
config
.
epay
.
encode_key
,
q
.
payToken
);
if
(
expected
!==
q
.
merchantToken
)
{
return
res
.
render
(
"admin/pay-result"
,
{
success
:
false
,
message
:
"Chữ ký không đúng"
,
});
}
return
res
.
render
(
"admin/pay-result"
,
{
success
:
true
,
message
:
"Thanh toán thành công"
,
});
});
};
exports
.
epayIPN
=
function
(
req
,
res
)
{
var
b
=
req
.
body
;
var
resultCd
=
b
.
resultCd
;
var
merTrxId
=
b
.
merTrxId
;
AdminTransaction
.
findOne
({
merTrxId
:
merTrxId
},
function
(
err
,
tx
)
{
if
(
err
||
!
tx
)
{
return
res
.
status
(
400
).
json
({
code
:
"99"
,
data
:
"TRX_NOT_FOUND"
});
}
var
expected
=
epaySign
.
signResponse
(
resultCd
,
tx
.
timeStamp
,
tx
.
merTrxId
,
b
.
trxId
,
config
.
epay
.
merchant_id
,
tx
.
amount
,
config
.
epay
.
encode_key
,
b
.
payToken
);
if
(
expected
!==
b
.
merchantToken
)
{
return
res
.
status
(
400
).
json
({
code
:
"99"
,
data
:
"INVALID_SIGNATURE"
});
}
var
newStatus
=
resultCd
===
"00_000"
?
"success"
:
"failed"
;
AdminTransaction
.
updateOne
(
{
merTrxId
:
merTrxId
},
{
status
:
newStatus
,
resultMsg
:
b
.
resultMsg
||
""
,
paidAt
:
newStatus
===
"success"
?
new
Date
()
:
tx
.
paidAt
,
},
function
(
updateErr
)
{
if
(
updateErr
)
{
return
res
.
status
(
500
).
json
({
code
:
"99"
,
data
:
"DB_ERROR"
});
}
return
res
.
status
(
200
).
json
({
code
:
"00"
,
data
:
"Success"
});
}
);
});
};
app/views/admin/pay-result.server.view.html
0 → 100644
View file @
8dcdfabb
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<title>
Kết quả thanh toán
</title>
<style>
body
{
font-family
:
Arial
,
sans-serif
;
max-width
:
480px
;
margin
:
60px
auto
;
text-align
:
center
;
}
</style>
</head>
<body>
{% if success %}
<h2
style=
"color:#276b45"
>
Thanh toán thành công
</h2>
{% else %}
<h2
style=
"color:#a3352a"
>
Thanh toán thất bại
</h2>
<p>
{{message}}
</p>
{% endif %}
</body>
</html>
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