Search...
getConversionRate( )
Returns the conversion rate between 2 currencies.
Admin Method
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function getConversionRate(identifiers: GetConversionRateIdentifiers): Promise<ConversionRateResponse>
getConversionRate Parameters
NAME
TYPE
DESCRIPTION
identifiers
GetConversionRateIdentifiers
Identifying details needed to get the conversion rate. The combination of the from
and to
properties together comprise the unique ID.
Returns
Return Type:
Promise<
ConversionRateResponse
>NAME
TYPE
DESCRIPTION
rate
DecimalValue
Conversion rate between 2 currencies.
rateTimestamp
Date
Date and time the conversion rate was last updated.
Was this helpful?
Return the conversion rate and timestamp (dashboard page code)
Copy Code
1import { currencies } from 'wix-ecom.v2';23currencies.getConversionRate('USD', 'GBP')4 .then((conversionRate) => {5 const rate = conversionRate.rate;6 const timestamp = conversionRate.rateTimestamp;7 });89/* Promise resolves to:10 * {11 * "rate": {12 * value: "20",13 * decimalPlaces: 214 * },15 * "rateTimestamp": "2020-03-15T20:00:00.181Z"16 * }17 */
Return the conversion rate and timestamp (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { currencies } from 'wix-ecom.v2';34export const getConversionRate = webMethod(Permissions.Anyone, async () => {5 try {6 const conversionRate = await currencies.getConversionRate('USD', 'GBP');7 const rate = conversionRate.rate;8 const timestamp = conversionRate.rateTimestamp;910 return conversionRate;11 } catch (error) {12 console.error(error);13 // Handle the error14 }15});1617getConversionRate()18 .then((conversionRate) => {19 const rate = conversionRate.rate;20 const timestamp = conversionRate.rateTimestamp;21 });2223/* Promise resolves to:24 * {25 * "rate": {26 * value: "20",27 * decimalPlaces: 228 * },29 * "rateTimestamp": "2020-03-15T20:00:00.181Z"30 * }31 */32