1. Go to this page and download the library: Download infinitypaul/laravel-cbs 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/ */
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Cbs;
class InvoiceController extends Controller
{
/**
* Redirect the User to Cbs Payment Page
* @return Url
*/
public function redirectToGateway()
{
return Cbs::setInvoice()->redirectNow();
}
/**
* Get The Invoice Information
* @return array
*/
public function getInvoice()
{
return Cbs::setInvoice()->getData();
}
/**
* Obtain Cbs payment information
* @return void
*/
public function handleGatewayCallback()
{
$paymentDetails = Cbs::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
}
}
/**
* This fluent method does all the dirty work of sending a POST request with the form data
* to Cbs Api, then it gets the payment Url and redirects the user to Cbs
* Payment Page. I abstracted all of it, so you don't have to worry about that.
* Just eat your cookies while coding!
*/
Cbs::setInvoice()->redirectNow();
/**
* SetInvoice can also accept an array instead of a request object and you are good to go, it will be in this format
*/
$data = [
"payerID" => "ST-000408",
"amount" => "230",
"description" => "Testing",
"callback" => route('callback'),
"quantity" => "5",
'externalRefNumber' => time()
];
$data = Cbs::setInvoice($data)->getData();
/**
* This fluent method does all the dirty work of verifying that the just concluded transaction was actually valid,
*/
Cbs::getPaymentData();
/**
* This method gets the invoice information generated on Cbs
* @returns array
*/
Cbs::setInvoice()->getData();