Search.../

getOfflineOrderPreview( )

Developer Preview

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

Description

The getOfflineOrderPreview() 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, 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. Thus 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 getPricePreview() function.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function getOfflineOrderPreview(planId: string, memberId: string, options: GetOfflineOrderPreviewOptions): Promise<GetOfflineOrderPreviewResponse>

getOfflineOrderPreview Parameters

NAME
TYPE
DESCRIPTION
planId
string

ID of the plan of the previewed order.

memberId
string

Member ID of the buyer the previewed order is for.

options
Optional
GetOfflineOrderPreviewOptions

Options for previewing the offline order.

Returns

Fulfilled - A preview of the order.

Return Type:

Promise<
GetOfflineOrderPreviewResponse
>
NAME
TYPE
DESCRIPTION
order
Order

The previewed order, 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?

Create an offline order preview

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 memberId value: '695568ff-1dc2-49ff-83db-2b518d35692b'
7 */
8
9const elevatedGetOfflineOrderPreview = elevate(orders.getOfflineOrderPreview);
10
11export async function myGetOfflineOrderPreviewFunction(planId, memberId) {
12 try {
13 const orderPreview = await elevatedGetOfflineOrderPreview(planId, memberId);
14
15 return orderPreview;
16 } catch (error) {
17 console.error(error);
18 // Handle the error
19 }
20}
21
22/* Promise resolves to:
23 * {
24 * order: {
25 * "_createdDate": "2024-01-31T08:51:46.516Z",
26 * "_id": "00000000-0000-0000-0000-000000000000",
27 * "_updatedDate": "2024-01-31T08:51:46.516Z",
28 * "autoRenewCanceled": false,
29 * "buyer": {
30 * "contactId": "695568ff-1dc2-49ff-83db-2b518d35692b",
31 * "memberId": "695568ff-1dc2-49ff-83db-2b518d35692b"
32 * },
33 * "currentCycle": {
34 * "endedDate": "2024-03-01T08:51:46.516Z",
35 * "index": 0,
36 * "startedDate": "2024-01-31T08:51:46.516Z"
37 * },
38 * "cycles": [
39 * {
40 * "endedDate": "2024-03-01T08:51:46.516Z",
41 * "index": 0,
42 * "startedDate": "2024-01-31T08:51:46.516Z"
43 * }
44 * ],
45 * "endDate": "2026-03-01T08:51:46.516Z",
46 * "earliestEndDate": "2026-03-01T08:51:46.516Z",
47 * "formData": {
48 * "submissionData": {}
49 * },
50 * "freeTrialDays": 30,
51 * "lastPaymentStatus": "PAID",
52 * "order": {
53 * "autoRenewCanceled": false,
54 * "buyer": {
55 * "contactId": "695568ff-1dc2-49ff-83db-2b518d35692b",
56 * "memberId": "695568ff-1dc2-49ff-83db-2b518d35692b"
57 * },
58 * "currentCycle": {
59 * "endedDate": "2024-03-01T08:51:46.516Z",
60 * "index": 0,
61 * "startedDate": "2024-01-31T08:51:46.516Z"
62 * },
63 * "cycles": [
64 * {
65 * "endedDate": "2024-03-01T08:51:46.516Z",
66 * "index": 0,
67 * "startedDate": "2024-01-31T08:51:46.516Z"
68 * }
69 * ],
70 * "endDate": "2026-03-01T08:51:46.516Z",
71 * "earliestEndDate": "2026-03-01T08:51:46.516Z",
72 * "formData": {
73 * "submissionData": {}
74 * },
75 * "freeTrialDays": 30,
76 * "lastPaymentStatus": "PAID",
77 * "orderMethod": "UNKNOWN",
78 * "orderType": "OFFLINE",
79 * "pausePeriods": [],
80 * "planDescription": "Complete with all features. One month free trial.",
81 * "planId": "838f2c9d-c8d0-4799-a10a-e2f23849db10",
82 * "planName": "Premium Plan - annual - 30 day trial",
83 * "planPrice": "500",
84 * "priceDetails": {
85 * "currency": "USD",
86 * "discount": "0",
87 * "freeTrialDays": 30,
88 * "planPrice": "500",
89 * "subtotal": "500.00",
90 * "total": "500.00",
91 * "subscription": {
92 * "cycleCount": 2,
93 * "cycleDuration": {
94 * "count": 1,
95 * "unit": "YEAR"
96 * }
97 * }
98 * },
99 * "pricing": {
100 * "prices": [
101 * {
102 * "duration": {
103 * "cycleFrom": 1,
104 * "numberOfCycles": 2
105 * },
106 * "price": {
107 * "currency": "USD",
108 * "discount": "0",
109 * "fees": [],
110 * "proration": "0",
111 * "subtotal": "500.00",
112 * "total": "500.00"
113 * }
114 * }
115 * ],
116 * "subscription": {
117 * "cycleCount": 2,
118 * "cycleDuration": {
119 * "count": 1,
120 * "unit": "YEAR"
121 * }
122 * }
123 * },
124 * "seller": {
125 * "subscriptionId": "00000000-0000-0000-0000-000000000000"
126 * },
127 * "startDate": "2024-01-31T08:51:46.516Z",
128 * "status": "ACTIVE",
129 * "statusNew": "ACTIVE",
130 * "type": "OFFLINE"
131 * },
132 * "orderMethod": "UNKNOWN",
133 * "pausePeriods": [],
134 * "planDescription": "Complete with all features. One month free trial.",
135 * "planId": "838f2c9d-c8d0-4799-a10a-e2f23849db10",
136 * "planName": "Premium Plan - annual - 30 day trial",
137 * "planPrice": "500",
138 * "pricing": {
139 * "prices": [
140 * {
141 * "duration": {
142 * "cycleFrom": 1,
143 * "numberOfCycles": 2
144 * },
145 * "price": {
146 * "currency": "USD",
147 * "discount": "0",
148 * "fees": [],
149 * "proration": "0",
150 * "subtotal": "500.00",
151 * "total": "500.00"
152 * }
153 * }
154 * ],
155 * "subscription": {
156 * "cycleCount": 2,
157 * "cycleDuration": {
158 * "count": 1,
159 * "unit": "YEAR"
160 * }
161 * }
162 * },
163 * "startDate": "2024-01-31T08:51:46.516Z",
164 * "status": "ACTIVE",
165 * "statusNew": "ACTIVE",
166 * "subscriptionId": "00000000-0000-0000-0000-000000000000",
167 * "type": "OFFLINE"
168 * }
169 * "purchaseLimitExceeded": false
170 * }
171 */
172
Create an offline order preview with options

