> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Pix JD antifraud partner check

> How Pix JD asks your institution's antifraud partner to screen sent and received Pix, how you turn each check on, and what the partner must implement.

Pix JD can ask your institution's own antifraud partner to screen a Pix before it moves money. The partner answers `ALLOW`, `REVIEW` or `DENY`. Each check is off by default. You turn it on for your tenant.

## The four checks

***

Each check is a flow. A flow has its own switch, route and credentials.

| Flow | What the partner screens |
| - | - |
| `out` | A Pix that your institution sends over SPI, from a direct or an indirect order. |
| `intra_out` | A Pix that your institution sends to a payee at the same ISPB: an internal transfer, on one ledger or between two, or a transfer to the other core of your institution. |
| `in` | A Pix that your institution receives from a payer at another institution. |
| `intra_in` | A Pix that the other core of your institution sends to your ledger through JD Courier. |

The `out` flow does not screen internal transfers, and the `intra_out` flow does not screen Pix over SPI. A devolução that you send is not screened.

## Sent Pix

***

With the `out` flow on, Pix JD holds the amount on the payer's account, then asks the partner, and only then sends the order to JD. With the `intra_out` flow on, an internal transfer also waits for the partner: nothing reaches the payee before the answer. The partner has at most the `syncBudgetMs` of the route, which is 1500 ms or less.

