VNPay Gateway Integration: Bank-Standard Payment Gateway for Businesses
If you need a "bank-standard", reputable payment gateway that supports almost all card types from domestic to international, VNPay is the first name to mention. As a strategic partner of over 40 banks in Vietnam, VNPay brings absolute trust to customers when making high-value transactions.
In this article, JAYbranding will guide you through integrating VNPay Gateway - a comprehensive payment solution trusted by industry giants like Vietnam Airlines and Vietjet Air.
1. Strengths of VNPay Gateway
- Diverse payment methods: Accepts domestic ATM cards (Napas), international cards (Visa/Master/JCB/UnionPay), and VNPay-QR code scanning.
- Installment support: Automatically calculates 0% interest installment plans for credit cards.
- High credibility: The VNPay-branded payment interface creates a sense of security just like transacting on E-Banking.
- Wide network: Over 25 million Mobile Banking users already have the VNPay QR scanning feature built in.
2. Merchant Registration Process
VNPay's process is typically stricter than e-wallets:
- Contact VNPay's sales department or go through an integration partner like JAYbranding.
- Submit documents: Business Registration Certificate + Website registered with the Ministry of Industry and Trade (MOIT).
- Sign the contract and pay the setup fee (if applicable).
- Receive test credentials on the Sandbox (Test) environment:
<li><code>vnp_TmnCode</code>: Website identifier code (Terminal ID).
- <code>vnp_HashSecret</code>: Secret string used to generate the Checksum.
</li>
3. Technical Integration Guide (VNPay API)
VNPay uses the Redirect method to ensure card security. You must not store customer card information on your website.
Step 1: Create the Payment URL
<code>$vnp_Url = "https://sandbox.vnpayment.vn/paymentv2/vpcpay.html";
$vnp_Returnurl = "https://yourwebsite.com/vnpay_return.php";
$vnp_TmnCode = "CGXZ..."; // Website ID at VNPay
$vnp_HashSecret = "XNBC..."; // Secret key
$vnp_TxnRef = date("YmdHis"); // Order ID
$vnp_OrderInfo = "Pay for order #123";
$vnp_OrderType = "billpayment";
$vnp_Amount = 100000 * 100; // Amount (multiply by 100)
$vnp_Locale = "vn";
$vnp_BankCode = "NCB"; // Bank code (leave blank if you want customers to choose)
$vnp_IpAddr = $_SERVER['REMOTE_ADDR'];
$inputData = array(
"vnp_Version" => "2.1.0",
"vnp_TmnCode" => $vnp_TmnCode,
"vnp_Amount" => $vnp_Amount,
"vnp_Command" => "pay",
"vnp_CreateDate" => date("YmdHis"),
"vnp_CurrCode" => "VND",
"vnp_IpAddr" => $vnp_IpAddr,
"vnp_Locale" => $vnp_Locale,
"vnp_OrderInfo" => $vnp_OrderInfo,
"vnp_OrderType" => $vnp_OrderType,
"vnp_ReturnUrl" => $vnp_Returnurl,
"vnp_TxnRef" => $vnp_TxnRef
);
// Sort data alphabetically to generate checksum
ksort($inputData);
$query = "";
$i = 0;
$hashdata = "";
foreach ($inputData as $key => $value) {
if ($i == 1) {
$hashdata .= '&' . urlencode($key) . "=" . urlencode($value);
} else {
$hashdata .= urlencode($key) . "=" . urlencode($value);
$i = 1;
}
$query .= urlencode($key) . "=" . urlencode($value) . '&';
}
$vnp_Url = $vnp_Url . "?" . $query;
if (isset($vnp_HashSecret)) {
$vnpSecureHash = hash_hmac('sha512', $hashdata, $vnp_HashSecret); // Use SHA512
$vnp_Url .= 'vnp_SecureHash=' . $vnpSecureHash;
}
// Redirect customer
header('Location: ' . $vnp_Url);</code></pre>
Step 2: Handle the Return Result (Return URL)
<p>After payment, the customer is redirected back to <code>vnp_Returnurl</code> along with GET parameters. You must verify the signature (SecureHash) to ensure the data has not been tampered with.
<code>// File: vnpay_return.php
$vnp_SecureHash = $_GET['vnp_SecureHash'];
$inputData = array();
foreach ($_GET as $key => $value) {
if (substr($key, 0, 4) == "vnp_") {
$inputData[$key] = $value;
}
}
unset($inputData['vnp_SecureHash']);
ksort($inputData);
$i = 0;
$hashdata = "";
foreach ($inputData as $key => $value) {
if ($i == 1) {
$hashdata .= '&' . urlencode($key) . "=" . urlencode($value);
} else {
$hashdata .= urlencode($key) . "=" . urlencode($value);
$i = 1;
}
}
$secureHash = hash_hmac('sha512', $hashdata, $vnp_HashSecret);
if ($secureHash == $vnp_SecureHash) {
if ($_GET['vnp_ResponseCode'] == '00') {
echo "Transaction successful!";
// Update order status
} else {
echo "Transaction failed. Error: " . $_GET['vnp_ResponseCode'];
}
} else {
echo "Invalid signature (Checksum mismatch)";
}</code></pre>
4. Important Notes When Integrating VNPay
- Checksum Algorithm: VNPay uses SHA512 (previously MD5/SHA256). Make sure you code with the latest algorithm.
- IPN (Instant Payment Notification): Similar to MoMo, you need to set up an additional IPN URL to receive results in the background, in case the customer closes the browser before being redirected to the Return URL.
- Sandbox Environment: Sandbox and Production API links are completely different. Remember to update them when going live.
5. Comprehensive Integration Support Services by JAYbranding
<p>Working with banking systems often requires strict security procedures. JAYbranding will help you:
- ✅ Fast-track Documentation: Support expediting the Merchant approval process with VNPAY.
- ✅ Standard Integration: Handle all APIs: Payment, Query (QueryDR), and automatic Refund.
- ✅ Custom Interface: Integrate VNPay into your checkout flow smoothly without causing friction for customers.
📞 Integrate VNPay today - Credibility in every transaction!
Hotline: 0989 971 131
FAQ About VNPay Gateway
[faqs]
#### How is VNPay-QR different from MoMo/ZaloPay QR?
VNPay-QR can be scanned by Mobile Banking apps of over 40 banks (Vietcombank, BIDV, Agribank...) without needing to install an additional e-wallet.
#### What is the VNPay transaction fee?
It typically ranges from 0.8% - 1.5% for QR transactions and higher for international cards. Contact JAYbranding for the best fee policy.
[/faqs]