changes
This commit is contained in:
35
server/api/vnpay/create-payment.post.ts
Normal file
35
server/api/vnpay/create-payment.post.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { VNPay } from "vnpay";
|
||||
import { secureSecret, tmnCode, vnpayHost } from "~~/server/utils/vnpaySettings";
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
|
||||
const vnpay = new VNPay({
|
||||
// ⚡ Cấu hình bắt buộc
|
||||
tmnCode,
|
||||
secureSecret,
|
||||
vnpayHost,
|
||||
|
||||
// 🔧 Cấu hình tùy chọn
|
||||
testMode: true, // Chế độ test
|
||||
// hashAlgorithm: 'SHA512', // Thuật toán mã hóa
|
||||
enableLog: true, // Bật/tắt log
|
||||
// loggerFn: ignoreLogger, // Custom logger
|
||||
|
||||
// 🔧 Custom endpoints
|
||||
endpoints: {
|
||||
paymentEndpoint: "paymentv2/vpcpay.html",
|
||||
queryDrRefundEndpoint: "merchant_webapi/api/transaction",
|
||||
getBankListEndpoint: "qrpayauth/api/merchant/get_bank_list",
|
||||
},
|
||||
});
|
||||
|
||||
const paymentUrl = vnpay.buildPaymentUrl({
|
||||
vnp_Amount: body.amount,
|
||||
vnp_IpAddr: "192.168.1.1",
|
||||
vnp_ReturnUrl: "http://localhost:3000/vnpay-return",
|
||||
vnp_TxnRef: `Test-${body.invoiceCode}-${new Date().toISOString()}`,
|
||||
vnp_OrderInfo: `Thanh toan don hang ${body.invoiceCode}`,
|
||||
});
|
||||
|
||||
return { paymentUrl };
|
||||
});
|
||||
Reference in New Issue
Block a user