PHP code example of kokos-api / kokos-activator-api

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

    

kokos-api / kokos-activator-api example snippets




namespace Example;

use KokosActivatorApi\KokosApiClient;
use KokosActivatorApi\Database\Types\UploadPack;

$client = new KokosApiClient(
    token: '<token>',
);
$client->database->uploadCodes(
    [
        new UploadPack([
            'denomination' => 60,
            'codes' => [
                'r3h4x2Jh2W2853g9g4',
                'Nq7QDWZw2F2eZ4ndZd',
                'Nq7QDHZA2Q2cZ7rdw3',
                'Nq7QDYZa2N22Z0r0vc',
                'Nq7QDDZ72U4738E64c',
            ],
        ]),
    ],
);


use KokosActivatorApi\Exceptions\KokosApiException;
use KokosActivatorApi\Exceptions\KokosException;

try {
    $response = $client->database->uploadCodes(...);
} catch (KokosApiException $e) {
    echo 'API Exception occurred: ' . $e->getMessage() . "\n";
    echo 'Status Code: ' . $e->getCode() . "\n";
    echo 'Response Body: ' . $e->getBody() . "\n";
    // Optionally, rethrow the exception or handle accordingly.
}

use KokosActivatorApi\KokosApiClient;

// Pass any PSR-18 compatible HTTP client implementation.
// For example, using Guzzle:
$customClient = new \GuzzleHttp\Client([
    'timeout' => 5.0,
]);

$client = new KokosApiClient(options: [
    'client' => $customClient
]);

// Or using Symfony HttpClient:
// $customClient = (new \Symfony\Component\HttpClient\Psr18Client())
//     ->withOptions(['timeout' => 5.0]);
//
// $client = new KokosApiClient(options: [
//     'client' => $customClient
// ]);

$response = $client->database->uploadCodes(
    ...,
    options: [
        'maxRetries' => 0 // Override maxRetries at the request level
    ]
);

$response = $client->database->uploadCodes(
    ...,
    options: [
        'timeout' => 3.0 // Override timeout at the request level
    ]
);