定制 tringuyenduc2903/vnpayvietnam-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tringuyenduc2903/vnpayvietnam-laravel

最新稳定版本:v2.0.0

Composer 安装命令:

composer require tringuyenduc2903/vnpayvietnam-laravel

包简介

VNPay SDK for Laravel framework (Only Vietnam Support)

README 文档

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.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-28