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
Requires
- php: ^8.3
- bensampo/laravel-enum: ^6.12
- guzzlehttp/guzzle: ^7.9
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^2.0||^3.0
- pestphp/pest-plugin-arch: ^2.5||^3.0
- pestphp/pest-plugin-laravel: ^2.0||^3.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- spatie/laravel-ray: ^1.35
This package is auto-updated.
Last update: 2025-12-24 04:04:49 UTC
README
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.