Search.../

onOrderPurchased( )

Developer Preview

Triggered when an order is purchased.

Description

This webhook is triggered for any of the following events:

  • Order is paid in full.
  • At least 1 order cycle payment is paid for.
  • Offline order is created, even if not yet marked as paid.
  • Free order is created.

Syntax

function wixPricingPlans_onOrderPurchased(event: OrderPurchasedEvent): void

onOrderPurchased Parameters

NAME
TYPE
DESCRIPTION
event
Optional
OrderPurchasedEvent

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

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