Skip to main content

Conditionals

Conditionals allow us to write configuration that changes based on various factors. For example, show different amounts based on the currency. To achieve something like that, you have to write a conditional. There are many different config keys that support conditionals. A conditional can either be a value of any kind – a simple value without a condition, or the same value wrapped into a if, then structure – a value inside a condition.

As an example, amounts without a condition:

As an example, with conditionals you can change the amounts depending on the currency like this.

A condition usually consists of operators and methods. In the example above, currency() would be a method and == an operator

Operators

You might write conditions either in traditional or functional format, for example, traditional: 1 < 2 and 3 > 2, functional: and(lt(1, 2), gt(3, 2)).

List of available operators:

OperatorDescription
and, &&Logical and operator
or, ||Logical or operator
>Greater then comparison
>=Greater then or equal to comparison
<Lesser then comparison
<=Lesser then or equal to Ocomparison
==Equal to comparison
===Strict equal to comparison
!=Not equal to comparison
!==Strict not equal to comparison
+, -, *, /Mathematical operators
%Modulo operator
!, not, unlessInversion operator
inCheck if in array
ninCheck if not in array

Methods

List of available methods:

MethodExampleDescription
andand(true, true)Logical and comparison
oror(true, false)Logical or comparison
gtgt(2, 1)Greater then comparison
gtegte(2, 2)Greater then equal to comparison
ltlt(1, 2)Lesser then equal to comparison
ltelte(2, 2)Lesser then equal to comparison
eqeq(1, 1)Equal to comparison
eqseqs(1, '1')Strict equal to comparison
neqneq(1, 2)Not equal to comparison
neqsneqs(1, '1')Strict not equal to comparison
addadd(1, 2)Mathematical + operator
subsub(2, 1)Mathematical - operator
mulmul(2, 3)Mathematical * operator
divdiv(6, 2)Mathematical / operator
modmod(10, 3)Mathematical % operator
arrarr(1, 2, 3)Create an array from inputs
roundround(1.5)Regular rounding
ceilceil(1.8)Round to next highest
floorfloor(1.2)Round to next lowest
nannan('1')Check that value is a number, not a string
inin(1, arr(1, 2, 3))Check that value is part of array
ninin(4, arr(1, 2, 3))Check that value is not part of array
negneg(true)Negate a value to the opposite
valval(1)Return given value, used internally
purposepurpose()Get payment form purpose
paymentTypepaymentType()Get payment form payment type
recurringIntervalrecurringInterval()Get payment form payment interval
currencycurrency()Get payment form currency
amountamount()Get payment form amount
feeAmountfeeAmount()Get payment form fee amount
formattedAmountformattedAmount()Get payment form formatted amount
formattedTotalAmountformattedTotalAmount()Get payment form formatted total amount
formattedFeeAmountformattedFeeAmount()Get payment form formatted fee amount
paymentMethodpaymentMethod()Get payment form payment method
isCardisCard('vis')Is given payment method a card payment method
paymentFormpaymentForm('stored_customer_firstname')Get payment form field value by name
showPaymentAddressshowPaymentAddress()Returns true if payment address block is mandatory
isPostFinanceIbanisPostFinanceIban()Returns true if iban, filled in payment form, is PostFinance iban
transtrans('blocks.payment_purposes.title')Get translation string by path (escaped)
transUnescapedtransUnescaped('blocks.payment_purposes.title')Get translation string by path (not escaped)
configconfig('epms.accountUuid')Get raw config option value by option name (path)
resolveConfigresolveConfig('amounts')Get resolved config option values by option name (path)
resolveConfigWithSingleResultresolveConfigWithSingleResult('allowCustomAmount')Get first resolved config option values by option name (path)
transactionInfotransactionInfo('payment_method')Get transactionInfo field value by name
subscriptionInfosubscriptionInfo('payment_method')Get subscriptionInfo field value by name
transactionFinalStatustransactionFinalStatus()Get final status of transaction
abTestVariantabTestVariant()Get current variant of AB testing

Adding custom methods

Methods are simple functions that may, or may not, take arguments and return a value. New methods can easily be added like this:

window.rnw.tamaro.events.afterCreate.subscribe((event) => {
const tamaro = event.data.api;

// Adding a new operator `todaysDay`
tamaro.parser.addMethods({
todaysDay: () => new Date().getDay(),
});

// On every second day we change the amounts
tamaro.extendConfig({
amounts: [
{
if: 'todaysDay() % 2 === 0',
then: [1, 2, 3, 4],
},
{
if: 'todaysDay() % 2 === 1',
then: [5, 6, 7, 8],
},
],
});
});

window.rnw.tamaro.runWidget('.rnw-tamaro-widget');