About Custom Discount Triggers Service Plugin

The eCommerce Custom Discount Triggers service plugin (formerly SPI) allows you to provide custom triggers that specify when a discount can apply to a cart and checkout.

Custom triggers play a part in the definition of discount rules - sets of triggers and scopes that together define the necessary conditions for a discount to apply to items in the cart and checkout. 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 (created in the Wix Studio workspace), and the Wix Custom Discount Triggers service plugin.

Learn more about service plugin extensions.

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, or by using the Discount Rules API.

Use cases

Configuration

Complete the following steps to adapt Wix system's integration to make your custom triggers available to merchants and their customers.

  1. Go to Extensions in your app's dashboard.

  2. Click Create Extension in the top right.

  3. Filter by eCommerce in the left menu, then find Ecom Discounts Trigger and click Create.

  4. Provide the following configuration:

    NameTypeDescription
    deploymentUristringRequired. 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/.
    componentNamestringA unique name for this component. This is an internal name that will only appear in the app dashboard.
Did this help?

Sample Flows

This article presents sample flows your app can support. You aren't limited to these exact flows, but they can be a helpful jumping off point as you plan your Custom Discount Triggers integration.

Offer a happy hour discount

Your app can allow sites to offer customers a happy hour discount. With a custom trigger based on the time an order is placed, an automatic discount can be applied.

To create a custom trigger for a happy hour discount:

  1. Configure your app with custom triggers that are retrieved by Wix when List Triggers is called. For example, give a custom trigger these properties:
  • "id": "happy-hour-trigger"
  • "name": "Happy Hour, weekdays, 16:00-18:00"
  1. Create a discount rule that includes the amount of the discount to apply, which items to apply the discount to, and which custom trigger to use to trigger the rule.

  2. Wix calls Get Eligible Triggers when actions are taken on the cart or checkout entities/pages. Your app should determine if the time of the customer's action should trigger the Happy Hour discount rule to apply. If so, the customer will see the discounted price.

Offer a sale on digital products

Your app can allow sites to offer discounts on certain types of products, such as, digital products.

To create a custom trigger for a digital discount:

  1. Configure your app with custom triggers that are retrieved by Wix when List Triggers is called. For example, give a custom trigger these properties:
  • "id": "digital-sale-trigger"
  • "name": "Digital products discount"
  1. Create a discount rule that includes the amount of the discount to apply, which category of items to apply the discount to, and which custom trigger to use to trigger the rule.

  2. Wix calls Get Eligible Triggers when actions are taken on the cart or checkout entities/pages. Use Get Product to check the productType and determine if the product a customer views triggers the digital discount rule to apply. If so, the customer will see the discounted price.

Did this help?

POST

List Triggers


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

Lists all custom triggers provided by your service plugin integration.

This method is automatically called by Wix eCommerce to populate the custom minimum requirements section of an automatic discount.

Endpoint
POST
{DEPLOYMENT-URI}/v1/list-triggers
Request
This endpoint does not take any parameters.
Response Object
customTriggersArray <CustomTrigger>

Custom triggers.

List custom triggers - decoded JWT

The data payload will include the following object as an encoded JWT. For the purposes of this example, we show the request and response objects decoded.

Request
cURL
curl -X POST https://provider.example.com/v1/listTriggers \ -H 'user-agent: Wix' \ -H 'accept-encoding: gzip, deflate' \ -H 'content-type: text/plain; charset=utf-8'
Response
JSON
{ "customTriggers": [ { "id": "my-happy-hour-trigger", "name": "Happy Hour 16:00-18:00" }, { "id": "my-digital-sale-trigger", "name": "Digital products discount" } ] }
Did this help?

POST

Get Eligible Triggers


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

Retrieves eligible custom discount triggers based on the provided items.

This method is automatically called by Wix eCommerce to retrieve the custom discount triggers provided by your extension. This happens when actions are performed on the cart and checkout entities/pages. For example, when an item is added to the cart.

Endpoint
POST
{DEPLOYMENT-URI}/v1/get-eligible-triggers
Body Params
lineItemsArray <LineItem>maxItems 1000

List of line items in the cart/checkout.


triggersArray <TriggerToFilterBy>minItems 1maxItems 100

List of triggers to be checked for discount eligibility.


purchaseFlowIdstringformat GUID

Persistent ID that correlates between the various eCommerce elements: cart, checkout, and order.

Response Object
eligibleTriggersArray <EligibleTrigger>minItems 0maxItems 100

List of eligible triggers. These are used by the Discount Rules API and Wix eCommerce to apply the relevant discount.

Get eligible custom triggers - decoded JWT

The data payload will include the following object as an encoded JWT. For the purposes of this example, we show the request and response objects decoded.

Request
cURL
curl -X POST https://provider.example.com/v1/getEligibleTriggers \ -H 'user-agent: Wix' \ -H 'accept-encoding: gzip, deflate' \ -H 'content-type: text/plain; charset=utf-8' --data-binary '{ "triggers": [ { "customTrigger": { "id": "my-happy-hour-trigger" }, "identifier": "123" }, { "customTrigger": { "id": "my-digital-sale-trigger" }, "identifier": "234" } ], "lineItems": [ { "catalogReference": { "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", "catalogItemId": "b8b60eb2-f0c0-2519-c884-4e45ba25f0f7" }, "id": "00000000-0000-0000-0000-000000000001", "price": "250.00", "quantity": { "value": 1 } }, { "catalogReference": { "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", "catalogItemId": "c11f4db2-50cd-f4ea-d278-18c0914215d9", }, "id": "00000000-0000-0000-0000-000000000002", "price": "215.00", "quantity": { "value": 1 } } ] }
Response
JSON
{ "eligibleTriggers": [ { "customTriggerId": "my-happy-hour-trigger", "identifier": "123" }, { "customTriggerId": "my-digital-sale-trigger", "identifier": "234" } ] }
Did this help?