PHPackages                             hennest/exchange-rate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. hennest/exchange-rate

ActiveLibrary[API Development](/categories/api)

hennest/exchange-rate
=====================

Exchange rate provider for laravel apps

v2.0.3(1y ago)1113[2 PRs](https://github.com/Hennest/exchange-rate/pulls)MITPHPPHP ^8.4CI passing

Since Dec 25Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/Hennest/exchange-rate)[ Packagist](https://packagist.org/packages/hennest/exchange-rate)[ RSS](/packages/hennest-exchange-rate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (14)Used By (0)

Exchange Rate Library
=====================

[](#exchange-rate-library)

This PHP library provides a flexible and efficient way to handle exchange rates, including fetching current rates, caching, and currency conversion. It's designed to integrate seamlessly with Laravel applications.

Features
--------

[](#features)

- Fetch exchange rates from multiple API sources
- Cache exchange rates for improved performance
- Parse and filter exchange rate data
- Perform currency conversions with configurable precision
- Dedicated converter service with arbitrary precision math
- Easily extensible and customizable
- Laravel integration via a service provider

Installation
------------

[](#installation)

You can install this library via Composer:

```
composer require hennest/exchange-rate
```

Laravel Integration
-------------------

[](#laravel-integration)

This library comes with a Laravel service provider for easy integration. After installation, add the service provider to your `config/app.php` file:

```
'providers' => [
    // Other Service Providers
    Hennest\ExchangeRate\Providers\ExchangeRateServiceProvider::class,
],
```

### Configuration

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=exchange-rate-config
```

This will create a `config/exchange-rate.php` file where you can customize the library settings.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Hennest\ExchangeRate\Contracts\ExchangeRateInterface;

class ExampleController
{
    public function __construct(
        private ExchangeRateInterface $exchangeRate
    ) {}

    public function example()
    {
        // Get exchange rates for specific currencies
        $rates = $this->exchangeRate->rates(['EUR', 'GBP', 'JPY']);

        // Get a single exchange rate
        $rate = $this->exchangeRate->getRate('EUR');

        // Convert currency
        $convertedAmount = $this->exchangeRate->convert(100, 'USD', 'EUR');
    }

    public function anotherExample()
    {
        // Get exchange rates for specific currencies
        $rates = app(ExchangeRateInterface::class)->rates(['EUR', 'GBP', 'JPY']);

        // Get a single exchange rate
        $rate = app(ExchangeRateInterface::class)->getRate('EUR');

        // Convert currency
        $convertedAmount = app(ExchangeRateInterface::class)->convert(100, 'USD', 'EUR');
    }
}
```

### Configuration Options

[](#configuration-options)

The `config/exchange-rate.php` file allows you to customize various aspects of the library. Here's a breakdown of the available options:

```
return [
    // Base currency for the exchange rate
    'base_currency' => env('EXCHANGE_RATE_BASE_CURRENCY', 'USD'),

    // API key for the exchange rate service
    'api_key' => env('EXCHANGE_RATE_API_KEY', ''),

    // Arbitrary Precision Calculator settings
    'math' => [
        'scale' => env('EXCHANGE_RATE_SCALE', 10),
    ],

    // Cache configuration
    'cache' => [
        'prefix' => env('EXCHANGE_RATE_CACHE_PREFIX', 'exchange_rate'),
        'driver' => env('EXCHANGE_RATE_CACHE_DRIVER', env('CACHE_STORE', 'file')),
        'ttl' => env('EXCHANGE_RATE_CACHE_TTL', 6 * 3600),
    ],

    // Builder classes for creating DTOs
    'assemblers' => [
        'response' => Hennest\ExchangeRate\Assembler\ResponseAssembler::class,
    ],

    // Customizable service classes
    'services' => [
        'api' => Hennest\ExchangeRate\Drivers\CurrencyApiService::class,
        'cache' => Hennest\ExchangeRate\Services\CacheService::class,
        'parser' => Hennest\ExchangeRate\Services\ParserService::class,
        'converter' => Hennest\ExchangeRate\Services\ConverterService::class,
        'exchange_rate' => Hennest\ExchangeRate\Services\ExchangeRateService::class,
    ],

    // Default driver
    'default_driver' => 'currency-api',

    // Available API drivers
    'drivers' => [
        'currency-api' => [
            'api' => Hennest\ExchangeRate\Drivers\CurrencyApiService::class,
        ],
        'currency-beacon' => [
            'api' => Hennest\ExchangeRate\Drivers\CurrencyBeaconApiService::class,
        ],
    ],
];
```

#### Key Configuration Options:

[](#key-configuration-options)

- `base_currency`: Set your preferred base currency (default: USD).
- `api_key`: If your chosen API requires a key, set it here or in your `.env` file.
- `math.scale`: Set the precision for decimal calculations used by the converter.
- `cache`: Configure caching options including driver, prefix, and TTL.
- `services`: Override default service implementations.
- `default_driver`: Choose the default API driver.
- `drivers`: Configure multiple API drivers for flexibility.

### Extending the Library

[](#extending-the-library)

You can set `default_driver` to `null` and update the `services` array to extend the library's functionality. You can create custom implementations of the following interfaces:

- `ApiInterface`: For custom API integrations
- `CacheInterface`: For custom caching mechanisms
- `ParserInterface`: For custom parsing logic
- `ConverterInterface`: For custom currency conversion logic
- `ExchangeRateInterface`: For custom exchange rate calculations

Register your custom implementations in the `services` section of the `config/exchange-rate.php` file:

```
'services' => [
    'api' => \App\Services\MyCustomApiService::class,
    'cache' => \App\Services\MyCustomCacheService::class,
    'parser' => \App\Services\MyCustomParserService::class,
    'converter' => \App\Services\MyCustomConverterService::class,
    'exchange_rate' => \App\Services\MyCustomExchangeRateService::class,
],
```

This allows you to have full control over which services are used throughout your application.

### Multiple API Drivers

[](#multiple-api-drivers)

The library supports multiple API drivers. You can add new drivers in the `drivers` section and switch between them by changing the `default_driver` setting.

### Adding Custom Drivers

[](#adding-custom-drivers)

To add a custom driver or use a different API service, extend the library by adding a new entry to the `drivers` array in the `config/exchange-rate.php` file:

```
'drivers' => [
    'currency-api' => [
        'api' => Hennest\ExchangeRate\Drivers\CurrencyApiService::class,
    ],
    'currency-beacon' => [
        'api' => Hennest\ExchangeRate\Drivers\CurrencyBeaconApiService::class,
    ],
    'my-custom-driver' => [
        'api' => \App\Services\MyCustomApiService::class,
    ],
],
```

### Selecting a Driver

[](#selecting-a-driver)

To use your custom driver, you can either:

1. Update the `default_driver` setting in the config file:

```
'default_driver' => 'my-custom-driver',
```

2. Or set it using an environment variable:

```
EXCHANGE_RATE_DRIVER=my-custom-driver

```

### Custom Implementations

[](#custom-implementations)

When creating custom implementations, ensure they adhere to the following interfaces:

- `ApiInterface`: For custom API integrations
- `CacheInterface`: For custom caching mechanisms
- `ParserInterface`: For custom parsing logic
- `ExchangeRateInterface`: For custom exchange rate calculations

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This library is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance71

Regular maintenance activity

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~47 days

Recently: every ~55 days

Total

11

Last Release

390d ago

Major Versions

0.0.4 → 1.0.02024-09-01

1.0.1 → v2.0.02025-02-01

PHP version history (3 changes)v0.0.0PHP ^8.1

0.0.2PHP ^8.2

v2.0.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/13d07283f77287ffd8872d8ce826152ce2c7953b1c58452520276358a7c9395b?d=identicon)[hennest](/maintainers/hennest)

---

Top Contributors

[![Hennest](https://avatars.githubusercontent.com/u/46072450?v=4)](https://github.com/Hennest "Hennest (64 commits)")

---

Tags

currencycurrency-converterexchangeexchange-rateslaravellaravel-currencylaravel-exchange-rate

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hennest-exchange-rate/health.svg)

```
[![Health](https://phpackages.com/badges/hennest-exchange-rate/health.svg)](https://phpackages.com/packages/hennest-exchange-rate)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
