PHP code example of prosperoking / kudaopenapi

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

    

prosperoking / kudaopenapi example snippets





use Prosperoking\KudaOpenApi\KudaOpenApiV2;

$email = "[email protected]"
// You can generate this on the developer dashboard
$apiKey = 'xxxxxxxxxxx';

// initialize the object and pass the path or string of your key in pem format
$openApi = KudaOpenApiV2::initLive($email, $apiKey);
// And for test environment 
$openApi = KudaOpenApiV2::initTest($email, $apiKey);

// You can also Use the constructor
$openApi = new KudaOpenApiV2($email,$openApi, null, $baseUrl )
    
try {
    // this will return the account NIBBS information
    var_dump($openApi->getAccountInfo([
        'beneficiaryAccountNumber'=> '1115744617',
        'beneficiaryBankCode'=>'999058',
    ]));

} catch (\Exception $th) {
    var_dump($th->getMessage());
}

use Prosperoking\KudaOpenApi\Contracts\IAuthCacheDriver
class MyAwesomeCacheDriver implements IAuthCacheDriver {
    public function setAuthToken(string $value): bool
    {
        // You may decide to encrypt  the value before saving it
        return Cache::set('kuda_key', $value, now()->addMinutes(12);
    }
    public function getAuthToken(): ?string
    {
        // And Decrypt it here before returning it 
        return Cache::get('kuda_key');
    }
}




use Prosperoking\KudaOpenApi\KudaOpenApiV2;

$email = "[email protected]"
// You can generate this on the developer dashboard
$apiKey = 'xxxxxxxxxxx';

// init your cache driver 
$myCacheDriver = new MyAwesomeCacheDriver()

// initialize the object and pass the path or string of your key in pem format
$openApi = KudaOpenApiV2::initLive($email, $apiKey, $myCacheDriver);
// And for test environment 
$openApi = KudaOpenApiV2::initTest($email, $apiKey, $myCacheDriver);

// You can set the cache driver using the set cache driver method

$openApi->setCacheDriver($myCacheDriver);

// You can also Use the constructor
$openApi = new KudaOpenApiV2($email,$openApi, $myCacheDriver, $baseUrl )




use Prosperoking\KudaOpenApi\KudaOpenApi;

$client = "your_client_id_here"
$baseUrl = 'https://sandbox.kudabank.com/v1';

// initialize the object and pass the path or string of your key in pem format
$openApi = new KudaOpenApi(
    __DIR__.'/private.pem',
    __DIR__.'/public.pem',
    
try {
    // this will return the account NIBSS information
    var_dump($openApi->getAccountInfo([
        'beneficiaryAccountNumber'=> '1115744617',
        'beneficiaryBankCode'=>'999058',
    ]));
    
    // or You can make use of makeRequest method
    $payload = [
        'beneficiaryAccountNumber'=> '1115744615',
        'beneficiaryBankCode'=>'999058'
    ];
    $requestRef= "myunique_identifier"
    // this will return the account information
    var_dump($openApi->makeRequest(
        ServiceTypes::NAME_ENQUIRY,
        $payload,
        $requestRef
    ));

} catch (\Exception $th) {
    var_dump($th->getMessage());
}



use Prosperoking\KudaOpenApi\KudaOpenApi;
use Prosperoking\KudaOpenApi\ServiceTypes;

$client = "your client id here"
$baseUrl = 'https://sandbox.kudabank.com/v1';
// initialize the object and pass the path or string of your key in pem format
$openApi = new KudaOpenApi(
    __DIR__.'/private.pem',
    __DIR__.'/public.pem',
    $clientId,
    $baseUrl
);
try {
    $payload = [
        'beneficiaryAccountNumber'=> '1115744615',
        'beneficiaryBankCode'=>'999058'
    ];
    $requestRef= "myunique_identifier"
    // this will return the account information
    var_dump($openApi->makeRequest(
        ServiceTypes::NAME_ENQUIRY,
        $payload,
        $requestRef
    ));

} catch (\Exception $th) {
    var_dump($th->getMessage());
}