1. Go to this page and download the library: Download zfhassaan/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/ */
zfhassaan / payfast example snippets
/*
* Package Service Providers...
*/
\zfhassaan\Payfast\PayfastServiceProvider::class,
...
...
$backend_callback = "signature=".$signature."&order_id=".$order_id;
...
...
$payload = array(
'MERCHANT_ID' => $merchant_id, // Merchant ID received from Payfast
'MERCHANT_NAME' => $merchant_name, // Merchant Name registered with Payfast.
'TOKEN' => $ACCESS_TOKEN, // Access Token received from Payfast.
'PROCCODE' => 00, // status code default is 00
'TXNAMT' => $amount, // Transaction Amount or total amount
'CUSTOMER_MOBILE_NO' => $mobile, // Customer Mobile Number
'CUSTOMER_EMAIL_ADDRESS' => $email, // Customer Email address
'SIGNATURE' => $signature, // Signature as described in above step 2.
'VERSION' => 'WOOCOM-APPS-PAYMENT-0.9', // Optional
'TXNDESC' => 'Products purchased from ' .$merchant_name, // Transaction Description to show on website
'SUCCESS_URL' => urlencode($successUrl), // Success URL where to redirect user after success
'FAILURE_URL' => urlencode($failUrl), // Failure URL where to redirect user after failure
'BASKET_ID' => $order_id, // Order ID from Checkout Page.
'ORDER_DATE' => date('Y-m-d H:i:s', time()), // Order Date
'CHECKOUT_URL' => urlencode($backend_callback), // Encrypted Checkout URL
);
use zfhassaan\Payfast\Payfast;
...
...
/**
* Validate Customer and get OTP Screen.
* Step 1
*/
public function checkout(Request $request) {
$payfast = new Payfast();
$response = $payfast->getToken();
if($response != null && $response->code == "00" ){
$payfast->setAuthToken($response->token);
} else {
abort(403, 'Error: Auth Token Not Generated.');
}
$show_otp = $payfast->customer_validate($request->all());
return $show_otp;
}
/**
* Receive 3ds PaRes from Callback.
* This will be called on Callback from OTP Screen.
* You can Show Proceed to Payment Screen or Complete Transaction Screen.
* Step 2
*/
public function callback(Request $request) {
return response()->json($request->all());
}
/**
* Send a request again with Required Params and complete the transaction
* Proceed to Payment and complete Transaction
* Step 3
*/
public function proceed(Request $request) {
$payfast = new Payfast();
$response = $payfast->initiate_transaction($request);
return $response;
}
/**
* Mobile Wallet Account Initiate Transaction
* This is demo function for Easy Paisa.
*
*/
public function payfast(Request $request)
{
$payfast = new Payfast();
$response = $payfast->getToken();
if($response != null && $response->code == "00" ){
$payfast->setAuthToken($response->token);
} else {
abort(403, 'Error: Auth Token Not Generated.');
}
$show_otp = $payfast->wallet($request->all());
return $show_otp;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.