previewOnlineOrder( )


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

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.

Method Declaration
Copy
function previewOnlineOrder(
  planId: string,
  options: PreviewOnlineOrderOptions,
): Promise<OrderPreview>;
Method Parameters
planIdstringRequired

ID of the plan to be previewed.


optionsPreviewOnlineOrderOptions

Additional options for previewing the online order.

Returns
Return Type:Promise<OrderPreview>
Preview an online order as if it was purchased with a coupon
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { checkout } from "wix-pricing-plans-backend"; /* Sample planId value: '38b3021a-8b43-4a31-98cc-4a05b522b7d3' * * Sample startDate value: new Date('August 01, 2022 11:00:00') */ export const myPreviewOnlineOrderFunction = webMethod( Permissions.Anyone, async (planId, startDate) => { try { const preview = await checkout.previewOnlineOrder(planId, startDate); const maxReached = preview.purchaseLimitExceeded; const orderPricing = preview.order.pricing; return preview; } catch (error) { console.error(error); } }, ); /* Promise resolves to: * * { * "order": { * "_id": "00000000-0000-0000-0000-000000000000", * "planId": "38b3021a-8b43-4a31-98cc-4a05b522b7d3", * "subscriptionId": "00000000-0000-0000-0000-000000000000", * "buyer": { * "memberId": "ea3d74df-b7dc-4ca1-a7c9-c416b9017a86", * "contactId": "ea3d74df-b7dc-4ca1-a7c9-c416b9017a86" * }, * "priceDetails": { * "subtotal": "10", * "discount": "0", * "total": "10", * "planPrice": "10", * "currency": "USD", * "subscription": { * "cycleDuration": { * "count": 1, * "unit": "MONTH" * }, * "cycleCount": 12 * }, * "freeTrialDays": 30 * }, * "pricing": { * "subscription": { * "cycleDuration": { * "count": 1, * "unit": "MONTH" * }, * "cycleCount": 12 * }, * "prices": [ * { * "duration": { * "cycleFrom": 1, * "numberOfCycles": 12 * }, * "price": { * "subtotal": "10", * "discount": "0", * "total": "10", * "currency": "USD" * } * } * ] * }, * "type": "ONLINE", * "orderMethod": "UNKNOWN", * "status": "ACTIVE", * "autoRenewCanceled": false, * "lastPaymentStatus": "PAID", * "startDate": "2022-08-01T11:00:00.000Z", * "endDate": "2023-08-31T11:00:00.000Z", * "pausePeriods": [], * "freeTrialDays": 30, * "earliestEndDate": "2023-08-31T11:00:00.000Z", * "planName": "Diabetic Cooking", * "planDescription": "Special recipes for those with diabetes.", * "planPrice": "10", * "_createdDate": "2022-07-13T05:02:40.265Z", * "_updatedDate": "2022-07-13T05:02:40.265Z" * }, * "purchaseLimitExceeded": false * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?