Skip to main content

Settlement Ingestion & Reconciliation Lifecycle

End-to-End Workflow​

The settlement and financial reconciliation pipeline transitions transactions through six core states:


1. Ingestion Channels & Triggers​

Settlements enter the system via two distinct mechanisms:

A. Automated Daily Sync​

  • Scheduler: Runs automatically via SettlementReconciliationScheduler (cron 0 2 * * *) and periodic interval syncs on APP_BULL_QUEUES.SYNC.
  • API Fetch: For platforms with direct financial APIs (e.g. Amazon SP-API Finances API), the system automatically polls for finalized disbursement cycles without manual user intervention.

B. Manual File Upload​

  • Endpoints: POST /v1/finance/settlement/import for settlement reports; POST /v1/finance/settlement/import/fba for the Amazon FBA Inventory Adjustments and Customer Returns reports (kind).
  • Supported Formats: .csv, .tsv, .txt, .xlsx
  • Supported Providers: Amazon Settlement Flat File V2, Flipkart Settlement File, Meesho Payout Flat File, Shopify Balance Settlement CSV. COD remittances and gateway files have their own endpoints.
  • Handling: The file is uploaded through the API (upload purpose settlement-imports), an ImportBatch is created, and a job upload is queued on APP_BULL_QUEUES.SETTLEMENT. The API returns the batch at once.

2. Processing & Parsing Rules​

The background worker in SettlementImportProcessor routes the file to its corresponding parser:

  1. Amazon Parser (AmazonSettlementFileParser / AmazonFinancesApiAdapter):
    • Extracts Order, Refund, and OtherTransaction lines.
    • Maps fee codes: Commission, ShippingChargeback, GiftwrapChargeback, VariableClosingFee, PickPackFee, TCS, and TDS.
  2. Flipkart Parser (FlipkartSettlementFileParser):
    • Extracts order items, marketplace fees, customer shipping fees, pick-and-pack charges, and reverse shipping fees.
  3. Meesho Parser (MeeshoSettlementFileParser):
    • Handles Meesho net settlement structures, waiver credits, and penalty adjustments.
  4. Shopify Parser (ShopifySettlementFileParser):
    • Parses payment gateway fees, refunds, adjustments, and payouts.

Idempotency & Deduplication​

  • File deduplication: an upload is hashed (SHA-256 of the bytes) and an ImportBatch with the same hash for the channel is returned instead of queuing a second parse.
  • Payout identity: a payout is unique on (tenantId, source, partnerId, externalPayoutId); a re-import adds lines to the same payout.
  • Line deduplication: every line carries a dedupeHash; re-importing the same report inserts nothing. A partner that restates a line produces a new line with the same identityKey, and the old line is marked supersededById (lines are never updated).

3. Auditing Rules & Tolerances​

Once transactions are normalized, the SettlementFeeAuditorService audits each line against configured rate cards:

Audit CheckTolerance RuleFailure Behavior
Marketplace CommissionConfigurable slab tolerance (default ₹0.50 or 0.1%)Flags PlatformFeeCategory.COMMISSION as OVERCHARGED; auto-generates claim line
Freight & Weight AuditCompared against courier billing weight vs warehouse captured volumetric weight (L * W * H / 5000)Flags weight discrepancy if billed weight exceeds captured weight by more than 50g
RTO Reverse ShippingStrict ₹0.00 allowance. If isRtoOrder === true, reverse fee must be 0Automatically flags PlatformFeeCategory.REVERSE_SHIPPING as OVERCHARGED with dispute reason
Marketplace chargesLines with no order (subjectType ACCOUNT, SKU, INBOUND_SHIPMENT…) carry their own category (advertising, storage, subscription)Posted to their own expense ledgers; never part of an order's receivable. A person can correct a line's category, which re-posts the payout's journal

4. Journal Vouchers​

Every payout (marketplace, COD or gateway) gets balanced vouchers from SettlementJournalService. The database refuses an unbalanced voucher at commit.

  • Sales →\rightarrow Credit 4000 Marketplace Sales
  • Commission, shipping, closing and fulfilment fees →\rightarrow Debit 5000–5050
  • GST TCS (s.52) →\rightarrow Debit 1300 TCS Receivable (claimed on the GST portal)
  • Income-tax TDS (s.194-O) →\rightarrow Debit 1310 TDS Receivable (claimed against Form 26AS)
  • Net payout →\rightarrow Debit the source's clearing account: 1120 marketplace, 1121 COD, 1122 gateway

A payout spanning months posts each month's lines in that month and carries the balance through 1250. When lines change, posted vouchers are reversed and fresh ones posted. See Settlements → Journal and ERP.


5. Bank Statement UTR Allocation​

When a bank statement is imported for a bank account:

  1. Each credit whose reference is a payout's UTR or id, and whose amount equals what those payouts should bank, is allocated at once.
  2. A person allocates the rest, splitting one credit across payouts of any source.
  3. Tolerance: allocations must add up to the credit within ₹1.00.
  4. Each payout's bankAllocated and bankStatus (UNMATCHED, PARTIAL, MATCHED) follow its allocations.

6. Direct ERP Export & Push​

Vouchers are pushed per payout, per voucher or per date range; one already sent to a system is skipped:

  • Tally Prime: Direct HTTP push to port 9000 or XML download (Tally Prime Guide).
  • Zoho Books: Direct OAuth REST API journal creation or CSV export (Zoho Books Guide).