ommani / payment-vnpay
支持集成VNPay支付网关的库。
dev-master / 1.0.x-dev
2023-09-25 03:49 UTC
Requires
- php: ^8.0.2
- omnipay/common: ^3.0
Requires (Dev)
- omnipay/tests: ^3.0
- scrutinizer/ocular: ^1.5
This package is auto-updated.
Last update: 2024-09-25 06:01:11 UTC
README
ommani: VNPay
安装
composer require ommani/payment-vnpay
使用方法
初始化网关
use Omnipay\Omnipay; $gateway = Omnipay::create('VNPay'); $gateway->initialize([ 'vnp_TmnCode' => 'Do VNPay cấp', 'vnp_HashSecret' => 'Do VNPay cấp', ]);
上面的网关初始化用于向VNPay发送处理请求,或用于接收VNPay发送的请求。
创建支付请求
$response = $gateway->purchase([ 'vnp_TxnRef' => time(), 'vnp_OrderType' => 100000, 'vnp_OrderInfo' => time(), 'vnp_IpAddr' => '127.0.0.1', 'vnp_Amount' => 1000000, 'vnp_ReturnUrl' => 'https://github.com/phpviet', ])->send(); if ($response->isRedirect()) { $redirectUrl = $response->getRedirectUrl(); // TODO: chuyển khách sang trang VNPay để thanh toán }
当客户被VNPay重定向回来时,检查 vnp_ReturnUrl 信息的完整性。
$response = $gateway->completePurchase()->send(); if ($response->isSuccessful()) { // TODO: xử lý kết quả và hiển thị. print $response->vnp_Amount; print $response->vnp_TxnRef; var_dump($response->getData()); // toàn bộ data do VNPay gửi sang. } else { print $response->getMessage(); }
有关VNPay返回时的参数值的更多信息,请参阅 这里。
检查VNPay发送的 IPN 信息
$response = $gateway->notification()->send(); if ($response->isSuccessful()) { // TODO: xử lý kết quả. print $response->vnp_Amount; print $response->vnp_TxnRef; var_dump($response->getData()); // toàn bộ data do VNPay gửi sang. } else { print $response->getMessage(); }
有关VNPay发送时的参数值的更多信息,请参阅 这里。
检查交易状态
$response = $gateway->queryTransaction([ 'vnp_TransDate' => 20190705151126, 'vnp_TxnRef' => 1562314234, 'vnp_OrderInfo' => time(), 'vnp_IpAddr' => '127.0.0.1', 'vnp_TransactionNo' => 496558, ])->send(); if ($response->isSuccessful()) { // TODO: xử lý kết quả và hiển thị. print $response->getTransactionId(); print $response->getTransactionReference(); var_dump($response->getData()); // toàn bộ data do VNPay gửi về. } else { print $response->getMessage(); }
有关创建请求和VNPay返回时的参数值的更多信息,请参阅 这里。
创建退款请求
$response = $gateway->refund([ 'vnp_Amount' => 10000, 'vnp_TransactionType' => '03', 'vnp_TransDate' => 20190705151126, 'vnp_TxnRef' => 32321, 'vnp_OrderInfo' => time(), 'vnp_IpAddr' => '127.0.0.1', 'vnp_TransactionNo' => 496558, ])->send(); if ($response->isSuccessful()) { // TODO: xử lý kết quả và hiển thị. print $response->getTransactionId(); print $response->getTransactionReference(); var_dump($response->getData()); // toàn bộ data do VNPay gửi về. } else { print $response->getMessage(); }