Skip to main content
The Pix Indirect Plugin (BTG) processes Pix refunds (devoluções) through the Refund a Received Pix Transfer endpoint. Two capabilities extend that flow for MED and fraud scenarios:
  • Distributed partial refunds — return a refund from multiple internal accounts in a single operation
  • Unblock — recover a refund or transfer that is stuck in PROCESSING

Distributed partial refunds


A received Pix can split internally across several accounts. For example, the principal amount goes to the customer account and a fee goes to a fee account. A later MED or fraud refund can then debit part of the amount from each account. The standard refund flow debits one account. To split the debit, send an optional operations array in the request body. The operations array is the only signal — there is no new endpoint, environment variable, or feature flag.

Request


  • Without operations → the current single-account flow runs unchanged.
  • With operations → the plugin debits each accountAlias for its amount in Midaz, and BTG receives a single pacs.004 for the total refund value.

Validation rules


The endpoint, BTG flow (pacs.004 with the total value), idempotency, and authentication match the standard refund. Only the internal Midaz debit composition changes.

Example — Cappta


The plugin split a R50,000.00cashin:R 50,000.00 cash-in: R 49,000.00 to the customer account and R1,000.00toafeeaccount.Afterfraud,therefundmustbeR 1,000.00 to a fee account. After fraud, the refund must be R 1,000.82. Only R0.82remainsinthecustomeraccount.TheoperationsarraydebitsR 0.82 remains in the customer account. The `operations` array debits R 0.82 from the customer account and R1,000.00fromthefeeaccount.BTGreceivesasingleR 1,000.00 from the fee account. BTG receives a single R 1,000.82 refund with no manual ledger consolidation.

Unblocking stuck operations


A reversal call to BTG can time out before BTG confirms it. The refund or transfer then stays stuck in PROCESSING, and Midaz still holds the funds. Two endpoints re-query BTG and drive the operation to its terminal state. Both require the X-Account-Id header.

How unblock works


The plugin re-queries the reversal or transfer status at BTG and:
  • If BTG reports CONFIRMED or ERROR → dispatches the corresponding settlement and moves the operation to its terminal state.
  • If BTG still reports INITIATED/PROCESSING → returns HTTP 200 with no action — retry later.
A consistency guard aborts the operation if BTG’s entity, returnIdentification, or originalEndToEndId diverge from the local record. This prevents settlement against the wrong transaction.
The response includes the updated refund, a message, and the btgStatus.

Handling a 404 from BTG


BTG can return 404 when it no longer has the reversal or transfer. The result then depends on the operation type and the opt-in allowNotFoundUnblock flag in the request body.
allowNotFoundUnblock defaults to false. An empty or absent body, or false, preserves the strict behavior. A BTG 404 then returns an error and never reverts the hold. Opt in only when you have confirmed that the operation must be released.
The opt-in 404 recovery applies only to CASHOUT operations in PENDING/PROCESSING with a non-empty endToEndId. Cash-ins and terminal statuses never enter this branch.

Intra-PSP limitation


The transfer unblock flow resolves state by querying BTG. It does not apply to intra-PSP (internal) transfers, which have no BTG transaction. See Intra-PSP transfers.

Next steps