Search.../

previewPrice( )

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

Description

The previewPrice() 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 previewOfflineOrder() or previewOnlineOrder() functions.

Syntax

function previewPrice(planId: string, [couponCode: string]): Promise<PricePreview>

previewPrice Parameters

NAME
TYPE
DESCRIPTION
planId
string

ID of the plan whose pricing should be previewed.

couponCode
Optional
string

Coupon code to apply.

To learn more about coupons, see applyCoupon().

Returns

Fulfilled - A preview of the pricing for the order.

Return Type:

Promise<PricePreview>
NAME
TYPE
DESCRIPTION
price
PriceDetails

Deprecated. Use prices instead.

prices
Prices

Pricing details.

Was this helpful?

Preview the pricing details for a plan to be purchased with a 10%-off coupon

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { checkout } from 'wix-pricing-plans-backend';
3
4// Sample planId value: '6d7537c5-beac-44a3-bea3-b947ddc56b31'
5//
6// Sample couponCode value: 'BACKTOSHAPE22'
7
8export const myPreviewPriceFunction = webMethod(Permissions.Anyone, async (planId, couponCode) => {
9 try {
10 const pricePreview = await checkout.previewPrice(planId, couponCode);
11 const orderPricing = pricePreview.prices.price.total;
12 const currency = pricePreview.prices.price.currency;
13
14 return pricePreview;
15 } catch (error) {
16 console.error(error);
17 }
18});
19
20/* Promise resolves to:
21 *
22 * {
23 * "price": {
24 * "subtotal": "14.99",
25 * "discount": "1.5",
26 * "total": "13.49",
27 * "planPrice": "14.99",
28 * "currency": "USD",
29 * "subscription": {
30 * "cycleDuration": {
31 * "count": 1,
32 * "unit": "MONTH"
33 * },
34 * "cycleCount": 0
35 * },
36 * "coupon": {
37 * "code": "BACKTOSHAPE22",
38 * "amount": "1.5",
39 * "_id": "52f73ce1-9e31-40f7-b5d4-a621b4b4057d"
40 * }
41 * },
42 * "prices": [
43 * {
44 * "duration": {
45 * "cycleFrom": 1
46 * },
47 * "price": {
48 * "subtotal": "14.99",
49 * "coupon": {
50 * "code": "BACKTOSHAPE22",
51 * "amount": "1.5",
52 * "_id": "52f73ce1-9e31-40f7-b5d4-a621b4b4057d"
53 * },
54 * "discount": "1.5",
55 * "total": "13.49",
56 * "currency": "USD"
57 * }
58 * }
59 * ]
60 * }
61 */