PHP code example of dansleboby / voipms-php-client

1. Go to this page and download the library: Download dansleboby/voipms-php-client 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/ */

    

dansleboby / voipms-php-client example snippets




zleHttp\Client as GuzzleClient;
use Monolog\Logger; // Or any PSR-3 compliant logger
use Monolog\Handler\StreamHandler;
use VoipMs\Client\Service\Client;
use VoipMs\Client\Exception\ApiException;
use VoipMs\Client\Exception\HttpException;
use VoipMs\Client\Exception\JsonException;

// Create a Guzzle client
$guzzleClient = new GuzzleClient([
    'base_uri' => Client::BASE_URI, // Optional: Guzzle base URI
]);

// Create a logger (example using Monolog)
$logger = new Logger('voipms-client');
$logger->pushHandler(new StreamHandler('path/to/your/log/file.log', Logger::DEBUG));

// Your VoIP.ms API credentials
$apiUsername = 'your_api_username';
$apiPassword = 'your_api_password';

// Instantiate the VoIP.ms Client
$voipMsClient = new Client($guzzleClient, $logger, $apiUsername, $apiPassword);

// Example: Get account balance
try {
    $params = [
        // Add any specific parameters for the getBalance method if ins the raw HTTP response body
} catch (JsonException $e) {
    // Handle errors during JSON decoding of the API response
    echo "JSON Decode Error: " . $e->getMessage() . "\n";
    echo "Raw Response: " . $e->getRawResponse() . "\n"; // Contains the raw, undecodable response string
} catch (\Exception $e) {
    // Handle other general exceptions
    echo "An unexpected error occurred: " . $e->getMessage() . "\n";
}

bash
composer