1. Go to this page and download the library: Download jayboss/paystack 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/ */
// Laravel 10.x and above
//import PaymentController class at the top
Route::post('/pay', [PaymentController::class, 'redirectToGateway'])->name('pay');
Route::get('/payment/callback', [PaymentController::class, 'handleGatewayCallback']);
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;
use Jayboss\Paystack\Paystack;
class PaymentController extends Controller
{
/**
* Redirect the User to Paystack Payment Page
* @return Url
*/
public function redirectToGateway()
{
try{
$paystack = new Paystack();
return $paystack->getAuthorizationUrl()->redirectNow();
}catch(\Exception $e) {
return Redirect::back()->withMessage(['msg'=>'The paystack token has expired. Please refresh the page and try again.', 'type'=>'error']);
}
}
/**
* Obtain Paystack payment information
* @return void
*/
public function handleGatewayCallback()
{
$paystack = new Paystack();
$paymentDetails = $paystack->getPaymentData();
dd($paymentDetails);
// Now you have the payment details,
// you can store the authorization_code in your db to allow for recurrent subscriptions
// you can then redirect or do whatever you want
}
}
/**
* In the case where you need to pass the data from your
* controller instead of a form
* Make sure to send:
* eference" => '4g4g5485g8545jg8gj',
"email" => '[email protected]',
"currency" => "NGN",
"orderID" => 23456,
);
return $paystack->getAuthorizationUrl($data)->redirectNow();
public function test()
{
$paystack = new Paystack();
$ref = $paystack->genTranxRef();
return view('welcome',compact('ref'));
}