Search.../

convertAmounts( )

Converts an array of amounts from one currency to another.

Description

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.

Syntax

function convertAmounts(options: ConvertAmountsOptions): ConvertedAmounts

convertAmounts Parameters

NAME
TYPE
DESCRIPTION
options
ConvertAmountsOptions

Currencies and amounts to convert.

Returns

Fulfilled - The converted amounts and the timestamp for the conversion rate.

Return Type:

Promise<ConvertedAmounts>
NAME
TYPE
DESCRIPTION
amounts
Array<number>

Array of converted amounts.

timestamp
Date

The date and time when the currency exchange rate was set.

Was this helpful?

Convert an array of amounts from one currency to another.

Copy Code
1import {currencies} from 'wix-pay-frontend';
2
3const conversionOptions = {
4 "amounts": [1.0, 2.5, 5.3],
5 "from": "USD",
6 "to": "GBP"
7};
8
9currencies.currencyConverter.convertAmounts(conversionOptions)
10 .then((convertedAmounts) => {
11 const firstConvertedAmount = convertedAmounts.amounts[0];
12 const timestamp = convertedAmounts.timestamp;
13 });
14
15/*
16 * {
17 * "amounts":[0.8149261982, 2.0373154955, 4.31910885046],
18 * "timestamp": "2020-03-15T21:00:00.277Z
19 * }
20 */