Constructing a Rule

A rule has two main parts: conditions and a fee. When Calculate Service Fees is called, it assesses each rule in relation to the specified order. When a rule is assessed, if the conditions are met, the fee is included in the API's response.

Conditions

Conditions can be either a single condition or a condition tree.

A single condition evaluates a specific field in the order. For example, it could check if the value of the field is greater than a certain number.

A condition tree contains two conditions and an operator. The conditions can each be either a single condition or a condition tree. There are two operator values:

  • "AND": Both conditions must be met for the condition tree to be considered met.
  • "OR": At least one of the conditions must be met for the condition tree to be considered met.

Condition tree example

Conditions

For the service fee to be applied, we would need to satisfy these conditions:

  • The price subtotal is greater than 50
    AND
  • Either:
    • Delivery type is "DELIVERY"
      OR
    • Order is made in the mobile app

Example: Conditions are met

We have the following values:

  • Subtotal is 70
  • Delivery type is "DELIVERY"
  • Order is "WEBSITE"

In this case, the conditions are met, because the subtotal is greater than 50 and the delivery type is "DELIVERY". It doesn't matter that the platform isn't "MOBILE_APP" because we only need that OR delivery type to be "DELIVERY".

Example: Conditions are not met

We have the following values:

  • Subtotal is 30
  • Delivery type is "DELIVERY"
  • Order is "MOBILE_APP"

In this case, the conditions are not met, because even though the delivery type is "DELIVERY" and the platform is "MOBILE_APP", the subtotal is not greater than 50.

Fee

A fee is either a fixed amount or a percentage of the order's subtotal. It can also include tax.

If the conditions are met, the fee is calculated and applied when Calculate Service Fees is called.

Did this help?

Service Fees: Supported Filters and Sorting

The following table shows field support for filters and sorting for the rules object:

FieldSupported FiltersSortable
id$eq, $ne, $in, $nin, $startsWithSortable
appId$eq, $ne, $in, $nin, $startsWithSortable
locationId$eq, $ne, $in, $nin, $startsWithSortable

Related content: API Query Language, Query Rules

Did this help?

Rule Object


A rule defines the fee that is applied when specific conditions (also defined by the rule) are met. You can use a rule to apply a service fee to a restaurant order.

Properties
idstringRead-only

Rule ID.


locationIdstringformat GUID

ID of the restaurant’s location.


namestringmaxLength 50minLength 1

Rule name.


createdDatestringRead-onlyformat date-time

Date and time the rule was created.


updatedDatestringRead-onlyformat date-time

Date and time the rule was updated.


taxRatestringdeprecated - use taxes insteaddecimalValue {"maxScale":2,"gte":"0","lte":"100"}

Percentage value to apply as a custom tax rate. For example, 5 represents a 5% fee applied to the order's total.
Min: '0'.
Max: 100.


conditionsTypestringdeprecated - use conditionType instead

Specifies the type of condition.


conditionTypestring

Specifies the type of condition.


enabledboolean

Whether the rule is enabled. If true, the rule is evaluated when service fees are calculated. If false, the rule will not be evaluated when service fees are calculated.


revisionintegerRead-onlyformat uint64

Revision number. Increments by 1 each time the rule is updated. To prevent conflicting changes, the existing revision must be used when updating a rule.


labelstringdeprecated - use appId insteadmaxLength 100minLength 1

DEPRECATED. Defines the app that the rule is connected to.


appIdstringformat GUID

Defines the app that the rule is connected to.


roundingStrategystring

Rounding strategy to apply to fee and tax calculation.

  • HALF_UP rounds up any number exactly halfway between two integers. For example, 2.5 rounds to 3, and 3.5 and rounds to 4.
  • HALF_EVEN rounds such numbers to the nearest even integer. For example, 2.5 rounds to 2, but 3.5 rounds to 4.

One Of
Choose one of the following parameters

amountAmountdeprecated - use fixedFee instead

Fixed fee. Must hold a positive value.


percentagestringdeprecated - use percentageFee insteaddecimalValue {"maxScale":2,"gte":"0","lte":"100"}

