大卫-马克西莫斯 / fawrypay
Laravel 对 FawryPay 的支付助手
1.0.2
2024-08-22 02:44 UTC
Requires
- php: >=7.0
- ext-curl: *
- ext-json: *
- laravel/framework: >=6.0
README
FawryPay/Lawry Accept 的 Laravel 支付助手
支持的方法
- 通过参考代码支付
- 通过信用卡/借记卡支付
- 通过移动钱包支付
安装
composer require david-maximous/fawrypay
发布供应商文件
php artisan vendor:publish --tag="fawrypay-config" php artisan vendor:publish --tag="fawrypay-lang" //or use all for all configrations php artisan vendor:publish --tag="fawrypay-all"
fawrypay.php 配置文件
<?php return [ 'FAWRY_URL' => env('FAWRY_URL', "https://atfawry.fawrystaging.com/"), //https://www.atfawry.com/ for production 'FAWRY_SECRET' => env('FAWRY_SECRET'), 'FAWRY_MERCHANT' => env('FAWRY_MERCHANT'), 'VERIFY_ROUTE_NAME' => "verify-payment", //Route name for the payment verify route 'APP_NAME'=>env('APP_NAME'), ];
如何创建支付请求
use DavidMaximous\Fawrypay\Classes\FawryPayment; $payment = new FawryPayment(); //pay function $response = $payment->pay( $amount, $user_id, $user_name, $user_email, $user_phone, $language, $method, $item, $quantity, $description, $itemImage ); //or use $response = $payment->setUserId($user_id) ->setUserName($user_full_name) ->setUserEmail($user_email) ->setUserPhone($user_phone) ->setMethod($method) //Optional, Use PayAtFawry/MWALLET/CARD ->setLanguage($language) //Optional, Default is en-gb ->setItem($item_name) //Optional, Default is 1 ->setQuantity($quantity) //Optional, Default is 1 ->setDescription($description) //Optional ->setItemImage($image_url) //Optional ->setAmount($amount) ->pay(); dd($response); //pay function response [ 'payment_id'=>"", // refrence code that should stored in your orders table 'redirect_url'=>"", // redirect url to the payment page ]
如何创建验证请求
- 仅使用以下方法之一
- 服务器通知(Webhook/回调请求)[推荐]
use DavidMaximous\Fawrypay\Classes\FawryVerify; //This method is used for sending the payment status directly to your server, better for payment methods that have pending status (Pay by Reference Code) to get updated when it's paid $verify = new FawryVerify(); //verify callback function $response = $payment->verifyCallback($verify); dd($response); //Success/Paid output [ 'success'=>true,//or false 'payment_id'=>"PID", 'message'=>"Done Successfully",//message for client 'process_data'=>""//fawry response ]
Web.php 必须有名为“verify-payment”的路由,还有一个用于回调的路由
Route::get('/payments/verify/{payment?}',[PaymentController::class,'payment_verify'])->name('verify-payment'); //Should redirect a user to a pending/confirmation page after finishing the payment Route::post('/payments/Callback',[PaymentController::class,'verifyCallback'])->name('verify-payment-callback'); //This route should be provided to Fawry in order to use it as your notification endpoint
- 获取支付状态(手动验证)
use DavidMaximous\Fawrypay\Classes\FawryVerify; //This method is for verifying payment after the user gets redirected back to your website, should be used inside the verify route function $verify = new FawryVerify(); //verify function $response = $payment->verify($verify); dd($response); //outputs [ 'success'=>true,//or false 'payment_id'=>"PID", 'message'=>"Done Successfully",//message for client 'process_data'=>""//fawry response ] //For manually checking the payment status, please use the following method $response = $payment->getPaymentStatus($payment_id); dd($response); //outputs [ 'status'=>"PAID", //or New, CANCELED, REFUNDED, EXPIRED, PARTIAL_REFUNDED, FAILED 'process_data'=>""//fawry response ]
Web.php 必须有名为“verify-payment”的路由
Route::get('/payments/verify/{payment?}',[PaymentController::class,'payment_verify'])->name('verify-payment'); //In this case the user should be redirected to a verify function that calls the verify function mentioned above
更多信息,请查看官方文档
安全
如果您发现任何安全相关的问题,请通过电子邮件 security@davidmaximous.me 而不是使用问题跟踪器。