Search.../

cancelOrder( )

Developer Preview

Cancels an existing order.

Description

The cancelOrder() function returns a Promise that resolves when the order is successfully canceled.

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.

Canceling an order changes the order status to CANCELED.

Canceling during the free trial period.

When a buyer cancels their order during the free trial period, the buyer's subscription expires at the end of the free trial period and they won't be billed. The buyer may continue using the benefits until the end of the free trial period.

When a site owner cancels an ordered plan during the free trial period, they choose to apply the cancellation IMMEDIATELY or at the NEXT_PAYMENT_DATE.

Canceling IMMEDIATELY will end the subscription for the buyer immediately, even during the free trial period and the buyer won't be billed. Canceling at the NEXT_PAYMENT_DATE allows the buyer to continue using the benefits of the subscription until the end of the free trial period. Then, the subscription ends and the buyer is not billed.

Admin Method

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

Syntax

function cancelOrder(_id: string, effectiveAt: string): Promise<void>

cancelOrder Parameters

NAME
TYPE
DESCRIPTION
_id
string

Order ID.

effectiveAt
string

When the order is canceled.

One time orders can only be canceled immediately. Supported values:

  • "IMMEDIATELY": The order is canceled immediately.
  • "NEXT_PAYMENT_DATE": The order is canceled at the next payment date.

Returns

Fulfilled - When the order is canceled.

Return Type:

Promise<
void
>

Was this helpful?

Cancel an order immediately (dashboard page code)

Copy Code
1import { orders } from 'wix-pricing-plans.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample _id value: 'e6f12ae0-2618-41e7-a643-31ca2ee51e2b'
5 *
6 * Sample effectiveAt value: 'IMMEDIATELY'
7 */
8
9const elevatedCancelOrder = elevate(orders.cancelOrder);
10
11export async function myCancelOrderFunction(_id, effectiveAt) {
12 try {
13 await elevatedCancelOrder(_id, effectiveAt);
14
15 return;
16 } catch (error) {
17 console.error(error);
18 // Handle the error
19 }
20}
21
22/* Promise resolves to void */
Cancel an order immediately (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/*
6 * Sample _id value: 'e6f12ae0-2618-41e7-a643-31ca2ee51e2b'
7 *
8 * Sample effectiveAt value: 'IMMEDIATELY'
9 */
10
11const elevatedCancelOrder = elevate(orders.cancelOrder);
12
13export const myCancelOrderFunction = webMethod(Permissions.Anyone, async (_id, effectiveAt) => {
14 try {
15 await elevatedCancelOrder(_id, effectiveAt);
16
17 return;
18 } catch (error) {
19 console.error(error);
20 // Handle the error
21 }
22});
23
24/* Promise resolves to void */
25