Percentage fee. For example, 5 represents a 5% fee applied to the order's total.


One Of
Choose one of the following parameters

fixedFeeFixedFee

Fixed fee. Must hold a positive value.


percentageFeestringdecimalValue {"maxScale":2,"gte":"0","lte":"100"}

Percentage fee. For example, 5 represents a 5% fee applied to the order's total.


One Of
Choose one of the following parameters

conditionConditiondeprecated - use conditionOptions instead

Single condition that must be met for the rule to be applied to an order.


conditionTreeConditionTreedeprecated - use conditionTreeOptions instead

Binary tree of conditions. Use the operator to indicate whether only one or both conditions must be met in order for a service fee rule to be applied to an order.


One Of
Choose one of the following parameters

conditionOptionsConditionOptions

Single condition that must be met for the rule to be applied to an order.


conditionTreeOptionsConditionTreeOptions

Binary tree of conditions. Use the operator to indicate whether only one or both conditions must be met in order for a service fee rule to be applied to an order.


One Of
Choose one of the following parameters

customTaxRatestring

Percentage value to apply as a custom tax rate. Range: [0-100].


taxGroupIdstringformat GUID

Tax group ID. Internal only.

JSON
Did this help?

POST

Calculate Service Fees


Developer Preview

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

Calculates service fees for an order.

The specified order information is evaluated against all rules created for the site. If the rule conditions are met, the service fee set in the rule is applied. Otherwise, no service fee is added.

Permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Endpoint
POST
https://www.wixapis.com/service-fees/v1/calculate

Body Params
orderOrderRequired

Order information needed to evaluate the rules and calculate the relevant fees.


labelstringdeprecated - use appId insteadmaxLength 100minLength 1

DEPRECATED. Defines the app that the rule is connected to.


appIdstringformat GUID

Defines the app that the rule is connected to.

Response Object
calculatedFeesArray <CalculatedFee>

A list of calculated fees based on rules evaluation.

Calculate service fees
Request
cURL
Response
JSON
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

GET

List Rules


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 an array of all rules.

You can filter by location or app that the rules are associated with.

Permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Endpoint
GET
https://www.wixapis.com/service-fees/v1/rules

Query Params
locationIdstring

Retrieve only rule that apply at the location with this ID. If this field is null, the rules will not be filtered by location.


labelstringdeprecated - use appId instead

DEPRECATED. Defines the app that the rule is connected to.


appIdstring

Defines the app that the rule is connected to.

Response Object
rulesArray <Rule>

Array containing the retrieved rules.

List rules associated with a specific location and specific app
Request
cURL
Response
JSON
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

POST

Create Rule


Developer Preview

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

Creates a rule.

To create multiple rules at once, use Bulk Create Rules.

Read more about constructing a rule.

Authentication

You can only call this method when authenticated as a Wix app or Wix user identity.

Permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Endpoint
POST
https://www.wixapis.com/service-fees/v1/rules

Body Params
ruleRuleRequired

Rule to create.

Response Object
ruleRule

Created rule

Request
cURL
Response
JSON
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Event TriggersThis method triggers the following events:
Did this help?

GET

Get Rule


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 a rule.

Permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Endpoint
GET
https://www.wixapis.com/service-fees/v1/rules/{ruleId}

Path Params
ruleIdstringRequired

ID of the rule to retrieve.

Response Object
ruleRule

The retrieved rule.

Get a rule
Request
cURL
Response
JSON
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

DELETE

Delete Rule


Developer Preview

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

Deletes a rule.

To delete multiple rules at once, use Bulk Delete Rules.

Authentication

You can only call this method when authenticated as a Wix app or Wix user identity.

Permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Endpoint
DELETE
https://www.wixapis.com/service-fees/v1/rules/{ruleId}

Path Params
ruleIdstringRequired

ID of the rule to delete.

Response Object
Returns an empty object.
Delete a rule
Request
cURL
Response
JSON
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Event TriggersThis method triggers the following events:
Did this help?