Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Exchanger Laravel Package

florianv/exchanger

Exchanger is a PHP framework for retrieving currency exchange rates from multiple providers (Fixer, Currency Data, Exchange Rates Data, and more). It offers a unified API for live and historical rates, supporting different base/quote currency constraints per service.

View on GitHub
Deep Wiki
Context7

Exchanger is a PHP framework for retrieving and normalizing currency exchange rates from multiple providers. It offers a consistent API across services like Fixer, Currency Data, and Exchange Rates Data, making it easy to switch providers or combine them without changing your application code.

Built for flexibility and extensibility, Exchanger supports common FX use cases including historical rates and provider-specific constraints (base/quote currency rules).

  • Unified interface for multiple exchange-rate services
  • Supports live and historical rates (provider-dependent)
  • Pluggable, extensible architecture for adding new services
  • Works with various base/quote currency limitations per provider
  • Designed as a framework (see Swap for a simpler wrapper)
Frequently asked questions about Exchanger
How do I integrate Exchanger with Laravel’s HTTP client (Guzzle) for currency exchange rates?
Use the `php-http/guzzle7-adapter` to bridge Laravel’s Guzzle client with Exchanger’s HTTPlug interface. Register the adapter in your service container, then bind Exchanger services (e.g., Fixer) with API keys from `.env`. Example: `Exchanger::service(Fixer::class)->withKey(env('FIXER_API_KEY'))`.
Can Exchanger handle rate limit errors from providers like Fixer or CurrencyData?
Yes, Exchanger supports fallback logic via the `Chain` service. Configure multiple providers in order of preference, and it will automatically switch to the next if a provider hits rate limits or fails. Pair this with Laravel’s queue system for retries or exponential backoff.
Does Exchanger work with Laravel’s caching system (Redis, database, etc.) for exchange rates?
Absolutely. Exchanger uses PSR-16/PSR-6 caching, so it integrates seamlessly with Laravel’s cache drivers. Configure a cache adapter (e.g., Redis) via `cache/simple-cache-bridge`, then set TTLs for rates. Example: `Exchanger::service(Fixer::class)->withCache($cache->driver('redis'))->ttl(3600)`.
What Laravel versions does Exchanger support, and are there breaking changes between major releases?
Exchanger is PHP 8.0+ compatible and works with Laravel 9+. Check the [changelog](https://github.com/florianv/exchanger/blob/master/CHANGELOG.md) for version-specific notes. Breaking changes are rare but typically involve provider API updates (e.g., Fixer’s endpoint changes). Always test in a staging environment.
How do I fetch historical exchange rates for compliance or auditing in Laravel?
Use the `historical()` method on supported providers (Fixer, CurrencyData, etc.). Example: `$rates = Exchanger::service(Fixer::class)->historical('2023-01-01')->fetch();`. For persistence, store results in Laravel’s database or cache driver, then query via Eloquent or a dedicated table.
Is Exchanger suitable for high-throughput applications like e-commerce checkouts?
Yes, but optimize for performance. Use the `Chain` service for parallel provider requests, cache aggressively (e.g., 1-hour TTL), and offload rate fetches to Laravel Queues. Monitor latency with Laravel’s logging or Prometheus. Avoid real-time fetches during peak traffic.
How do I mock Exchanger for unit testing in Laravel?
Use `php-http/mock-client` to simulate HTTP responses. Bind a mock client to Exchanger’s HTTPlug stack in your test setup. Example: `$mock = new MockClient(); $stack = new ClientStack($mock); Exchanger::setClient($stack)`. Test edge cases like rate limits or provider failures explicitly.
What are the alternatives to Exchanger for Laravel currency exchange rates?
For simplicity, consider **Swap** (by the same author), a lightweight wrapper around Exchanger. For broader financial data, explore **MoneyPHP** (for currency math) or **Laravel Money** (for monetary values). If you need crypto support, **CoinGecko’s API** or **Binance** integrations may be better, though they lack fiat-crypto hybrid features.
How do I handle multi-tenancy in Laravel with Exchanger (e.g., per-user currency rates)?
Cache rates per tenant using Laravel’s cache tags or a dedicated table with `tenant_id`. Example: `$cache->tags(['tenant:123'])->put('rates', $rates, 3600)`. For historical data, scope queries by tenant in Eloquent. Avoid global caching to prevent cross-tenant data leaks.
Are there any known issues with Exchanger in production, like cache key truncation or provider deprecations?
Cache keys are limited to 64 chars (PSR-16 constraint), so prefix them concisely (e.g., `app:rates-`). Monitor provider deprecations (e.g., exchangeratesapi.io) via their changelogs and update Exchanger manually. Set up cron jobs to refresh cached rates nightly to mitigate stale data risks.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport