---
id: TST-ACC-TRX-080
title: Payment reversals suite
kind: integration
product_area: accounting
module: transactions
revision: 1
status: draft
source_sha:
  services-accounting: f47cb263875bbc0c5640fba7dae6785ec32695f8
repository: services-accounting
files:
  - >-
    modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js
implements:
  - ATS-ACC-TRX-007-09
  - ATS-ACC-TRX-013-02
  - ATS-ACC-TRX-013-03
  - ATS-ACC-TRX-013-04
  - ATS-ACC-TRX-013-05
  - ATS-ACC-TRX-013-07
  - ATS-ACC-TRX-013-08
implements_parts:
  - scenario: ATS-ACC-TRX-007-09
    assertion: >-
      it refuses settling a payment not awaiting settlement
      (payment_not_pending_settlement)
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      refuses settling a payment not awaiting settlement
      (payment_not_pending_settlement)
  - scenario: ATS-ACC-TRX-013-02
    assertion: >-
      it refuses a kind the method does not allow (reversal_kind_mismatch): an
      ACH return of a check, a bounced check of a card
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      refuses a kind the method does not allow (reversal_kind_mismatch): an ACH
      return of a check, a bounced check of a card
  - scenario: ATS-ACC-TRX-013-03
    assertion: >-
      it completes the reversal at once for the whole 5000, numbered from
      1,000,000, and the payment is returned with 5000 reversed
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      completes the reversal at once for the whole 5000, numbered from
      1,000,000, and the payment is returned with 5000 reversed
  - scenario: ATS-ACC-TRX-013-03
    assertion: >-
      it reverses the live allocation so the line owes again, and the payment
      item’s facts sum to zero (FC-16)
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      reverses the live allocation so the line owes again, and the payment
      item’s facts sum to zero (FC-16)
  - scenario: ATS-ACC-TRX-013-03
    assertion: >-
      it refuses reversing it again (payment_not_live) and replays the same key
      as the same reversal
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      refuses reversing it again (payment_not_live) and replays the same key as
      the same reversal
  - scenario: ATS-ACC-TRX-013-04
    assertion: >-
      it refuses a payment with a credit made from it that is not void
      (payment_has_credit)
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      refuses a payment with a credit made from it that is not void
      (payment_has_credit)
  - scenario: ATS-ACC-TRX-013-05
    assertion: >-
      it completes with the dummy’s reference: the payment voided, 2000
      reversed, its allocation reversed
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      completes with the dummy’s reference: the payment voided, 2000 reversed,
      its allocation reversed
  - scenario: ATS-ACC-TRX-013-05
    assertion: >-
      it records the void’s settlement item beside the capture: kind void, minus
      2000
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      records the void’s settlement item beside the capture: kind void, minus
      2000
  - scenario: ATS-ACC-TRX-013-05
    assertion: >-
      it fails a void the processor says is already settled (payment_settled):
      the reversal failed, the payment untouched
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      fails a void the processor says is already settled (payment_settled): the
      reversal failed, the payment untouched
  - scenario: ATS-ACC-TRX-013-07
    assertion: >-
      it opens an inquiry for the payment’s whole amount, numbered from
      1,000,000, and closing it won leaves the payment as it was
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      opens an inquiry for the payment’s whole amount, numbered from 1,000,000,
      and closing it won leaves the payment as it was
  - scenario: ATS-ACC-TRX-013-07
    assertion: >-
      it refuses closing a closed dispute (dispute_not_open), a dispute of a
      check (reversal_kind_mismatch) and an amount beyond the payment
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      refuses closing a closed dispute (dispute_not_open), a dispute of a check
      (reversal_kind_mismatch) and an amount beyond the payment
  - scenario: ATS-ACC-TRX-013-08
    assertion: >-
      it closes a chargeback lost by reversing the payment as a chargeback:
      charged_back, the item keyed dispute:<id>:withdrawn
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js#it
      closes a chargeback lost by reversing the payment as a chargeback:
      charged_back, the item keyed dispute:<id>:withdrawn
environment: local
implementation_state: implemented
latest_result: not-run
latest_run_at: null
latest_run_ref: null
conformance: not-verified
estimated_minutes: 3
isolation: >-
  Suite-marked records in the prepared local test database; fixture teardown
  removes owned records.
provenance: test
source: >-
  services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js
