Search.../

removeCoupon( )

Removes the coupon from a specified checkout.

Description

The removeCoupon() function returns a Promise that resolves to the updated checkout when the coupon is removed from the specified checkout.

Note: A checkout can only hold 1 coupon.

Syntax

function removeCoupon(_id: string): Promise<RemoveCouponResponse>

removeCoupon Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the checkout to remove the coupon from.

Returns

Return Type:

Promise<
RemoveCouponResponse
>
NAME
TYPE
DESCRIPTION
checkout
Checkout

Updated checkout after removal of coupon.

Was this helpful?

Remove coupon from a checkout

Copy Code
1/**************************************
2 * Backend code - my-backend-file.jsw *
3 **************************************/
4
5import { checkout } from 'wix-ecom-backend';
6
7export async function myRemoveCouponFunction(checkoutId) {
8 try {
9 const updatedCheckout = await checkout.removeCoupon(checkoutId);
10 console.log('Success! Updated checkout:', updatedCheckout);
11 return updatedCheckout;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16}
17
18/*************
19 * Page code *
20 ************/
21
22import { myRemoveCouponFunction } from 'backend/my-backend-file';
23
24// Sample checkoutId:
25const checkoutId = '75b0d071-8ca0-4227-962f-91d0605c8c3a';
26
27myRemoveCouponFunction(checkoutId)
28 .then((updatedCheckout) => {
29 const checkoutId = updatedCheckout._id;
30 const appliedDiscounts = updatedCheckout.appliedDiscounts;
31 // appliedCoupon boolean value is false if no coupon exists on checkout
32 const appliedCoupon = appliedDiscounts.some(({ coupon }) => coupon);
33
34 console.log('Success! Updated checkout:', updatedCheckout);
35 return updatedCheckout;
36 })
37 .catch((error) => {
38 console.error(error);
39 // Handle the error
40 });
41
42/* Promise resolves to:
43 *
44 * {
45 * "_id": "75b0d071-8ca0-4227-962f-91d0605c8c3a",
46 * "lineItems": [
47 * {
48 * "_id": "00000000-0000-0000-0000-000000000001",
49 * "quantity": 3,
50 * "catalogReference": {
51 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",
52 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"
53 * },
54 * "productName": {
55 * "original": "Shirt",
56 * "translated": "Shirt"
57 * },
58 * "url": "https://example.wixsite.com",
59 * "price": {
60 * "amount": "10",
61 * "convertedAmount": "10",
62 * "formattedAmount": "$10.00",
63 * "formattedConvertedAmount": "$10.00"
64 * },
65 * "lineItemPrice": {
66 * "amount": "30",
67 * "convertedAmount": "30",
68 * "formattedAmount": "$30.00",
69 * "formattedConvertedAmount": "$30.00"
70 * },
71 * "fullPrice": {
72 * "amount": "10",
73 * "convertedAmount": "10",
74 * "formattedAmount": "$10.00",
75 * "formattedConvertedAmount": "$10.00"
76 * },
77 * "priceBeforeDiscounts": {
78 * "amount": "10",
79 * "convertedAmount": "10",
80 * "formattedAmount": "$10.00",
81 * "formattedConvertedAmount": "$10.00"
82 * },
83 * "totalPriceAfterTax": {
84 * "amount": "30",
85 * "convertedAmount": "30",
86 * "formattedAmount": "$30.00",
87 * "formattedConvertedAmount": "$30.00"
88 * },
89 * "totalPriceBeforeTax": {
90 * "amount": "30",
91 * "convertedAmount": "30",
92 * "formattedAmount": "$30.00",
93 * "formattedConvertedAmount": "$30.00"
94 * },
95 * "taxDetails": {
96 * "taxableAmount": {
97 * "amount": "30",
98 * "convertedAmount": "30",
99 * "formattedAmount": "$30.00",
100 * "formattedConvertedAmount": "$30.00"
101 * },
102 * "taxRate": "0",
103 * "totalTax": {
104 * "amount": "0",
105 * "convertedAmount": "0",
106 * "formattedAmount": "$0.00",
107 * "formattedConvertedAmount": "$0.00"
108 * },
109 * "rateBreakdown": []
110 * },
111 * "discount": {
112 * "amount": "0",
113 * "convertedAmount": "0",
114 * "formattedAmount": "$0.00",
115 * "formattedConvertedAmount": "$0.00"
116 * },
117 * "descriptionLines": [],
118 * "media": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",
119 * "availability": {
120 * "status": "AVAILABLE"
121 * },
122 * "physicalProperties": {
123 * "sku": "364115376135191",
124 * "shippable": true
125 * },
126 * "couponScopes": [
127 * {
128 * "namespace": "stores",
129 * "group": {
130 * "name": "collection",
131 * "entityId": "00000000-000000-000000-000000000001"
132 * }
133 * },
134 * {
135 * "namespace": "stores",
136 * "group": {
137 * "name": "product",
138 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"
139 * }
140 * }
141 * ],
142 * "itemType": {
143 * "preset": "PHYSICAL"
144 * },
145 * "paymentOption": "FULL_PAYMENT_ONLINE",
146 * "rootCatalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a"
147 * },
148 * {
149 * "_id": "00000000-0000-0000-0000-000000000002",
150 * "quantity": 1,
151 * "catalogReference": {
152 * "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e",
153 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",
154 * "options": {
155 * "variantId": "2f430d69-9b75-4874-bfbd-c5f6fa5aff3d",
156 * "customTextFields": {
157 * "birthday card": "Happy Birthday!"
158 * }
159 * }
160 * },
161 * "productName": {
162 * "original": "Shoe",
163 * "translated": "Shoe"
164 * },
165 * "url": "https://example.wixsite.com",
166 * "price": {
167 * "amount": "85",
168 * "convertedAmount": "85",
169 * "formattedAmount": "$85.00",
170 * "formattedConvertedAmount": "$85.00"
171 * },
172 * "lineItemPrice": {
173 * "amount": "85",
174 * "convertedAmount": "85",
175 * "formattedAmount": "$85.00",
176 * "formattedConvertedAmount": "$85.00"
177 * },
178 * "fullPrice": {
179 * "amount": "85",
180 * "convertedAmount": "85",
181 * "formattedAmount": "$85.00",
182 * "formattedConvertedAmount": "$85.00"
183 * },
184 * "priceBeforeDiscounts": {
185 * "amount": "85",
186 * "convertedAmount": "85",
187 * "formattedAmount": "$85.00",
188 * "formattedConvertedAmount": "$85.00"
189 * },
190 * "totalPriceAfterTax": {
191 * "amount": "85",
192 * "convertedAmount": "85",
193 * "formattedAmount": "$85.00",
194 * "formattedConvertedAmount": "$85.00"
195 * },
196 * "totalPriceBeforeTax": {
197 * "amount": "85",
198 * "convertedAmount": "85",
199 * "formattedAmount": "$85.00",
200 * "formattedConvertedAmount": "$85.00"
201 * },
202 * "taxDetails": {
203 * "taxableAmount": {
204 * "amount": "85",
205 * "convertedAmount": "85",
206 * "formattedAmount": "$85.00",
207 * "formattedConvertedAmount": "$85.00"
208 * },
209 * "taxRate": "0",
210 * "totalTax": {
211 * "amount": "0",
212 * "convertedAmount": "0",
213 * "formattedAmount": "$0.00",
214 * "formattedConvertedAmount": "$0.00"
215 * },
216 * "rateBreakdown": []
217 * },
218 * "discount": {
219 * "amount": "0",
220 * "convertedAmount": "0",
221 * "formattedAmount": "$0.00",
222 * "formattedConvertedAmount": "$0.00"
223 * },
224 * "descriptionLines": [
225 * {
226 * "name": {
227 * "original": "Color",
228 * "translated": "Color"
229 * },
230 * "colorInfo": {
231 * "original": "Brown",
232 * "translated": "Brown",
233 * "code": "#783f04"
234 * },
235 * "lineType": "COLOR",
236 * "color": "Brown"
237 * },
238 * {
239 * "name": {
240 * "original": "birthday card",
241 * "translated": "birthday card"
242 * },
243 * "plainText": {
244 * "original": "Happy Birthday!",
245 * "translated": "Happy Birthday!"
246 * },
247 * "lineType": "PLAIN_TEXT",
248 * "plainTextValue": {
249 * "original": "Happy Birthday!",
250 * "translated": "Happy Birthday!"
251 * }
252 * }
253 * ],
254 * "media": "wix:image://v1/3c76e2_bf235c38610f4d2a905db71095b351cf~mv2.jpg#originWidth=1000&originHeight=1000",
255 * "availability": {
256 * "status": "AVAILABLE",
257 * "quantityAvailable": 30
258 * },
259 * "physicalProperties": {
260 * "sku": "364215376135191",
261 * "shippable": true
262 * },
263 * "couponScopes": [
264 * {
265 * "namespace": "stores",
266 * "group": {
267 * "name": "collection",
268 * "entityId": "00000000-000000-000000-000000000001"
269 * }
270 * },
271 * {
272 * "namespace": "stores",
273 * "group": {
274 * "name": "product",
275 * "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"
276 * }
277 * }
278 * ],
279 * "itemType": {
280 * "preset": "PHYSICAL"
281 * },
282 * "paymentOption": "FULL_PAYMENT_ONLINE",
283 * "rootCatalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"
284 * },
285 * {
286 * "_id": "00000000-0000-0000-0000-000000000003",
287 * "quantity": 1,
288 * "catalogReference": {
289 * "catalogItemId": "9fe8c5b2-9c94-7153-ebb9-8533695e2b6f",
290 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",
291 * "options": {
292 * "Size": "Large",
293 * "Color": "White"
294 * }
295 * },
296 * "price": {
297 * "amount": "0",
298 * "convertedAmount": "0",
299 * "formattedAmount": "$0.00",
300 * "formattedConvertedAmount": "$0.00"
301 * },
302 * "fullPrice": {
303 * "amount": "0",
304 * "convertedAmount": "0",
305 * "formattedAmount": "$0.00",
306 * "formattedConvertedAmount": "$0.00"
307 * },
308 * "priceBeforeDiscounts": {
309 * "amount": "0",
310 * "convertedAmount": "0",
311 * "formattedAmount": "$0.00",
312 * "formattedConvertedAmount": "$0.00"
313 * },
314 * "descriptionLines": [],
315 * "availability": {
316 * "status": "NOT_FOUND"
317 * },
318 * "couponScopes": [],
319 * "paymentOption": "FULL_PAYMENT_ONLINE"
320 * }
321 * ],
322 * "billingInfo": {
323 * "address": {
324 * "addressLine1": "235 West 23rd Street",
325 * "addressLine2": "3rd floor",
326 * "city": "New York",
327 * "subdivision": "US-NY",
328 * "country": "US",
329 * "postalCode": "10011"
330 * },
331 * "contactDetails": {
332 * "firstName": "Jane",
333 * "lastName": "Doe",
334 * "phone": "+1234567890"
335 * }
336 * },
337 * "shippingInfo": {
338 * "shippingDestination": {
339 * "address": {
340 * "addressLine1": "235 West 23rd Street",
341 * "addressLine2": "3rd floor",
342 * "city": "New York",
343 * "subdivision": "US-NY",
344 * "country": "US",
345 * "postalCode": "10011"
346 * },
347 * "contactDetails": {
348 * "firstName": "Jane",
349 * "lastName": "Doe",
350 * "phone": "+1234567890"
351 * }
352 * },
353 * "selectedCarrierServiceOption": {
354 * "code": "ed5bbce2-9533-dff4-7db0-13702fd139c5",
355 * "title": "Standard US Shipping",
356 * "logistics": {
357 * "deliveryTime": ""
358 * },
359 * "cost": {
360 * "totalPriceAfterTax": {
361 * "amount": "10",
362 * "convertedAmount": "10",
363 * "formattedAmount": "$10.00",
364 * "formattedConvertedAmount": "$10.00"
365 * },
366 * "totalPriceBeforeTax": {
367 * "amount": "10",
368 * "convertedAmount": "10",
369 * "formattedAmount": "$10.00",
370 * "formattedConvertedAmount": "$10.00"
371 * },
372 * "taxDetails": {
373 * "taxRate": "0",
374 * "totalTax": {
375 * "amount": "0",
376 * "convertedAmount": "0",
377 * "formattedAmount": "$0.00",
378 * "formattedConvertedAmount": "$0.00"
379 * },
380 * "rateBreakdown": []
381 * },
382 * "price": {
383 * "amount": "10",
384 * "convertedAmount": "10",
385 * "formattedAmount": "$10.00",
386 * "formattedConvertedAmount": "$10.00"
387 * }
388 * },
389 * "requestedShippingOption": true,
390 * "otherCharges": [],
391 * "carrierId": "c8a08776-c095-4dec-8553-8f9698d86adc"
392 * },
393 * "region": {
394 * "_id": "009fbe5d-89d3-7825-cbbf-1aab4d908b73",
395 * "name": "USA shipping"
396 * },
397 * "carrierServiceOptions": [
398 * {
399 * "carrierId": "c8a08776-c095-4dec-8553-8f9698d86adc",
400 * "shippingOptions": [
401 * {
402 * "code": "ed5bbce2-9533-dff4-7db0-13702fd139c5",
403 * "title": "Standard US Shipping",
404 * "logistics": {
405 * "deliveryTime": ""
406 * },
407 * "cost": {
408 * "price": {
409 * "amount": "10",
410 * "convertedAmount": "10",
411 * "formattedAmount": "$10.00",
412 * "formattedConvertedAmount": "$10.00"
413 * },
414 * "otherCharges": []
415 * }
416 * }
417 * ]
418 * }
419 * ]
420 * },
421 * "buyerNote": "Please wrap it up as a present",
422 * "buyerInfo": {
423 * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db",
424 * "email": "Janedoe@example.com",
425 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
426 * },
427 * "conversionCurrency": "USD",
428 * "priceSummary": {
429 * "subtotal": {
430 * "amount": "115",
431 * "convertedAmount": "115",
432 * "formattedAmount": "$115.00",
433 * "formattedConvertedAmount": "$115.00"
434 * },
435 * "shipping": {
436 * "amount": "10",
437 * "convertedAmount": "10",
438 * "formattedAmount": "$10.00",
439 * "formattedConvertedAmount": "$10.00"
440 * },
441 * "tax": {
442 * "amount": "0",
443 * "convertedAmount": "0",
444 * "formattedAmount": "$0.00",
445 * "formattedConvertedAmount": "$0.00"
446 * },
447 * "discount": {
448 * "amount": "0",
449 * "convertedAmount": "0",
450 * "formattedAmount": "$0.00",
451 * "formattedConvertedAmount": "$0.00"
452 * },
453 * "total": {
454 * "amount": "125",
455 * "convertedAmount": "125",
456 * "formattedAmount": "$125.00",
457 * "formattedConvertedAmount": "$125.00"
458 * },
459 * "additionalFees": {
460 * "amount": "0",
461 * "convertedAmount": "0",
462 * "formattedAmount": "$0.00",
463 * "formattedConvertedAmount": "$0.00"
464 * }
465 * },
466 * "calculationErrors": {
467 * "orderValidationErrors": []
468 * },
469 * "appliedDiscounts": [],
470 * "customFields": [
471 * {
472 * "value": "12345",
473 * "title": "Tax ID",
474 * "translatedTitle": "Tax ID"
475 * }
476 * ],
477 * "weightUnit": "KG",
478 * "currency": "USD",
479 * "channelType": "WEB",
480 * "siteLanguage": "en",
481 * "buyerLanguage": "en",
482 * "completed": false,
483 * "taxIncludedInPrice": false,
484 * "createdBy": {
485 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
486 * },
487 * "_createdDate": "2022-10-19T14:22:03.847Z",
488 * "_updatedDate": "2022-10-19T14:22:30.842Z",
489 * "payNow": {
490 * "subtotal": {
491 * "amount": "115",
492 * "convertedAmount": "115",
493 * "formattedAmount": "$115.00",
494 * "formattedConvertedAmount": "$115.00"
495 * },
496 * "shipping": {
497 * "amount": "10",
498 * "convertedAmount": "10",
499 * "formattedAmount": "$10.00",
500 * "formattedConvertedAmount": "$10.00"
501 * },
502 * "tax": {
503 * "amount": "0",
504 * "convertedAmount": "0",
505 * "formattedAmount": "$0.00",
506 * "formattedConvertedAmount": "$0.00"
507 * },
508 * "discount": {
509 * "amount": "0",
510 * "convertedAmount": "0",
511 * "formattedAmount": "$0.00",
512 * "formattedConvertedAmount": "$0.00"
513 * },
514 * "total": {
515 * "amount": "125",
516 * "convertedAmount": "125",
517 * "formattedAmount": "$125.00",
518 * "formattedConvertedAmount": "$125.00"
519 * },
520 * "additionalFees": {
521 * "amount": "0",
522 * "convertedAmount": "0",
523 * "formattedAmount": "$0.00",
524 * "formattedConvertedAmount": "$0.00"
525 * }
526 * },
527 * "payLater": {
528 * "subtotal": {
529 * "amount": "0",
530 * "convertedAmount": "0",
531 * "formattedAmount": "$0.00",
532 * "formattedConvertedAmount": "$0.00"
533 * },
534 * "shipping": {
535 * "amount": "0",
536 * "convertedAmount": "0",
537 * "formattedAmount": "$0.00",
538 * "formattedConvertedAmount": "$0.00"
539 * },
540 * "tax": {
541 * "amount": "0",
542 * "convertedAmount": "0",
543 * "formattedAmount": "$0.00",
544 * "formattedConvertedAmount": "$0.00"
545 * },
546 * "discount": {
547 * "amount": "0",
548 * "convertedAmount": "0",
549 * "formattedAmount": "$0.00",
550 * "formattedConvertedAmount": "$0.00"
551 * },
552 * "total": {
553 * "amount": "0",
554 * "convertedAmount": "0",
555 * "formattedAmount": "$0.00",
556 * "formattedConvertedAmount": "$0.00"
557 * },
558 * "additionalFees": {
559 * "amount": "0",
560 * "convertedAmount": "0",
561 * "formattedAmount": "$0.00",
562 * "formattedConvertedAmount": "$0.00"
563 * }
564 * },
565 * "membershipOptions": {
566 * "eligibleMemberships": [],
567 * "invalidMemberships": [],
568 * "selectedMemberships": {
569 * "memberships": []
570 * }
571 * },
572 * "additionalFees": []
573 * }
574 *
575 */
576