What are settlement items?
A settlement item is a clearing link that applies a portion (or all) of a ledger entry to a real settlement operation. Each settlement item represents an actual money movement:- PIX payment to a merchant’s bank account
- Internal transfer between accounts
- Invoice payment for monthly costs
- Boleto payment for settlements
Entity relationships
Core attributes
Each settlement item contains:- ledger_entry_id: Which ledger entry is being settled
- settled_amount: How much of the entry is being settled (in cents)
- settlement_date: When the money actually moved
- method: How the money moved (PIX, internal transfer, etc.)
- status: Current state of the settlement
- operation_id: External reference (transaction ID, transfer ID, etc.)
- affiliation_bank_account_id: Destination bank account (if applicable)
Settlement methods
Rinne supports multiple settlement methods:PIX
Instant payments to merchant bank accounts (D+0)
Internal transfer
Transfers between Rinne accounts (organization fees)
Invoice
Monthly invoices for platform/provider costs
Boleto
Bank slip payments for settlements
Settlement status lifecycle
Settlement items follow a state machine with strict transition rules:Valid transitions
- PENDING → PROCESSING: Settlement initiated
- PENDING → PAID: Instant settlement (PIX)
- PENDING → FAILED: Settlement failed immediately
- PROCESSING → PAID: Settlement completed
- PROCESSING → FAILED: Settlement failed during processing
Terminal states
- PAID: Settlement completed successfully (no further transitions)
- FAILED: Settlement failed permanently (no further transitions)
PIX settlement flow
For PIX transactions, Rinne creates settlement items immediately after the transaction is approved:1. Transaction settlement
The main transaction amount is settled instantly:2. Organization fee settlement
Organization fees are settled via internal transfer:PAID.
3. Platform and provider costs
Platform and provider costs remain outstanding for monthly invoice settlement:Two-step settlement creation
To prevent race conditions, Rinne uses a two-step process for creating settlement items:Step 1: Create with null operation_id
Settlement items are created first withoperation_id: null and status: PENDING:
Step 2: Update with actual operation_id
After the operation (e.g., internal transfer) is created, settlement items are updated:Step 3: Status updates
When the operation completes, settlement items are updated again:Race condition prevention
Rinne usespair_token lookups to prevent race conditions between settlement creation and status updates:
The problem
When an internal transfer status changes, the handler needs to find associated settlement items. However, there’s a race condition where the status change event could fire before settlement items are updated with theoperation_id.
The solution
Instead of looking up settlement items byoperation_id, Rinne uses the pair_token from ledger entries:
- Settlement items are created with
operation_id: null - Internal transfer is created with
request_id= ledger entrypair_token - Status change handler finds settlement items using
pair_token(via ledger entry relationship) - Settlement items are updated with the actual
operation_id
Ledger entry updates
When settlement items are created or updated, the corresponding ledger entries are automatically updated:Outstanding amount calculation
Settlement status
Example progression
Initial state (after ledger entry creation):Partial settlements
Settlement items support partial settlements, where a ledger entry is settled in multiple operations:Refund settlements
Refund settlements follow the same pattern as transaction settlements:Transaction refund
Organization fee refund
Idempotency
Settlement item creation is idempotent. If settlement items already exist for a ledger entry and operation ID, Rinne skips creation:Settlement invariants
Rinne enforces strict invariants for settlement items:Settlement bounds
Outstanding accuracy
Non-negative outstanding
Settlement status consistency
Complete settlement example
Here’s a complete example showing how a R$100 PIX transaction is settled:1. Ledger entries created
2. Settlement items created
3. Ledger entries updated
Key principles
Actual movements
Track real money movements, not just accounting
State machine
Strict status transitions prevent invalid states
Race-safe
Two-step creation prevents race conditions
Idempotent
Safe to retry settlement operations

