Search.../

onOrderStarted( )

An event that triggers when the start date of a purchased or free order is reached.

Description

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.

Syntax

function onOrderStarted(event: OrderUpdatedEvent): void

onOrderStarted Parameters

NAME
TYPE
DESCRIPTION
event
OrderUpdatedEvent

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

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

An event triggered when an order starts

Copy Code
1// Place this code in the events.js file
2// of your site's Backend section.
3// Add the file if it doesn't exist.
4
5export function wixPricingPlans_onOrderStarted(event) {
6 const orderId = event.entity.order._id;
7 const eventId = event.metadata.id;
8 const eventTime = event.metadata.eventTime;
9}
10
11/* Full event object:
12 * {
13 * "metadata": {
14 * "id":"260d91e5-6353-404f-a466-fc2d72a5c94a",
15 * "entityId":"a4599201-c592-4f29-87e0-4eda76117ede",
16 * "eventTime":"2022-07-27T00:00:03.157685Z",
17 * "triggeredByAnonymizeRequest":false
18 * },
19 * "data": {
20 * "order": {
21 * "_id":"a4599201-c592-4f29-87e0-4eda76117ede",
22 * "planId":"099e2c86-3b7e-4477-8c27-f77402b8cceb",
23 * "subscriptionId":"9c1b85a0-83f9-430e-bff0-b1d1abfcfb70",
24 * "buyer": {
25 * "memberId":"ea3d74df-b7dc-4ca1-a7c9-c416b9017a86",
26 * "contactId":"ea3d74df-b7dc-4ca1-a7c9-c416b9017a86"
27 * },
28 * "priceDetails": {
29 * "subtotal":"74.99",
30 * "discount":"0",
31 * "total":"74.99",
32 * "planPrice":"74.99",
33 * "currency":"EUR",
34 * "subscription": {
35 * "cycleDuration": {
36 * "count":1,
37 * "unit":"MONTH"
38 * },
39 * "cycleCount":3
40 * }},
41 * "pricing": {
42 * "subscription": {
43 * "cycleDuration": {
44 * "count":1,
45 * "unit":"MONTH"
46 * },
47 * "cycleCount":3
48 * },
49 * "prices": [{
50 * "duration": {
51 * "cycleFrom":1,
52 * "numberOfCycles":3
53 * },
54 * "price": {
55 * "subtotal":"74.99",
56 * "discount":"0",
57 * "total":"74.99",
58 * "currency":"EUR"
59 * }
60 * }]},
61 * "type":"OFFLINE",
62 * "orderMethod":"UNKNOWN",
63 * "status":"ACTIVE",
64 * "autoRenewCanceled":false,
65 * "lastPaymentStatus":"PAID",
66 * "startDate":"2022-07-27T00:00:00Z",
67 * "endDate":"2022-10-27T00:00:00Z",
68 * "pausePeriods": [],
69 * "earliestEndDate":"2022-10-27T00:00:00Z",
70 * "currentCycle":{
71 * "index":1,
72 * "startedDate":"2022-07-27T00:00:00Z",
73 * "endedDate":"2022-08-27T00:00:00Z"
74 * },
75 * "planName":"Platinum Pro",
76 * "planDescription":"",
77 * "planPrice":"74.99",
78 * "_createdDate":"2022-07-26T15:23:33.437Z",
79 * "_updatedDate":"2022-07-26T15:23:34.076Z"
80 * }
81 * }
82 * }
83 */