Pricing rules allow you to package and bundle your product in completely unique ways and provides you extreme flexibility to monetize as you see fit. This is an advanced rule engine that can be used to apply different rules on existing rate cards in an invoice or other static/dynamic fields and apply a computed logic while you generate an Invoice.

Configurability of pricing rules


Pricing rules in Togai are configurable using supported javascript operators. Computation of a pricing rule happens along with the computation of the invoice (near real-time). The following entities should be defined for a pricing rule.

  • Description - This is the line item description you would like customers to see in their invoice for the pricing rule computation value.
  • Type - You can configure the pricing rule to be a discount or an additional charge
  • Rule - A rule is a condition that is based on the values of a variable in the price plan/invoice. You can use multiple variables to create a condition across multiple rate cards of the plan. You can define rules using the supported javascript operators mentioned below.
  • Computation - Currently, the target action is split into computation and destination as 2 configurable values. You can define the computation as a mathematical formula using supported javascript operators.
  • Add/update - You can either add a new line item for the target computation or update an existing line item of the invoice.
  • Order - Here, you define the priority of computing the pricing rules since inter-dependent pricing rules will cause conflict, if parallelized.
The variables that can be used to create conditions and computations are the usage and revenue data for the different rate cards configured in the price plan. The variable names will be populated as ‘drop-down suggestions’ when you type usage. or revenue. You cannot apply conditions, computations or update In Advance rate cards currently.

Supported variable types and names

Currently, you can use the below variables from the price plan to create conditions and computations in a pricing rule:

Fixed fee: <revenue>.ff.<rate_card_id>
Usage fee: <usage/revenue>.urc.<rate_card_id>
License fee: <usage/revenue>.lic.<rate_card_id>
Entitlement fee: <revenue>.ber.<rate_card_id>
Entitlement Overage fee: <usage/revenue>.eo.<rate_card_id>
Credit Grant fee: <revenue/credit>.cg.<rate_card_id>
Tag: <usage/revenue>.tag.<tag_name>
Sum of all rate cards(Before credits): <revenue>.rate_card_total 

Supported javascript operators

You can use the below logical and mathematical operators on the above variables while creating a pricing rule condition/computation:

Supported literals: 

Boolean Literals 		        true, false
String Literals     		    "string1", "string2", 
Template Literals	        	`string1, ${var1}`
Numeric Literals		        1, 2.04, -10292.64, 0b01011010, 0xFF00FF, etc.
Null Literals	                null
Object Expressions          	{ key1: [1, 2, 2], key2: "value2", key3: 'value3' }
Array Literals                  [1, 2, 3, 4]
Variables                       var1,var2,var3 etc.

Mathematical Operations:

Comparison 		                 var1 > var2, var1 < var2, var1 <= var2, var1 === var2, var1 !== var2
Arithmetic                  	 var1 + var2, var1 * var2, var1 - var2, var1 / var2, var1 % var2
Unary		                     !cond, !!cond, -var, +var
Conditional                      var1 && var2, var1 || var2, condition ? var1 : var2
If Statements	                 if (conditionA) { var1 } else if (conditionB) { var2 } else { var3 }
Maximum 		                 max(var1, var2, var3)
Minimum                      	 min(var1, var2, var3)

String Operations: 

Concatenation		            cat("a", "b","c")"abc"
Substring                       substr("abcd", 1, 2)"bc"

Grouping : 

Parentheses		                (1 + 2) * 39

Array Operations:

Spread                         [1, 2, ...var1]

Example 1: Payments company volume based discount

Let’s take the case of a payment processor like Stripe. Stripe’s pricing model is based on the transaction amount and their default pricing is 2.9% of the transaction amount + 30 cents per transaction. For simplicity, let’s assume Stripe’s default pricing is 3%.

Now, they have a custom contract with a large enterprise which follows the below pricing -

  • 2.8% for credit card transactions
  • 2% for debit card transactions
  • Flat $1 per ACH or Wire
  • If the overall payment value during a month across all payment modes cross $1 million dollars, then provide additional 10% discount on the overall invoice.

In this case, we model the 3 separate payment modes as 3 individual usage meters and usage rate cards in Togai. The aggregated volume discount is configured as a pricing rule as per the below logic -

Rule - Total payment value (recorded as a usage meter) of rate card 1 + rate card 2 + rate card 3 > $1mn

Computation - 10% of total invoice value

Add/update - Add as a discount to the invoice

Rule : (revenue.usageRateCard1 + revenue.usageRateCard2 +
        revenue.usageRateCard3 > 1000000)
Computation : revenue.totalRevenue * 0.1
Action : Add as New Line Item
Description : Discount based on usage

Example 2: Communications company doing bundling

Another example - we have a cloud contact center solution that offers license based pricing based on the number of call center agents using their product. However, they also provide a tele-calling facility which is priced based on the number of minutes.

Let’s add a complex scenario where the company wants to provide a bundled offering where each license gets a free call usage of upto 1000 minutes per month and beyond that, there is an overage price.

In this case, we have 2 individual rate cards to model the license fees with number of licenses as input quantity and the usage based rate card for the tele-calling fees. For the bundled pricing, we create the below rule

Rule - Usage quantity of tele-calling > 0

Computation - Minimum of [(Number of licenses * 1000 * price per unit of a call) , Actual tele-calling usage revenue]

Add/update - Add as a discount to the invoice

Rule : (usage.teleCallingLicenseRateCard > 0)
Computation : min(usage.teleCallingLicenseRateCard * 1000 * 0.1, 
Action : Add as New Line Item
Description : Discount based on purchased licenses