PHP Classes

PHP Currency Converter API: Provides an API to return currency exchange rates

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 132 All time: 9,329 This week: 206Up
Version License PHP version Categories
currencyexchangeapi 1.0.0Custom (specified...5PHP 5, Web services, Finances
Description 

Author

This package provides an API to return currency exchange rates.

It implements a REST API server that can process requests to perform several types of operations with currencies. Currently it can:

- Return the exchange rate between two given currencies
- Update the rate between a given currency and the Euro
- Delete the current exchange rate of a given currency

Innovation Award
PHP Programming Innovation award nominee
December 2019
Number 6
Many applications need to deal with different currencies used in payments that they may take, so they may need to convert money amounts between different currencies.

Often those applications use remote APIs that rely on remote exchange conversion APIs to work well.

If for some reason those APIs may not be reachable when the application needs to use the conversion exchange rate values, the application may fail to operate, thus leading to eventual financial losses.

This package provides a more reliable alternative based on its own API to obtain the conversion exchange rates, thus avoiding to rely so much on external APIs.

Manuel Lemos
Picture of Manolo Salsas
  Performance   Level  
Innovation award
Innovation award
Nominee: 6x

Winner: 1x

 

Example

<?php

use App\Kernel;
use
Symfony\Component\Debug\Debug;
use
Symfony\Component\HttpFoundation\Request;

require
dirname(__DIR__).'/config/bootstrap.php';

if (
$_SERVER['APP_DEBUG']) {
   
umask(0000);

   
Debug::enable();
}

if (
$trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
   
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if (
$trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
   
Request::setTrustedHosts([$trustedHosts]);
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);


Details

Currency exchange REST API Build Status

Currency exchange is a REST API made with Symfony.

Documentation

GET /currency/{currencyFrom}/{currencyTo}/?number=number
example: GET /currency/eur/dol/?number=3.45

POST /currency/{currency}
parameters: json => {rateToEur, symbol}
example: POST /currency/eur with {rateToEur: 1, symbol: "?"}

PUT /currency/{currency}
parameters: json => {rateToEur, symbol}
example: PUT /currency/eur with {rateToEur: 1, symbol: "eur"}

DELETE /currency/{currency}
example: DELETE /currency/eur

Installation

git clone https://github.com/msalsas/currency-exchange.git

cd currency-exchange

composer install

php bin/console doctrine:database:create

php bin/console doctrine:database:create --env=test

php bin/console doctrine:migrations:migrate

php bin/console doctrine:migrations:migrate --env=test

symfony server:start 

you will need:

- The Symfony installer

- php-sqlite3 as database is sqlite by default

Testing

php ./bin/phpunit

License

This bundle is under the MIT license. See the complete license in the bundle

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker.


  Files folder image Files (41)  
File Role Description
Files folder imagebin (2 files)
Files folder imageconfig (4 files, 2 directories)
Files folder imagepublic (1 file)
Files folder imagesrc (1 file, 6 directories)
Files folder imagetests (2 directories)
Accessible without login Plain text file .env Data Auxiliary data
Accessible without login Plain text file .env.test Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file symfony.lock Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:132
This week:0
All time:9,329
This week:206Up