Search.../

requestCancellation( )

Developer Preview

Starts the process of canceling an order.

Description

The requestCancellation() function returns a Promise that resolves when the order cancellation is successfully requested.

For orders with recurring payments, a cancellation can be set to occur either immediately or at the next payment date. For orders with one-time payments, a cancellation occurs immediately after the request is processed.

Requesting an order cancellation starts the cancellation process. There may be some operations that continue to be processed before the status of the order is changed to "CANCELED". For example, payments might need to be refunded before the order is fully canceled.

Authorization

Request

This endpoint does not take any parameters

Response Object

Fulfilled - When the cancellation process is started.

Returns an empty object.

Status/Error Codes

Was this helpful?

Cancel an order immediately

Copy Code
1import { orders } from 'wix-pricing-plans.v2';
2
3/* Sample _id value: '7b4ec42c-582a-4e2f-874b-09e66e0ae09d'
4 *
5 * Sample effectiveAt value: 'IMMEDIATELY'
6 */
7
8export async function myRequestCancellationFunction(_id, effectiveAt) {
9 try {
10 await orders.requestCancellation(_id, effectiveAt);
11
12 return;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17}
18
19/* Promise resolves to void */
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}