PHP code example of rrcatto / ikhokha-php-sdk

1. Go to this page and download the library: Download rrcatto/ikhokha-php-sdk 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/ */

    

rrcatto / ikhokha-php-sdk example snippets




khokha\Client;
use Ikhokha\Exception\HttpException;
use Ikhokha\Exception\IkhokhaException;

$client = new Client(
    'YourAppIDHere',      // IK-APPID
    'YourAppSecretHere',  // AppSecret
    'APPID123'            // entityID / Application key ID
);

$payload = [
    'amount'                => 10000, // R100.00
    'currency'              => 'ZAR',
    'requesterUrl'          => 'https://example.com/requester',
    'mode'                  => 'live',
    'description'           => 'Cape Motorcycle Adventures – Suzuki DS250 rental',
    'externalTransactionID' => 'CMA-2025-0001',
    'urls' => [
        'callbackUrl'    => 'https://yourdomain/api/ikhokha/webhook',
        'successPageUrl' => 'https://yourdomain/payment/success',
        'failurePageUrl' => 'https://yourdomain/payment/failure',
        'cancelUrl'      => 'https://yourdomain/payment/cancel',
    ],
];

try {
    $response   = $client->createPaymentLink($payload);
    $paylinkUrl = $response['paylinkUrl'] ?? null;

    // Redirect or show link/button to $paylinkUrl
} catch (HttpException $e) {
    // Handle HTTP errors from Ikhokha
} catch (IkhokhaException $e) {
    // Handle client-side errors
}

$f3->set('IKHOKHA.APP_ID',     'YourAppIDHere');
$f3->set('IKHOKHA.APP_SECRET', 'YourAppSecretHere');
$f3->set('IKHOKHA.ENTITY_ID',  'APPID123');
$f3->set('IKHOKHA.BASE_URL',   'https://api.ikhokha.com'); // optional

$f3->route('POST /api/paylink', function($f3) {
    $svc     = \Ikhokha\F3\Service::instance();
    $payload = json_decode($f3->get('BODY'), true) ?: [];
    $result  = $svc->createPaymentLink($payload);

    header('Content-Type: application/json');
    echo json_encode($result);
});

$f3->route('POST /api/ikhokha/webhook', function($f3) {
    $rawBody = $f3->get('BODY');
    $headers = getallheaders();

    // Here you could verify ik-sign if you want, reusing the same signing logic.
    $payload = json_decode($rawBody, true) ?: [];

    // TODO: store $payload['status'], $payload['paylinkID'], $payload['externalTransactionID'], etc.
    http_response_code(200);
    echo 'OK';
});
bash
composer