Search.../

checkout( )

Performs a checkout on reserved tickets.

Description

The checkout() function returns a Promise that resolves to a CheckoutResponse when the ticket reservation has been checked out.

To checkout tickets, you must first call the reserve() function to reserve the tickets.

Use the returned order to process payment for the tickets by passing the order's paymentId to the startPayment() function. Note that since the order has a paymentId, you do not need to first call createPayment() to create a payment.

Before using the startPayment() function, you will need to set up your site to accept payments. To learn more, see About Accepting Payments. When setting up your site to accept payments, be sure to select the payment methods you want to offer and set your payment currency.

Notes:

  • To work with the Wix Events API, you need to publish your site.
  • With this function it's not possible to have separate ticket reservation forms for each ticket. You can only have 1 reservation form per ticket order.

Authorization

Request

This endpoint does not take any parameters

Response Object

Fulfilled - Information about the checkout that was performed.

NAME
TYPE
DESCRIPTION
reservations
Array<Reservation>

Ticket reservations.

order
Order

Ticket order.

expirationTime
Date

Time the reservations expire.

Status/Error Codes

Related Content:

Was this helpful?

Checkout reserved tickets

Copy Code
1import wixEventsFrontend from 'wix-events-frontend';
2import wixPayFrontend from 'wix-pay-frontend';
3
4// ...
5
6const eventId = // Get the event ID
7
8// ...
9
10let reservationId = // Returned from the reserve() function
11
12// ...
13
14let formValues = // get form values
15let coupon = // get coupon
16
17wixEventsFrontend.tickets.checkout(eventId, reservationId, {formValues, coupon})
18 .then((response) => {
19 let order = response.order;
20 wixPayFrontend.startPayment(order.paymentId);
21
22 let expirationTime = response.expirationTime;
23 let firstReservation = response.reservations[0];
24 });
25
26/* response:
27 *
28 * {
29 * "order": {
30 * "orderNumber": "FMQR-VSN7-E1",
31 * "reservationId": "7f6a522f-f34c-4a03-8d9a-05e88506c012",
32 * "eventId": "9a513b88-a223-4144-b0dc-938fd7cc5b4a",
33 * "contactId": "",
34 * "memberId": "",
35 * "firstName": "John",
36 * "lastName": "Doe",
37 * "email": "john@doe.com",
38 * "checkoutForm": {
39 * "inputValues": [
40 * {
41 * "inputName": "firstName",
42 * "value": "John",
43 * "values": [],
44 * },
45 *
46 * ...
47 *
48 * {
49 * inputName: "custom",
50 * value: "",
51 * values: ["Gluten free", "Vegetarian"],
52 * }
53 * ]
54 * },
55 * "confirmed": false,
56 * "status": "INITIATED",
57 * "ticketsPdf": "https://apps.wix.com/events/doc/tickets/v2/Tickets.pdf?request=JWS...",
58 * "tickets": [],
59 * "archived": false,
60 * "anonymized": false,
61 * "fullName": "John Doe",
62 * "invoice": {
63 * "items": [
64 * {
65 * "id": "de8e3fd8-b257-40a7-933b-77c627d884e4",
66 * "quantity": 2,
67 * "name": "VIP ticket",
68 * "price": {
69 * "amount": "6.00",
70 * "currency": "USD"
71 * },
72 * "total": {
73 * "amount": "12.00",
74 * "currency": "USD"
75 * },
76 * "discount":{
77 * "amount":{
78 * "amount":"2.0",
79 * "currency":"USD"
80 * },
81 * "afterDiscount":{
82 * "amount":"10.00",
83 * "currency":"USD"
84 * },
85 * "code":"CouponCode",
86 * "name":"Coupon Name",
87 * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59",
88 * "discounts":[
89 * {
90 * "amount":{
91 * "amount":"2.0",
92 * "currency":"USD"
93 * },
94 * "coupon":{
95 * "name":"Coupon Name",
96 * "code":"CouponCode",
97 * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59"
98 * }
99 * }
100 * ]
101 * },
102 * "fees": [
103 * {
104 * "name": "WIX_FEE",
105 * "type": "FEE_ADDED",
106 * "rate": "2.5",
107 * "amount": {
108 * "amount": "0",
109 * "currency": "USD"
110 * }
111 * }
112 * ]
113 * },
114 * {
115 * "id": "9207637c-3d49-43af-b91e-32e496620c60",
116 * "quantity": 1,
117 * "name": "Regular ticket",
118 * "price": {
119 * "amount": "3.50",
120 * "currency": "USD"
121 * },
122 * "total": {
123 * "amount": "3.50",
124 * "currency": "USD"
125 * },
126 * "discount":{
127 * "amount":{
128 * "amount":"1.0",
129 * "currency":"USD"
130 * },
131 * "afterDiscount":{
132 * "amount":"2.50",
133 * "currency":"USD"
134 * },
135 * "code":"CouponCode",
136 * "name":"Coupon Name",
137 * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59",
138 * "discounts":[
139 * {
140 * "amount":{
141 * "amount":"1.0",
142 * "currency":"USD"
143 * },
144 * "coupon":{
145 * "name":"Coupon Name",
146 * "code":"CouponCode",
147 * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59"
148 * }
149 * }
150 * ]
151 * },
152 * "fees": [
153 * {
154 * "name": "WIX_FEE",
155 * "type": "FEE_ADDED",
156 * "rate": "2.5",
157 * "amount": {
158 * "amount": "0",
159 * "currency": "USD"
160 * }
161 * }
162 * ]
163 * }
164 * ],
165 * "total":{
166 * "amount":"15.50",
167 * "currency":"BIF"
168 * },
169 * "discount":{
170 * "amount":{
171 * "amount":"3.0",
172 * "currency":"BIF"
173 * },
174 * "afterDiscount":{
175 * "amount":"12.50",
176 * "currency":"BIF"
177 * },
178 * "code":"CouponCode",
179 * "name":"Coupon Name",
180 * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59",
181 * "discounts":[
182 * {
183 * "amount":{
184 * "amount":"3.0",
185 * "currency":"BIF"
186 * },
187 * "coupon":{
188 * "name":"Coupon Name",
189 * "code":"CouponCode",
190 * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59"
191 * }
192 * }
193 * ]
194 * },
195 * "subTotal":{
196 * "amount":"15.50",
197 * "currency":"BIF"
198 * },
199 * "grandTotal":{
200 * "amount":"12.50",
201 * "currency":"BIF"
202 * },
203 * "fees":[],
204 * "revenue":{
205 * "amount":"12.50",
206 * "currency":"BIF"
207 * }
208 * },
209 * "fullyCheckedIn": false,
210 * "transactionId": "",
211 * "paymentId": "b0fb4d1c-858b-45cb-991d-2fd79bfb60d3",
212 * "createdDate": "2020-04-22T13:25:32.018Z",
213 * "paymentMethod": "",
214 * "ticketQuantity": 3,
215 * "price": {
216 * "amount": "15.50",
217 * "currency": "USD"
218 * }
219 * },
220 * "reservations": [
221 * {
222 * "quantity": 1,
223 * "ticket": {
224 * "id": "de8e3fd8-b257-40a7-933b-77c627d884e4",
225 * "price": {
226 * "amount": "6.00",
227 * "currency": "USD"
228 * },
229 * "free": false,
230 * "name": "VIP ticket",
231 * "description": "Super special ticket",
232 * "limitPerCheckout": 0,
233 * "orderIndex": 0,
234 * "policy": "No refunds",
235 * "eventId": "9a513b88-a223-4144-b0dc-938fd7cc5b4a"
236 * }
237 * },
238 * {
239 * "quantity": 2,
240 * "ticket": {
241 * "id" :"9207637c-3d49-43af-b91e-32e496620c60",
242 * "price": {
243 * "amount": "3.50",
244 * "currency": "USD"
245 * },
246 * "free": false,
247 * "name": "Regular ticket",
248 * "description": "Just a regular ticket",
249 * "limitPerCheckout": 0,
250 * "orderIndex": 0,
251 * "policy": "",
252 * "eventId": "9a513b88-a223-4144-b0dc-938fd7cc5b4a"
253 * }
254 * }
255 * ],
256 * "expirationTime": "2020-04-22T13:44:46.395Z"
257 * }
258 */
Reserve, checkout, and update tickets

Copy Code
1import wixEventsFrontend from 'wix-events-frontend';
2import wixData from 'wix-data';
3import wixPayFrontend from 'wix-pay-frontend';
4
5let eventId;
6let reservationId;
7let orderNumber;
8let tickets;
9
10$w.onReady(function () {
11 // Retrieve data and set up page
12 await getData();
13 $w("#ticketRepeater").onItemReady(displayTickets);
14 $w("#ticketRepeater").data = tickets;
15
16 // Define button click actions
17 $w("#reservationButton").onClick(reserveTickets);
18 $w("#checkoutButton").onClick(checkoutTickets);
19 $w("#updateButton").onClick(updateTickets);
20
21 // Verify coupon code when it is entered
22 $w("#couponCode").onCustomValidation(verifyCouponCode);
23});
24
25async function getData() {
26 // Run a query that returns only one event. Add
27 // additional filtering to the query if necessary.
28 const eventResults = await wixData.query("Events/Events")
29 .eq("title", "My Event")
30 .find();
31
32 if (eventResults.items.length > 0) {
33 eventId = eventResults.items[0]._id;
34
35 // Get tickets for the event
36 const ticketResults = await wixData.query("Events/Tickets")
37 .eq("event", eventId)
38 .find();
39
40 if (ticketResults.items.length > 0) {
41 tickets = ticketResults.items;
42 } else {
43 $w("#ticketRepeater").hide();
44 console.log("Could not find tickets");
45 }
46 } else {
47 console.log("Could not find event");
48 }
49}
50
51function displayTickets($item, itemData, index) {
52 $item("#ticketName").text = itemData.name;
53 $item("#ticketPrice").text = itemData.price.toString();
54 $item("#ticketQuantity").value = 0;
55}
56
57function reserveTickets() {
58 const selectedTickets = getSelectedTickets();
59
60 wixEventsFrontend.tickets.reserve(eventId, selectedTickets)
61 .then((reservation) => {
62 reservationId = reservation.id;
63 })
64 .catch((error) => {
65 console.log("Error", error.message)
66 });
67}
68
69function getSelectedTickets() {
70 let selectedTickets = [];
71
72 $w("#ticketRepeater").forEachItem(($item, itemData, index) => {
73 if ($item("#ticketQuantity").value > 0) {
74 selectedTickets.push( {
75 "ticketId": itemData._id,
76 "quantity": $item("#ticketQuantity").value
77 });
78 }
79 });
80
81 return selectedTickets;
82}
83
84function checkoutTickets() {
85 wixEventsFrontend.tickets.checkout(eventId, reservationId, {
86 "formValues": getFormValues(),
87 "coupon": $w("#couponCode").value
88 })
89 .then(({order}) => {
90 orderNumber = order.orderNumber
91 wixPayFrontend.startPayment(order.paymentId);
92 // Note that PDF tickets are available before payment is complete
93 $w("#ticketsPdfLink").value = order.ticketsPdf;
94 })
95 .catch((error) => {
96 console.log("Error", error.message)
97 });
98}
99
100function updateTickets() {
101 wixEventsFrontend.tickets.updateOrder(eventId, orderNumber, {
102 "formValues": getFormValues()
103 })
104 .catch((error) => {
105 console.log("Error", error.message)
106 });
107}
108
109function verifyCouponCode(value, reject) {
110 const coupon = $w("#couponCode").value;
111 wixEventsFrontend.tickets.verifyCoupon(eventId, reservationId, coupon)
112 .then((result) => {
113 if (result.discountErrors) {
114 // handle verification failure
115 $w("#couponCode").updateValidityIndication();
116 $w("#couponErrorMsg").show();
117 $w("#couponSuccessMsg").hide();
118 reject("Coupon is invalid");
119 } else {
120 // handle coupon verified
121 $w("#couponErrorMsg").hide()
122 $w("#couponSuccessMsg").show()
123 }
124 });
125}
126
127function getFormValues() {
128 return [
129 {"name": "firstName", "value": $w("#firstName").value},
130 {"name": "lastName", "value": $w("#lastName").value},
131 {"name": "email", "value": $w("#email").value},
132 {"name": "custom", "value": $w("#foodAllergies").value},
133
134 // When a form contains an address, the way you format the
135 // address information for submission depends on what type
136 // of input elements you use to gather that information.
137
138 // Wix address input element.
139 {"name": "address", "value": $w("#address").value},
140
141 // Single element which is not an address
142 // input element, such as a text input.
143 {"name": "address", "value": [$w("#address").value]},
144
145 // Multiple elements for the
146 // various parts of an address.
147 {
148 "name": "address",
149 "value": [
150 $w("#street").value,
151 $w("#city").value,
152 $w("#state").value,
153 $w("#country").value,
154 $w("#postalCode").value
155 ]
156 },
157
158 // When a form contains an input for adding more guests to an
159 // RSVP, format the guest names for submission in an array
160 // where each element is the full name of a guest.
161 {"name": "additionalGuests", "value": $w("#additionalGuests").value},
162 {
163 "name": "guestNames",
164 "value": [
165 `${$w("#guest1FirstName").value} ${$w("#guest1LastName").value}`,
166 `${$w("#guest2FirstName").value} ${$w("#guest2LastName").value}`,
167 ]
168 }
169 ];
170}