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 totrue
.
Syntax
function previewOfflineOrder(planId: string, buyerId: string, [options: PreviewOfflineOrderOptions]): Promise<OrderPreview>
previewOfflineOrder Parameters
NAME
TYPE
DESCRIPTION
ID of the plan being previewed.
Member ID for the buyer who might order the plan offline. The buyerId
must be entered because the buyer might not be logged in.
Additional options for previewing the offline order.
Returns
Fulfilled - A preview of the order.
Return Type:
NAME
TYPE
DESCRIPTION
The preview, as if the plan had been ordered.
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.
Related Content:
Was this helpful?
Preview an offline order as if it was purchased, bypassing permission checks
1import { Permissions, webMethod } from 'wix-web-module';2import { checkout } from 'wix-pricing-plans-backend';34/* Sample planId value: '7251b9e9-3852-4e9f-958e-af630f039802'5 *6 * Sample buyerId value: '4c47c608-cfa8-4037-93ac-738f09560ed3'7 *8 * Sample options value:9 * {10 * startDate: new Date('July 17, 2022 10:00:00'),11 * suppressAuth: true12 * }13 */1415export const myPreviewOfflineOrderFunction = webMethod(Permissions.Anyone, async (planId, buyerId, options) => {16 try {17 const preview = await checkout.previewOfflineOrder(planId, buyerId, options);18 const maxReached = preview.purchaseLimitExceeded;19 const orderPricing = preview.order.pricing;2021 return preview;22 } catch (error) {23 console.error(error);24 }25});2627/* Promise resolves to:28 *29 * {30 * "order": {31 * "_id": "00000000-0000-0000-0000-000000000000",32 * "planId": "7251b9e9-3852-4e9f-958e-af630f039802",33 * "subscriptionId": "00000000-0000-0000-0000-000000000000",34 * "buyer": {35 * "memberId": "4c47c608-cfa8-4037-93ac-738f09560ed3",36 * "contactId": "4c47c608-cfa8-4037-93ac-738f09560ed3"37 * },38 * "priceDetails": {39 * "subtotal": "0",40 * "discount": "0",41 * "total": "0",42 * "planPrice": "0",43 * "currency": "USD",44 * "singlePaymentUnlimited": true45 * },46 * "pricing": {47 * "singlePaymentUnlimited": true,48 * "prices": [49 * {50 * "duration": {51 * "cycleFrom": 1,52 * "numberOfCycles": 153 * },54 * "price": {55 * "subtotal": "0",56 * "discount": "0",57 * "total": "0",58 * "currency": "USD"59 * }60 * }61 * ]62 * },63 * "type": "OFFLINE",64 * "orderMethod": "UNKNOWN",65 * "status": "ACTIVE",66 * "lastPaymentStatus": "PAID",67 * "startDate": "2022-07-17T10:00:00.000Z",68 * "pausePeriods": [],69 * "planName": "Family Cooking",70 * "planDescription": "Weekly delivery of home cooking recipes and time-saving tips",71 * "planPrice": "0",72 * "_createdDate": "2022-07-13T04:54:23.503Z",73 * "_updatedDate": "2022-07-13T04:54:23.503Z"74 * },75 * "purchaseLimitExceeded": false76 * }77 */