Search.../

getPricePreview( )

Developer Preview

Retrieves a preview of an order's pricing as if it was purchased.

Description

The getPricePreview() function returns a Promise that resolves to a temporary preview of the order's price.

The price preview uses the same logic for calculating prices as used when purchasing a plan, but the preview is not saved. If taxes are configured for the site, taxes are applied to the preview. If not, the tax previews as null.

Buyers do not have to be logged in to preview the price, as such, the details returned by this function are not buyer-specific. To generate a preview of a purchase for a specific-buyer, use the getOfflineOrderPreview().

Syntax

function getPricePreview(planId: string, options: GetPricePreviewOptions): Promise<GetPricePreviewResponse>

getPricePreview Parameters

NAME
TYPE
DESCRIPTION
planId
string

ID of plan to preview.

options
Optional
GetPricePreviewOptions

Options for getting a price preview.

Returns

Fulfilled - A preview of the pricing for the order.

Return Type:

Promise<
GetPricePreviewResponse
>
NAME
TYPE
DESCRIPTION
prices
Array<
SpannedPrice
>

Pricing details.

Was this helpful?

Get a price preview for an order

Copy Code
1import { orders } from 'wix-pricing-plans.v2';
2
3/* Sample planId value: '838f2c9d-c8d0-4799-a10a-e2f23849db10' */
4
5export async function myGetPricePreviewFunction(planId) {
6 try {
7 const pricePreview = await orders.getPricePreview(planId);
8
9 return pricePreview;
10 } catch (error) {
11 console.error(error);
12 // Handle the error
13 }
14}
15/* Promise resolves to:
16 * {
17 * "prices": [
18 * {
19 * "duration": {
20 * "cycleFrom": 1,
21 * "numberOfCycles": 2
22 * },
23 * "price": {
24 * "currency": "USD",
25 * "discount": "0"
26 * "proration": "0",
27 * "subtotal": "500.00",
28 * "tax": {
29 * "name": "Tax",
30 * "includedInPrice": false,
31 * "rate": "6.5",
32 * "amount": "32.50"
33 * },
34 * "total": "532.50"
35 * }
36 * }
37 * ]
38 * }
39 */
Get a price preview for an order (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { orders } from 'wix-pricing-plans.v2';
3
4// Sample planId value: '838f2c9d-c8d0-4799-a10a-e2f23849db10'
5
6
7export const myGetPricePreviewFunction = webMethod(Permissions.Anyone, async (planId) => {
8 try {
9 const pricePreview = await orders.getPricePreview(planId);
10
11 return pricePreview;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16});
17/* Promise resolves to:
18 * {
19 * "prices": [
20 * {
21 * "duration": {
22 * "cycleFrom": 1,
23 * "numberOfCycles": 2
24 * },
25 * "price": {
26 * "currency": "USD",
27 * "discount": "0"
28 * "proration": "0",
29 * "subtotal": "500.00",
30 * "tax": {
31 * "name": "Tax",
32 * "includedInPrice": false,
33 * "rate": "6.5",
34 * "amount": "32.50"
35 * },
36 * "total": "532.50"
37 * }
38 * }
39 * ]
40 * }
41 */
42
Get a price preview for an order with options

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { orders } from 'wix-pricing-plans.v2';
3
4/* Sample planId value: '838f2c9d-c8d0-4799-a10a-e2f23849db10'
5 *
6 * Sample options value:
7 * {
8 * couponCode: 'SUMMERSALE'
9 * }
10 */
11
12export const myGetPricePreviewFunction = webMethod(Permissions.Anyone, async (planId, options) => {
13 try {
14 const pricePreview = await orders.getPricePreview(planId, options);
15
16 return pricePreview;
17 } catch (error) {
18 console.error(error);
19 // Handle the error
20 }
21});
22
23/* Promise resolves to:
24 * {
25 * "prices": [
26 * {
27 * "duration": {
28 * "cycleFrom": 1,
29 * "numberOfCycles": 1
30 * },
31 * "price": {
32 * "coupon": {
33 * "code": "SUMMERSALE",
34 * "amount": "90.00",
35 * "_id": "271d5fe4-2105-47b8-81c1-b24201d1be68"
36 * },
37 * "discount": "90.00",
38 * "currency": "USD",
39 * "subtotal": "125.00",
40 * "tax": {
41 * "amount": "2.28",
42 * "includedInPrice": false,
43 * "name": "Tax",
44 * "rate": "6.5",
45 * },
46 * "total": "37.28"
47 * }
48 * },
49 * {
50 * "duration": {
51 * "cycleFrom": 2
52 * },
53 * "price": {
54 * "coupon": {
55 * "code": "SUMMERSALE",
56 * "amount": "90.00",
57 * "_id": "271d5fe4-2105-47b8-81c1-b24201d1be68"
58 * },
59 * "discount": "90.00",
60 * "currency": "USD",
61 * "subtotal": "100.00",
62 * "tax": {
63 * "amount": "0.65",
64 * "includedInPrice": false,
65 * "name": "Tax",
66 * "rate": "6.5"
67 * },
68 * "total": "10.65",
69 * }
70 * }
71 * ]
72 * }
73 */
74