Trivio Logo
Docs
v0.1.0
Core Engine

@trivio.ink/core Quick Start

Pure calculation primitives for fee deduction and settlement date estimation.

Installation

npm install @trivio.ink/core

Unified Calculation API

The calculatePaymentSettlementEstimate function combines MDR percentage calculations, fixed acquirer levies, and settlement calendar adjustments into a single deterministic call:

unified-estimate.tstypescript
import { calculatePaymentSettlementEstimate } from "@trivio.ink/core";

// Execute consolidated calculation
const estimate = calculatePaymentSettlementEstimate(
  {
    grossMinor: 1000000, // $10,000.00
    currency: "USD",
    transactionTime: "2026-11-16T17:30:00Z",
    acquirerId: "ACQ_PRIMARY",
  },
  {
    feeRules: [
      {
        id: "RULE_VISA_CREDIT",
        version: "1.0.0",
        priority: 10,
        acquirerId: "ACQ_PRIMARY",
        currency: "USD",
        effectiveFrom: "2026-01-01",
        rateSource: "merchant_configured",
        feeStructure: {
          rateBasisPoints: 250, // 2.50% MDR
          fixedFeeMinor: 1500,  // $15.00 fixed
        },
      },
    ],
    settlementPolicies: [
      {
        id: "POLICY_T_PLUS_1",
        version: "1.0.0",
        acquirerId: "ACQ_PRIMARY",
        currency: "USD",
        effectiveFrom: "2026-01-01",
        cycleLength: 1,
        cycleUnit: "business_days",
        cutOffTime: "16:00:00",
        timeZone: "UTC",
        calendarId: "CAL_US",
      },
    ],
    calendars: [
      {
        id: "CAL_US",
        version: "2026.1",
        timeZone: "UTC",
        workingDays: [1, 2, 3, 4, 5],
        holidays: ["2026-12-25", "2027-01-01"],
      },
    ],
  }
);

console.log("Net Settlement:", estimate.netMinor); // 973500 ($9,735.00)
console.log("Settlement Date:", estimate.expectedSettlementDate); // "2026-11-18"
console.log("Cut-off Shifted:", estimate.isPastCutOff); // true (17:30 > 16:00)

Key Return Properties

grossMinor: Exact integer gross authorized minor units.

percentageFeeMinor: Computed percentage MDR deduction.

fixedFeeMinor: Fixed per-transaction charge.

totalFeeMinor: Combined sum of percentage and fixed fees.

netMinor: Final estimated deposit credit (grossMinor - totalFeeMinor).

expectedSettlementDate: Projected bank deposit clearance date (ISO format YYYY-MM-DD).