convertCurrency( )
Returns an array of amounts converted from the original (from
) currency to the target (to
) currency and the timestamp for the conversion rate used.
Description
Use the convertCurrency()
function to convert an array of one or more amounts between two currencies. The convertCurrency()
function returns an array of converted amounts and the timestamp for the conversion rate used.
Note: The currency codes used must exist in the array of supported currencies returned by the
listCurrencies()
function.
This function is not a universal function and runs only on the backend
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function convertCurrency(identifiers: ConvertCurrencyIdentifiers, amounts: Array<DecimalValue>): Promise<ConvertCurrencyResponse>
convertCurrency Parameters
NAME
TYPE
DESCRIPTION
Identifying details needed to determine which currency rate to convert. The combination of the from
and to
properties together comprise the unique ID.
Amounts to convert.
Returns
Return Type:
NAME
TYPE
DESCRIPTION
Converted amounts.
Date and time the conversion rate was last updated.
Was this helpful?
Convert an array of amounts from one currency to another
1import { currencies } from 'wix-ecom.v2';23const identifiers = {4 'from': 'USD',5 'to': 'GBP'6};78const amounts = [9 {10 'decimalPlaces': 2,11 'value': '1000'12 },13 {14 'decimalPlaces': 2,15 'value': '20324'16 }17];1819currencies.convertCurrency(identifiers, amounts)20 .then((convertedAmounts) => {21 const firstConvertedAmount = convertedAmounts.amounts[0];22 const timestamp = convertedAmounts.rateTimestamp;23 });2425/* Promise resolves to:26 * {27 * "amounts": [28 * {29 * "decimalPlaces": 2,30 * "value": "795"31 * },32 * {33 * "decimalPlaces": 2,34 * "value": "1616287"35 * }36 * ],37 * "rateTimestamp": "2023-04-30T21:00:00.277Z"38 * }39 */