PHP code example of rainwaves / payfast-payment
1. Go to this page and download the library: Download rainwaves/payfast-payment 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/ */
rainwaves / payfast-payment example snippets
composer
$config = array('merchant_id' => 10000100,
'merchant_key'=> env('MERCHANT_KEY', '46f0cd694581a'),
'env'=> 'local',
'return_url'=> 'https://www.example.com/success',
'cancel_url'=> 'https://www.example.com/cancel',
'notify_url'=> 'https://www.example.com/notify',
'pass_phrase' => 'jt7NOE43FZPn',
);
$input = array(
'amount' => 100.00,
'item_name' => 'Test Product',
'name_first' => 'First Name',
'name_last' => 'Last Name',
'email_address'=> '[email protected] ',
'm_payment_id' => '1234',
'email_confirmation' => true,
);
$payFast = new PayFast($config);
echo $payFast->makePaymentWithAForm($input)->createForm();
use Illuminate\Http\Request;
use rainwaves\PayfastPayment\PayFast;
class PaymentController extends Controller
{
public function makePayment(Request $request)
{
$config = [
'merchant_id' => config('payfast.merchant_id'),
'merchant_key' => config('payfast.merchant_key'),
'env' => config('payfast.env'),
'return_url' => config('payfast.return_url'),
'cancel_url' => config('payfast.cancel_url'),
'notify_url' => config('payfast.notify_url'),
'pass_phrase' => config('payfast.pass_phrase'),
];
$input = [
'amount' => 100.00,
'item_name' => 'Test Product',
'name_first' => $request->input('name_first'),
'name_last' => $request->input('name_last'),
'email_address' => $request->input('email'),
'm_payment_id' => '1234',
'email_confirmation' => true,
];
$payFast = new PayFast($config);
return $payFast->makePaymentWithAForm($input)->createForm();
}
}