PHP code example of payfastsdk / payfast-php-sdk
1. Go to this page and download the library: Download payfastsdk/payfast-php-sdk 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/ */
payfastsdk / payfast-php-sdk example snippets
try {
$payfast = new PayFastPayment(
[
'merchantId' => '10000100',
'merchantKey' => '46f0cd694581a',
'passPhrase' => '',
'testMode' => true
]
);
$data = [
'amount' => '100.00',
'item_name' => 'Order#123'
];
echo $payfast->custom->createFormFields($data, ['value' => 'PAY NOW', 'class' => 'btn']);
} catch(Exception $e) {
echo 'There was an exception: '.$e->getMessage();
}
try {
$payfast = new PayFastPayment(
[
'merchantId' => '10000100',
'merchantKey' => '46f0cd694581a',
'passPhrase' => '',
'testMode' => false
]
);
$data = [
'amount' => '100.00',
'item_name' => 'Order#123'
];
// Generate payment identifier
$identifier = $payfast->onsite->generatePaymentIdentifier($data);
if($identifier!== null){
echo '<script type="text/javascript">window.payfast_do_onsite_payment({"uuid":"'.$identifier.'"});</script>';
}
} catch(Exception $e) {
echo 'There was an exception: '.$e->getMessage();
}
try {
$api = new PayFastApi(
[
'merchantId' => '10018867',
'passPhrase' => '2uU_k5q_vRS_',
'testMode' => true
]
);
$fetchArray = $api->subscriptions->fetch('2afa4575-5628-051a-d0ed-4e071b56a7b0');
$pauseArray = $api->subscriptions->pause('2afa4575-5628-051a-d0ed-4e071b56a7b0', ['cycles' => 1]);
$unpauseArray = $api->subscriptions->unpause('2afa4575-5628-051a-d0ed-4e071b56a7b0');
$cancelArray = $api->subscriptions->cancel('2afa4575-5628-051a-d0ed-4e071b56a7b0');
$updateArray = $api->subscriptions->update('2afa4575-5628-051a-d0ed-4e071b56a7b0', ['cycles' => 1]);
$adhocArray = $api->subscriptions->adhoc('290ac9a6-25f1-cce4-5801-67a644068818', ['amount' => 500, 'item_name' => 'Test adhoc']);
} catch(Exception $e) {
echo 'There was an exception: '.$e->getMessage();
}
try {
$api = new PayFastApi(
[
'merchantId' => '10018867',
'passPhrase' => '2uU_k5q_vRS_',
'testMode' => true
]
);
$rangeArray = $api->transactionHistory->range(['from' => '2020-08-01', 'to' => '2020-08-07']);
$dailyArray = $api->transactionHistory->daily(['date' => '2020-08-07']);
$weeklyArray = $api->transactionHistory->weekly(['date' => '2020-08-07']);
$monthlyArray = $api->transactionHistory->monthly(['date' => '2020-08']);
} catch(Exception $e) {
echo 'There was an exception: '.$e->getMessage();
}
try {
$api = new PayFastApi(
[
'merchantId' => '10018867',
'passPhrase' => '2uU_k5q_vRS_',
'testMode' => true
]
);
$creditCardArray = $api->creditCardTransactions->fetch('1124148');
} catch(Exception $e) {
echo 'There was an exception: '.$e->getMessage();
}
bash
composer