Skip to main content
The Indirect Pix Plugin (BTG) can ask your institution’s own antifraud partner to screen a Pix before it sends the Pix to BTG or credits it. The partner answers ALLOW, REVIEW or DENY. Each check is off by default. You turn it on for your institution.

The four checks


Each check is a flow. A flow has its own settings, route and credentials. With intra_out and intra_in both on, the partner screens the same Pix twice, and a payee that intra_in denies never reaches intra_out. The plugin never screens a received return, MED returns included, an intra-PSP refund, or the payer side (out, intra_out) of a cash-out with X-Purpose INSTANT_PAYMENT_REFUND.

Sent Pix


With the out flow on, the plugin debits the account in Midaz, asks the partner, and only then sends the Pix to BTG. The partner has at most the syncBudgetMs of the route, which is 1500 ms or less. The question carries the metadata that you sent to POST /v1/transfers/cashout/process. The plugin reverts the debit and answers 201 with REJECTED in these cases:
  • The partner gives no valid decision, and the posture of the route is CLOSED.
  • The configuration of the flow is broken, under any posture. Examples are a missing route, a missing credential bundle, an empty ANTIFRAUD_SECRETS_BACKEND, and an address that the plugin does not call.
When the partner gives no valid decision and the posture is OPEN, the plugin sends the Pix without screening. The check shows origin FALLBACK and the cause. A CLOSED posture with an OPEN band that holds the amount behaves the same way. If Midaz does not answer the revert, the answer is 201 with PENDING. The Pix never reaches BTG, and POST /v1/transfers/{id}/unblock with allowNotFoundUnblock set to true, 150 seconds after its last change, reverses the debit and ends it FAILED with BTG_NOT_FOUND. Read the outcome from status and fraudCheck. The failureReason of the event cashout.rejected is FRAUD_DENIED for a refusal by the partner, and FRAUD_CHECK_UNAVAILABLE for the cases above. A screened Pix carries fraudCheck: the decision, its origin (PROVIDER or FALLBACK), the cause, the analysisId, the score and the reasons. The score and the reasons are the partner’s, as it sent them. The text of a reason can name a third party. fraudCheck is in the /process response, in GET /v1/transfers/{id}, in the transfer webhook and in the events cashout.processing and cashout.rejected. A Pix Agendado goes through the same check when its schedule fires. A refusal closes the schedule FAILED with failureReason FRAUD_REJECTED, and the plugin does not retry it.

Hold a sent Pix for review

A sent Pix that the partner answers REVIEW waits in FRAUD_ANALYSIS only when all of these hold:
  • ANTIFRAUD_OUT_REVIEW_HOLD_ENABLED is true. The default is false.
  • The review_window_minutes of the flow is above 0.
  • The Pix is a TRANSFER, not a Saque or a Troco.
  • The deadline decideBy is still ahead.
Run the schedule worker with SCHEDULE_WORKER_ENABLED=true before you turn the hold on. Without it, nothing cuts a Pix in analysis at decideBy, and its debit stays. The call answers 201 with FRAUD_ANALYSIS and fraudCheck.decideBy. The debit stays, and the plugin sends nothing to BTG. The plugin queues a FRAUD_ANALYSIS transfer webhook and publishes cashout.fraud_analysis, both in the same transaction as the status. Unblock answers 422 while the Pix is in analysis. decideBy is the creation time plus the shorter of two windows, less 3 minutes. The first is the Pix manual window: 30 minutes from 08:00 to 20:00 on a business day, and 60 minutes at any other time, in UTC-3. The second is the review window of the flow. A review window of 1 to 3 minutes gives a deadline that has already passed, and the plugin refuses that REVIEW. A Pix in FRAUD_ANALYSIS ends in one of these ways:
  1. The partner decides. The partner calls POST /v1/transfers/{evaluation_key}/resolve with its application token. The evaluation_key is pix-out: and the endToEndId, the key that the partner evaluated. The body has analysisId, decision (ALLOW or DENY) and optional reasons. A malformed reasons list is dropped, and the decision still applies. The route ignores X-Idempotency.
  2. Your back office decides. A person with the operator or editor role calls the same route, and adds a justification of 10 to 500 characters. The plugin does not publish it.
  3. The payer cancels it. POST /v1/transfers/{transfer_id}/cancel takes X-Account-Id and X-Idempotency. The plugin reverts the debit and closes the Pix CANCELLED, with the CANCELLED webhook and the event cashout.cancelled. A Pix Agendado that fired it ends FAILED with failureReason CASHOUT_CANCELLED.
  4. decideBy passes. The plugin reverts the debit and closes the Pix REJECTED with fraudCheck.resolution EXPIRED. The REJECTED webhook and cashout.rejected follow. The failureReason of the event is FRAUD_ANALYSIS_EXPIRED.
