Converts an array of amounts from one currency to another.
Use the convertAmounts()
function to convert an array of one or more amounts between two currencies.
The convertAmounts()
function returns a Promise that resolves to a ConvertedAmounts
object which contains an array of converted amounts and the timestamp for the conversion rate used.
Note:
The currency codes used must exist in the array returned by the
getAllCurrencies()
function.
function convertAmounts(
options: ConvertAmountsOptions,
): Promise<ConvertedAmounts>;
Currencies and amounts to convert.
import { currencies } from "wix-pay-frontend";
const conversionOptions = {
amounts: [1.0, 2.5, 5.3],
from: "USD",
to: "GBP",
};
currencies.currencyConverter
.convertAmounts(conversionOptions)
.then((convertedAmounts) => {
const firstConvertedAmount = convertedAmounts.amounts[0];
const timestamp = convertedAmounts.timestamp;
});
/*
* {
* "amounts":[0.8149261982, 2.0373154955, 4.31910885046],
* "timestamp": "2020-03-15T21:00:00.277Z
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.