| Answer | Result |
| - | - |
| `ALLOW` | Pix JD sends the Pix. |
| `DENY` or `REVIEW` | [Create transaction](https://docs.lerian.studio/en/reference/interfaces/pix-jd/create-transaction.md) answers `422` with `PIX-0163`. Pix JD releases the hold, if it took one, and JD receives nothing. |

A `REVIEW` refuses the Pix like a `DENY`.

Pix JD also answers `422` with `PIX-0163` 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`, an `hmac-v1` secret with fewer than 32 characters, and an address that Pix JD does not call.

When the partner gives no valid decision and the posture is `OPEN`, Pix JD sends the Pix without screening. The check shows `origin` `FALLBACK` and the `cause`. When the secret manager does not answer, the posture of the route applies too.

A refused Pix leaves a transaction with `fraudCheck` and the status `ERROR`. It does not count against the period limit. When the ledger does not confirm the release of the hold, the transaction stays `PENDING` until the worker proves the release. Read it with [Retrieve transaction status](https://docs.lerian.studio/en/reference/interfaces/pix-jd/retrieve-transaction-status.md).

A resend under the same `X-Idempotency` key answers `409` with `PIX-0133`, and the partner is not asked again. When Pix JD cannot read the switch or the route of the flow, the call answers a server error and nothing is held.

The transaction of a screened Pix carries `fraudCheck`: read it with [Retrieve transaction status](https://docs.lerian.studio/en/reference/interfaces/pix-jd/retrieve-transaction-status.md). It holds 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. The text of a reason can name a third party. The `transaction.*` events carry `fraudCheck` too. See [Pix Direct via JD events](https://docs.lerian.studio/en/reference/events/pix-direct-jd.md).

## Received Pix

***

With the `in` flow on, Pix JD asks the partner when JD validates the account of a received Pix, in the synchronous validation and in the asynchronous one. The partner has at most the `syncBudgetMs` of the route, which is 1000 ms or less.

Pix JD asks the partner last. A Pix that the account checks or your [Tracer](https://docs.lerian.studio/en/interfaces/pix-jd/pix-jd-environment-variables.md#inbound-credit-screening) refuse does not reach the partner. These Pix never reach it either: a devolução, a credit to a customer of an indirect participant, and a Pix from a Bacen payer.

| Answer | Result |
| - | - |
| `ALLOW` | Pix JD answers JD that the account is valid. |
| `DENY` or `REVIEW` | Pix JD answers JD that the account is invalid, with the reason `FRAD`. |
| `DENY` or `REVIEW` with the partner reason `AG01` | Pix JD answers JD that the account is invalid, with the reason `DS04`. |
| No valid answer, posture `OPEN` | Pix JD answers JD that the account is valid, without screening. |
| No valid answer, posture `CLOSED` | Pix JD answers JD that the account is invalid, with the reason `DS04`. |

A broken configuration refuses the Pix with `DS04`, under any posture. The causes are the same as for a sent Pix. A validation with no `endToEndId` is refused with `DS04` too. When the secret manager does not answer, the posture of the route applies. When Pix JD cannot read the switch or the route, the validation fails with an error and gives no verdict.

Pix JD stores the answer of the partner by `endToEndId`. When the credit lands, its transaction carries it as `fraudCheck`. The event `cashin.denied` announces each received Pix that account validation refused, and carries the answer too. See [Pix Direct via JD events](https://docs.lerian.studio/en/reference/events/pix-direct-jd.md).

With the `intra_in` flow on, Pix JD asks the partner before it books a credit that the other core of your institution relays through JD Courier. A refusal answers `422` with `PIX-0163`, and Pix JD books nothing.

## The outcome of each Pix

***

When the route of a flow has a `feedbackEndpoint`, Pix JD reports how each screened Pix ended. This works for all four flows. A worker sends the report. It sends it for up to 24 hours after the Pix ended.

* For `out` and `intra_out`, the key is `pix-out:<transactionId>`.
* For `in` and `intra_in`, the key is `pix-cashin:<endToEndId>`.

The body has `evaluationKey` (the key), `analysisId`, `decisionOrigin` (`PROVIDER` or `FALLBACK`), `outcome` and `occurredAt`. `outcome` is `SETTLED` or `REJECTED`. A received Pix that Pix JD refused is `REJECTED`, unless its credit landed later: the credit then reports its own outcome under the same key.

The `Idempotency-Key` is the key, a colon and the outcome. The partner must apply each outcome once. Pix JD sends a report again after a `5xx`, `408`, `429` or network failure. It never sends again a report that the partner refuses with another `4xx`.

## Turn a check on

***

Write the settings in the Pix JD runtime configuration, namespace `tenant_policy`, with the [Systemplane](https://docs.lerian.studio/en/reference/platform/systemplane/overview.md) admin API. The **Plugin PIX JD Editor** group writes them. For each flow:

| Key | Meaning |
| - | - |
| `antifraud.<flow>.enabled` | Turns the check on. The default is off. |
| `antifraud.<flow>.route` | The partner route, as one JSON object. `{}` means not set. Pix JD checks the route when you write it. |

The route holds these fields:

| Field | Meaning |
| - | - |
| `endpoint` | The address that receives the evaluation. |
| `feedbackEndpoint` | Optional. The address that receives the outcome of each screened Pix. |
| `auth` | `mode` (`hmac-v1`, `lerian-m2m` or `oauth2-client-credentials`). The two token modes also need `tokenUrl` and `clientId`. `oauth2-client-credentials` accepts `scopes`. Optional `staticHeaders` apply to every mode. |
| `syncBudgetMs` | The longest wait for one evaluation, retries included. From 100 to 1500 for `out` and `intra_out`. From 100 to 1000 for `in` and `intra_in`. |
| `attemptTimeoutMs` | The time limit of one attempt. It cannot be more than `syncBudgetMs`. |
| `maxAttempts` | The number of attempts, 1 or more. For `in` and `intra_in`, it must be exactly 1. |
| `posture` | `default` (`OPEN` or `CLOSED`) is required. Optional `bands` list an `upTo` amount and a `posture` each, in ascending order of `upTo`. The first band that covers the amount decides. |

```json theme={null}
{
  "endpoint": "https://antifraud.example.com/evaluate",
  "auth": { "mode": "hmac-v1" },
  "syncBudgetMs": 800,
  "attemptTimeoutMs": 800,
  "maxAttempts": 1,
  "posture": { "default": "CLOSED" }
}
```

In BYOC, Pix JD 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, Pix JD refuses it. See the [environment variables](https://docs.lerian.studio/en/interfaces/pix-jd/pix-jd-environment-variables.md#antifraud-partner).

In BYOC, Pix JD reads a credential bundle from the secret manager that `ANTIFRAUD_SECRETS_BACKEND` names. The path is `tenants/{env}/single-tenant/plugin-br-pix-jd/external/antifraud-<flow>/credentials`. `{env}` is the value of `ENVIRONMENT_NAME`, or of `ENV_NAME` when `ENVIRONMENT_NAME` is not set: `development`, `staging` or `production`. `<flow>` is `out`, `intra-out`, `intra-in` or `in`. The bundle accepts these keys:

* `secret`: the client secret, or the HMAC secret for `hmac-v1`. It is required for every auth mode. 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 Pix JD sends on each call.

## What the partner receives

***

With a flow on, Pix JD sends the partner the data it holds of the parties: the name, the CPF or CNPJ, the person type, the ISPB, the branch and the account. The payee of a received Pix carries no name. It also sends the amount, the `endToEndId`, the initiation type, the QR code `txId` when there is one, and the payee's Pix key. A sent Pix, and a Pix from the other core, also carry the description. A sent Pix also carries the account type and the `metadata` of the order. A manually typed order goes to the partner without an `endToEndId`.

## What the partner implements

***

For the full contract the partner implements, see [Antifraud partner contract](https://docs.lerian.studio/en/reference/antifraud-partner-contract.md).

Pix JD sends each evaluation as a `POST` of a JSON body to the `endpoint` of the route. The headers are:

| Header | Value |
| - | - |
| `Idempotency-Key` | The key of the evaluation: `pix-out:<transactionId>` for a sent Pix, and `pix-cashin:<endToEndId>` for a received Pix. The same key returns the same analysis. |
| `X-Lerian-Decide-By` | The deadline of the decision, in RFC 3339 UTC. |
| `X-Lerian-Payload-Schema` | `pix-out.v1` for a sent Pix. `pix-cashin.v1` for a received Pix. |

A sent Pix body has `transferId`, `endToEndId`, `flow` (`EXTERNAL` or `INTRA`), `initiationType`, `transactionType`, `amount`, `currency` (`BRL`), `description`, `txId`, `payer`, `payee`, `createdAt` and `metadata`. A received Pix body has `endToEndId`, `flow`, `initiationType`, `amount`, `currency`, `payer` and `payee`, plus `txId` on a Pix from another institution and `description` on a Pix from the other core. A field with no value is left out. Each party has `name`, `taxId`, `personType`, `ispb`, `branch`, `account`, `accountType` and `key`. The payer of a sent Pix, the payee of an internal transfer and the payee of a received Pix carry `accountId`.

Pix JD 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`: Pix JD 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:

| Field | Meaning |
| - | - |
| `decision` | `ALLOW`, `REVIEW` or `DENY`, in upper case. |
| `analysisId` | 1 to 64 printable ASCII characters, with no space. Required with `REVIEW`. |
| `score`, `reasons` | Optional. Pix JD does not decide by them. With `DENY` or `REVIEW`, the reason `AG01` makes Pix JD refuse a received Pix with `DS04` instead of `FRAD`. |

A `202` counts as `REVIEW`, and it needs an `analysisId`, unless the body says `DENY`. Any status other than `200` or `202`, or a `REVIEW` with no valid `analysisId`, is not a decision. Pix JD then applies the `posture` of the route.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.