onOrderEnded( )


An event that triggers when an order expires or is canceled immediately.

The onOrderEnded() event handler runs when an order expires. The received OrderEndedEvent object contains information about the order that expired.

Note: Backend events don't work when previewing your site.

Method Declaration
Copy
function onOrderEnded(event: OrderEndedEvent): void;
Method Parameters
eventOrderEndedEventRequired

Information about the order that ended and metadata for the event.

An event triggered when an order ends
JavaScript
// Place this code in the events.js file // of your site's Backend section. // Add the file if it doesn't exist. export function wixPricingPlans_onOrderEnded(event) { const orderId = event.data.order._id; const eventId = event.metadata.id; const eventTime = event.metadata.eventTime; } /* Full event object: * { * "metadata": { * "id":"664bce7f-d30a-4d3f-8e1b-57840a766d25", * "entityId":"c778761f-0d19-4533-ac6d-434408398bf9", * "eventTime":"2022-08-08T11:00:03.912278Z", * "triggeredByAnonymizeRequest":false * }, * "data": { * "order": { * "_id":"c778761f-0d19-4533-ac6d-434408398bf9", * "planId":"099e2c86-3b7e-4477-8c27-f77402b8cceb", * "subscriptionId":"5493bc14-2ca4-4496-ba43-bcfc0fc3a47c", * "wixPayOrderId":"c63bcec6-dc46-4080-8892-82cb09492986", * "buyer": { * "memberId":"fac761ea-e6f1-4e3d-8b30-a4852f091415", * "contactId":"fac761ea-e6f1-4e3d-8b30-a4852f091415" * }, * "priceDetails": { * "subtotal":"74.99", * "discount":"0", * "total":"74.99", * "planPrice":"74.99", * "currency":"EUR", * "subscription": { * "cycleDuration": { * "count":1, * "unit":"MONTH" * }, * "cycleCount":3 * }}, * "pricing": { * "subscription": { * "cycleDuration": { * "count":1, * "unit":"MONTH" * }, * "cycleCount":3 * }, * "prices": [{ * "duration": { * "cycleFrom":1, * "numberOfCycles":3 * }, * "price": { * "subtotal":"74.99", * "discount":"0", * "total":"74.99", * "currency":"EUR" * } * }]}, * "type":"OFFLINE", * "orderMethod":"UNKNOWN", * "status":"CANCELED", * "autoRenewCanceled":true, * "cancellation": { * "cause":"OWNER_ACTION", * "effectiveAt":"NEXT_PAYMENT_DATE" * }, * "lastPaymentStatus":"PAID", * "startDate":"2022-06-08T11:00:00.000Z", * "endDate":"2022-08-08T11:00:02.862Z", * "pausePeriods":[], * "earliestEndDate":"2022-09-08T11:00:00.000Z", * "planName":"Platinum Pro", * "planDescription":"", * "planPrice":"74.99", * "_createdDate":"2022-08-08T10:54:30.869Z", * "_updatedDate":"2022-08-08T11:00:03.781Z" * } * } * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?