PHP code example of daibe / reloadly-php

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

    

daibe / reloadly-php example snippets




    



    use ReloadlyPHP\Client;
    
    // Instantiate ReloadlyPHP 
    $reloadly = new Client('yourClientId', 'yourClientSecret');



    use ReloadlyPHP\Client;

    $isProd = (bool) App::environment('production'); // Laravel
    
    // Instantiate ReloadPHP 
    $reloadly = new Client('yourClientId', 'yourClientSecret', $isProd);

// Check your account's balance using Reloadly's REST API and PHP


    use ReloadlyPHP\Client;

    $client_id      = 'ACXXXXXX'; // Your developer client secret from www.reloadly.com/dashboard
    $client_secret  = 'YYYYYY'; // Your developer client password from www.reloadly.com/dashboard
    
    try {
    
        $reloadly   = new Client($client_id, $client_secret);
        $balance    = $reloadly->getBalance();
    
        echo '<pre>';
        echo sprintf("Amount: <strong>%s</strong> <br/>", $balance->getBalance());
        echo sprintf("Currency name: <strong>%s</strong> <br/>", $balance->getCurrencyName());
        echo sprintf("Currency code: <strong>%s</strong> <br/>", $balance->getCurrencyCode());
        echo '</pre>';
        

    } catch (Exception $e) {
        echo "Exception: ".$e->getMessage();
    }



    try {    
        $operators = $reloadly->getOperators();
        
        echo '<pre>';
        foreach ($operators as $operator) {
            echo sprintf("Operator name: <strong>%s</strong> <br/>", $operator->getName());
            echo sprintf("Operator ID: <strong>%d</strong> <br/>", $operator->getOperatorId());
        }
        echo '</pre>';
    
    } catch (Exception $e) {
        // ... 
    }



    try {    
        
        $fxRate = $reloadly->getFxRate(506, 1);
    
        if ($fxRate) {
            echo sprintf("Name: <strong>%s</strong> <br/>", $fxRate->getName());
            echo sprintf("FX Rate: <strong>%s</strong> <br/>", $fxRate->getFxRate());
            echo sprintf("Currency Code: <strong>%s</strong> <br/>", $fxRate->getCurrencyCode());
            echo sprintf("Operator ID: <strong>%d</strong> <br/>", $fxRate->getOperatorId());
        }
    
    } catch (Exception $e) {
        // ... 
    }

composer