Skip to content

UniRate-API/unirate-bundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UniRate Bundle — Symfony Integration

Symfony bundle that integrates the UniRate API as an autowired service for currency exchange rates, conversions, and VAT data.

Install

composer require unirate-api/unirate-bundle

Register the bundle in config/bundles.php:

UniRateApi\Bundle\UniRateBundle::class => ['all' => true],

Configuration

Create config/packages/unirate.yaml:

unirate:
    api_key: '%env(UNIRATE_API_KEY)%'
    # base_url: 'https://api.unirateapi.com'  # default
    # timeout: 30                              # seconds, default

Usage

The UniRateClient service is autowired automatically:

use UniRateApi\Bundle\UniRateClient;

class CurrencyController
{
    public function __construct(private readonly UniRateClient $unirate) {}

    public function rate(): Response
    {
        // Single rate
        $rate = $this->unirate->getRate('USD', 'EUR');       // → 0.9234

        // All rates for a base
        $rates = $this->unirate->getRates('USD');            // → ['EUR' => 0.92, ...]

        // Convert amount
        $result = $this->unirate->convert(100.0, 'USD', 'EUR'); // → 92.34

        // Supported currencies
        $currencies = $this->unirate->listCurrencies();      // → ['USD', 'EUR', ...]

        // VAT rates
        $allVat = $this->unirate->getVatRates();             // all countries
        $deVat  = $this->unirate->getVatRates('DE');         // Germany only
    }
}

Error handling

use UniRateApi\Bundle\UniRateException;

try {
    $rate = $this->unirate->getRate('USD', 'EUR');
} catch (UniRateException $e) {
    $httpStatus = $e->getStatusCode(); // 401, 403, 404, 429, etc.
    $message    = $e->getMessage();
}

HTTP status codes: 401 = invalid key · 403 = Pro required · 404 = currency not found · 429 = rate limit exceeded.

Free vs Pro tier

Free tier: rates, convert, currencies, VAT. Historical data requires Pro.

Packagist

Distribution via Packagist. Registration is required once at packagist.org — point it at this GitHub repo and GitHub webhooks handle all subsequent updates automatically.

Related packages

UniRate API client libraries: Python · Node.js · Go · Rust · Ruby · PHP · Java · Swift · .NET

PHP ecosystem: Laravel Money · WordPress · Symfony Bundle (this package)

Framework integrations: Next.js · Nuxt · SvelteKit · Astro · NestJS · Strapi

Data & AI: LangChain Python · FastAPI · Flask · Django REST · dbt · Airflow

Other: MCP server · CLI · Directus · Medusa · Home Assistant

License

MIT © Unirate Team

About

Symfony bundle for the UniRate currency-exchange API — autowired UniRateClient service, exchange rates, conversions, and VAT data.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages