Currency Exchange
Introduction
The Currency Exchange service exposes features for:
- Getting currency exchange rate quote
- Creating currency exchange rate quote
Use the following code to obtain an instance of CurrencyExchangeService
:
- Kotlin
- Swift
val currencyExchangeService = Wallet.getInstance().getCurrencyExchangeService()
import PaysafeWallet
let currencyExchangeService = Wallet.instance.currencyExchangeService
Get an FxRate
Use getQuote
method to retrieve an FxRate by passing the id of the FxRate:
- Kotlin
- Swift
try {
val id = "404679be-ccbf-4528-b880-e14cc5041753"
val fxRate = currencyExchangeService.getQuote(id)
Log.d(TAG, fxRate.toString())
} catch (exception: Exception) {
Log.d(TAG, exception.toString())
}
let id = "404679be-ccbf-4528-b880-e14cc5041753"
currencyExchangeService.getQuote(id: id, completion: { result in
switch result {
case .success(let fxRate):
// Handle fxRate
case .failure(let error):
// Handle error
}
})
Create an FxRate
Use createQuote
method to create an FxRate for the current source and target currencies:
FxRateRequest
Parameter | Data type | Description | Example |
---|---|---|---|
sourceCurrency | string | Required parameter for currency of the fxRateQuote. Format ISO 4217. | "USD" |
targetCurrency | string | Required parameter for currency of the fxRateQuote. Format ISO 4217. | "EUR" |
- Kotlin
- Swift
try {
val fxRateRequest = FxRateRequest(sourceCurrency = "USD", targetCurrency = "EUR")
val fxRate = = currencyExchangeService.createQuote(fxRateRequest)
Log.d(TAG, fxRate.toString())
} catch (exception: Exception) {
Log.d(TAG, exception.toString())
}
let fxRateRequest = Wallet.FXRateRequest(sourceCurrency: "USD", targetCurrency: "EUR")
currencyExchangeService.createQuote(fxRateRequest: fxRateRequest, completion: { result in
switch result {
case .success(let fxRate):
// Handle fxRate
case .failure(let error):
// Handle error
}
})