ommani/payment-vnpay
Composer 安装命令:
composer require ommani/payment-vnpay
包简介
Thư viện hổ trợ tích hợp cổng thanh toán VNPay.
README 文档
README
ommani: VNPay
Cài đặt
composer require ommani/payment-vnpay
Cách sử dụng
Khởi tạo gateway:
use Omnipay\Omnipay; $gateway = Omnipay::create('VNPay'); $gateway->initialize([ 'vnp_TmnCode' => 'Do VNPay cấp', 'vnp_HashSecret' => 'Do VNPay cấp', ]);
Gateway khởi tạo ở trên dùng để tạo các yêu cầu xử lý đến VNPay hoặc dùng để nhận yêu cầu do VNPay gửi đến.
Tạo yêu cầu thanh toán:
$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 }
Kiểm tra thông tin vnp_ReturnUrl khi khách được VNPay redirect về:
$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(); }
Kham khảo thêm các tham trị khi VNPay trả về tại đây.
Kiểm tra thông tin IPN do VNPay gửi sang:
$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(); }
Kham khảo thêm các tham trị khi VNPay gửi sang tại đây.
Kiểm tra trạng thái giao dịch:
$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(); }
Kham khảo thêm các tham trị khi tạo yêu cầu và VNPay trả về tại đây.
Yêu cầu hoàn tiền:
$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(); }
统计信息
- 总下载量: 72
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-22