Skip to main content

Validate Discount Codes

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.

note

If your store is on Magento 1 or Adobe Commerce, you cannot use Bold Checkout validate discount codes. You must manage and validate discount codes through the Magento 1 or Adobe Commerce admin or a third-party integration.

Use Bold-provided discounts

To use Bold-provided discount functionality, ensure that discounts are enabled within the Bold Checkout app. To find these settings, click 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:

  1. The store must have discounts enabled within the Bold Checkout app.
  2. The order cannot have more than one discount.
  3. The discount code must exist on the store.
  4. The discount must not be already applied to the order.
  5. If the discount code has defined start and end dates, the time the discount was applied must fall between those dates.
  6. If the discount has a use limit (for example, if the first 100 customers get a discount), ensure the limit is not reached.
  7. 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.
note

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:

  1. Follow the instructions outlined in the Create a Plugin documentation, including the following pages:
    1. Getting Started with Plugins. Ensure that when you submit the plugin intake form, you select the initialize_checkout event.
    2. Implement the Plugin Installation Flow. Ensure that you included the provide_discounts scope when requesting permissions from the store.
  2. Create a discount override. For more information about how overrides work, refer to Override Default Checkout Behavior.
    1. In response to the initialize_checkout event, respond with an override_discount action. 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.
    2. 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 override_discount URL.
    3. 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.