lukapeharda / hmrc-exchange-rates
Fetch HM Revenue & Customs exchange rates for customs & VAT
v1.1.0
2024-03-04 14:36 UTC
Requires
- guzzlehttp/guzzle: ^6.3
This package is auto-updated.
Last update: 2024-12-04 16:24:39 UTC
README
Fetch monthly exchange rates from HMRC website using PHP. Rates are parsed from monthly files.
Fetched CSV files are stored in a provided path to optimise and speed up the process.
Installation
Install it using composer:
composer require lukapeharda/hmrc-exchange-rates
Usage
Fetch all currency / exchange rates value pairs:
<?php // Initialize the client and provide storage path for file cache. // If path isn't provided "/tmp" will be used. $hmrcClient = new LukaPeharda\HmrcExchangeRates\Hmrc('/storage/path'); // First param is a four digit representation of a year (2024). Second one is a // numeric representation of a month (5) without leading zeros. // Only first param is required. Others are optional. Current year and month // will be used. $rates = $hmrcClient->getMonthlyRates(date('Y'), date('n')); // $rates = [... , 'EUR' => 1.1545, ... , 'USD' => 1.3049, ...] at the time of // writting documentation
Fetch rate for a specific currency (USD used in this example):
<?php // Initialize the client and provide storage path for file cache. // If path isn't provided "/tmp" will be used. $hmrcClient = new LukaPeharda\HmrcExchangeRates\Hmrc('/storage/path'); // First param is currency code in ISO 4217. Second one a four digit // representation of a year (2024). Third one is a numeric representation of a // month (5) without leading zeros. // Only first param is required. Others are optional. Current year and month // will be used. $usdRate = $hmrcClient->getMonthlyRateForCurrency('USD', date('Y'), date('n')); // $usdRate = 1.3049 at the time of writting documentation