Scaled values
To handle transactions with different levels of precision, the Fee Engine uses a scale format to represent monetary values. This approach ensures consistency across fiat and cryptocurrencies alike. The formula is straightforward:Example: buying a coffee (BRL)
A coffee bought for R$ 5.50 is represented in the API asBRL 550|2
:
Example: transferring Bitcoin (BTC)
A transfer of 0.00123456 BTC appears asBTC 123456|8
:
Fee calculation rules
Each fee uses anapplicationRule
to define how it’s calculated. You can choose from three rule types:
TipYou can combine different rules in a single package to match your use case.
- The
isDeductibleFrom
field defines how the calculation will be made in relation to thereferenceAmount
field, meaning it is possible to specify whether the fee should be deducted from the initial or net value of the transaction. priority
determines the order in which each fee is applied.
maxBetweenTypes
Applies the higher value between a flat and a percentage-based fee. It uses thereferenceAmount
and isDeductibleFrom
fields to determine the result.
Example
- Flat fee value: R$ 5.
- Percentual fee: 2%.
- Reference amount: R$ 1,000.
Field | Raw Value | Scale | Scaled Value |
---|---|---|---|
value (Flat) | 5.00 | 2 | 500 |
value (Percent) | 0.02 | 2 | 2 |
referenceAmount | 1,000.00 | 2 | 100000 |
flatFee
Applies a fixed fee amount to the transaction, depending onreferenceAmount
and isDeductibleFrom
.
Example
- Fixed value: R$ 15.
- Reference amount: R$ 115.
- Scale: 2.
isDeductibleFrom | Formula | Total Fee |
---|---|---|
false | referenceAmount + value | R$ 130.00 |
true | referenceAmount - value | R$ 100.00 |
Field | Raw Value | Scale | Scaled Value |
---|---|---|---|
value | 15.00 | 2 | 1500 |
referenceAmount | 115.00 | 2 | 11500 |
TotalFee | 130.00 / 100.00 | 2 | 13000 / 10000 |
percentual
Applies a fee as a percentage of the reference amount. Example- Value: 30%.
- Reference amount: R$ 389.50.
- Scale: 2.
isDeductibleFrom | Formula | Total Fee |
---|---|---|
false | referenceAmount * value | R$ 116.85 |
true | referenceAmount - (referenceAmount * value) | R$ 272.65 |
Field | Raw Value | Scale | Scaled Value |
---|---|---|---|
value | 30 | 2 | 0.30 |
referenceAmount | 389.50 | 2 | 38950 |
TotalFee | 116.85 / 272.65 | 2 | 11685 / 27265 |
Fee splitting
When a transaction involves multiple source accounts, fees are split proportionally among them.Example
- Total amount: R$ 4,000.00.
- Fixed fee: R$ 15.00.
- Tax: 4%.
isDeductibleFrom
: false.
- @account1: R$ 1,000.
- @account2: R$ 1,000.
- @account3: R$ 1,600.
- @account4: R$ 400.
Participation %
Formula: (Account Amount ÷ Total Amount) × 100- @account1: 25%.
- @account2: 25%.
- @account3: 40%.
- @account4: 10%.
Fixed fee split
TipFormula:
fixed Fee × participation %
Account | % | Fee Share | Total w/ Fee |
---|---|---|---|
@account1 | 25% | R$ 3.75 | R$ 1,003.75 |
@account2 | 25% | R$ 3.75 | R$ 1,003.75 |
@account3 | 40% | R$ 6.00 | R$ 1,606.00 |
@account4 | 10% | R$ 1.50 | R$ 401.50 |
Proportional tax
TipFormula:
account amount × tax %
Account | Tax Share | Total w/ Tax |
---|---|---|
@account1 | R$ 40.00 | R$ 1,040.00 |
@account2 | R$ 40.00 | R$ 1,040.00 |
@account3 | R$ 64.00 | R$ 1,664.00 |
@account4 | R$ 16.00 | R$ 416.00 |
Final amount per Account
TipFormula:
principal + fee + tax
Account | Principal | Fee Share | Tax Share | Final Total |
---|---|---|---|---|
@account1 | R$ 1,000 | R$ 3.75 | R$ 40.00 | R$ 1,043.75 |
@account2 | R$ 1,000 | R$ 3.75 | R$ 40.00 | R$ 1,043.75 |
@account3 | R$ 1,600 | R$ 6.00 | R$ 64.00 | R$ 1,670.00 |
@account4 | R$ 400 | R$ 1.50 | R$ 16.00 | R$ 417.50 |
Fee splitting validation
To ensure correctness:- Participation % must total 100%.
- The fee split must equal the original fixed fee.
- Tax must total 4% of the transaction.
- Final total = original amount + fees + tax → R 4,175.00.
Fee exemptions: rules & hierarchy
By transaction amount
UseminimumAmount
and maximumAmount
to define when fees should apply. For example: If the range is R 301 won’t trigger fees.
By account
The system checkswaivedAccounts
. If the source is listed, it’s exempt from fees.
TipHierarchy: Amount -> Account.
Mixed example: fee exemptions and fee splitting
Let’s look at an example of a package that includes accounts with fee exemptions and requires splitting fees proportionally.Scenario
We’re processing a transaction of R$ 4,000, which includes:- A fixed fee of R$ 16.
- An IOF tax of 6% to be deducted.
Split on the source side
Source Account | % | Proportional Value |
---|---|---|
@account1 | 15% | R$ 600 |
@account2 | 35% | R$ 1,400 |
@account3 | 40% | R$ 1,600 |
@account4 | 10% | R$ 400 |
Split on the destination side
Destination Account | % |
---|---|
@donation1 | 25% |
@donation2 | 25% |
@donation3 | 25% |
@donation4 | 25% |
- The IOF is set with
"isDeductibleFrom": true
, meaning it will be deducted from the amount to be distributed. Its “priority”: 1 makes it the first fee to be applied. - The Administrative Fee has
"isDeductibleFrom": false
, meaning it gets added to the transaction amount. Its"priority": 2
means it’s applied after the IOF.
Breaking down the fee calculations
Source Account | % | Proportional Value | Admin Fee | Final Transfer Amount |
---|---|---|---|---|
@account1 | 15% | R$ 600 | Exempt | R$ 600 |
@account2 | 35% | R$ 1,400 | Exempt | R$ 1,400 |
@account3 | 40% | R$ 1,600 | R$ 12.80 | R$ 1,612.80 |
@account4 | 10% | R$ 400 | R$ 3.20 | R$ 403.20 |
- Total subject to fee: R 400 = R$ 2,000.
- Share of
@account1
: 1,600 / 2,000 = 80% → 16 × 0.8 = R$ 12.80. - Share of
@account2
: 400 / 2,000 = 20% → 16 × 0.2 = R$ 3.20.
And what about the IOF?
Since the IOF is a deduction, it’s subtracted from each destination account proportionally to their share.Destination Account | % | Gross Value | IOF (6%) | Net Value Received |
---|---|---|---|---|
@donation1 | 25% | R$ 1,000 | R$ 60 | R$ 940 |
@donation2 | 25% | R$ 1,000 | R$ 60 | R$ 940 |
@donation3 | 25% | R$ 1,000 | R$ 60 | R$ 940 |
@donation4 | 25% | R$ 1,000 | R$ 60 | R$ 940 |