1. Go to this page and download the library: Download kalkulus/thetellara 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 Kalkulus\Thetellara\Thetellara;
use Illuminate\Support\Facades\Redirect;
class PaymentController extends Controller
{
/**
* Redirect the User to Theteller Payment Page
* @return Url
*/
public function redirectToGateway()
{
$transactionId = mt_rand(100000000000,999999999999); // Must be unique for all transactions...
// You may use the function I wrote below for unique transaction id `genTransactionId()`
// In that case you keep track of the transaction IDs in payments table in the database.
// Hence call it as $transactionId = $this->genTransactionId();
$email = request()->input('email'); //Customer email
$amount = request()->input('amount');; //Amount with is in pesewas. So 200 is actually GHS 2.00
$desc = request()->input('desc');
try{
$theteller = new Thetellara();
$response = $theteller->initialize($transactionId, $email, $amount, $desc);
return redirect($response->checkout_url);
}catch(\Exception $e) {
return Redirect::back()->withMessage(['error'=>'The transaction has expired']);
}
}
/**
* Get Theteller payment information
* @return void
*/
public function handleGatewayCallback()
{
$theteller = new Thetellara();
$response = $theteller->getPaymentDetails();
dd($response);
// Now you have the payment details,
// you can then redirect or do whatever you want
}
/**
* Get unique transaction ID
* @return string
*/
private function genTransactionId(){
$this->transactionId = [
'transactionId' => mt_rand(100000000000,999999999999)
];
$rules = ['transactionId' => 'unique:payments'];
$validate = Validator::make($this->transactionId, $rules)->passes();
return $validate ? $this->transactionId['transactionId'] : $this->genTransactionId();
}
}