Search.../

updateOrder( )

Updates a ticket order.

Description

The updateOrder() function returns a Promise that resolves to an UpdateOrderResponse when the ticket order has been updated with the new form values specified in the updateInfo parameter.

You cannot update an order after payment has been processed.

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

Syntax

function updateOrder(eventId: string, orderNumber: string, updateInfo: UpdateInfo): UpdateOrderResponse

updateOrder Parameters

NAME
TYPE
DESCRIPTION
eventId
string

ID of the event that the ticket reservations are for.

orderNumber
string

Number of the order to update.

updateInfo
UpdateInfo

Information related to the update.

Returns

Fulfilled - Information about the order that was updated.

Return Type:

Promise<UpdateOrderResponse>
NAME
TYPE
DESCRIPTION
order
Order

Updated ticket order.

Related Content:

Was this helpful?

Update a ticket order

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