The interface
getRate() returns the multiplier that converts an amount in $from into $to. It’s called during checkout, so it must be fast and must not throw for a currency pair you support.
Those two methods are the whole contract. canConvert() and getProviderRates(), which the admin panel and the MRR calculation use, belong to the core wrapper described below, not to your provider.
Custom rates override yours
Aikeedo never hands your provider to the rest of the application directly. It wraps the selected provider inBilling\Infrastructure\Currency\CustomRateProvider, and that wrapper is what’s bound to RateProviderInterface. Administrators set custom rates under Settings → Exchange → Custom rates, stored in option.currency.rates as units of each currency per 1 USD.
For each conversion, the wrapper:
- Passes the pair to your provider unchanged when neither currency has a custom rate.
- Otherwise uses the custom rate for each side that has one, and asks your provider for the other side against USD, as
getRate(USD, $currency).
$from currency for every currency you cover, even if your API quotes against another base. The custom rates page also shows your provider’s rate next to each custom one, fetched the same way.
Implementation
Rates change slowly, so fetch them in bulk and cache them. Storing them in an option makes them survive cache clears and keeps the checkout path free of network calls.src/AcmeRates.php
Register it
src/Plugin.php
option.currency.provider.
Settings page
The billing page links to/admin/settings/rate-providers/{key}, so declare that route and point extra.default_url at it:
Testing
Set a gateway to a currency other than the platform default and confirm the charge is converted.
The converted amount is plausible, and rounding lands on whole minor units.
Rates are fetched once and reused until they expire.
The custom rates page shows your rate next to each currency, and a custom rate overrides yours.
With an invalid API key, checkout still completes in the default currency.