alfaexchange/laravel-package
Laravel SDK for Alfa Exchange API. Fetch real-time currency exchange rates for 170+ currencies from 15+ data sources, with endpoints for latest rates, conversions, time-series, and fluctuation data. Configure your API key and start querying in minutes.
Installation
composer require alfaexchange/laravel-package
Publish the config file (if needed):
php artisan vendor:publish --provider="AlfaExchange\LaravelPackage\PackageServiceProvider"
Configuration
Edit .env or config/alfaexchange.php with your API credentials:
ALFAEXCHANGE_API_KEY=your_api_key_here
ALFAEXCHANGE_API_SECRET=your_api_secret_here
First Use Case: Fetching Market Data
use AlfaExchange\LaravelPackage\Facades\AlfaExchange;
$markets = AlfaExchange::markets()->get();
AlfaExchange (for quick access to API endpoints).config('alfaexchange') for runtime settings.Authenticated Requests Use the facade to handle OAuth2 token management:
$account = AlfaExchange::account()->get();
Pagination & Rate Limiting
Handle paginated responses with ->paginate() or ->cursor():
$orders = AlfaExchange::orders()->paginate(10);
Retry failed requests with exponential backoff:
try {
$response = AlfaExchange::trades()->get();
} catch (\AlfaExchange\Exceptions\RateLimitExceeded $e) {
sleep($e->retryAfter);
retry();
}
Webhook Integration
Validate incoming webhooks via the AlfaExchange\LaravelPackage\Webhook class:
use AlfaExchange\LaravelPackage\Webhook;
$payload = request()->all();
$webhook = new Webhook($payload);
if ($webhook->isValid()) {
// Process event
}
Custom Endpoints Extend the client for undocumented endpoints:
$client = app(\AlfaExchange\LaravelPackage\Client::class);
$response = $client->get('/undocumented/endpoint', ['param' => 'value']);
\Queue::later(now()->addSeconds(10), fn() => $this->processAlfaExchangeData());
$markets = Cache::remember('alfaexchange_markets', now()->addHours(1), fn() =>
AlfaExchange::markets()->get()
);
$this->app->instance(\AlfaExchange\LaravelPackage\Client::class, Mockery::mock());
Deprecated API
Error Handling
\AlfaExchange\Exceptions\*) may not cover all cases. Wrap calls in try-catch:
try {
$response = AlfaExchange::orders()->get();
} catch (\Exception $e) {
Log::error("AlfaExchange API failed: " . $e->getMessage());
abort(503);
}
Rate Limits
X-RateLimit-Remaining headers.Webhook Validation
if (!$webhook->isValid()) {
abort(403, 'Invalid webhook signature');
}
ALFAEXCHANGE_DEBUG=true in .env to log raw API responses.tap to inspect requests:
AlfaExchange::markets()->get()->tap(fn($response) => Log::debug($response));
Authorization and Content-Type headers are correct:
$client->withHeaders(['Authorization' => 'Bearer ' . $token]);
Custom Middleware Add middleware to the client for logging or auth:
$client->withMiddleware(new \AlfaExchange\LaravelPackage\Middleware\LogRequests);
Event Listeners Listen for webhook events:
event(new \AlfaExchange\Events\OrderFilled($webhook->payload));
Service Provider Binding
Override the default client binding in your AppServiceProvider:
$this->app->bind(\AlfaExchange\LaravelPackage\Client::class, fn($app) => new CustomAlfaClient());
Testing Utilities Extend the package’s test helpers for custom assertions:
$this->assertAlfaExchangeResponse($response, 200, 'success');
How can I help you explore Laravel packages today?