payu/fx-client

FX API PHP Client

v0.1.0 2018-06-19 10:26 UTC

This package is auto-updated.

Last update: 2024-12-10 00:04:55 UTC


README

Build Status

PHP client for FX API

Introduction

This is a PHP implementation of a HTTP client for accessing the FX API.

Installation

You can install the client by using composer:

composer require payu/fx-client-php:^1.0

You need at least PHP 5.6, having cURL with HTTPS support enabled.

Usage

To begin, you will need to provide your account Merchant Code and Secret Key. To do this, create a \PayU\FX\Config\MerchantCredentials configuration instance:

<?php

use PayU\FX\Config\MerchantCredentials;

require_once 'vendor/autoload.php';

$config = new MerchantCredentials(
    'MY_CODE',
    'MY_SECRET_KEY'
);

Next, create the API client by providing the above config instance and the platform/country you are going to use (possible values: Platform::RO(), Platform::TR(), Platform::RU()):

<?php

use PayU\FX\Client;
use PayU\FX\Config\MerchantCredentials;
use PayU\FX\Config\Platform;

require_once 'vendor/autoload.php';

$config = new MerchantCredentials(
    'MY_CODE',
    'MY_SECRET_KEY'
);

$platform = Platform::RO();

$client = new Client($config, $platform);

Every method of the FX client is throwing the PayU\FX\Exceptions\ClientException exception is something won't work as expected. For instance:

<?php

use PayU\FX\Client;
use PayU\FX\Config\MerchantCredentials;
use PayU\FX\Config\Platform;
use PayU\FX\Exceptions\ClientException;


require_once 'vendor/autoload.php';

$config = new MerchantCredentials(
    'MY_CODE',
    'MY_SECRET_KEY'
);

$platform = Platform::RO();

$client = new Client($config, $platform);

try {
    $client->getAllFxRates('RON');
} catch (ClientException $e) {
    echo $e->getMessage();
}

More example code can be found in examples dir.

License

This library is licensed under Apache-2.0 license. Please see the LICENSE file.