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 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.For the service fee to be applied, we would need to satisfy these conditions:
50
"DELIVERY"
We have the following values:
70
"DELIVERY"
"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"
.
We have the following values:
30
"DELIVERY"
"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
.
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.
The following table shows field support for filters and sorting for the rules object:
Field | Supported Filters | Sortable |
---|---|---|
id | $eq , $ne , $in , $nin , $startsWith | Sortable |
appId | $eq , $ne , $in , $nin , $startsWith | Sortable |
locationId | $eq , $ne , $in , $nin , $startsWith | Sortable |
Related content: API Query Language, Query Rules
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.
Rule ID.
ID of the restaurant’s location.
Rule name.
Date and time the rule was created.
Date and time the rule was updated.
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
.
Specifies the type of condition.
Specifies the type of condition.
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.
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.
DEPRECATED. Defines the app that the rule is connected to.
Defines the app that the rule is connected to.
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
.Fixed fee. Must hold a positive value.
Percentage fee. For example, 5
represents a 5% fee applied to the order's total.
Fixed fee. Must hold a positive value.
Percentage fee. For example, 5
represents a 5% fee applied to the order's total.
Single condition that must be met for the rule to be applied to an order.
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.
Single condition that must be met for the rule to be applied to an order.
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.
Percentage value to apply as a custom tax rate. Range: [0-100].
Tax group ID. Internal only.
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.
Order information needed to evaluate the rules and calculate the relevant fees.
DEPRECATED. Defines the app that the rule is connected to.
Defines the app that the rule is connected to.
A list of calculated fees based on rules evaluation.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
Retrieve only rule that apply at the location with this ID. If this field is null
, the rules will not be filtered by location.
DEPRECATED. Defines the app that the rule is connected to.
Defines the app that the rule is connected to.
Array containing the retrieved rules.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
You can only call this method when authenticated as a Wix app or Wix user identity.
Rule to create.
Created rule
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
ID of the rule to retrieve.
The retrieved rule.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
You can only call this method when authenticated as a Wix app or Wix user identity.
ID of the rule to delete.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.