PHP code example of tamkeen-tech / laravel-payfort

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

    

tamkeen-tech / laravel-payfort example snippets


return [
    'gateway_host' => env('PAYFORT_GATEWAY_HOST', 'https://checkout.payfort.com/'),
    'gateway_sandbox_host' => env('PAYFORT_GATEWAY_SAND_BOX_HOST', 'https://sbcheckout.payfort.com/'),

    'merchants' => [
        'default' => [
            'merchant_identifier' => env('PAYFORT_MERCHANT_IDENTIFIER', null),
            'access_code' => env('PAYFORT_ACESS_CODE', null),
            'SHA_request_phrase' => env('PAYFORT_SHAR_REQUEST_PHARSE', null),
            'SHA_response_phrase' => env('PAYFORT_SHAR_RESPONSE_PHRASE', null),
        ],
    ],

    'sandbox_mode' => env('PAYFORT_SANDBOX_MODE', true),
    'SHA_type' => env('PAYFORT_SHA_TYPE', 'sha256'),
    'language' => env('PAYFORT_LANGUAGE', 'en'),
];

Payfort::tokenization(
    1000, # Bill amount
    'redirect_url', # the recirect to url after tokenization
    true # either to return form html or not (optional)
);

$response = Payfort::purchase(
    [],  # Request body coming from the tokenization
    100, # Bill amount
    '[email protected]', # User email
    'redirect_url', # The return back url after purchase
    [] # installment data (optional)
);

$response = Payfort::authorize(
    [],  # Request body coming from the tokenization
    100, # Bill amount
    '[email protected]', # User email
    'redirect_url' # The return back url after purchase
);

if ($response->should3DsRedirect()) {
    return redirect()->away($response->get3DsUri());
}

$response->getResponseFortId();

$response->getResponsePaymentMethod()

Payfort::processResponse(
    [] # the response array
);

$response->getResponseFortId();

$response->getResponsePaymentMethod()

Payfort::capture(
    'fort_id', # fort id for the payment transaction
    100.0 # bill amount
);

Payfort::void(
    'fort_id' # fort id for the payment transaction
);

Payfort::refund(
    'fort_id', # fort id for the payment transaction
    1000 # amount to be reunded must not exceed the bill amount
);

Payfort::setMerchantExtra('test')->tokenization(
    1000, # Bill amount
    'redirect_url', # the recirect to url after tokenization
    true # either to return form html or not (optional)
);

Payfort::applePay(
    [], # fort params (please make sure to match the fort params mentioned below)
    1000, # bill amount
    '[email protected]', # User email
    'PURCHASE', # command to be sent to apple pay either PURCHASE or AUTHORIZE
);

[
    "paymentData" => [
        "data" => "apple_data",
        "header" => [
            'ephemeralPublicKey' => 'apple_ephemeralPublicKey',
            'publicKeyHash' => 'apple_publicKeyHash',
            'transactionId' => 'apple_transactionId',
        ],
        "signature" => "signature",
    ],
    "paymentMethod" => [
        'displayName' => 'apple_displayName',
        'network' => 'apple_network',
        'type' => 'apple_type',
    ],
]

$log = app(PayfortLog::class);

$log->contract_id = data_get($event->request, 'merchant_extra', data_get($event->response, 'merchant_extra', null));

if (isset($event->response['card_number'])) {
    $last_four_digits = substr($event->response['card_number'], -4);
    $log->card_number = '************'.$last_four_digits;
}

if (isset($event->response['amount'])) {
    $log->amount = floatval($event->response['amount'] / 100);
}

if (isset($event->response['response_message'])) {
    $log->response_message = data_get($event->response, 'response_message');
}

if (isset($event->response['merchant_reference'])) {
    $log->merchant_reference = $event->response['merchant_reference'];
}

if (isset($event->request['merchant_reference'])) {
    $log->merchant_reference = $event->request['merchant_reference'];
}

$log->fort_id = data_get($event->response, 'fort_id');
$log->payment_option = data_get($event->response, 'payment_option');
$log->command = data_get($event->response, 'command', data_get($event->response, 'service_command'));
$log->response_code = data_get($event->response, 'response_code');

$log->request = $event->request ? json_encode($event->request) : "";
$log->response = json_encode($event->response);

$log->save();
bash
php artisan vendor:publish --tag payfort-config