Skip to Content
StagePayDocs v2

Batch Status, Verification, and Approval

The settlement batch state machine (DRAFT→VERIFIED→APPROVED→PAID, CARRIED_FORWARD, CANCELLED), three-way reconciliation, checksums, four-eyes approval, payout processing, and cancellation rules.

Batch number

STL-{period start date YYYYMMDD (policy timezone)}-{appId}-{currency}-{4-digit sequence number}
Example: STL-20260101-6650f0c2a1b2c3d4e5f60718-KRW-0007

The sequence number increases per app and currency and is never reused. If you cancel a batch and create the same period again, a new number is issued.

Status

DRAFT ──verify──▶ VERIFIED ──approve──▶ APPROVED ──process payout──▶ PAID
  │                │  (re-verification mismatch → back to DRAFT)
  │                │                     │
  └────────────────┴──────── cancel ─────┴──▶ CANCELLED

CARRIED_FORWARD ── consumed as a carried-forward amount when the next batch is created (can be cancelled before it is consumed)
StatusMeaningExposed to merchants via REST
DRAFTCreated; not yet verified, or verification mismatchedNo
VERIFIEDPassed three-way reconciliationYes
APPROVEDApproved, awaiting payoutYes
PAIDPaid out (payoutRef and paidAt recorded). Cannot be changed afterwardsYes
CARRIED_FORWARDNet amount is negative or below the minimum payout → carried forward to the next batchYes
CANCELLEDCancelled. Transaction locks releasedNo

Every status change is recorded in the batch's history[] (time, actor, previous → new status, note) and in the audit log (audit_logs, with before and after values). If two people change the status at the same time, only one succeeds and the other receives 409.

Creation and transaction locking

Batch creation is processed in a single DB transaction.

  1. Calculate using the policy snapshot → 2. Issue the batch number → 3. Save the batch and lines → 4. Lock the target transactions and refunds with the batch ID → 5. Consume carried-forward batches

If the number of locked items differs from the number of items calculated (because another batch took the same transactions concurrently), everything is rolled back. As a result, the same transaction never ends up in two batches. Admins can also use a preview that shows the result without saving.

Verification (three-way reconciliation)

Verification recalculates the stored totals in three mutually independent ways and compares them.

AxisMethod
① Engine recalculationRebuild the input from only the transactions and refunds locked into this batch and run the calculation engine again
② DB aggregationCalculate the totals with a MongoDB aggregation, independently of the engine
③ Stored linesSum the stored settlement_lines (sum of line net + carry-forward = batch net)
ChecksumWhether the checksum from ① equals the stored checksum

If all items (count, gross, refund, fee, vat, adjustment, carriedIn, net) and the checksum match, the batch moves DRAFT → VERIFIED. If any item differs, the status remains DRAFT and a list of mismatches (verification.mismatches) is recorded. If a batch that is already VERIFIED is verified again and a mismatch is found, it reverts to DRAFT.

Batches created by the scheduler or in the console are verified automatically right after creation by default.

Checksum

A SHA-256 digest of the normalized contents of the entire batch. If a transaction amount or refund changes in the DB after the batch is created, the checksum differs on re-verification, so tampering or omissions can be detected.

sha256(
  "v2|{policyId}|{policyVersion}|{appId}|{currency}|{feeRateBps}|{fixedFeeMinor}|{vatRateBps}|{refundFeeRefundable?1:0}|{periodStart ISO}|{periodEnd ISO}\n"
  + for each line (sorted by kind|tid|refundId) "{kind}:{tid}:{refundId}:{gross}:{refund}:{fee}:{vat}:{net}\n"
  + "T:{count}:{gross}:{refund}:{fee}:{vat}:{carriedIn}:{net}"
)

Merchants can keep the checksum received via REST/CSV and later compare it with a newly received value to confirm that the batch has not changed.

Approval (four-eyes)

  • The person who created a batch cannot approve it. Another admin must approve it. Batches created by the scheduler (creator system:scheduler) can be approved by any admin.
  • Three-way reconciliation is run again right before approval. If there is a mismatch, the batch is not approved and 409 is returned with the mismatch details.
  • The approver and approval time (approvedBy, approvedAt) are recorded.

For single-operator environments, the server setting SETTLEMENT_ALLOW_SELF_APPROVAL=true allows self-approval, but do not use it in production.

Payout processing

After actually transferring an APPROVED batch, enter the payout reference number (such as the bank transfer transaction number; required) and the payout time to change it to PAID. PAID batches cannot be cancelled. Differences found after payout are handled as adjustments in the next batch.

Cancellation

  • DRAFT, VERIFIED, APPROVED, and CARRIED_FORWARD batches can be cancelled. A cancellation reason is required.
  • Cancelling reverts, in a single transaction, the transaction locks, the refund-applied markers, and any carry-forwards consumed by this batch, and deletes its lines. The reverted transactions become eligible for settlement again when the next batch is created.
  • A CARRIED_FORWARD batch that has already been consumed by a later batch cannot be cancelled. Cancel the batch that received the carry-forward first.

On this page