PHP code example of sevaske / payfort

1. Go to this page and download the library: Download sevaske/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/ */

    

sevaske / payfort example snippets


return [
    'sandbox_mode' => env('PAYFORT_SANDBOX_MODE', true),
    'log_channel' => env('PAYFORT_LOG_CHANNEL', 'stack'),
    'debug_mode' => env('PAYFORT_DEBUG_MODE', false),
    'language' => env('PAYFORT_LANGUAGE', 'en'), // en|ar
    'enable_requests_validation' => env('PAYFORT_ENABLE_REQUESTS_VALIDATION', true),
    'merchants' => [
        'default' => [
            'merchant_identifier' => env('PAYFORT_MERCHANT_IDENTIFIER'),
            'access_code' => env('PAYFORT_ACCESS_CODE'),
            'sha_request_phrase' => env('PAYFORT_SHA_REQUEST_PHRASE'),
            'sha_response_phrase' => env('PAYFORT_SHA_RESPONSE_PHRASE'),
            'sha_type' => env('PAYFORT_SHA_TYPE', 'sha256'),
        ],
        'apple' => [
            'merchant_identifier' => env('PAYFORT_APPLE_MERCHANT_IDENTIFIER'),
            'access_code' => env('PAYFORT_APPLE_ACCESS_CODE'),
            'sha_request_phrase' => env('PAYFORT_APPLE_SHA_REQUEST_PHRASE'),
            'sha_response_phrase' => env('PAYFORT_APPLE_SHA_RESPONSE_PHRASE'),
            'sha_type' => env('PAYFORT_APPLE_SHA_TYPE', 'sha256'),
        ],
        // multiple merchants can be added here
    ],
];

use \Sevaske\Payfort\Exceptions\PayfortMerchantCredentialsException;
use \Sevaske\Payfort\Exceptions\PayfortRequestException;
use \Sevaske\Payfort\Exceptions\PayfortResponseException;
use \Sevaske\Payfort\Http\PayfortSignature;
use \Sevaske\Payfort\Http\PayfortResponse;
use \Sevaske\Payfort\Payfort;

try {
    $response = Payfort::merchant('default')
        ->api()
        ->checkStatus(merchantReference: 'ORDER-123456') // PayfortResponse
        ->getData(); // array
} catch (PayfortMerchantCredentialsException $exception) {
    // handle
} catch (PayfortRequestException $exception) {
    // handle
} catch (PayfortResponseException $exception) {
    // handle
}

// also
 Payfort::merchant('default')->api()->capture();
 Payfort::merchant('default')->api()->checkStatus();
 Payfort::merchant('default')->api()->createToken();
 Payfort::merchant('default')->api()->recurring();
 Payfort::merchant('default')->api()->refund();
 Payfort::merchant('default')->api()->updateToken();
 Payfort::merchant('default')->api()->voidAuthorization();

// custom request
Payfort::http()->request('POST', '/FortAPI/paymentApi', []);

// signature
$signature = (new PayfortSignature(shaPhrase: '', shaType: 'sha256'))
    ->calculateSignature([]);

bash
php artisan vendor:publish --tag="payfort-config"