Overview
TheExchangeRates class provides functionality to retrieve current foreign exchange rates and convert amounts between different currencies using Flutterwave’s forex API.
Class: ExchangeRates
Methods
forex()
Retrieves the exchange rate and converts an amount from one currency to another.JSONObject - Exchange rate information and converted amount
Description: This method fetches the current exchange rate between two currencies and calculates the converted amount. It uses Flutterwave’s forex endpoint to get real-time exchange rates.
Parameters Required
Before calling this method, set the following properties:The amount to convert
The source currency code (e.g., “USD”, “NGN”, “GHS”)
The target currency code to convert to
Example
Response Fields
The response typically includes:Status of the request (success/error)
Contains the exchange rate details
The exchange rate between the two currencies
The converted amount in the destination currency
Setter Methods
TheExchangeRates class uses a fluent interface pattern for easy configuration.
setAmount()
Sets the amount to be converted.The amount to convert as a string
ExchangeRates - Returns the instance for method chaining
setOrigin_currency()
Sets the source currency.The source currency code (e.g., “USD”, “EUR”, “GBP”, “NGN”)
ExchangeRates - Returns the instance for method chaining
setDestination_currency()
Sets the destination currency.The destination currency code
ExchangeRates - Returns the instance for method chaining
Getter Methods
getAmount()
Retrieves the currently set amount.String - The amount to convert
getOrigin_currency()
Retrieves the currently set origin currency.String - The source currency code
getDestination_currency()
Retrieves the currently set destination currency.String - The destination currency code
This method requires your secret key to be configured in
RaveConstant.SECRET_KEY.