PHP code example of midoelhawy / laravel-payfort

1. Go to this page and download the library: Download midoelhawy/laravel-payfort library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

midoelhawy / laravel-payfort example snippets


'providers' => [
    // Other service providers...
    LaravelPayfort\Providers\PayfortServiceProvider::class,
],

'Payfort' => LaravelPayfort\Facades\Payfort::class

return Payfort::redirection()->displayRedirectionPage([
    'command' => 'AUTHORIZATION',              # AUTHORIZATION/PURCHASE according to your operation.
    'merchant_reference' => 'ORDR.'.rand(10000,100000),   
    'amount' => 3501.35,                           
    'currency' => 'SAR',                      
    'customer_email' => '[email protected]',  
    'payment_option' => 'VISA', //Mada and others types 
    "language"=>'ar',
    'return_url'=>"https://expm.com/response"
]);

return Payfort::redirection()->displayTokenizationPage([
    'merchant_reference' => 'ORDR.34562134',   # You reference id for this operation (Order id for example).
]); 

$checkpayfort->captureOperationByFortId(
                [
                    "fort_id"=>$payfort_return["fort_id"],
                    "merchant_reference"=>$payfort_return["merchant_reference"],
                    "amount"=>3501.35,//your amount to capture (max : the authraized amount)
                    "currency"=>"SAR",
                ]
);

$ php artisan vendor:publish --provider "LaravelPayfort\Providers\PayfortServiceProvider"

use LaravelPayfort\Traits\PayfortResponse as PayfortResponse;

class PayfortOrdersController extends Controller{
    use PayfortResponse;
    
    public function processReturn(Request $request){
        $payfort_return = $this->handlePayfortCallback($request);
        $checkpayfort =new PayfortAPI(config('payfort'));
        $checkStatus = $checkpayfort->checkOrderStatusByFortId($payfort_return["fort_id"]);
        if($checkStatus->isSuccess()){
            return $checkStatus->getResponse();//return payfort json array 
        }
        
        if($payfort_return["command"] == "AUTHORIZATION"){
            $captureAuthorizaPymnt = $checkpayfort->captureOperationByFortId(
                [
                    "fort_id"=>$payfort_return["fort_id"],
                    "merchant_reference"=>$payfort_return["merchant_reference"],
                    "amount"=>3501.35,//your amount to capture (max : the authraized amount)
                    "currency"=>"SAR",
                ]
            );
            
            if($captureAuthorizaPymnt->isSuccess()){
                //success payment
            }
            //....
            
        }
        
    }
}