An event that triggers when the start date of a purchased or free order is reached.
The onOrderStarted()
event handler runs when an order is started.
This means the order's start date is reached and the buyer can start using
the plan.
The received OrderStartedEvent
object contains information about the order that started.
Note: Backend events don't work when previewing your site.
function onOrderStarted(event: OrderUpdatedEvent): void;
Information about the order that started and metadata for the event.
// 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_onOrderStarted(event) {
const orderId = event.entity.order._id;
const eventId = event.metadata.id;
const eventTime = event.metadata.eventTime;
}
/* Full event object:
* {
* "metadata": {
* "id":"260d91e5-6353-404f-a466-fc2d72a5c94a",
* "entityId":"a4599201-c592-4f29-87e0-4eda76117ede",
* "eventTime":"2022-07-27T00:00:03.157685Z",
* "triggeredByAnonymizeRequest":false
* },
* "data": {
* "order": {
* "_id":"a4599201-c592-4f29-87e0-4eda76117ede",
* "planId":"099e2c86-3b7e-4477-8c27-f77402b8cceb",
* "subscriptionId":"9c1b85a0-83f9-430e-bff0-b1d1abfcfb70",
* "buyer": {
* "memberId":"ea3d74df-b7dc-4ca1-a7c9-c416b9017a86",
* "contactId":"ea3d74df-b7dc-4ca1-a7c9-c416b9017a86"
* },
* "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":"ACTIVE",
* "autoRenewCanceled":false,
* "lastPaymentStatus":"PAID",
* "startDate":"2022-07-27T00:00:00Z",
* "endDate":"2022-10-27T00:00:00Z",
* "pausePeriods": [],
* "earliestEndDate":"2022-10-27T00:00:00Z",
* "currentCycle":{
* "index":1,
* "startedDate":"2022-07-27T00:00:00Z",
* "endedDate":"2022-08-27T00:00:00Z"
* },
* "planName":"Platinum Pro",
* "planDescription":"",
* "planPrice":"74.99",
* "_createdDate":"2022-07-26T15:23:33.437Z",
* "_updatedDate":"2022-07-26T15:23:34.076Z"
* }
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.