Search.../

previewOfflineOrder( )

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

Description

The previewOfflineOrder() function returns a Promise that resolves to a temporary preview of the offline 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 as null.

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 not available to the buyer. You specify the member ID for the buyer whose order should be previewed. To get a general price preview for a plan that's not buyer-specific, use the previewPrice() function.

Note: Only those with the Manage Pricing Plans and Manage Subscriptions permissions can preview offline orders. You can override the permissions by setting the function's suppressAuth option to true.

Syntax

function previewOfflineOrder(planId: string, buyerId: string, [options: PreviewOfflineOrderOptions]): Promise<OrderPreview>

previewOfflineOrder Parameters

NAME
TYPE
DESCRIPTION
planId
string

ID of the plan being previewed.

buyerId
string

Member ID for the buyer who might order the plan offline. The buyerId must be entered because the buyer might not be logged in.

options
Optional
PreviewOfflineOrderOptions

Additional options for previewing the offline 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 offline order as if it was purchased, bypassing permission checks

Copy Code
1import { checkout } from 'wix-pricing-plans-backend';
2
3/* Sample planId value: '7251b9e9-3852-4e9f-958e-af630f039802'
4 *
5 * Sample buyerId value: '4c47c608-cfa8-4037-93ac-738f09560ed3'
6 *
7 * Sample options value:
8 * {
9 * startDate: new Date('July 17, 2022 10:00:00'),
10 * suppressAuth: true
11 * }
12 */
13
14export async function myPreviewOfflineOrderFunction(planId, buyerId, options) {
15 try {
16 const preview = await checkout.previewOfflineOrder(planId, buyerId, options);
17 const maxReached = preview.purchaseLimitExceeded;
18 const orderPricing = preview.order.pricing;
19
20 return preview;
21 } catch (error) {
22 console.error(error);
23 }
24}
25
26/* Promise resolves to:
27 *
28 * {
29 * "order": {
30 * "_id": "00000000-0000-0000-0000-000000000000",
31 * "planId": "7251b9e9-3852-4e9f-958e-af630f039802",
32 * "subscriptionId": "00000000-0000-0000-0000-000000000000",
33 * "buyer": {
34 * "memberId": "4c47c608-cfa8-4037-93ac-738f09560ed3",
35 * "contactId": "4c47c608-cfa8-4037-93ac-738f09560ed3"
36 * },
37 * "priceDetails": {
38 * "subtotal": "0",
39 * "discount": "0",
40 * "total": "0",
41 * "planPrice": "0",
42 * "currency": "USD",
43 * "singlePaymentUnlimited": true
44 * },
45 * "pricing": {
46 * "singlePaymentUnlimited": true,
47 * "prices": [
48 * {
49 * "duration": {
50 * "cycleFrom": 1,
51 * "numberOfCycles": 1
52 * },
53 * "price": {
54 * "subtotal": "0",
55 * "discount": "0",
56 * "total": "0",
57 * "currency": "USD"
58 * }
59 * }
60 * ]
61 * },
62 * "type": "OFFLINE",
63 * "orderMethod": "UNKNOWN",
64 * "status": "ACTIVE",
65 * "lastPaymentStatus": "PAID",
66 * "startDate": "2022-07-17T10:00:00.000Z",
67 * "pausePeriods": [],
68 * "planName": "Family Cooking",
69 * "planDescription": "Weekly delivery of home cooking recipes and time-saving tips",
70 * "planPrice": "0",
71 * "_createdDate": "2022-07-13T04:54:23.503Z",
72 * "_updatedDate": "2022-07-13T04:54:23.503Z"
73 * },
74 * "purchaseLimitExceeded": false
75 * }
76 */