Overview
TheExchangeRates class enables you to query real-time foreign exchange rates between different currencies. This is useful for displaying conversion rates to users or calculating cross-currency transaction amounts.
Class: ExchangeRates
Properties
| Property | Type | Description |
|---|---|---|
origin_currency | String | The currency to convert from (e.g., “NGN”) |
destination_currency | String | The currency to convert to (e.g., “USD”) |
amount | String | The amount to convert |
Method: forex()
Queries the exchange rate between two currencies for a specified amount. Returns:JSONObject containing the exchange rate information
Usage Example
Setter Methods
TheExchangeRates class supports method chaining for convenient configuration:
setAmount(String amount)
Sets the amount to convert. Parameters:amount: The amount as a string
ExchangeRates instance (for chaining)
setOrigin_currency(String currency)
Sets the source currency code. Parameters:currency: Three-letter currency code (e.g., “NGN”, “USD”, “GBP”)
ExchangeRates instance (for chaining)
setDestination_currency(String currency)
Sets the target currency code. Parameters:currency: Three-letter currency code (e.g., “USD”, “EUR”, “GHS”)
ExchangeRates instance (for chaining)
All three properties (amount, origin_currency, and destination_currency) must be set before calling the
forex() method.Supported Currencies
Flutterwave supports a wide range of currencies. Common examples include:- NGN - Nigerian Naira
- USD - US Dollar
- EUR - Euro
- GBP - British Pound
- GHS - Ghanaian Cedi
- KES - Kenyan Shilling
- ZAR - South African Rand
Exchange rates are queried in real-time and may fluctuate based on market conditions.
Use Cases
- Display current exchange rates to customers
- Calculate transaction amounts in different currencies
- Provide currency conversion estimates before payment
- Build multi-currency pricing displays
- Implement currency converters in your application
Next Steps
Card Payments
Accept card payments in multiple currencies
Configuration
Configure your API keys