Skip to main content

Discount Codes

The implementation of discount codes into a shopping cart is a great way to promote customer purchase behavior and track marketing effectiveness. there are several new fields to facilitate the application of discount codes to individual items and to the cart total.

Item-Level Discounts

Item-level discounts are applied to individual items within the cart. For example, a discount code might provide a 15% discount on a specific item. To handle this, we have included the "discount" field within the "price" object of each line item in the cart. This field indicates the price of the item after the discount is applied.

Here's a sample of how it would look:

"line_items": [
{
...
"price": {
"amount": 290.77,
"discount": 261.69,
...
},
...
},
],


Fetching Available Discount Codes

This section details how to fetch and handle the available discount codes for a user. Use the query discounts to retrieve an array of available discounts.

The query returns a promise that resolves to an array of discount objects. Each object represents an available discount and contains information such as the discount code, the discount percentage, and the start and end dates of the discount.

Here is an example of how to use this query:



Verifying a Discount Code

This section outlines how to validate a discount code using the verify Discount mutation provided by the GRAPHQL.

This mutation is used to check whether a provided discount code is valid. It takes an object with a code property as argument, which should be the discount code you want to verify.

The mutation returns a promise that resolves to an object, which includes a valid property indicating whether the discount code is valid.

Here is an example of how to use this mutation:



Applying a Discount Code

This section outlines how to apply a discount code using the apply Discount mutation provided by GRAPHQL SDK. This mutation is used to apply a provided discount code to a shopping cart. It accepts an object with two properties: code (the discount code) and cartId (the ID of the cart to apply the discount to).

The mutation returns a promise that resolves to an object, which includes an executed property that indicates whether the discount code was successfully applied.

Here is an example of how to use this mutation:



Deleting an Applied Discount Code

This section outlines how to delete a previously applied discount code using the delete Applied Discount mutation provided by the GRAPHQL. This mutation is used to remove a discount code from a shopping cart. It accepts an object with two properties: code (the discount code) and cartId (the ID of the cart from which the discount will be removed).

The mutation returns a promise that resolves to an object, which includes an executed property that indicates whether the discount code was successfully deleted.

Here is an example of how to use this mutation: