Search.../

onCheckoutCompleted( )

An event that triggers when a checkout is completed. This happens either when an order is created from a checkout, or after using markCheckoutAsCompleted().

Description

The onCheckoutCompleted() event handler runs when a checkout is completed. The received CheckoutCompleted object contains information about the checkout that was completed and event metadata.

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

Syntax

function wixEcom_onCheckoutCompleted(event: CheckoutCompleted): void

onCheckoutCompleted Parameters

NAME
TYPE
DESCRIPTION
event
Optional
CheckoutCompleted

Information about the checkout that was completed and event metadata.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

An event fired when a checkout is completed

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 wixEcom_onCheckoutCompleted(event) {
6 const checkoutSubtotal = event.entity.subtotal.amount;
7 const checkoutId = event.entity._id;
8 const checkoutComplete = event.entity.completed;
9 const eventId = event.metadata.id;
10 console.log('Checkout completed', event)
11}
12
13/* Full event object:
14 *
15 * {
16 * "metadata": {
17 * "id": "d94b500b-3906-434f-bd90-92c521e4f0e3",
18 * "entityId": "81b73bc6-d403-4afe-8464-226f9505b1c2",
19 * "eventTime": "2022-10-27T11:58:12.667470Z",
20 * "triggeredByAnonymizeRequest": false
21 * },
22 * "data": {
23 * "checkout": {
24 * "_id": "81b73bc6-d403-4afe-8464-226f9505b1c2",
25 * "lineItems": [
26 * {
27 * "_id": "00000000-0000-0000-0000-000000000001",
28 * "quantity": 3,
29 * "catalogReference": {
30 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",
31 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"
32 * },
33 * "productName": {
34 * "original": "Shirt",
35 * "translated": "Shirt"
36 * },
37 * "url": "https://example.wixsite.com",
38 * "price": {
39 * "amount": "10",
40 * "convertedAmount": "10",
41 * "formattedAmount": "$10.00",
42 * "formattedConvertedAmount": "$10.00"
43 * },
44 * "lineItemPrice": {
45 * "amount": "30",
46 * "convertedAmount": "30",
47 * "formattedAmount": "$30.00",
48 * "formattedConvertedAmount": "$30.00"
49 * },
50 * "fullPrice": {
51 * "amount": "10",
52 * "convertedAmount": "10",
53 * "formattedAmount": "$10.00",
54 * "formattedConvertedAmount": "$10.00"
55 * },
56 * "priceBeforeDiscounts": {
57 * "amount": "10",
58 * "convertedAmount": "10",
59 * "formattedAmount": "$10.00",
60 * "formattedConvertedAmount": "$10.00"
61 * },
62 * "totalPriceAfterTax": {
63 * "amount": "20",
64 * "convertedAmount": "20",
65 * "formattedAmount": "$20.00",
66 * "formattedConvertedAmount": "$20.00"
67 * },
68 * "totalPriceBeforeTax": {
69 * "amount": "20",
70 * "convertedAmount": "20",
71 * "formattedAmount": "$20.00",
72 * "formattedConvertedAmount": "$20.00"
73 * },
74 * "taxDetails": {
75 * "taxableAmount": {
76 * "amount": "20",
77 * "convertedAmount": "20",
78 * "formattedAmount": "$20.00",
79 * "formattedConvertedAmount": "$20.00"
80 * },
81 * "taxRate": "0",
82 * "totalTax": {
83 * "amount": "0",
84 * "convertedAmount": "0",
85 * "formattedAmount": "$0.00",
86 * "formattedConvertedAmount": "$0.00"
87 * },
88 * "rateBreakdown": []
89 * },
90 * "discount": {
91 * "amount": "10",
92 * "convertedAmount": "10",
93 * "formattedAmount": "$10.00",
94 * "formattedConvertedAmount": "$10.00"
95 * },
96 * "descriptionLines": [],
97 * "media": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",
98 * "availability": {
99 * "status": "AVAILABLE"
100 * },
101 * "physicalProperties": {
102 * "sku": "364115376135191",
103 * "shippable": true
104 * },
105 * "couponScopes": [
106 * {
107 * "namespace": "stores",
108 * "group": {
109 * "name": "collection",
110 * "entityId": "00000000-000000-000000-000000000001"
111 * }
112 * },
113 * {
114 * "namespace": "stores",
115 * "group": {
116 * "name": "product",
117 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"
118 * }
119 * }
120 * ],
121 * "itemType": {
122 * "preset": "PHYSICAL"
123 * },
124 * "paymentOption": "FULL_PAYMENT_ONLINE",
125 * "rootCatalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a"
126 * }
127 * ],
128 * "shippingInfo": {
129 * "carrierServiceOptions": []
130 * },
131 * "buyerInfo": {
132 * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db",
133 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
134 * },
135 * "conversionCurrency": "USD",
136 * "priceSummary": {
137 * "subtotal": {
138 * "amount": "30",
139 * "convertedAmount": "30",
140 * "formattedAmount": "$30.00",
141 * "formattedConvertedAmount": "$30.00"
142 * },
143 * "shipping": {
144 * "amount": "0",
145 * "convertedAmount": "0",
146 * "formattedAmount": "$0.00",
147 * "formattedConvertedAmount": "$0.00"
148 * },
149 * "tax": {
150 * "amount": "0",
151 * "convertedAmount": "0",
152 * "formattedAmount": "$0.00",
153 * "formattedConvertedAmount": "$0.00"
154 * },
155 * "discount": {
156 * "amount": "10",
157 * "convertedAmount": "10",
158 * "formattedAmount": "$10.00",
159 * "formattedConvertedAmount": "$10.00"
160 * },
161 * "total": {
162 * "amount": "20",
163 * "convertedAmount": "20",
164 * "formattedAmount": "$20.00",
165 * "formattedConvertedAmount": "$20.00"
166 * },
167 * "additionalFees": {
168 * "amount": "0",
169 * "convertedAmount": "0",
170 * "formattedAmount": "$0.00",
171 * "formattedConvertedAmount": "$0.00"
172 * }
173 * },
174 * "calculationErrors": {
175 * "orderValidationErrors": []
176 * },
177 * "appliedDiscounts": [
178 * {
179 * "discountType": "GLOBAL",
180 * "lineItemIds": [],
181 * "coupon": {
182 * "_id": "fbb94b06-7447-4161-9c48-59bfcdc39e77",
183 * "code": "SUMMERSALE10",
184 * "amount": {
185 * "amount": "10",
186 * "convertedAmount": "10",
187 * "formattedAmount": "$10.00",
188 * "formattedConvertedAmount": "$10.00"
189 * },
190 * "name": "SUMMERSALE10",
191 * "couponType": "MoneyOff"
192 * }
193 * }
194 * ],
195 * "customFields": [],
196 * "weightUnit": "KG",
197 * "currency": "USD",
198 * "channelType": "WEB",
199 * "siteLanguage": "en",
200 * "buyerLanguage": "en",
201 * "completed": true,
202 * "taxIncludedInPrice": false,
203 * "createdBy": {
204 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
205 * },
206 * "_createdDate": "2022-10-27T11:42:17.059Z",
207 * "_updatedDate": "2022-10-27T11:58:12.657Z",
208 * "payNow": {
209 * "subtotal": {
210 * "amount": "30",
211 * "convertedAmount": "30",
212 * "formattedAmount": "$30.00",
213 * "formattedConvertedAmount": "$30.00"
214 * },
215 * "shipping": {
216 * "amount": "0",
217 * "convertedAmount": "0",
218 * "formattedAmount": "$0.00",
219 * "formattedConvertedAmount": "$0.00"
220 * },
221 * "tax": {
222 * "amount": "0",
223 * "convertedAmount": "0",
224 * "formattedAmount": "$0.00",
225 * "formattedConvertedAmount": "$0.00"
226 * },
227 * "discount": {
228 * "amount": "10",
229 * "convertedAmount": "10",
230 * "formattedAmount": "$10.00",
231 * "formattedConvertedAmount": "$10.00"
232 * },
233 * "total": {
234 * "amount": "20",
235 * "convertedAmount": "20",
236 * "formattedAmount": "$20.00",
237 * "formattedConvertedAmount": "$20.00"
238 * },
239 * "additionalFees": {
240 * "amount": "0",
241 * "convertedAmount": "0",
242 * "formattedAmount": "$0.00",
243 * "formattedConvertedAmount": "$0.00"
244 * }
245 * },
246 * "payLater": {
247 * "subtotal": {
248 * "amount": "0",
249 * "convertedAmount": "0",
250 * "formattedAmount": "$0.00",
251 * "formattedConvertedAmount": "$0.00"
252 * },
253 * "shipping": {
254 * "amount": "0",
255 * "convertedAmount": "0",
256 * "formattedAmount": "$0.00",
257 * "formattedConvertedAmount": "$0.00"
258 * },
259 * "tax": {
260 * "amount": "0",
261 * "convertedAmount": "0",
262 * "formattedAmount": "$0.00",
263 * "formattedConvertedAmount": "$0.00"
264 * },
265 * "discount": {
266 * "amount": "0",
267 * "convertedAmount": "0",
268 * "formattedAmount": "$0.00",
269 * "formattedConvertedAmount": "$0.00"
270 * },
271 * "total": {
272 * "amount": "0",
273 * "convertedAmount": "0",
274 * "formattedAmount": "$0.00",
275 * "formattedConvertedAmount": "$0.00"
276 * },
277 * "additionalFees": {
278 * "amount": "0",
279 * "convertedAmount": "0",
280 * "formattedAmount": "$0.00",
281 * "formattedConvertedAmount": "$0.00"
282 * }
283 * },
284 * "membershipOptions": {
285 * "eligibleMemberships": [],
286 * "invalidMemberships": [],
287 * "selectedMemberships": {
288 * "memberships": []
289 * }
290 * },
291 * "additionalFees": []
292 * }
293 * }
294 * }
295 *
296 */