PHP code example of giftbalogun / kudaapitoken

1. Go to this page and download the library: Download giftbalogun/kudaapitoken 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/ */

    

giftbalogun / kudaapitoken example snippets


KUDA_API_TOKEN=XXXXXXXXXXXXXXXXXXXX
KUDA_API_URL=XXXXXXXXXXXXXXXXXXXXXX
KUDA_USER_EMAIL=YOUR_EMAIL
ENVIRONMENT_ENV=LIVE_OR_TEST

//simple
$data = [
    'email' => $request->email,
    'phoneNumber' => $request->phone,
    'lastName' => $request->l_name,
    'firstName' => $request->f_name,
    'businessName' => $request->business_name,
    'trackingReference' => $customer_code,
]; # $data is the format for making request to the api 

$ref = rand(); #used to generate randon unique number for the request

//For Pay with Transfer
$data = [
    "Amount"=>5000000,
    "IsFlexiblePayment"=>true, //true or false
    "RemittingAccounts"=>[
    {
        "SplitPercentage"=>50,
        "AccountName"=>"foods",
        "AccountNumber"=>"3020806687"
    },
    {
        "SplitPercentage"=>50,
        "AccountName"=>"foods",
        "AccountNumber"=>"3020808612"
    }
    ]
];


use Giftbalogun\Kudaapitoken\Controllers\KudaBankController;

$this->kudabankservice->create_virtual_account($data, $ref);

use Giftbalogun\Kudaapitoken\Kuda;

$this->kuda->initController('default')->create_virtual_account($data, $ref);
## Controllers 



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Giftbalogun\Kudaapitoken\Controllers\KudaBankController;
use Giftbalogun\Kudaapitoken\Kuda;

class CustomController extends Controller
{
    private $kuda;
    private $kudabankservice;

    public function __construct()
    {
        $this->kudabankservice = new KudaBankController();
        ## Or call from Kuda service
        $this->kuda = new Kuda;
    }

    public function createcustomeraccount()
    {
        $customer_code = '000' . random_int(100000, 999999) . '0000';

        $data = [
            'email' => $request->email,
            'phoneNumber' => $request->phone,
            'lastName' => $request->l_name,
            'firstName' => $request->f_name,
            'businessName' => $request->business_name,
            'trackingReference' => $customer_code,
        ];
        $ref = rand();

        $newcustomeraccount = $this->kudabankservice->create_virtual_account($data, $ref);

        ## Or you can load from the Kuda Service
        
        $newcustomeraccount = $this->kuda->initController('default')->create_virtual_account($data, $ref);
        ## Controllers 



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Giftbalogun\Kudaapitoken\Kuda;

class CustomController extends Controller
{
    private $kuda;
    private $kudabankservice;

    public function __construct()
    {
        ##Kuda service
        $this->kuda = new Kuda;
    }

    public function getadminbalance()
    {
        $data = [];

        $ref = rand();

        ##load from the Kuda Service
        $balance = $this->kuda->initController('KudaBank')->getadminbalance($data, $ref);
        ## Controllers