requestCancellation( )
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.
Syntax
function requestCancellation(_id: string, effectiveAt: string): Promise<void>
requestCancellation Parameters
NAME
TYPE
DESCRIPTION
Order ID.
Whether to cancel the order immediately or at the next payment date. One-time payment orders can only be canceled immediately.
Supported values:
"IMMEDIATELY"
: Indicates that the order should be canceled immediately."NEXT_PAYMENT_DATE"
: Indicates that the order be canceled at the next payment date.
Returns
Fulfilled - When the cancellation process is started.
Return Type:
Was this helpful?
1import { orders } from 'wix-pricing-plans.v2';23/* Sample _id value: '7b4ec42c-582a-4e2f-874b-09e66e0ae09d'4 *5 * Sample effectiveAt value: 'IMMEDIATELY'6 */78export async function myRequestCancellationFunction(_id, effectiveAt) {9 try {10 await orders.requestCancellation(_id, effectiveAt);1112 return;13 } catch (error) {14 console.error(error);15 // Handle the error16 }17}1819/* Promise resolves to void */
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.
1/*******************************2 * Backend code - order.web.js *3********************************/45import { Permissions, webMethod } from 'wix-web-module';6import { orders } from 'wix-pricing-plans.v2';7import { elevate } from 'wix-auth';89const elevatedPauseOrder = elevate(orders.pauseOrder);1011export const listCurrentMemberOrders = webMethod(12 Permissions.Anyone,13 async (orderStatuses) => {14 try {15 const result = await orders.memberListOrders(orderStatuses);1617 return result;18 } catch (error) {19 console.error(error);20 // Handle the error21 }22 });2324export const requestCancellation = webMethod(25 Permissions.Anyone,26 async (orderId) => {27 const effectiveAt = 'NEXT_PAYMENT_DATE';28 try {29 await orders.requestCancellation(orderId, effectiveAt) ;3031 return;32 } catch (error) {33 console.error(error);34 // Handle the error35 }36 });3738export const pauseOrder = webMethod(39 Permissions.Anyone,40 async (orderId) => {41 try {42 await elevatedPauseOrder(orderId);4344 return;45 } catch (error) {46 console.error(error);47 // Handle the error48 }49 });5051/*************52 * Page code *53 *************/5455import { listCurrentMemberOrders, requestCancellation, pauseOrder } from 'backend/order.web';5657$w.onReady(function () {58 // Disabe UI elements on page load59 $w('#requestCancelOrderBtn').disable();60 $w('#pauseOrderBtn').disable();61 $w('#ordersDropdown').disable();6263 let selectedOrderId;64 populateOrdersDropdown();6566 $w('#ordersDropdown').onChange( () => {67 selectedOrderId = $w('#ordersDropdown').value;68 $w('#requestCancelOrderBtn').enable();69 $w('#pauseOrderBtn').enable();70 });7172 $w('#requestCancelOrderBtn').onClick(async () => {73 await requestCancellation(selectedOrderId);74 });7576 $w('#pauseOrderBtn').onClick(async () => {77 await pauseOrder(selectedOrderId);78 });79});8081async 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._id87 }88 });89 $w('#ordersDropdown').enable();90}