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 planscancelOrder()
function. The deprecated function will continue to work, but will not receive updates. To keep any existing code compatible with future changes, see thecancelOrder()
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
The order ID of the order whose cancellation is requested.
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:
Was this helpful?
1import { orders } from 'wix-pricing-plans-frontend';23// Sample orderId value: 'e9667014-b773-40b1-871d-041cedd9302d'4//5// Sample effectiveAt value: 'IMMEDIATELY'67$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 });
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.
1import { orders } from 'wix-pricing-plans-frontend';2import wixData from 'wix-data';3import wixMembersFrontend from 'wix-members-frontend';4import wixWindowFrontend from 'wix-window-frontend';56$w.onReady(function () {78 $w('#subscriptionDataset').onReady( () => {910 // Get the order ID for the subscription to cancel11 const subscription = $w('#subscriptionDataset').getCurrentItem();12 const orderId = subscription.orderId;1314 $w('cancelButton').onClick((event) => {1516 // Cancel the specific subscription of the plan immediately17 orders.requestCurrentMemberOrderCancellation(orderId, "IMMEDIATELY")18 .then(() => {1920 // Let user know that cancellation succeeded21 wixWindowFrontend.openLightbox('orderCanceled');2223 // Get details for updating status of existing subscription24 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 true33 dateUpdated: Date().toString()34 };3536 // Update subscription in collection to show the subscription is canceled37 wixData.update('Subscriptions', toUpdate);38 })3940 // Let user know if cancellation failed41 .catch((error) => {42 wixWindowFrontend.openLightbox('cancelFailed');43 });44 });45 });46 });47