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

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