PHP code example of payfast / payfast-common

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

    

payfast / payfast-common example snippets


use Payfast\PayfastCommon\Aggregator\Request\PaymentRequest;

$paymentRequest = new PaymentRequest($testMode);

use Payfast\PayfastCommon\PayfastCommon;

$payfastCommon = new PayfastCommon($testMode);

try {
    $paymentRequest   = new PaymentRequest($merchantId, $encryptionKey);
    $response = $paymentRequest->initiate($data);
} catch (Exceptione $e) {
    echo 'Error initiating payment: ' . $e->getMessage();
}

echo $paymentRequest->getRedirectHTML($payRequestId, $checksum);

try {
    $paymentRequest   = new PaymentRequest($merchantId, $encryptionKey);
    $response = $paymentRequest->query($payRequestId, $reference);
} catch (Exceptione $e) {
    echo 'Error querying transaction: ' . $e->getMessage();
}

// Debug mode
$aggregatorPaymentRequest = new PaymentRequest(true);

// Module parameters for pfValidData
$moduleInfo = [
    "pfSoftwareName"       => 'GravityForms',
    "pfSoftwareVer"        => '2.8.7',
    "pfSoftwareModuleName" => 'PayFast-GravityForms',
    "pfModuleVer"          => '1.5.4',
];
$pfValid = $aggregatorPaymentRequest->pfValidData($moduleInfo, $pfHost, $pfParamString);

// Calling methods on Payfast\PayfastCommon\Aggregator\Request\PaymentRequest
$pfData = $aggregatorPaymentRequest->pfGetData();
$aggregatorPaymentRequest->pflog('Verify data received');