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