Payment Fee Engine Design
Last Updated: 2026-12-01 Status: Complete
A payment fee engine computes what each sub-merchant owes, what each party in the chain earns and what the processor costs you, all from versioned fee schedules. After this page you will be able to model a schedule, calculate fees in integer arithmetic with an explicit rounding rule, record true-ups and adjustments as new ledger entries, and distribute revenue between the platform, the PayFac and ISO partners.
Quick Reference
| Decision | Recommended default |
|---|---|
| Rate storage | Basis points (integer), never a decimal percentage |
| Amounts | bigint minor units |
| Rounding | Explicit mode (half-up or half-even), stored in the schedule version |
| Schedule changes | New effective-dated version; old versions are never edited |
| Estimate vs actual | Estimate at capture, true-up at settlement with new entries |
| Corrections | Credit entries with reason code and approval, never edits |
Fee amounts, interchange rates and tax treatment change and differ by region. This page gives no rates; for interchange values see Key Numbers. Confirm tax treatment of fees with tax advisors.
How Do You Model a Fee Schedule?
A schedule is a versioned, effective-dated set of components. Assign it at platform, pricing tier or merchant level, and resolve with a precedence rule: merchant override beats tier beats platform default, evaluated at the transaction's effective date.
| Component | Stored as | Notes |
|---|---|---|
| Percentage | rate_bps | 290 bps means 2.90% |
| Fixed per transaction | fixed_minor + currency | Per-item fee |
| Min and max | min_minor, max_minor | Applied after percentage and fixed |
| Tiered or volume | Rows with from_volume_minor | State whether tiers are marginal or whole-volume |
| Interchange-plus | markup_bps, markup_fixed_minor | Cost pass-through plus markup; see interchange-plus pricing |
| Monthly or account | period_fee_minor | Billed by a periodic job |
| Event fees | One row per event type | Chargeback, refund, payout, instant payout, cross-border and FX |
CREATE TABLE fee_schedule (
id uuid PRIMARY KEY, name text NOT NULL, version int NOT NULL,
rounding_mode text NOT NULL, -- half_away_from_zero | half_even
rounding_scope text NOT NULL, -- per_transaction | per_component
refund_fee_policy text NOT NULL, -- percentage | fixed | both | none
effective_from timestamptz NOT NULL, effective_to timestamptz,
UNIQUE (name, version)
);
CREATE TABLE fee_component (
id uuid PRIMARY KEY, schedule_id uuid NOT NULL REFERENCES fee_schedule(id),
kind text NOT NULL, -- percentage | fixed | event | monthly | markup
applies_to text NOT NULL, -- e.g. card_credit, ach_debit, payout_instant
currency char(3), rate_bps int, fixed_minor bigint,
min_minor bigint, max_minor bigint,
markup_bps int, markup_fixed_minor bigint, -- interchange-plus markup
period_fee_minor bigint -- monthly or account fee
);
CREATE TABLE fee_tier ( -- tiered or volume pricing
id uuid PRIMARY KEY, component_id uuid NOT NULL REFERENCES fee_component(id),
from_volume_minor bigint NOT NULL, rate_bps int NOT NULL, fixed_minor bigint
);
CREATE TABLE fee_assignment (
id uuid PRIMARY KEY, level text NOT NULL, -- platform | tier | merchant
subject_id uuid NOT NULL, schedule_id uuid NOT NULL REFERENCES fee_schedule(id),
effective_from timestamptz NOT NULL, effective_to timestamptz
);
Pricing-plan assignment as an entity is covered in Entity Model. Event fees are fee_component rows with kind = 'event'. Note that int columns come back from TypeORM as number and bigint columns as strings, so convert at the repository boundary (BigInt(row.rate_bps)) before doing arithmetic. Stamp each fee entry with the schedule id and version used, so any charge can be explained later.
When Do You Calculate Fees: Capture or Settlement?
At capture you know the merchant's side of the fee. You may not know the real interchange: it is determined at clearing and can be downgraded (see Qualification and Downgrades). Under interchange-plus, the true cost arrives with the settlement data described in Clearing and Settlement.
- At capture: post an estimated fee (or a flat-rate fee that is final).
- At settlement: compute the actual fee from the cleared data.
- True-up: post the difference as a new entry (
fee_trueup) linked to the original. Never update the estimate.
This keeps reports reproducible: the estimate was true when it was posted, and the correction is visible on its own line.
Integer Arithmetic and Rounding
Percentage fees are amount × bps ÷ 10,000, which usually yields a fraction of a minor unit. Rules:
- Compute in
bigint; never use floating point. - State the rounding mode (half-up or half-even) in the schedule version. Half-even reduces bias over many transactions; half-up is easier to explain to merchants. Either is valid if it is explicit and consistent. The sketch below calls half-up
half_away_from_zero, because a plain half-up on a negative value (a refund or fee reversal) rounds away from zero; decide deliberately whether reversals should mirror the original rounding, and test negatives. - Decide per schedule what a refund returns of the original fee: the percentage fee, the fixed fee, both or neither. Store it as a schedule field (
refund_fee_policy), apply it with the same rounding mode, and post the result as a reversing entry. - Choose scope: round per transaction (the merchant sees exact line items) or aggregate then round (less drift, but lines may not sum). Per-transaction is the common default.
- Post any rounding difference (for example when splitting a fee across parties) to a rounding account so entries always balance.
// half_away_from_zero: .5 rounds up for positives and down (more negative) for negatives
export type RoundingMode = 'half_away_from_zero' | 'half_even';
export function divRound(n: bigint, d: bigint, mode: RoundingMode): bigint {
const sign = n < 0n ? -1n : 1n;
const abs = n < 0n ? -n : n;
let q = abs / d;
const r2 = (abs % d) * 2n;
if (r2 > d || (r2 === d && (mode === 'half_away_from_zero' || q % 2n === 1n))) q += 1n;
return sign * q;
}
export interface FeeComponent { rateBps: bigint; fixedMinor: bigint; minMinor?: bigint; maxMinor?: bigint }
@Injectable()
export class FeeCalculator {
calculate(amountMinor: bigint, c: FeeComponent, mode: RoundingMode): bigint {
let fee = divRound(amountMinor * c.rateBps, 10_000n, mode) + c.fixedMinor;
if (c.minMinor !== undefined && fee < c.minMinor) fee = c.minMinor;
if (c.maxMinor !== undefined && fee > c.maxMinor) fee = c.maxMinor;
return fee;
}
}
For a payment of 1,999 minor units at 290 bps plus a 30 minor-unit fixed fee, half-up gives 58 + 30 = 88. Unit and property tests for this code are covered in Testing.
How Is Revenue Distributed?
A single payment can create value for several parties. See Fee Breakdown for the economics: interchange to the issuer, network fees, processor cost, and the markup you keep. In a PayFac with partners, add the platform (ISV) share and any ISO or agent residual income.
| Party | Earns | Ledger account |
|---|---|---|
| Processor and networks | Cost passed through | Processor cost payable |
| Platform (ISV) | Agreed share of the merchant fee | Platform fee payable |
| ISO or agent | Residual per contract | Residual payable |
| PayFac | Remainder | PayFac revenue |
Example ledger entry for an 88 fee (units illustrative: cost 40, platform 20, residual 8, PayFac 20):
| Debit | Credit | Amount |
|---|---|---|
| Sub-merchant payable | Fee clearing | 88 |
| Fee clearing | Processor cost payable | 40 |
| Fee clearing | Platform fee payable | 20 |
| Fee clearing | Residual payable | 8 |
| Fee clearing | PayFac revenue | 20 |
Fee clearing nets to zero. Where shares are percentages, compute all but one share and make the last the remainder, so the parts always equal the whole, or post any difference to the rounding account. A monthly residual statement is a report over residual payable entries by partner and merchant; make it derivable from the ledger, not from a separate table. Contract terms decide the percentages; this page does not.
How Do You Collect Fees?
| Method | How it works | Engineering implication |
|---|---|---|
| Deduction from payout (net) | Fee reduces the payout | Simple, no receivable; payout report must itemize |
| Invoicing or debit (gross) | Fee billed separately | Track a fee receivable, collect by ACH debit with authorization, handle failures |
If the balance is too small to absorb a deducted fee, the shortfall becomes a negative balance; see Reserves and Negative Balances. Payout timing and net vs gross are in Payout Architecture.
How Do You Handle Fee Adjustments and Disputes?
When a merchant disputes a fee or you find an error, post a credit entry, never an edit:
- reason code (for example
pricing_error,goodwill,downgrade_refund), - reference to the original fee entry,
- approver and approval timestamp, with a limit per role,
- optional link to the support case.
The adjustment reverses the original through the ledger, and if the schedule was wrong, a corrected assignment version applies from the right date. See Audit Trails for who-did-what records.
How Do You Reconcile Fees to Processor Costs?
Compute the expected cost per transaction from your own model and compare with what the processor billed; the differences are downgrades, schedule changes or contract misconfiguration. For PayFacs, reconcile what the acquirer billed you separately from what you billed each sub-merchant; the difference is margin and should be explainable. The method is in Reconciliation. Track effective rate by brand, product and merchant.
Multi-Currency Fees and Taxes
Compute fees in the currency of the schedule component; if the fee currency differs from the balance currency, post an explicit FX entry with the rate and its source rather than converting silently. Read minor-unit exponents from ISO 4217. Taxes on fees (for example VAT or sales tax) vary by jurisdiction and service type; keep the tax as a separate component and confirm treatment with tax advisors. No rates belong in code constants.
Related Topics
- Payout Architecture — how fees reduce payouts and how splits are posted
- Reserves and Negative Balances — fees that exceed balances
- Fee Breakdown — interchange, network and markup economics
- Double-Entry Ledger — entries, clearing accounts and reversals
- Check your understanding: Money Movement Quiz
References
- Interchange and fee economics — guide page, sources listed there
- ISO 4217 data standards — SIX
- Ledger: Stripe's system for tracking and validating money movement — Stripe Engineering, 2024