1. Go to this page and download the library: Download shubhamc4/cgrate-php 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/ */
shubhamc4 / cgrate-php example snippets
$config = [
'username' => 'your-username', // Required
'password' => 'your-password', // Required
'endpoint' => 'https://543.cgrate.co.zm/Konik/KonikWs?wsdl', // Production endpoint
'testEndpoint' => 'http://test.543.cgrate.co.zm:55555/Konik/KonikWs?wsdl', // Test endpoint
'testMode' => false, // Set to true for test environment
'options' => [ // SOAP client options
'soap_version' => SOAP_1_1,
'connection_timeout' => 30,
'keep_alive' => false,
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => true,
'trace' => false, // Set to true for test environment
],
];
$client = new \CGrate\Php\Services\CGrateService($config);
use CGrate\Php\Config\CGrateConfig;
use CGrate\Php\Services\CGrateService;
// Create config with username, password and test mode (optional)
$config = CGrateConfig::create(
username: 'your-username',
password: 'your-password',
testMode: true
);
$client = new CGrateService($config);
// Generate a reference with the default prefix 'CG'
$reference = \CGrate\Php\Services\CGrateService::generateTransactionReference();
// Result: CG-1714504562-a1b2c3d4e5f6
// Generate a reference with a custom prefix
$reference = \CGrate\Php\Services\CGrateService::generateTransactionReference('ORDER');
// Result: ORDER-1714504562-a1b2c3d4e5f6
// Get issuer name using the the customer account
$issuerName = \CGrate\Php\Services\CGrateService::getCustomerIssuerName('26097XXXXXXX');
// Result: Airtel
$issuerName = \CGrate\Php\Services\CGrateService::getCustomerIssuerName('26076XXXXXXX');
// Result: MTN
$issuerName = \CGrate\Php\Services\CGrateService::getCustomerIssuerName('26095XXXXXXX');
// Result: Zamtel
$issuerName = \CGrate\Php\Services\CGrateService::getCustomerIssuerName('26065XXXXXXX');
// Result: Unknown Issuer
use CGrate\Php\Enums\ResponseCode;
// Check if a response matches a specific code
if ($response->responseCode->is(ResponseCode::SUCCESS)) {
// Handle successful response
}
// Get the description for any response code
$description = ResponseCode::descriptionFromValue(0); // "Success"
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.