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.

Authorization

Request

This endpoint does not take any parameters

Response Object

NAME
TYPE
DESCRIPTION
rate
DecimalValue

Conversion rate between 2 currencies.

rateTimestamp
Date

Date and time the conversion rate was last updated.

Status/Error Codes

Was this helpful?

Return the conversion rate and timestamp (dashboard page code)

Copy Code
1import { currencies } from 'wix-ecom.v2';
2
3currencies.getConversionRate('USD', 'GBP')
4 .then((conversionRate) => {
5 const rate = conversionRate.rate;
6 const timestamp = conversionRate.rateTimestamp;
7 });
8
9/* Promise resolves to:
10 * {
11 * "rate": {
12 * value: "20",
13 * decimalPlaces: 2
14 * },
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';
3
4export 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;
9
10 return conversionRate;
11 } catch (error) {
12 console.error(error);
13 // Handle the error
14 }
15});
16
17getConversionRate()
18 .then((conversionRate) => {
19 const rate = conversionRate.rate;
20 const timestamp = conversionRate.rateTimestamp;
21 });
22
23/* Promise resolves to:
24 * {
25 * "rate": {
26 * value: "20",
27 * decimalPlaces: 2
28 * },
29 * "rateTimestamp": "2020-03-15T20:00:00.181Z"
30 * }
31 */
32