Download the PHP package wprigollopes/bcb-ptax without Composer
On this page you can find all versions of the php package wprigollopes/bcb-ptax. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wprigollopes/bcb-ptax
More information about wprigollopes/bcb-ptax
Files in wprigollopes/bcb-ptax
Package bcb-ptax
Short Description PHP client for Banco Central do Brasil PTAX currency exchange rates
License MIT
Informations about the package bcb-ptax
BCB PTAX
A PHP library to fetch daily PTAX exchange rates from Banco Central do Brasil's public API.
Background
This project was born out of a real operational need at a Brazilian import company. Every business day, the company needed the official PTAX closing rate to price imports, settle invoices, and comply with Brazilian customs regulations. What started as a quick utility script grew into a Composer package shared with the community.
In 2026, the library was modernized with the help of Claude Code — rewritten from the ground up with PHP 8.1+ features, proper type safety, full test coverage, and i18n support while keeping the same simple API.
Requirements
- PHP 8.1 or higher
- Composer
Installation
Usage
Basic example
Custom HTTP client
If you need to configure timeouts, proxies, or other HTTP options, pass your own Guzzle client:
Portuguese error messages
Exception messages default to English (en_US). To get messages in Portuguese:
Handling errors
Working with user input
The Currency enum provides safe parsing from strings:
Supported Currencies
The BCB PTAX service provides daily closing rates for the following currencies against BRL:
| Code | Currency |
|---|---|
| AUD | Australian Dollar |
| CAD | Canadian Dollar |
| CHF | Swiss Franc |
| DKK | Danish Krone |
| EUR | Euro |
| GBP | British Pound |
| JPY | Japanese Yen |
| NOK | Norwegian Krone |
| SEK | Swedish Krona |
| USD | US Dollar |
Source: BCB PTAX Moedas endpoint
API Reference
PTAX
get(Currency $currency, DateTimeInterface $date): PTAXResult
Fetches the closing PTAX rate for the given currency and date. Throws ApiException if the API returns an error, the response is malformed, or no closing PTAX exists for that date (weekends, holidays).
PTAXResult
| Property | Type | Description |
|---|---|---|
buyRate |
float |
Purchase rate (cotacaoCompra) |
sellRate |
float |
Selling rate (cotacaoVenda) |
date |
DateTimeImmutable |
Quotation timestamp |
bulletinType |
string |
Bulletin type (always "Fechamento PTAX") |
Currency
PHP 8.1 string-backed enum with all 10 supported currency codes. Use Currency::tryFrom('USD') for safe parsing from user input.
Development
License
MIT