Currency Exchange
Introduction
The Currency Exchange Service provides a solution for managing currency conversions in your application, enabling the creation and retrieval of exchange rate quotes, ensuring rate stability, and simplifying currency exchange integration.
Key Features:
- Creating Currency Exchange Rate Quote.
- Getting Currency Exchange Rate Quote.
The exchange rate includes the respective Paysafe fees. It should be noted, that because of the way Paysafe applies the fee some rounding might internally cause minor difference in the actual conversion output. Usually this would be in customer benefit.
Prerequisites
Before integrating the Currency Exchange Service, ensure you have:
- A valid Paysafe account with appropriate permissions.
- Set up instructions for Paysafe SDK Android or iOS.
To get started, initialize the CurrencyExchangeService
instance in your app as shown below:
- Kotlin
- Swift
val currencyExchangeService = Wallet.getInstance().getCurrencyExchangeService()
import PaysafeWallet
let currencyExchangeService = Wallet.instance.currencyExchangeService
Create a FxRate
- Kotlin
- Swift
To create a specific exchange rate quote, use the createQuote
method, providing a FxRateRequest with the source and target currencies in ISO 4217 Format (e.g., "USD", "EUR"). This method returns a FxRate object that can be used to ensure stability and predictability for transactions. The created quote remains valid for a specified period, allowing you to avoid fluctuations in exchange rates during the transaction process.
val fxRateRequest = FxRateRequest(sourceCurrency = "USD", targetCurrency = "EUR")
val fxRate = currencyExchangeService.createQuote(fxRateRequest)
To create a specific exchange rate quote, use the createQuote
method, providing a FxRateRequest with the source and target currencies in ISO 4217 Format (e.g., "USD", "EUR"). This method returns a FxRate object that can be used to ensure stability and predictability for transactions. The created quote remains valid for a specified period, allowing you to avoid fluctuations in exchange rates during the transaction process.
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
}
})
Retrieve a FxRate
- Kotlin
- Swift
To retrieve a specific exchange rate, use the getQuote
method by pass the unique ID of the quote to get a FxRate object with the details of the quote. Each quote has a limited validity period, during which it can be used to avoid fluctuations in exchange rates.
val id = "404679be-ccbf-4528-b880-e14cc5041753"
val fxRate = currencyExchangeService.getQuote(id)
To retrieve a specific exchange rate, use the getQuote
method by pass the unique ID of the quote to get a FxRate object with the details of the quote. Each quote has a limited validity period, during which it can be used to avoid fluctuations in exchange rates.
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
}
})
Exchange Currency
- Kotlin
- Swift
The exchange rate quote can be used to transfer money between two accounts for same customer. This is done by creating a CustomerTransferRequest without specifying a recipient but including the ID of the FX rate quote you created and then proceeding with the transfer normally as described here. If the quote has expired, the currency conversion/transfer will fail.
val fxRateRequest = FxRateRequest(sourceCurrency = "USD", targetCurrency = "EUR")
val fxRate = currencyExchangeService.createQuote(fxRateRequest)
val transferRequest = CustomerTransferRequest(
amount = 200,
currencyCode = "USD",
merchantRefNum = "2b01127a-4929-4d0e-b9cb-a29a8d1c499c",
fxQuote = fxRate.id,
transferDetails = TransferDetails(
reason = TransferReason.CURRENCY_EXCHANGE,
description = "Exchange USD to EUR"
)
)
val transferPreview = transferService.preview(transferRequest)
// Proceed with the transfer
After creating a FX rate quote you can use it to exchange currency between two of your accounts. This is done by creating a CustomerTransferRequest without specifying a recipient but including the ID of the FX rate quote you created and then proceeding with the transfer normally as described here. If expired quote is passed the currency conversion will fail.
let fxRateRequest = Wallet.FXRateRequest(sourceCurrency: "USD", targetCurrency: "EUR")
currencyExchangeService.createQuote(fxRateRequest: fxRateRequest, completion: { result in
switch result {
case .success(let fxRate):
let transferRequest = Wallet.CustomerTransferRequest(amount: 200,
currencyCode: "USD",
merchantRefNum: "2b01127a-4929-4d0e-b9cb-a29a8d1c499c",
fxQuote: fxRate.id,
transferDetails: .init(reason: .currencyExchange,
description: "Exchange USD to EUR"))
transferService.preview(transferRequest: transferRequest, completion: { result in
switch result {
case .success(let transferPreview):
// Proceed with the transfer
case .failure(let error):
// Handle error
}
})
case .failure(let error):
// Handle error
}
}))