david-maximous / fawrypay
Laravel Payment helper for FawryPay
1.0.2
2024-08-22 02:44 UTC
Requires
- php: >=7.0
- ext-curl: *
- ext-json: *
- laravel/framework: >=6.0
README
Laravel Payment Helper for FawryPay/Fawry Accept
Supported methods
- Pay By Reference Code
- Pay By Credit/Debit Card
- Pay By Mobile Wallet
Installation
composer require david-maximous/fawrypay
Publish Vendor Files
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 config file
<?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'), ];
How To Make payment request
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 ]
How To Make verify request
- Use only one of the following methods:
- Server Notifications (Webhook/Callback Request) [Recommended]
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 MUST Have Route with name “verify-payment” and another route for Callback
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
- Get Payment Status (Manual Verification)
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 MUST Have Route with name “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
For more information, please check the official documentation
Security
If you discover any security-related issues, please email security@davidmaximous.me instead of using the issue tracker.