Search.../

onOrderCreated( )

Developer Preview

Triggered when an order is created.

Syntax

function wixPricingPlans_onOrderCreated(event: OrderCreated): void

onOrderCreated Parameters

NAME
TYPE
DESCRIPTION
event
Optional
OrderCreated

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

onOrderCreated example

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_onOrderCreated(event) {
6 const orderId = event.entity._id;
7 const createdDate = event.entity._createdDate;
8 const buyer = event.entity.buyer;
9
10 console.log(`The order with ID ${event.orderId} to purchase the ${event.plan.name} plan was created on ${createdDate} by the buyer ${buyer}. The full event object:`, event);
11}
12
13/* Full event object:
14 * {
15 * "entity": {
16 * "_createdDate": "2024-01-25T11:45:05.036Z",
17 * "_id": "3b620f8b-33f3-4e29-b1db-c21d7a6afa01",
18 * "_updatedDate": "2024-01-25T11:45:05.036Z",
19 * "buyer": {
20 * "contactId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4",
21 * "memberId": "554c9e11-f4d8-4579-ac3a-a17f7e6cb0b4"
22 * },
23 * "currentCycle": {
24 * "index": 1,
25 * "startedDate": "2024-01-25T11:45:05.036Z"
26 * },
27 * "cycles": [
28 * {
29 * "index": 1,
30 * "startedDate": "2024-01-25T11:45:05.036Z"
31 * }
32 * ],
33 * "formData": {
34 * "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
35 * "submissionData": {},
36 * "submissionId": "1b282868-0a1e-42c6-9123-3a611b0014bf"
37 * },
38 * "lastPaymentStatus": "NOT_APPLICABLE",
39 * "orderMethod": "UNKNOWN",
40 * "pausePeriods": [],
41 * "planDescription": "",
42 * "planId": "aa0d8e0e-99ad-4c95-ac48-4955e37956c5",
43 * "planName": "Default",
44 * "planPrice": "0",
45 * "pricing": {
46 * "prices": [
47 * {
48 * "duration": {
49 * "cycleFrom": 1,
50 * "numberOfCycles": 1
51 * },
52 * "price": {
53 * "currency": "EUR",
54 * "discount": "0",
55 * "fees": [],
56 * "proration": "0",
57 * "subtotal": "0.00",
58 * "total": "0"
59 * }
60 * }
61 * ],
62 * "singlePaymentUnlimited": true
63 * },
64 * "startDate": "2024-01-25T11:45:05.036Z",
65 * "status": "ACTIVE",
66 * "statusNew": "DRAFT",
67 * "subscriptionId": "e9fff457-bc89-4c8c-94c0-1d162711c9a6",
68 * "type": "ONLINE"
69 * },
70 * "metadata": {
71 * "entityId": "3b620f8b-33f3-4e29-b1db-c21d7a6afa01",
72 * "eventTime": "2024-01-25T11:45:06.457639259Z",
73 * "id": "6a0b2d17-6211-4394-b3e4-9c1a1bb1b1cc",
74 * "triggeredByAnonymizeRequest": false
75 * }
76 * }
77 */
78