Copy Code
1import { orders } from 'wix-pricing-plans.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample planId value: 'd2fa5805-0d1a-4cfb-9b43-e683cf5fa990'
5 *
6 * Sample memberId value: '554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4'
7 *
8 * Sample options value:
9 * {
10 * couponCode: 'seasonal',
11 * startDate: new Date()
12 * }
13 */
14
15const elevatedGetOfflineOrderPreview = elevate(orders.getOfflineOrderPreview);
16
17export async function myGetOfflineOrderPreviewFunction(planId, memberId, options) {
18 try {
19 const orderPreview = await elevatedGetOfflineOrderPreview(planId, memberId, options);
20
21 return orderPreview;
22 } catch (error) {
23 console.error(error);
24 // Handle the error
25 }
26}
27
28/* Promise resolves to:
29 * {
30 * "order": {
31 * "_createdDate": "2024-02-01T07:58:49.777Z",
32 * "_id": "00000000-0000-0000-0000-000000000000",
33 * "_updatedDate": "2024-02-01T07:58:49.777Z",
34 * "autoRenewCanceled": false,
35 * "buyer": {
36 * "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",
37 * "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"
38 * },
39 * "currentCycle": {
40 * "endedDate": "2024-02-15T07:58:49.387Z",
41 * "index": 0,
42 * "startedDate": "2024-02-01T07:58:49.387Z"
43 * },
44 * "formData": {
45 * "fomrId":
46 * "submissionData": {
47 * "email_0fd2": "Jboss@email.com",
48 * "form_field_aa30": false,
49 * "first_name_c551": "Jason",
50 * "last_name_78e9": "Bollinger",
51 * "phone_8cf1": "212-909-2222"
52 * },
53 * "submissionId": "10206732-e789-40e9-957d-2c7f3398efc6"
54 * },
55 * "freeTrialDays": 14,
56 * "lastPaymentStatus": "PAID",
57 * "pausePeriods": [],
58 * "planDescription": "The value plan",
59 * "planId": "d2fa5805-0d1a-4cfb-9b43-e683cf5fa990",
60 * "planName": "Silver Membership - Monthly",
61 * "planPrice": "100",
62 * "status": "ACTIVE",
63 * "orderMethod": "UNKNOWN",
64 * "pricing": {
65 * "prices": [
66 * {
67 * "duration": {
68 * "cycleFrom": 1,
69 * "numberOfCycles": 1
70 * },
71 * "price": {
72 * "coupon": {
73 * "code": "seasonal",
74 * "amount": "95.00",
75 * "_id": "8673834a-a5c6-4e77-af9c-83f9bf609659"
76 * },
77 * "total": "30.00",
78 * "proration": "0",
79 * "fees": [
80 * {
81 * "name": "Setup Fee",
82 * "amount": "25"
83 * }
84 * ],
85 * "currency": "USD",
86 * "subtotal": "125.00",
87 * "discount": "95.00"
88 * }
89 * },
90 * {
91 * "duration": {
92 * "cycleFrom": 2
93 * },
94 * "price": {
95 * "coupon": {
96 * "code": "seasonal",
97 * "amount": "95.00",
98 * "_id": "8673834a-a5c6-4e77-af9c-83f9bf609659"
99 * },
100 * "total": "5.00",
101 * "proration": "0",
102 * "fees": [],
103 * "currency": "USD",
104 * "subtotal": "100.00",
105 * "discount": "95.00"
106 * }
107 * }
108 * ]
109 * "subscription": {
110 * "cycleCount": 0,
111 * "cycleDuration": {
112 * "count": 1,
113 * "unit": "MONTH"
114 * }
115 * }
116 * },
117 * "startDate": "2024-02-01T07:58:49.387Z",
118 * "status": "ACTIVE",
119 * "subscriptionId": "00000000-0000-0000-0000-000000000000",
120 * "type": "OFFLINE",
121 * },
122 * "purchaseLimitExceeded": false
123 * }
124 */