changes
This commit is contained in:
36
server/api/vnpay/return.get.ts
Normal file
36
server/api/vnpay/return.get.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { VNPay } from "vnpay";
|
||||
|
||||
export default defineEventHandler<{
|
||||
query: {
|
||||
vnp_Amount: string;
|
||||
vnp_BankCode: string;
|
||||
vnp_BankTranNo: string;
|
||||
vnp_CardType: string;
|
||||
vnp_OrderInfo: string;
|
||||
vnp_PayDate: string;
|
||||
vnp_ResponseCode: string;
|
||||
vnp_TmnCode: string;
|
||||
vnp_TransactionNo: string;
|
||||
vnp_TransactionStatus: string;
|
||||
vnp_TxnRef: string;
|
||||
vnp_SecureHash: string;
|
||||
};
|
||||
}>(async (event) => {
|
||||
const query = getQuery(event);
|
||||
const vnpay = new VNPay({ tmnCode, secureSecret, vnpayHost });
|
||||
|
||||
try {
|
||||
const verify = vnpay.verifyReturnUrl(query);
|
||||
/*
|
||||
!isVerified -> Xác thực tính toàn vẹn dữ liệu thất bại
|
||||
!isSuccess -> Đơn hàng thanh toán thất bại
|
||||
*/
|
||||
return {
|
||||
isSuccess: verify.isSuccess,
|
||||
isVerified: verify.isVerified,
|
||||
message: verify.message,
|
||||
};
|
||||
} catch (error) {
|
||||
return { error: "Dữ liệu không hợp lệ" };
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user