The Service Fees API allows you to manage your service fee rules and apply them to orders.
With the Service Fees API, you can:
It's important to note the following point before starting to code:
To use the ServiceFees API, install the @wix/restaurants
package using npm or Yarn:
or
Then import { serviceFees }
from @wix/restaurants
:
A rule has two main parts: conditions and a fee. When calculateServiceFees()
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 calculateServiceFees()
is called.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
The bulkCreateRules()
function returns a Promise that resolves to the created rules.
To create only one rule, use the createRule()
function.
Rules to create.
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.
The bulkDeleteRules()
function returns a Promise that resolves to the deleted rules.
To delete only one rule, use the deleteRule()
function.
IDs of the rules to delete.
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.
The bulkUpdateRules()
function returns a Promise that resolves to the updated rules.
Each time the task is updated, revision
increments by 1. The existing revision
must be included when updating the task. This ensures you're working with the latest task and prevents unintended overwrites.
To update only one rule, use the updateRule()
function.
Masked rules to update.
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.
The calculateServiceFees()
function returns a Promise that resolves to an array containing the calculated fees.
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.
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.
The createRule()
function returns a Promise that resolves to the created rule.
To create multiple rules at once, use the bulkCreateRules()
function.
Rule to create.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.