tringuyenduc2903/vnpayvietnam-laravel

VNPay SDK for Laravel framework (Only Vietnam Support)

Fund package maintenance!
Beetech Asia

Installs: 8

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 2

pkg:composer/tringuyenduc2903/vnpayvietnam-laravel

v2.0.0 2025-08-29 10:22 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require tringuyenduc2903/vnpayvietnam-laravel

You can publish the config file with:

php artisan vendor:publish --tag="vnpayvietnam-config"

This is the contents of the published config file:

return [
    'url' => env('VNPAY_API_URL', 'https://sandbox.vnpayment.vn'),
    'tmn_code' => env('VNPAY_TMN_CODE', ''),
    'hash_secret' => env('VNPAY_HASH_SECRET', ''),
];

Giải thích

  • url: Môi trường phát triển tích hợp (Sandbox: https://sandbox.vnpayment.vn)
  • tmn_code: Terminal ID / Mã Website
  • hash_secret: Secret Key / Chuỗi bí mật tạo checksum

File .env:

VNPAY_API_URL=https://sandbox.vnpayment.vn
VNPAY_TMN_CODE=
VNPAY_HASH_SECRET=

Usage

Tạo URL Thanh toán

use BeetechAsia\VNPay\Enums\OrderType;use BeetechAsia\VNPay\Facades\VNPay;

$data = [
    'vnp_Amount' => 843_035,
    'vnp_IpAddr' => '10.100.0.1',
    'vnp_OrderInfo' => 'Description',
    'vnp_OrderType' => OrderType::FOOD_CONSUMPTION,
    'vnp_ReturnUrl' => 'https://example.com/return',
    'vnp_ExpireDate' => now('Asia/Ho_Chi_Minh')->addMinutes(10)->format('YmdHis'),
    'vnp_TxnRef' => 'b663e2c8-ed95-34bb-b7e7-355c7121d3a8',
];
VNPay::createPaymentUrl($data);

Danh sách Ngân hàng (vnp_BankCode)

use BeetechAsia\VNPay\Facades\VNPay;

VNPay::getBankCodes();

Cài đặt Code IPN URL

use BeetechAsia\VNPay\Facades\VNPay;

$order_id = '9d8849ec-ed01-3324-83d1-85b61484412f'; // Mã tham chiếu của giao dịch tại hệ thống
$order_amount = 843_035; // Số tiền thanh toán
$check_updated_order_callback = fn(): bool => false // Closure kiểm tra trạng thái xác nhận giao dịch tại hệ thống
$update_order_callback = function () { } // Closure thực hiện cập nhật trạng thái xác nhận giao dịch tại hệ thống
$handle = VNPay::handleIpn(
    $order_id,
    $order_amount,
    $check_updated_order_callback,
    $update_order_callback,
);

Truy vấn kết quả thanh toán

use BeetechAsia\VNPay\Facades\VNPay;

$data = [
    'vnp_RequestId' => 1,
    'vnp_TxnRef' => 'b663e2c8-ed95-34bb-b7e7-355c7121d3a8',
    'vnp_OrderInfo' => 'Description',
    'vnp_TransactionDate' => '20250828132325',
    'vnp_IpAddr' => '10.100.0.1',
];
VNPay::getPaymentResult($data);

Giao dịch hoàn tiền

use BeetechAsia\VNPay\Facades\VNPay;
use BeetechAsia\VNPay\Enums\RefundTransactionType;

$data = [
    'vnp_RequestId' => 1,
    'vnp_TransactionType' => RefundTransactionType::FULL,
    'vnp_TxnRef' => 'b663e2c8-ed95-34bb-b7e7-355c7121d3a8',
    'vnp_Amount' => 843_035,
    'vnp_OrderInfo' => 'Description',
    'vnp_TransactionDate' => '20250828132325',
    'vnp_CreateBy' => 'NGUYEN VAN A',
    'vnp_IpAddr' => '10.100.0.1',
];
VNPay::sendRefundRequest($data);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.