ExchangeRatesAPI icon indicating copy to clipboard operation
ExchangeRatesAPI copied to clipboard

Fetching exchange rate for specific date does not work

Open SDekkers opened this issue 1 year ago • 1 comments

Version: 4.2.0

After upgrading from v3 to v4, fetching exchange rate on a specific date does not work, using code below:

$lookup = new ExchangeRatesAPI($key, false);
$lookup->setBaseCurrency('USD');
$lookup->addRate('EUR');

$lookup->setFetchDate('2024-01-01');
$rates = $lookup->fetch();

Exception:

BenMajor\ExchangeRatesAPI\Exception

Undefined property: stdClass::$timestamp

It seems, using this, the $date is used as API endpoint, as per https://github.com/benmajor/ExchangeRatesAPI/blob/e545948617379d8dcb41e4a3e1d1529cdbb72ec8/src/ExchangeRatesAPI.php#L379

SDekkers avatar Jan 26 '24 10:01 SDekkers

Good spot, that's an error in the endpoint assignment, which is then causing the following line in the Response object to be undefined:

https://github.com/benmajor/ExchangeRatesAPI/blob/e545948617379d8dcb41e4a3e1d1529cdbb72ec8/src/Response.php#L32C15-L32C54

I'll push a fix up for this.

benmajor avatar Jan 26 '24 12:01 benmajor

I randomly run some old code, updated to the latest version, and I run into a similar error: `In ExchangeRatesAPI.php line 433:

[BenMajor\ExchangeRatesAPI\Exception] Warning: Undefined property: stdClass::$timestamp`

I am not specifying any date at all. Is there any quick fix?

Schyzophrenic avatar May 06 '24 17:05 Schyzophrenic

Thanks @Schyzophrenic. This should now be fixed by https://github.com/benmajor/ExchangeRatesAPI/commit/acdaaeaf35eb025563e38847cede5adb3f005fc3.

I've pushed a new release out, so please update and let me know!

benmajor avatar May 08 '24 21:05 benmajor