mtgofa / laravel-fawrypay
Laravel FawryPay在线支付网关包
1.2
2024-01-25 20:54 UTC
Requires
- php: >=5.4
- laravel/framework: ^6.0|^7.0|^8.0|^9.0|^10.0
This package is auto-updated.
Last update: 2024-09-25 22:21:11 UTC
README
一个Laravel在线支付网关。
安装
通过composer要求
composer require mtgofa/laravel-fawrypay
运行此命令以生成FawryPay配置文件
php artisan vendor:publish --provider="MTGofa\FawryPay\FawryPayServiceProvider"
任何方法都会从config/fawrypay.php
文件获取凭据,所以在发送任何请求之前,请填写merchant_code
和secure_key
。
config/fawrypay.php
<?php return [ /* |-------------------------------------------------------------------------- | FawryPay Enviroment |-------------------------------------------------------------------------- | | should be on of this ('TEST','LIVE'). | */ 'enviroment' => 'TEST', /* |-------------------------------------------------------------------------- | FawryPay Credentials (Test) |-------------------------------------------------------------------------- | | use your fawrypay test credentials | */ 'merchant_code_test' => '', 'secure_key_test' => '', /* |-------------------------------------------------------------------------- | FawryPay Credentials (LIVE) |-------------------------------------------------------------------------- | | use your fawrypay live credentials | */ 'merchant_code' => '', 'secure_key' => '', /* |-------------------------------------------------------------------------- | FawryPay Expiry |-------------------------------------------------------------------------- | | use 1 for one hour, 24 for one day, 72 for 3 days and etc | */ 'expiry_in_hours' => '72', ];
如何使用
生成Fawry支付URL
use MTGofa\FawryPay\FawryPay; public function generate(){ $fawryPay = new FawryPay; //optional if you have the customer data $fawryPay->customer([ 'customerProfileId' => '1', 'name' => 'Mohamed Tarek', 'email' => 'example@site.com', 'mobile' => '010******', ]); //you can add this method info foreach if you have multible items $fawryPay->addItem([ 'productSKU' => '1', //item id 'description' => 'Order 100001 Invoice', //item name 'price' => '50.00', //item price 'quantity' => '1', //item quantity ]); //generatePayURL('your order unique id','your order discription','success url','failed url') $pay_url = $fawryPay->generatePayURL('100001','Order 100001 Invoice','http://success_url','http://failed_url'); return redirect($pay_url); }
重定向响应 / 回调响应 / 检查状态
use MTGofa\FawryPay\FawryPay; public function callback(){ $ref_id = NULL; if(request('merchantRefNum')){ //fawry failed $ref_id = request('merchantRefNum'); } elseif(request('MerchantRefNo')){ //fawry ipn $ref_id = request('MerchantRefNo'); } elseif(request('chargeResponse')){ //fawry response is success $chargeResponse = json_decode(request('chargeResponse')); $ref_id = isset($chargeResponse->merchantRefNumber)?$chargeResponse->merchantRefNumber:NULL; } if(!$ref_id) return abort('404'); $response = (new FawryPay)->checkStatus($ref_id); if (isset($response->paymentStatus) and $response->paymentStatus=='PAID') { //paid dd('Paid Successfully',$response); } else { dd($response); } }
别忘了从csrf token执行回调路由
<?php namespace App\Http\Middleware; use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware; class VerifyCsrfToken extends Middleware { /** * The URIs that should be excluded from CSRF verification. * * @var array */ protected $except = [ '/your_callback_url_here' ]; }