cancelOrder( )
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.
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
Order ID.
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:
Was this helpful?
1import { orders } from 'wix-pricing-plans.v2';2import { elevate } from 'wix-auth';34/* Sample _id value: 'e6f12ae0-2618-41e7-a643-31ca2ee51e2b'5 *6 * Sample effectiveAt value: 'IMMEDIATELY'7 */89const elevatedCancelOrder = elevate(orders.cancelOrder);1011export async function myCancelOrderFunction(_id, effectiveAt) {12 try {13 await elevatedCancelOrder(_id, effectiveAt);1415 return;16 } catch (error) {17 console.error(error);18 // Handle the error19 }20}2122/* Promise resolves to void */
1import { Permissions, webMethod } from 'wix-web-module';2import { orders } from 'wix-pricing-plans.v2';3import { elevate } from 'wix-auth';45/*6 * Sample _id value: 'e6f12ae0-2618-41e7-a643-31ca2ee51e2b'7 *8 * Sample effectiveAt value: 'IMMEDIATELY'9 */1011const elevatedCancelOrder = elevate(orders.cancelOrder);1213export const myCancelOrderFunction = webMethod(Permissions.Anyone, async (_id, effectiveAt) => {14 try {15 await elevatedCancelOrder(_id, effectiveAt);1617 return;18 } catch (error) {19 console.error(error);20 // Handle the error21 }22});2324/* Promise resolves to void */25