On ALLOW, the plugin sends the Pix to BTG as a payment of type FRAUD, and the status goes back to PENDING, then PROCESSING. On DENY, it reverts the debit and closes the Pix REJECTED, and the failureReason of cashout.rejected is FRAUD_DENIED. fraudCheck.resolvedBy is PARTNER, OPERATOR or PAYER. The first decision that records its resolution wins. The same decision again answers 200 with the current transfer and moves no money. The route needs the transfers permission with the action decide. The operator and editor roles hold it. The cancel needs the transfers permission with the action post.

Internal Pix between accounts of your institution

With the intra_out flow on, the plugin asks the partner after it validates the payee and prepares the credit, and before it posts. A payee that intra_in denied never reaches the partner. When intra_in put the payee under a block, any answer other than ALLOW refuses the transfer. If Midaz refuses the hold, the answer is 422 with PIX-0600 when the balance is short, and the cash-out is FAILED with MIDAZ_HOLD_FAILED. The same /resolve, cancel and cut decide it. On ALLOW, the plugin commits the hold and completes the transfer. The cash-out is COMPLETED, or PENDING until POST /v1/transfers/{transfer_id}/unblock finishes it, or FAILED with MIDAZ_COMMIT_FAILED when Midaz refuses the commit. On DENY, a cancel or the cut, the plugin cancels the hold. Nothing was debited, so there is nothing to reverse.

The outcome of each sent Pix

When the route of a sent flow has a feedbackEndpoint, the plugin reports how each screened Pix ended. A route with no feedbackEndpoint sends nothing. The Idempotency-Key is pix-out:, the endToEndId, a colon and the outcome. A Pix that the sent flow never screened sends no report, and neither does an intra-PSP Pix that intra_in refused. A partner that is down is retried every 5 minutes for 24 hours. A permanent refusal, such as a 4xx, is not retried. The partner must apply each outcome once.

Received Pix


With the in flow on, the plugin asks the partner when BTG asks it to approve a received Pix. With intra_in on, it asks before the single Midaz transaction of an internal Pix. The plugin checks the destination account first, and a Pix that the account check refuses does not reach the partner. The partner has at most the syncBudgetMs of the route, which is 1000 ms or less. The plugin makes one attempt and does not retry. A refused Pix is never stored or credited. An intra-PSP Pix that intra_in refuses rejects the cash-out with no debit. The answer to a received Pix stays on the cash-in as fraudCheck. For the external flow, Get an inbound webhook shows the audit keys in payload.metadata: antifraudDecision, antifraudOrigin, antifraudCause, antifraudAnalysisId, antifraudScore, antifraudReasons and antifraudLatencyMs. They are absent when the flow is off or the credit is a MED return. The event cashin.received carries fraudCheck. The event cashin.denied announces a refusal of a received Pix, external or intra-PSP.

Credit a received Pix under a block

A received Pix that the partner answers REVIEW is credited and held, instead of refused, when both of these are on:
  • ANTIFRAUD_IN_CAUTELAR_ENABLED is true. The default is false. It needs Midaz 4.1.0 or later with overrides.allowFeeSkip and overrides.allowTracerSkip on the ledger, and SCHEDULE_WORKER_ENABLED=true on the schedule worker, because its tick releases the block at the deadline.
  • antifraud.in.cautelar_enabled is true for an external Pix, or antifraud.intra_in.cautelar_enabled is true for an internal Pix. Both default to false.
