Search.../

onOrderPurchased( )

An event that triggers when an order is purchased.

Description

The onOrderPurchased() event handler runs when an order is purchased. The received OrderPurchasedEvent object contains information about the order that was purchased.

An order is considered purchased if:

  • The order is paid for in full, or at least one of its billing cycle payments is paid.
  • An offline order is created, even if not yet marked as paid.
  • A free online order is created.

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

Syntax

function onOrderPurchased(event: OrderPurchasedEvent): void

onOrderPurchased Parameters

NAME
TYPE
DESCRIPTION
event
OrderPurchasedEvent

Information about the order that was purchased and metadata for the event.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

An event triggered when an order is purchased

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_onOrderPurchased(event) {
6 const orderId = event.data.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":"f2e01b16-48c3-4365-89c7-1e3710639f50",
15 * "entityId":"938ca26d-41e0-4aae-81a2-286ae9afd6ef",
16 * "eventTime":"2022-07-26T14:59:49.951623Z",
17 * "triggeredByAnonymizeRequest":false
18 * },
19 * "data": {
20 * "order": {
21 * "_id":"938ca26d-41e0-4aae-81a2-286ae9afd6ef",
22 * "planId":"099e2c86-3b7e-4477-8c27-f77402b8cceb",
23 * "subscriptionId":"1b879750-b4c3-4b17-9687-1f18f6b0ea19",
24 * "wixPayOrderId":"3eb01dc8-45c7-426f-a910-13d8c6008532",
25 * "buyer": {
26 * "memberId":"ea3d74df-b7dc-4ca1-a7c9-c416b9017a86",
27 * "contactId":"ea3d74df-b7dc-4ca1-a7c9-c416b9017a86"
28 * },
29 * "priceDetails": {
30 * "subtotal":"74.99",
31 * "discount":"0",
32 * "total":"74.99",
33 * "planPrice":"74.99",
34 * "currency":"EUR",
35 * "subscription": {
36 * "cycleDuration": {
37 * "count":1,
38 * "unit":"MONTH"
39 * },
40 * "cycleCount":3
41 * }},
42 * "pricing": {
43 * "subscription": {
44 * "cycleDuration": {
45 * "count":1,
46 * "unit":"MONTH"
47 * },
48 * "cycleCount":3
49 * },
50 * "prices": [{
51 * "duration": {
52 * "cycleFrom":1,
53 * "numberOfCycles":3
54 * },
55 * "price": {
56 * "subtotal":"74.99",
57 * "discount":"0",
58 * "total":"74.99",
59 * "currency":"EUR"
60 * }
61 * }]},
62 * "type":"OFFLINE",
63 * "orderMethod":"UNKNOWN",
64 * "status":"ACTIVE",
65 * "autoRenewCanceled":false,
66 * "lastPaymentStatus":"PAID",
67 * "startDate":"2022-01-25T16:23:00.000Z",
68 * "endDate":"2022-04-25T16:23:00.000Z",
69 * "pausePeriods":[],
70 * "earliestEndDate":"2022-04-25T16:23:00.000Z",
71 * "currentCycle": {
72 * "index":3,
73 * "startedDate":"2022-03-25T16:23:00.000Z",
74 * "endedDate":"2022-04-25T16:23:00.000Z"
75 * },
76 * "planName":"Platinum Pro",
77 * "planDescription":"",
78 * "planPrice":"74.99",
79 * "_createdDate":"2022-07-26T14:59:49.314Z",
80 * "_updatedDate":"2022-07-26T14:59:49.314Z"
81 * }
82 * }
83 * }
84 */