Search.../

previewOnlineOrder( )

Provides a preview of an online order as if it was purchased.

Description

The previewOnlineOrder() function returns a Promise that resolves to a temporary preview of the online order.

The buyer must be logged in to preview an online order.

The preview uses the same logic as purchasing a plan, but the preview is not saved. Because an order is not actually created, the preview's _id and subscriptionId properties are displayed as a string of multiple zero characters (000000-0000).

If taxes are configured for the site, taxes are applied to the preview. If not, the tax previews asnull.

You can preview the order to check purchase limitations, but the limitations are not enforced for the preview. If a pricing plan has a limit on the amount of purchases per buyer, that limit is not considered for generating the preview. But, if that limit has been reached and this order would then exceed the amount of purchases permitted for this buyer, then purchaseLimitExceeded will return as true.

This function is available to the site owner and the buyer. Because the buyer is logged in, you do not need to specify the buyerId when previewing an online order. To get a general price preview for a plan that's not buyer-specific, use the previewPrice() function.

Syntax

function previewOnlineOrder(planId: string, [options: PreviewOnlineOrderOptions]): Promise<OrderPreview>

previewOnlineOrder Parameters

NAME
TYPE
DESCRIPTION
planId
string

ID of the plan to be previewed.

options
Optional
PreviewOnlineOrderOptions

Additional options for previewing the online order.

Returns

Fulfilled - A preview of the order.

Return Type:

Promise<OrderPreview>
NAME
TYPE
DESCRIPTION
order
Order

The preview, as if the plan had been ordered.

purchaseLimitExceeded
boolean

Whether this previewed order would exceed the permitted amount of purchases available for this plan for this buyer.

Always false for plans that do not have purchase limits.

Was this helpful?

Preview an online order as if it was purchased with a coupon

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { checkout } from 'wix-pricing-plans-backend';
3
4/* Sample planId value: '38b3021a-8b43-4a31-98cc-4a05b522b7d3'
5 *
6 * Sample startDate value: new Date('August 01, 2022 11:00:00')
7 */
8
9export const myPreviewOnlineOrderFunction = webMethod(Permissions.Anyone, async (planId, startDate) => {
10 try {
11 const preview = await checkout.previewOnlineOrder(planId, startDate);
12 const maxReached = preview.purchaseLimitExceeded;
13 const orderPricing = preview.order.pricing;
14
15 return preview;
16 } catch (error) {
17 console.error(error);
18 };
19});
20
21/* Promise resolves to:
22 *
23 * {
24 * "order": {
25 * "_id": "00000000-0000-0000-0000-000000000000",
26 * "planId": "38b3021a-8b43-4a31-98cc-4a05b522b7d3",
27 * "subscriptionId": "00000000-0000-0000-0000-000000000000",
28 * "buyer": {
29 * "memberId": "ea3d74df-b7dc-4ca1-a7c9-c416b9017a86",
30 * "contactId": "ea3d74df-b7dc-4ca1-a7c9-c416b9017a86"
31 * },
32 * "priceDetails": {
33 * "subtotal": "10",
34 * "discount": "0",
35 * "total": "10",
36 * "planPrice": "10",
37 * "currency": "USD",
38 * "subscription": {
39 * "cycleDuration": {
40 * "count": 1,
41 * "unit": "MONTH"
42 * },
43 * "cycleCount": 12
44 * },
45 * "freeTrialDays": 30
46 * },
47 * "pricing": {
48 * "subscription": {
49 * "cycleDuration": {
50 * "count": 1,
51 * "unit": "MONTH"
52 * },
53 * "cycleCount": 12
54 * },
55 * "prices": [
56 * {
57 * "duration": {
58 * "cycleFrom": 1,
59 * "numberOfCycles": 12
60 * },
61 * "price": {
62 * "subtotal": "10",
63 * "discount": "0",
64 * "total": "10",
65 * "currency": "USD"
66 * }
67 * }
68 * ]
69 * },
70 * "type": "ONLINE",
71 * "orderMethod": "UNKNOWN",
72 * "status": "ACTIVE",
73 * "autoRenewCanceled": false,
74 * "lastPaymentStatus": "PAID",
75 * "startDate": "2022-08-01T11:00:00.000Z",
76 * "endDate": "2023-08-31T11:00:00.000Z",
77 * "pausePeriods": [],
78 * "freeTrialDays": 30,
79 * "earliestEndDate": "2023-08-31T11:00:00.000Z",
80 * "planName": "Diabetic Cooking",
81 * "planDescription": "Special recipes for those with diabetes.",
82 * "planPrice": "10",
83 * "_createdDate": "2022-07-13T05:02:40.265Z",
84 * "_updatedDate": "2022-07-13T05:02:40.265Z"
85 * },
86 * "purchaseLimitExceeded": false
87 * }
88 */