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
postureof the route isCLOSED. - 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.
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 answersREVIEW waits in FRAUD_ANALYSIS only when all of these hold:
ANTIFRAUD_OUT_REVIEW_HOLD_ENABLEDistrue. The default isfalse.- The
review_window_minutesof the flow is above0. - The Pix is a
TRANSFER, not a Saque or a Troco. - The deadline
decideByis still ahead.
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:
- The partner decides. The partner calls
POST /v1/transfers/{evaluation_key}/resolvewith its application token. Theevaluation_keyispix-out:and theendToEndId, the key that the partner evaluated. The body hasanalysisId,decision(ALLOWorDENY) and optionalreasons. A malformedreasonslist is dropped, and the decision still applies. The route ignoresX-Idempotency. - Your back office decides. A person with the
operatororeditorrole calls the same route, and adds ajustificationof 10 to 500 characters. The plugin does not publish it. - The payer cancels it.
POST /v1/transfers/{transfer_id}/canceltakesX-Account-IdandX-Idempotency. The plugin reverts the debit and closes the PixCANCELLED, with theCANCELLEDwebhook and the eventcashout.cancelled. A Pix Agendado that fired it endsFAILEDwithfailureReasonCASHOUT_CANCELLED. decideBypasses. The plugin reverts the debit and closes the PixREJECTEDwithfraudCheck.resolutionEXPIRED. TheREJECTEDwebhook andcashout.rejectedfollow. ThefailureReasonof the event isFRAUD_ANALYSIS_EXPIRED.
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 theintra_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 afeedbackEndpoint, 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 answersREVIEW is credited and held, instead of refused, when both of these are on:
ANTIFRAUD_IN_CAUTELAR_ENABLEDistrue. The default isfalse. It needs Midaz 4.1.0 or later withoverrides.allowFeeSkipandoverrides.allowTracerSkipon the ledger, andSCHEDULE_WORKER_ENABLED=trueon the schedule worker, because its tick releases the block at the deadline.antifraud.in.cautelar_enabledistruefor an external Pix, orantifraud.intra_in.cautelar_enabledistruefor an internal Pix. Both default tofalse.
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:
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 forhmac-v1. Anhmac-v1secret has at least 32 characters.certPemandkeyPem: an optional client certificate pair. Send both or neither.header.<Name>: an optional header that the plugin sends on each call.
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-Timestamphas the Unix time in seconds.X-Webhook-Signatureisv1,sha256=followed by the hex HMAC-SHA256 ofv1:<timestamp>.<raw body>with thesecret.lerian-m2mandoauth2-client-credentials: the plugin gets a token fromauth.tokenUrlwith theclientIdand thesecret. It sends the token as a bearer token.
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.
