Apply a Coupon Code to a Cart

This topic describes how you can apply a coupon code to an active shopping cart. Coupon codes are also called discount codes or promotional codes. Coupon codes encourage sales in your stores by providing discounts on products or shipping costs. Coupon code offers are configured in Global Commerce.

During the checkout process, a shopper manually enters a coupon code in your storefront and clicks the Apply button. The API applies the discount associated with the PoP (Point-of-Promotion) offer to the cart. The call returns the contents of the cart with the adjusted pricing information.

Applying a promo code

Send a POST shoppers/me/carts/active request to the Carts API with the required promoCode query parameter. The request must include a valid limited or full access token. There is no payload associated with this request; the request body is empty. The following request applies a promotional code value of wb32xjtam:

POST https://api.digitalriver.com/v1/shoppers/me/carts/active?promoCode=wb32xjtam HTTP/1.1

A successful request returns a status code of 200 in the response header; otherwise, error codes are returned in the response. The ID of the cart is 1234567890.

1.  <cart uri="https://api.digitalriver.com/v1/shoppers/me/carts/active">
2.     <id>1234567890</id>
3.     <lineitems uri="https://api.digitalriver.com/v1/shoppers/me/carts/active/line-items">
4.        <lineitem uri="https://api.digitalriver.com/v1/shoppers/me/carts/active/line-items/12765711619">
5.           <id>12765711619</id>
6.           <quantity>1</quantity>
7.           <product uri="https://api.digitalriver.com/v1/shoppers/me/products/232054400">
8.              <displayname>Displayable Product Name</displayname>
9.              <thumbnailimage>http://drh1.img.digitalriver.com/DRHM/Storefront/images/product/thumbnail/small-product-image.jpg</thumbnailimage>
10.          </product>
11.          <pricing>
12.             <listprice currency="USD">24.95</listprice>
13.             <listpricewithquantity currency="USD">24.95</listpricewithquantity>
14.             <salepricewithquantity currency="USD">14.95</salepricewithquantity>
15.             <formattedlistprice>$24.95</formattedlistprice>
16.             <formattedlistpricewithquantity>$24.95</formattedlistpricewithquantity>
17.             <formattedsalepricewithquantity>$14.95</formattedsalepricewithquantity>
18.          </pricing>
19.       </lineitem>
20.    </lineitems>
21.    <billingaddress uri="https://api.digitalriver.com/v1/shoppers/me/carts/active/billing-address">
22.    <shippingaddress uri="https://api.digitalriver.com/v1/shoppers/me/carts/active/shipping-address">
23.    <payment>
24.       <name>Visa</name>
25.       <displayablenumber>************1111</displayablenumber>
26.       <expirationyear>2017</expirationyear>
27.    </payment>
28.    <shippingmethod>
29.       <code>142400</code>
30.       <description>USPS - Priority Mail</description>
31.    </shippingmethod>
32.    <shippingoptions uri="https://api.digitalriver.com/v1/shoppers/me/shipping-options">
33.    <pricing>
34.       <subtotal currency="USD">24.95</subtotal>
35.       <discount currency="USD">10.00</discount>
36.       <shippingandhandling currency="USD">0.00</shippingandhandling>
37.       <tax currency="USD">0.00</tax>
38.       <ordertotal currency="USD">14.95</ordertotal>
39.       <formattedsubtotal>$24.95</formattedsubtotal>
40.       <formatteddiscount>$10.00</formatteddiscount>
41.       <formattedshippingandhandling>$0.00</formattedshippingandhandling>
42.       <formattedtax>$0.00</formattedtax>
43.       <formattedordertotal>$14.95</formattedordertotal>
44.    </pricing>
45. </shippingoptions></shippingaddress></billingaddress></cart>

Typically, the next steps after applying a coupon code are submitting the cart and creating an order to complete the checkout process.