1. Go to this page and download the library: Download sharifur/payfast 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/ */
sharifur / payfast example snippets
/*
|--------------------------------------------------------------------------
| Merchant Settings
|--------------------------------------------------------------------------
| All Merchant settings below are for example purposes only. for more info
| see www.payfast.co.za. The Merchant ID and Merchant Key can be obtained
| from your payfast.co.za account.
|
*/
[
'testing' => true, // Set to false when in production.
'currency' => 'ZAR', // ZAR is the only supported currency at this point.
'merchant' => [
'merchant_id' => env('PF_MERCHANT_ID', '10000100'), // TEST Credentials. Replace with your merchant ID from Payfast.
'merchant_key' => env('PF_MERCHANT_KEY', '46f0cd694581a'), // TEST Credentials. Replace with your merchant key from Payfast.
'return_url' => env('PF_RETURN_URL', 'http://your-domain.co.za/success'), // Redirect URL on Success.
'cancel_url' => env('PF_CANCEL_URL', 'http://your-domain.co.za/cancel'), // Redirect URL on Cancellation.
'notify_url' => env('PF_ITN_URL', 'http://your-domain.co.za/itn'), // ITN URL.
],
];
use Billow\Contracts\PaymentProcessor;
Class PaymentController extends Controller
{
public function confirmPayment(PaymentProcessor $payfast)
{
// Eloqunet example.
$cartTotal = 9999;
$order = Order::create([
'm_payment_id' => '001', // A unique reference for the order.
'amount' => $cartTotal
]);
// Build up payment Paramaters.
$payfast->setBuyer('first name', 'last name', 'email');
$payfast->setAmount($order->amount);
$payfast->setItem('item-title', 'item-description');
$payfast->setMerchantReference($order->m_payment_id);
// Optionally send confirmation email to seller
$payfast->setEmailConfirmation();
$payfast->setConfirmationAddress(env('PAYFAST_CONFIRMATION_EMAIL'));
// Optionally make this a subscription
$payfast->setSubscriptionType(); // will default to 1
$payfast->setFrequency(); // will default to 3 = monthly if not set
$payfast->setCycles(); // will default to 0 = indefinite if not set
// Return the payment form.
return $payfast->paymentForm('Place Order');
}
}
use Billow\Contracts\PaymentProcessor;
Class PaymentController extends Controller
{
public function itn(Request $request, PaymentProcessor $payfast)
{
// Retrieve the Order from persistance. Eloquent Example.
$order = Order::where('m_payment_id', $request->get('m_payment_id'))->firstOrFail(); // Eloquent Example
// Verify the payment status.
$status = $payfast->verify($request, $order->amount, $order->m_payment_id)->status();
// Handle the result of the transaction.
switch( $status )
{
case 'COMPLETE': // Things went as planned, update your order status and notify the customer/admins.
break;
case 'FAILED': // We've got problems, notify admin and contact Payfast Support.
break;
case 'PENDING': // We've got problems, notify admin and contact Payfast Support.
break;
default: // We've got problems, notify admin to check logs.
break;
}
}
}
$cartTotal = 9999; // Laravel Payfast will parse this value and format it accordingly. See sebastianbergmann/money
$payfast->setAmount($cartTotal);
$payfast->paymentForm() // Default Text: 'Pay Now'
$payfast->paymentForm(false) // No submit button, handy for submitting the form via javascript
$payfast->paymentForm('Confirm and Pay') // Override Default Submit Button Text.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.