Search.../

requestCurrentMemberOrderCancellation( )

Requests the cancellation of a specific order of a plan for the currently logged-in member.

Description

The requestCurrentMemberOrderCancellation() function requests the cancellation of an order, after verifying that the site member is logged in.

This function does not immediately cancel the order. The cancellation request is initiated and the status of the order is updated to "PENDING_CANCELLATION". When the cancellation is completed, the order status is updated to "CANCELED".

Keep in mind that a site member can order several subscriptions of the same plan. This API does not cancel the plan and remove all corresponding subscriptions. This API removes only the one specified order of the plan.

If a plan's Allow Plan Cancellation setting is disabled and the currently logged-in site member tries to cancel an order for the plan using the requestCurrentMemberOrderCancellation() function, an error is thrown.

Notes:

  • The pricing plan requestCurrentMemberOrderCancellation() function replaces the deprecated paid plans cancelOrder() function. The deprecated function will continue to work, but will not receive updates. To keep any existing code compatible with future changes, see the cancelOrder() migration instructions.

  • To work with the Pricing Plans API, you need to publish your site.

Syntax

function requestCurrentMemberOrderCancellation(orderId: string, effectiveAt: string): Promise<void>

requestCurrentMemberOrderCancellation Parameters

NAME
TYPE
DESCRIPTION
orderId
string

The order ID of the order whose cancellation is requested.

effectiveAt
string

When the cancellation should take effect. One of:

  • "IMMEDIATELY". The cancellation occurs immediately and the buyer cannot use the plan at this point.
  • "NEXT_PAYMENT_DATE". The cancellation occurs at the next payment date. The buyer can continue to use the plan until that date.

Returns

Fulfilled - When the order cancellation is requested.

Return Type:

Promise<void>

Was this helpful?

Request cancellation of an order on button click

Copy Code
1import { orders } from 'wix-pricing-plans-frontend';
2
3// Sample orderId value: 'e9667014-b773-40b1-871d-041cedd9302d'
4//
5// Sample effectiveAt value: 'IMMEDIATELY'
6
7$w('#cancelMyOrderButton').onClick((event) => {
8 orders.requestCurrentMemberOrderCancellation(orderId, effectiveAt)
9 .then(() => {
10 console.log('Order cancellation requested.');
11 })
12 .catch((error) => {
13 console.error(error);
14 });
15 });
A full cancel order request scenario

This example demonstrates a more robust scenario for requesting the cancellation of a pricing plan order, including updates to a collection.

In the interest of simplicity the code does not deal with display considerations or validations that would normally be required to make sure users perform the flow as intended.

Customized elements include:

  • A cancelButton button that the site member clicks to cancel an order of a plan.
  • A Subscriptions collection. This custom collection contains all plan orders purchased by the site member and each subscription's status.
  • A subscriptionDataset dataset that connects the page to the Subscriptions collection.
  • Two lightboxes, orderCanceled and cancelFailed that notify the site member if a subscription is cancelled.

Copy Code
1import { orders } from 'wix-pricing-plans-frontend';
2import wixData from 'wix-data';
3import wixMembersFrontend from 'wix-members-frontend';
4import wixWindowFrontend from 'wix-window-frontend';
5
6$w.onReady(function () {
7
8 $w('#subscriptionDataset').onReady( () => {
9
10 // Get the order ID for the subscription to cancel
11 const subscription = $w('#subscriptionDataset').getCurrentItem();
12 const orderId = subscription.orderId;
13
14 $w('cancelButton').onClick((event) => {
15
16 // Cancel the specific subscription of the plan immediately
17 orders.requestCurrentMemberOrderCancellation(orderId, "IMMEDIATELY")
18 .then(() => {
19
20 // Let user know that cancellation succeeded
21 wixWindowFrontend.openLightbox('orderCanceled');
22
23 // Get details for updating status of existing subscription
24 const member = wixMembersFrontend.currentMember;
25 const toUpdate = {
26 _id: subscription._id,
27 planName: subscription.planName,
28 planId: subscription.planId,
29 orderId: subscription.orderId,
30 memberId: user.id,
31 dateCreated: subscription.dateCreated,
32 canceled: true, // Set cancellation to true
33 dateUpdated: Date().toString()
34 };
35
36 // Update subscription in collection to show the subscription is canceled
37 wixData.update('Subscriptions', toUpdate);
38 })
39
40 // Let user know if cancellation failed
41 .catch((error) => {
42 wixWindowFrontend.openLightbox('cancelFailed');
43 });
44 });
45 });
46 });
47