Setting up order fees

Order fees allow you to automatically add fees or discounts to an order when certain conditions are met. It can be used for example to add a ticket delivery fee or a transaction fee to the order.

Automatic order fees are added automatically to an order if the order matches the rules of the orderfee. Rules are based on sales channel, delivery scenario and/or payment scenario. Order fees can be expressed as either a fixed amount or a percentage of the ticket price. If you need even more flexibility, you can use Script order fees to define a script that will decide which fee to add to an order.

Order fees are managed in the Settings app. Click the button below to go to the Order fees module:

Go to order fees

Automatic order fees

An automatic order fee can have multiple rules. The general rules should be defined first and the exceptions later. Whenever the rules of an (automatic) order fee are checked it will execute the last rule that matches.

A match will occur if the order has a saleschannel, delivery scenario and payment scenario that matches the OrderfeeAutoRule. If it’s matched (and it is was the last rule that matched) the defined value will be added, based on the status (fixedfee or percentagefee).

For example: we can define a fixed fee of 3€ for all Web orders that use delivery scenario “Send via mail”:

example


Script order fees

In certain cases a percentage or value based order fee is not sufficient. In these cases an order fee script can be written in plain Javascript. This javascript is executed when needed and the return value of the script decides the fee that will be added. This script has an order object available.

Simple script

The script should be written in Javascript and should always return a number. It’s not necessary to write a function, only the script itself. The order (as defined in the public data model) is always available in the script environment.

For example, we can write a script to calculate an order fee of 0.5 euro per ticket, but only if the total amount of the order is smaller than 20€:

1 if (order.totalamount < 20) {
2     return order.nbroftickets * 0.5
3 }
4 return 0;

Context queries

By default, you can use order information in a script. If you need more information that is not available in the order object, you can create a context variable. A context variable is a query that is executed before the script runs. The result of the query is available in the script environment.

To define a context variable three things need to be provided:

  • key: The key (variable name) that will be made available in the script.
  • query: The query that should be executed on the public data model. If the placeholder {1} is placed in the query, it will be replaced by the orderid.
  • cacheable : If set to true this query will be cached for 60 seconds. If not set the query will be executed every time the order fee script is evaluated.

Each context variable will be available in the script environment as an array. The first row can be accessed via context[0]. It’s good practice to give the context query specific column names. These can then be accessed via context[0].columnname.

For example:

Context variables:

1 [
2     {
3         "key": "ticketcount",
4         "query": "select count(*) as cnt from tm.ticket where orderid={1}",
5         "cacheable" : false
6     }
7 ]

Script:

1 return ticketcount[0].cnt;

This script will return the number of tickets in the order as an order fee.


Questions?

We're always happy to help! Send us an e-mail