> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt ## Resource: Introduction ## Article: Introduction ## Article Link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/extensions/discounts/custom-discount-triggers-integration-service-plugin/introduction.md ## Article Content: # About the Custom Discount Triggers Service Plugin
__Important:__ When developing websites or building apps with Blocks, use [Velo service plugins](https://dev.wix.com/docs/velo/events-service-plugins/about-events-service-plugins-and-the-sdk.md).As a discount trigger provider, you can integrate with Wix to provide a merchant's stores or businesses with custom triggers that specify when a discount applies on the site's cart and checkout pages. Together with [discount rules](https://dev.wix.com/docs/rest/business-solutions/e-commerce/extensions/discounts/discount-rules/introduction.md), custom triggers define the necessary conditions for a discount to apply. For example, a trigger that only fires between 4pm-6pm on Mondays through Thursdays. The integration is done via an app in the Wix App Market and by implementing the Custom Discount Triggers [service plugin](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/service-plugins/about-service-plugin-extensions.md). After the app is installed on a site, Wix triggers a call to your service whenever actions are performed on the cart or checkout entities/pages. For example, when adding an item to the cart. Using the service plugin, you can design your app to: + Offer a happy hour discount. + Offer a sale on digital products. ## Before you begin To use a custom trigger to apply a discount, you must first create a discount rule. Create an automatic discount [using the dashboard](https://support.wix.com/en/article/wix-stores-creating-automatic-discounts), or by using the [Discount Rules API](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/extensions/discounts/discount-rules/create-discount-rule.md). :::tabs ::::REST_TAB ## Get started To enable Wix to communicate with your app: 1. Go to [Extensions](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/about-extensions.md) in your app's dashboard. 1. Click **Create Extension** in the top right. 1. Filter by **eCommerce** in the left menu, then find **Ecom Discounts Trigger** and click **Create**. 1. Provide the following configuration: | Name | Type | Description | |-----------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `deploymentUri` | string | Required. Base URI where the endpoints are called. Wix appends the endpoint path to the base URI. For example, to call the Get Eligible Triggers endpoint at `https://my-discount-app.com/v1/getEligibleTriggers`, the base URI you provide here is `https://my-discount-app.com/`. | | `componentName` | string | A unique name for this component. This is an internal name that will only appear in the app dashboard. | ::: :::SDK_TAB ## Get started Follow these steps to begin implementing your service plugin. ### Choose a framework You can implement this service plugin with the following [frameworks](https://dev.wix.com/docs/build-apps/get-started/overview/wix-s-development-frameworks.md): + **Wix CLI:** Learn how to [implement a service plugin with the CLI and the SDK](https://dev.wix.com/docs/build-apps/develop-your-app/frameworks/wix-cli/supported-extensions/backend-extensions/service-plugins/add-service-plugin-extensions-with-the-cli.md). + **Self-hosted:** Learn how to [implement a self-hosted service plugin with the SDK and the Wix Dev Center](https://dev.wix.com/docs/build-apps/develop-your-app/frameworks/self-hosting/supported-extensions/backend-extensions/add-self-hosted-service-plugin-extensions-with-the-sdk.md). ### Configure your service plugin To configure and customize your plugin, you need to provide important information in the service plugin configuration file. You can [configure your plugin in your app's dashboard](https://dev.wix.com/docs/build-apps/develop-your-app/frameworks/self-hosting/supported-extensions/backend-extensions/add-self-hosted-service-plugin-extensions-with-the-sdk.md#step-1--add-a-service-plugin-extension-to-your-app). For details, see [Custom Discount Trigger Extension Configuration](https://dev.wix.com/docs/rest/business-solutions/e-commerce/extensions/discounts/custom-discount-triggers-integration-service-plugin/extension-config.md). ### Define handler functions Use [`customTriggers.provideHandlers()`](https://dev.wix.com/docs/build-apps/develop-your-app/frameworks/self-hosting/supported-extensions/backend-extensions/add-self-hosted-service-plugin-extensions-with-the-sdk.md#step-4--define-handler-functions) to define the following handler functions that implement your custom business logic. Make sure you define all required functions. | Function | Required | |-----------------------------|----------------| | [`getEligibleTriggers()`](https://dev.wix.com/docs/rest/business-solutions/e-commerce/extensions/discounts/custom-discount-triggers-integration-service-plugin/get-eligible-triggers.md) | Yes | | [`listTriggers()`](https://dev.wix.com/docs/rest/business-solutions/e-commerce/extensions/discounts/custom-discount-triggers-integration-service-plugin/list-triggers.md) | Yes | ## Code examples Below is an example for implementing the Custom Discount Triggers service plugin in your code. ### CLI: Basic code structure This is the basic code structure for implementing the Custom Discount Triggers service plugin with the Wix CLI: ```js import { customTriggers } from '@wix/ecom/service-plugins' customTriggers.provideHandlers({ getEligibleTriggers: async (payload) => { const {request, metadata} = payload; // Add your logic here }, listTriggers: async (payload) => { const {request, metadata} = payload; // Add your logic here } }); ``` ### Self-hosted: Basic code structure This is the basic code structure for implementing a self-hosted Custom Discount Triggers service plugin: ```js import { createClient } from '@wix/sdk'; import { customTriggers } from '@wix/ecom/service-plugins' const wixClient = createClient({ auth: { appId: