This is an example plugin that enables commerce currency rates to be updated with live rates from the fixer.io api.
-
Copy the
currencyrates
folder into yourcraft/plugins
folder. -
Click install on the plugin within
settings > plugins
-
Make a currencyrates.php file in your
craft/config/
directory with the following:
<?php
return [
'secret' => '123'
];
-
Replace
123
from the file above with a long unique password or hash. -
Set up a cron job to hit this url:
http://yourdomain.dev/actions/currencyRates/update/rates?code=123
-
Notice the
code=123
. Replace123
with the unique password that you populated in step 4. -
Set the cron to hit that url periodically. The example below is a cron command which hits the url every 24 hours at midnight:
0 0 * * * wget -O - http://yourdomain.dev/actions/currencyRates/update/rates?code=123 >/dev/null 2>&1
You can manually visit the url to test the rates are updated correctly before setting up your cron job.
The plugin uses the http://fixer.io/ api for the live rates.
Fixer.io is a free JSON API for current and historical foreign exchange rates published by the European Central Bank.
The rates are updated daily around 4PM CET.