Search.../

pauseOrder( )

Developer Preview

Pauses a pricing plan order.

Description

The pauseOrder() function returns a Promise that resolves when the order is successfully paused.

For orders with recurring payments, pauseOrder() also pauses the payment schedule. Buyers are not charged when an order is paused. Use pauseOrder(), for example, if the buyer is away and would like to put their pricing plan membership on hold until they return. Pausing an order affects the end date of the order by adding the time the order is paused to the endDate. You can only pause orders with an "ACTIVE" status.

Pausing an order causes the following changes:

  • The order status changes to "PAUSED".
  • The pausePeriods array is updated.

The endDate and the earliestEndDate for the order are adjusted to include the pause period when the order is resumed.

Paused orders can be continued with the resumeOrder() function.

Admin Method

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

Syntax

function pauseOrder(_id: string): Promise<void>

pauseOrder Parameters

NAME
TYPE
DESCRIPTION
_id
string

Order ID.

Returns

Fulfilled - When the order is paused.

Return Type:

Promise<
void
>

Was this helpful?

Pause a pricing plan order (dashboard page code)

Copy Code
1import { orders } from 'wix-pricing-plans.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample _id value: '9af3cbe6-fe27-4fdb-a0b0-892289b03d22' */
5
6const elevatedPauseOrder = elevate(orders.pauseOrder);
7
8export async function myPauseOrderFunction(_id) {
9 try {
10 await elevatedPauseOrder(_id);
11
12 return;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17}
18
19/* Promise resolves to void */
Pause a pricing plan order (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { orders } from 'wix-pricing-plans.v2';
3import { elevate } from 'wix-auth';
4
5// Sample _id value: '9af3cbe6-fe27-4fdb-a0b0-892289b03d22'
6
7const elevatedPauseOrder = elevate(orders.pauseOrder);
8
9export const myPauseOrderFunction = webMethod(Permissions.Anyone, async (_id) => {
10 try {
11 await elevatedPauseOrder(_id);
12
13 return;
14 } catch (error) {
15 console.error(error);
16 // Handle the error
17 }
18});
19
20/* Promise resolves to void */
21
Cancel or pause a member order

This example provides a dropdown list of active orders for a logged-in member. The member selects a plan from the #ordersDropdown and clicks the #cancelOrderBtn to cancel the plan or the #pauseOrderBtn to pause the plan.

Copy Code
1/*******************************
2 * Backend code - order.web.js *
3********************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { orders } from 'wix-pricing-plans.v2';
7import { elevate } from 'wix-auth';
8
9const elevatedPauseOrder = elevate(orders.pauseOrder);
10
11export const listCurrentMemberOrders = webMethod(
12 Permissions.Anyone,
13 async (orderStatuses) => {
14 try {
15 const result = await orders.memberListOrders(orderStatuses);
16
17 return result;
18 } catch (error) {
19 console.error(error);
20 // Handle the error
21 }
22 });
23
24export const requestCancellation = webMethod(
25 Permissions.Anyone,
26 async (orderId) => {
27 const effectiveAt = 'NEXT_PAYMENT_DATE';
28 try {
29 await orders.requestCancellation(orderId, effectiveAt) ;
30
31 return;
32 } catch (error) {
33 console.error(error);
34 // Handle the error
35 }
36 });
37
38export const pauseOrder = webMethod(
39 Permissions.Anyone,
40 async (orderId) => {
41 try {
42 await elevatedPauseOrder(orderId);
43
44 return;
45 } catch (error) {
46 console.error(error);
47 // Handle the error
48 }
49 });
50
51/*************
52 * Page code *
53 *************/
54
55import { listCurrentMemberOrders, requestCancellation, pauseOrder } from 'backend/order.web';
56
57$w.onReady(function () {
58 // Disabe UI elements on page load
59 $w('#requestCancelOrderBtn').disable();
60 $w('#pauseOrderBtn').disable();
61 $w('#ordersDropdown').disable();
62
63 let selectedOrderId;
64 populateOrdersDropdown();
65
66 $w('#ordersDropdown').onChange( () => {
67 selectedOrderId = $w('#ordersDropdown').value;
68 $w('#requestCancelOrderBtn').enable();
69 $w('#pauseOrderBtn').enable();
70 });
71
72 $w('#requestCancelOrderBtn').onClick(async () => {
73 await requestCancellation(selectedOrderId);
74 });
75
76 $w('#pauseOrderBtn').onClick(async () => {
77 await pauseOrder(selectedOrderId);
78 });
79});
80
81async function populateOrdersDropdown() {
82 const activeOrdersList = await listCurrentMemberOrders({orderStatuses: 'ACTIVE'});
83 $w('#ordersDropdown').options = activeOrdersList.orders.map((order) => {
84 return {
85 label: order.planName,
86 value: order._id
87 }
88 });
89 $w('#ordersDropdown').enable();
90}