evidence:
  - provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/payments/payment-reversals.integration.spec.js
    assertion_titles:
      - payment_has_credit
      - 'payment reversals, disputes and clearings (integration)'
      - a check recorded as bounced
      - >-
        completes the reversal at once for the whole 5000, numbered from
        1,000,000, and the payment is returned with 5000 reversed
      - >-
        reverses the live allocation so the line owes again, and the payment
        item’s facts sum to zero (FC-16)
      - >-
        records the reversal row, the reverse document events and the reversed
        payment event
      - >-
        refuses reversing it again (payment_not_live) and replays the same key
        as the same reversal
      - a card voided through the processor
      - >-
        completes with the dummy’s reference: the payment voided, 2000 reversed,
        its allocation reversed
      - >-
        records the void’s settlement item beside the capture: kind void, minus
        2000
      - >-
        fails a void the processor says is already settled (payment_settled):
        the reversal failed, the payment untouched
      - what cannot be reversed
      - >-
        refuses a kind the method does not allow (reversal_kind_mismatch): an
        ACH return of a check, a bounced check of a card
      - >-
        refuses a payment with a credit made from it that is not void
        (payment_has_credit)
      - disputes
      - >-
        opens an inquiry for the payment’s whole amount, numbered from
        1,000,000, and closing it won leaves the payment as it was
      - >-
        closes a chargeback lost by reversing the payment as a chargeback:
        charged_back, the item keyed dispute:<id>:withdrawn
      - >-
        refuses closing a closed dispute (dispute_not_open), a dispute of a
        check (reversal_kind_mismatch) and an amount beyond the payment
      - the clearing of electronic checks
      - >-
        tendered both pending_settlement, their capture items not yet eligible
        (premise)
      - >-
        settles the one the bank cleared: succeeded, settled_at, its capture
        item eligible, the settle event
      - >-
        reverses the one the bank returned as an ACH return: returned, its
        allocation reversed, the line owing again
      - >-
        refuses settling a payment not awaiting settlement
        (payment_not_pending_settlement)
    imports:
      - 'const { sql } = require(''drizzle-orm'');'
      - >-
        const { manualClock } =
        require('@rhythmsoftware/macroservice-time/clock');
      - 'const { stage } = require(''@rhythmsoftware/macroservice-testing/stage'');'
      - >-
        const { TEST_NOW } =
        require('@rhythmsoftware/macroservice-testing/execution-context');
      - >-
        const { createCredit } =
        require('../../../../services/credits/credit-commands');
      - >-
        const { sweepProcessingIntents } =
        require('../../../../services/payments/intent-sweeper');
      - >-
        const { receivePayment } =
        require('../../../../services/payments/payment-receive');
      - >-
        const { closeDispute, markPaymentSettled, openDispute, reversePayment }
        = require('../../../../services/payments/payment-reverse');
      - '} = require(''../../payments-fixtures'');'
      - "\t\t\tconst { invoice } = world.require();"
      - "\t\t\tconst { check, outcome } = bounced.require();"
      - "\t\t\tconst { invoice } = world.require();"
      - "\t\t\tconst { check } = bounced.require();"
      - "\t\t\tconst { check } = bounced.require();"
      - "\t\t\tconst { check, outcome } = bounced.require();"
      - "\t\t\tconst { invoice } = world.require();"
      - "\t\t\tconst { card, outcome } = voided.require();"
      - "\t\t\tconst { card } = voided.require();"
      - "\t\t\tconst { first, inquiry, won } = disputed.require();"
      - "\t\t\tconst { second, chargeback, lost } = disputed.require();"
      - "\t\t\tconst { inquiry } = disputed.require();"
      - "\t\t\t\tconst { invoice } = world.require();"
      - "\t\t\tconst { clears, returns } = clearing.require();"
      - "\t\t\tconst { clears, swept } = clearing.require();"
      - "\t\t\tconst { invoice } = world.require();"
      - "\t\t\tconst { returns, swept } = clearing.require();"
      - "\t\t\tconst { clears } = clearing.require();"
    test_double_declarations: []
---

# Payment reversals suite

## Verification Boundary

The suite exercises transaction commands and database protections in the local prepared test environment. Registration records the existing executable file; it does not report a run or establish product approval.

## What This Suite Proves

Its cited assertions contribute evidence for bank clearing finishes pending receipts; reversal type follows instrument behavior; returned check restores debt exactly once; source credit blocks payment void; processor settlement determines void eligibility; dispute lifecycle permits one conclusion; lost inquiry differs from lost chargeback. The structured assertion bindings identify which parts of combined scenarios it executes.

## What It Does Not Prove

Local commands and route invocations do not establish deployed routing, live processor guarantees or the complete staff browser experience. An unbound feature chain remains proposed, and this registration carries no execution result.

## Real Dependencies and Test Doubles

The suite uses the imported commands, route handlers or persistence code against the local test database. Fixture helpers supply accounting context; any stepped clock, dummy processor or substituted external client is retained in the evidence declarations.

## Must Not Be Doubled

The command or persistence behavior under assertion and its relevant database protections must remain real. Substituting the final financial result removes evidence of transactional effects.
