When a customer applies a discount code during checkout, it is important to validate the discount code before applying it. You have two options for providing discount codes with Bold Checkout — you can either use the out-of-the-box functionality to provide and validate discount codes, or you can use a plugin to provide custom discount functionality.
This page covers both methods for providing and validating discounts.
Use Bold-provided discounts
To use Bold-provided discount functionality, ensure that discounts are enabled within the Bold Checkout app. To find these settings, select Payment Options in the left-hand menu, then Discount codes. Once enabled, you can create and configure discounts.
To validate discounts through the Checkout Frontend API, you can use either of the following endpoints:
- Validate Discount Code — This endpoint enables you to check whether a discount code is valid without applying it to the order.
- Add Discount Code — This endpoint performs all the same steps of the Validate Discount Code endpoint and applies the discount to the order if valid.
The discount code is also validated for a final time when you call the Process Order endpoint.
Components of validation
When you call the Validate Discount Code endpoint, Bold verifies the following:
- The store must have discounts enabled within the Bold Checkout app.
- The order cannot have more than one discount.
- The discount code must exist on the store.
- The discount must not be already applied to the order.
- If the discount code has defined start and end dates, the time the discount was applied must fall between those dates.
- If the discount has a use limit (for example, if the first 100 customers get a discount), ensure the limit is not reached.
- If the discount has a use-per-customer limit (for example, if the discount can only be used five times per customer), ensure the limit is not reached.
There are some scenarios in which you need to validate a discount code more than once, especially if the customer information changes.
For example, if a customer first uses an email that indicates they are eligible for a discount, and the customer changes their email, you must re-validate the discount to ensure it still applies.
Use other discount providers
If you want to use custom discount logic, you must create a Bold Checkout plugin.
The following steps provide a high-level overview for how to create a plugin that overrides Bold Checkout discount logic:
- Follow the instructions outlined in the Create a Plugin documentation, including the following pages:
- Create a discount override. For more information about how overrides work, refer to Override Default Checkout Behavior.
- In response to the
initialize_checkoutevent, respond with an
override_discountaction. This sets up your plugin so that when discount validation is performed later in the checkout, Bold knows to call your override URL instead of validating the discount.
- When Bold would normally validate a discount (during calls to the Validate Discount Code, Add Discount Code, or Process Order endpoints), Bold instead sends a POST request to your
- Provide custom discount functionality. The plugin is responsible for validating the discount based on the requirements it deems appropriate. Respond with the appropriate discount information.
- In response to the