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.

Note: To work with the Wix Events API, you need to publish your site.

Syntax

function checkout(eventId: string, reservationId: string, checkoutInfo: CheckoutInfo): Promise<CheckoutResponse>

checkout Parameters

NAME
TYPE
DESCRIPTION
eventId

string

ID of the event that the ticket reservations are for.

reservationId

string

ID of the ticket reservations.

checkoutInfo

CheckoutInfo

Information related to the checkout.

Returns

Fulfilled - Information about the checkout that was performed.

Return Type:

Promise<CheckoutResponse>

Related Content:

Was this helpful?

Checkout reserved tickets

Code Example

Copy Code
1import wixEvents from 'wix-events';
2import wixPay from 'wix-pay';
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
17wixEvents.tickets.checkout(eventId, reservationId, {formValues, coupon})
18 .then( (response) => {
19 let order = response.order;
20 wixPay.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

Code Example

Copy Code
1import wixEvents from 'wix-events';
2import wixData from 'wix-data';
3import wixPay from 'wix-pay';
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 will return 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 }
43 else {
44 $w("#ticketRepeater").hide();
45 console.log("Could not find tickets");
46 }
47 }
48 else {
49 console.log("Could not find event");
50 }
51}
52
53function displayTickets($item, itemData, index) {
54 $item("#ticketName").text = itemData.name;
55 $item("#ticketPrice").text = itemData.price.toString();
56 $item("#ticketQuantity").value = 0;
57}
58
59function reserveTickets() {
60 const selectedTickets = getSelectedTickets();
61
62 wixEvents.tickets.reserve(eventId, selectedTickets)
63 .then( (reservation) => {
64 reservationId = reservation.id;
65 } )
66 .catch( (error) => {
67 console.log("Error", error.message)
68 } );
69}
70
71function getSelectedTickets() {
72 let selectedTickets = [];
73
74 $w("#ticketRepeater").forEachItem( ($item, itemData, index) => {
75 if($item("#ticketQuantity").value > 0) {
76 selectedTickets.push( {
77 "ticketId": itemData._id,
78 "quantity": $item("#ticketQuantity").value
79 } );
80 }
81 } );
82
83 return selectedTickets;
84}
85
86function checkoutTickets() {
87 wixEvents.tickets.checkout(eventId, reservationId, {
88 "formValues": getFormValues(),
89 "coupon": $w("#couponCode").value
90 })
91 .then( ({order}) => {
92 orderNumber = order.orderNumber
93 wixPay.startPayment(order.paymentId);
94 // Note that PDF tickets are available before payment is complete
95 $w("ticketsPdfLink").value = order.ticketsPdf;
96 })
97 .catch( (error) => {
98 console.log("Error", error.message)
99 } );
100}
101
102function updateTickets() {
103 wixEvents.tickets.updateOrder(eventId, orderNumber, {
104 "formValues": getFormValues()
105 })
106 .catch( (error) => {
107 console.log("Error", error.message)
108 } );
109}
110
111function verifyCouponCode(value, reject) {
112 const coupon = $w("#couponCode").value;
113 wixEvents.tickets.verifyCoupon(eventId, reservationId, coupon)
114 .then( (result) => {
115 if (result.discountErrors) {
116 // handle verification failure
117 $w("#couponCode").updateValidityIndication();
118 $w("#couponErrorMsg").show();
119 $w("#couponSuccessMsg").hide();
120 reject("Coupon is invalid");
121 }
122 else {
123 // handle coupon verified
124 $w("#couponErrorMsg").hide()
125 $w("#couponSuccessMsg").show()
126 }
127 } );
128}
129
130function getFormValues() {
131 return [
132 {"name": "firstName", "value": $w("#firstName").value},
133 {"name": "lastName", "value": $w("#lastName").value},
134 {"name": "email", "value": $w("#email").value},
135 {"name": "custom", "value": $w("#foodAllergies").value},
136
137 // When a form contains an address, the way you format the
138 // address information for submission depends on what type
139 // of input elements you use to gather that information.
140
141 // Wix address input element.
142 {"name": "address", "value": $w("#address").value},
143
144 // Single element which is not an address
145 // input element, such as a text input.
146 {"name": "address", "value": [$w("#address").value]},
147
148 // Multiple elements for the
149 // various parts of an address.
150 {
151 "name": "address",
152 "value": [
153 $w("#street").value,
154 $w("#city").value,
155 $w("#state").value,
156 $w("#country").value,
157 $w("#postalCode").value
158 ]
159 },
160
161 // When a form contains an input for adding more guests to an
162 // RSVP, format the guest names for submission in an array
163 // where each element is the full name of a guest.
164 {"name": "additionalGuests", "value": $w("#additionalGuests").value},
165 {
166 "name": "guestNames",
167 "value": [
168 `${$w("#guest1FirstName").value} ${$w("#guest1LastName").value}`,
169 `${$w("#guest2FirstName").value} ${$w("#guest2LastName").value}`,
170 ]
171 }
172 ];
173}