The block holds through the refund operation routes: MIDAZ_CASHOUT_REFUND_*, which fall back to MIDAZ_CASHOUT_*. With accounting.validateRoutes on in Midaz, give those routes the entries for the hold, its commit and its cancel. The plugin credits the Pix and places a pending hold of the holder’s net amount in one Midaz batch. For an internal Pix, one batch posts the payer debit, the payee credit and the hold. The block lasts until the approval time plus 72 hours, less 15 minutes (block.expiresAt). The block webhooks and events carry its status in block.status: The events are cashin.blocked, cashin.block_released, with releaseReason ALLOW, EXPIRED or RETURNED, and cashin.block_fraud_confirmed. Each event has a webhook to your endpoint. The three arrive as TRANSFER / CASHIN, with a block object (blockId, amount, status, blockedAt, expiresAt). Tell them apart by block.status, by fraudCheck.resolution (DENY after a refusal) and by releaseReason, which only the release carries. The partner and a person with the transfers permission and the action decide decide the block on POST /v1/transfers/pix-cashin:{endToEndId}/resolve. It takes the same body and authorization as the sent Pix route, and answers with the cash-in. A person’s ALLOW after the partner’s DENY releases the block, with a justification, and keeps the DENY on the record. The plugin does nothing else on a DENY. When the deadline passes, the schedule worker releases the block. The partner gets one report per block, on the feedbackEndpoint of the in route, or of the intra_in route for an internal Pix: SETTLED when someone decided a release, and when the plugin could hold nothing (UNPLACED), EXPIRED when the deadline ended it, and RETURNED for a completed return. A DENY reports nothing. A return of a BLOCKED cash-in through POST /v1/transfers/{id}/refunds takes one amount: the held amount when the hold is below the net amount, otherwise the whole received amount. It takes no operations split, no description and no reason SL02, and one return at a time. It is refused while a release is due. Any other request answers 409 PIX-0440. POST /v1/transfers/{id}/unblock on a cash-in whose block is due but not recorded answers 503 PIX-0016 for up to 130 minutes past the deadline.

Turn a check on


In BYOC, write the settings in the systemplane namespace plugin-br-pix-indirect-btg.policy, with PUT /v1/system/plugin-br-pix-indirect-btg.policy/{key}. The editor role writes them, and every role reads them. The settings API needs PLUGIN_AUTH_ENABLED=true: with authentication off, every call to /v1/system answers 403, and no check can be turned on. The body is {"value": <the setting>}. See systemplane. The plugin reads them on every call, so a change applies without a restart. For each flow: The route holds these fields:
In BYOC, the plugin calls an endpoint, feedbackEndpoint or tokenUrl only when it is https on a public address, unless its host is in ANTIFRAUD_ALLOWED_PRIVATE_HOSTS. When you write a route that does not meet this rule, the plugin refuses it. See the environment variables. In BYOC, the plugin reads a credential bundle from the secret manager that ANTIFRAUD_SECRETS_BACKEND names. The path is tenants/{env}/single-tenant/plugin-br-pix-indirect-btg/external/antifraud-<flow>/credentials. {env} is the value of ENV_NAME, in lower case and with no spaces. With ENV_NAME empty, the path has no {env}/ segment. <flow> is out, intra-out, in or intra-in. The bundle is a JSON object of strings:
  • secret: the client secret, or the HMAC secret for hmac-v1. An hmac-v1 secret has at least 32 characters.
  • certPem and keyPem: an optional client certificate pair. Send both or neither.
  • header.<Name>: an optional header that the plugin sends on each call.
Any other key makes the bundle invalid, and the flow then denies every Pix. In BYOC, the plugin caches a bundle for 30 seconds. Rotate a secret by overwriting the bundle, and keep the partner accepting the old secret for at least 30 seconds after. Deleting and recreating a bundle denies every Pix of the flow while it is missing.

What the partner implements


For the full contract the partner implements, see Antifraud partner contract. The plugin sends each evaluation as a POST of a JSON body to the endpoint of the route. The headers are: Each body has flow (EXTERNAL or INTRA), amount, currency (BRL), payer and payee. It also has endToEndId, initiationType, transactionType, description and txId when they exist. pix-out.v1 adds transferId, createdAt and the metadata of the Pix. pix-cashin.v1 always has endToEndId. Each party has name, taxId (the CPF or CNPJ), ispb, branch, account and accountType, and accountId when the party has an account in your ledger. The payee also has key when the Pix used one. The plugin signs each call with the auth.mode of the route:
  • hmac-v1: X-Webhook-Timestamp has the Unix time in seconds. X-Webhook-Signature is v1,sha256= followed by the hex HMAC-SHA256 of v1:<timestamp>.<raw body> with the secret.
  • lerian-m2m and oauth2-client-credentials: the plugin gets a token from auth.tokenUrl with the clientId and the secret. It sends the token as a bearer token.
The partner answers 200 with a JSON body: A 202 counts as REVIEW, and it needs an analysisId, unless the body says DENY. Any other status, or a REVIEW with no valid analysisId, is not a decision: the posture of the route decides. The partner decides a held Pix or block later with the resolve call described above. The outcome report is a POST to feedbackEndpoint, signed the same way, with evaluationKey, analysisId, decisionOrigin, outcome and occurredAt. Answer 2xx. A 408, 429 or 5xx is retried, and any other status is final. The plugin also sends an unsigned HEAD to the endpoint of each enabled flow every 25 seconds, and ignores the answer.