> ## 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.

# TED JD antifraud partner check

> How TED JD asks your institution's antifraud partner to screen sent TEDs, internal transfers, cross-core transfers and received TEDs, who decides a held transfer, and what the partner implements.

TED JD can ask your institution's own antifraud partner to screen a transfer before money moves. 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.

| Flow | What the partner screens |
| - | - |
| `out` | A TED OUT that your institution sends. |
| `intra_out` | A P2P transfer from the payer side, and a cross-core TED that you send. |
| `intra_in` | A P2P transfer from the recipient side, and a cross-core credit that another core of your institution sends to you. |
| `in` | A TED that your institution receives from the STR. |

A P2P transfer with both internal flows on goes to the partner twice: the payer side first, then the recipient side. The recipient side has its own evaluation key, the `transferId` followed by `.in`. TED JD stops at the first refusal. It never screens the refund leg of a returned TED, and it never screens a return.

## Sent TEDs, cross-core TEDs and P2P

***

TED JD asks the partner when you confirm the transfer with `POST /v1/transfers/process`, before it sends anything. For a TED OUT and a cross-core TED, it asks after it holds the amount and reserves the usage limit. For a P2P transfer, it asks before it posts in Midaz. The partner has at most the `syncBudgetMs` of the route, which is 4000 ms or less. For a TED OUT, [Send (TED OUT)](https://docs.lerian.studio/en/interfaces/ted-jd/ted-out.md#antifraud-check) describes the answers in full. Cross-core TEDs and P2P follow the same rules.

| Answer | Result |
| - | - |
| `ALLOW` | A TED OUT goes to JD. A cross-core TED goes to the other core. A P2P transfer posts in Midaz once every side is allowed. |
| `DENY` | `/process` answers `422` with `BTF-0126`. The transfer is `REJECTED`, and TED JD releases the hold and the usage limit. A P2P transfer that the partner denies before TED JD holds the amount posts nothing and has no hold to release. |
| `REVIEW` | The transfer waits in `FRAUD_ANALYSIS`, and `/process` answers `200` with `decideBy`. TED JD keeps the hold and the usage limit, sends nothing, and sends the event `transfer.fraud_analysis`. |

For a P2P transfer, TED JD posts nothing to the ledger while a `REVIEW` waits. The amount of the payer and the fee stay in hold in Midaz, in one transaction, or in one group when the transfer crosses two ledgers. An `ALLOW` on the payer side can open the analysis of the recipient side. The call then answers `FRAUD_ANALYSIS` again, with a new `analysisId`, and TED JD sends `transfer.fraud_analysis` again.

When the partner cannot answer, the `posture` of the route decides. `OPEN` lets the transfer go on, and `fraudCheck` shows the `origin` `FALLBACK` and the `cause`. `CLOSED` rejects it like a `DENY`. TED JD rejects the transfer with `BTF-0126`, under any posture, when the route is not set, when the credential bundle is missing, or when `ANTIFRAUD_SECRETS_BACKEND` is empty. If TED JD cannot read whether a check is on, `/process` answers `503` with `BTF-0125` before it holds anything.

`decideBy` follows the rule of a TED OUT: the earliest of the confirmation plus 30 minutes, the confirmation plus the review window of the tenant, and `expiresAt` of the initiation, less 7 minutes and 30 seconds. The close of the operating window counts only for a transfer that has one, so a P2P transfer and a cross-core TED ignore it. With flows on at both sides of a P2P transfer, the shortest review window applies.

A transfer in `FRAUD_ANALYSIS` ends in one of these ways:

1. **The partner decides** on the [decision route](#decide-a-held-transfer). On `DENY`, TED JD rejects the transfer. On `ALLOW`, it sends the TED OUT, sends the cross-core credit, or commits the P2P hold.
2. **Your back office decides** on the same route, and adds a justification. On a P2P transfer, an `ALLOW` of your back office decides the whole transfer, and TED JD does not ask the partner about the other side.
3. **You cancel it.** See [Cancel a transfer](https://docs.lerian.studio/en/interfaces/ted-jd/ted-out.md#cancel-a-transfer). TED JD releases the hold and the usage limit.
4. **`decideBy` passes.** TED JD rejects the transfer, and releases the hold and the usage limit. `transfer.rejected` carries `failureCode` `BTF-0127`.

## Received TEDs

***

With the `in` flow on, TED JD asks the partner before it credits a TED that it received from the STR. The partner has at most the `syncBudgetMs` of the route, which is 4000 ms or less. This flow takes no `posture`, and TED JD refuses a route that carries one.

| Answer | Result |
| - | - |
| `ALLOW` | TED JD credits the recipient. `transfer_incoming.completed` carries `fraudCheck`. |
| `DENY` | TED JD returns the TED to the paying bank with an STR0010 of code 9. |
| `REVIEW` | TED JD credits nothing and returns nothing. The TED waits until `decideBy` for the partner. |
| No valid answer | The TED waits for a person of your institution. `fraudCheck` shows the `origin` `FALLBACK` and the `cause`. |

The credit window is 60 minutes from the settlement of the TED, or from receipt when the TED carries no settlement time (Res. BCB 256, art. 8). `decideBy` is that deadline less 15 minutes.

A held TED shows in the queue of retained messages. Read it with `GET /v1/transfers/ted-in/retained` and the `reason` `FRAUD_REVIEW_PENDING` or `FRAUD_REVIEW_DESK`. Each held message carries `transferId`, `fraudCheck` and `creditDeadlineAt`. A pending hold also carries `decideBy`.

* `FRAUD_REVIEW_PENDING`: the partner answered `REVIEW` and decides until `decideBy`.
* `FRAUD_REVIEW_DESK`: nobody decides it until a person does. The partner did not answer, or its `REVIEW` passed `decideBy` and `antifraud.in.auto_return_enabled` is off.

A held TED ends in one of these ways:

1. **The partner decides** on the [decision route](#decide-a-held-transfer), with its application token, under the `transferId`.
2. **A person decides on the desk.** `POST /v1/transfers/ted-in/fraud-holds/{messageId}/resolve` takes `Authorization`, `X-Idempotency` and a body with `decision` (`ALLOW` or `DENY`) and a `justification` of 10 to 500 characters. `messageId` is the `id` of the row in the retained queue. The route needs the `transfers` permission with the action `resolve`, which the `editor` role holds. Only a person can call it: an application gets `403` with `BTF-0406`.
3. **`decideBy` passes.** With `antifraud.in.auto_return_enabled` on, TED JD returns the TED with code 9. With it off, the TED goes to the desk, and TED JD sends `transfer_incoming.fraud_analysis` again with `retentionReason` `FRAUD_REVIEW_DESK`.

A decision writes only the closing block of the check. No money moves on the call. The next re-drive of the held message credits the recipient on `ALLOW`, or returns the TED with code 9 on `DENY`, so the effect comes at the next poll. A decision after `creditDeadlineAt` is still applied, late.

The desk answers `400` with `BTF-0001` when `X-Idempotency` is missing or `messageId` is not valid. It answers `409` with `BTF-0128` when the partner, another person or the deadline already decided the hold. It answers `404` with `BTF-0200` when no open hold exists for the message, and `403` with `BTF-0405` when the caller lacks the permission. After a `5xx`, read the hold, and if it is still open, send the decision again under a new `X-Idempotency` key. Do not close a held TED with the close of unsettled TED IN: it answers `BTF-0217`. A TED that you settled outside the platform still gets the action of the decision, so a `DENY` returns money that you already moved. Read the TED and the ledger before you decide a hold older than the credit window.

A person who decides a received TED on the decision route of the partner gets `403` with `BTF-0405`, and the partner that decides a TED it did not answer gets `409`. The desk is the route of the person.

`transfer_incoming.undeliverable` carries `rejectionCategory` `fraud_denied` when the partner or a person denied the TED, and `fraud_review_expired` when the review ran past `decideBy` and the tenant auto-returns.

## Received cross-core credits

***

With the `intra_in` flow on, TED JD asks the partner before it books a credit that another core of your institution relays. Nothing waits on this flow: an answer other than `ALLOW` refuses the credit at once. `REVIEW` is a refusal here.

When TED JD refuses the credit, it books nothing and answers the paying core. It sends `transfer_incoming.refused` with `reason` `antifraud` and the `fraudCheck`. When the partner cannot answer, the `posture` of the route decides: `CLOSED` refuses the credit, and `OPEN` books it. A credit that the ledger refuses after an `ALLOW` is refused with `reason` `ledger_refused`, and the event carries the `fraudCheck` too.

## Turn a check on

***

In BYOC, you write the route and the credential as [Configuration](https://docs.lerian.studio/en/interfaces/ted-jd/ted-configuration.md#antifraud-check-settings) describes. Each flow has its own route, credential bundle and switch.

## Decide a held transfer

***

`POST /v1/transfers/{evaluationKey}/fraud-decision` applies the final decision of an analysis. The `evaluationKey` is the key that the partner received: the `transferId` for a TED OUT, a cross-core TED, a received TED and the payer side of a P2P transfer, and the `transferId` followed by `.in` for the recipient side of a P2P transfer. The call takes these parts:

| Part | Meaning |
| - | - |
| `Authorization` | The token of the application of your institution that holds the `decide` permission of `transfers`, or of a person with the `operator` or `editor` role. The application decides only with `AUTH_M2M_INVERSION_ENABLED=true`. Read the warning in [Machine-to-machine authorization](https://docs.lerian.studio/en/interfaces/ted-jd/ted-environment-variables.md#machine-to-machine-authorization) first. |
| `X-Idempotency` | Required. The partner sends `<analysisId>:<decision>`. The route does not fence it: the status of the transfer is the durable check, so a repeat reaches the decision and answers what it finds. |
| `decision`, `analysisId`, `reasons` | The body of the resolve call. |
| `justification` | Required from a person, 10 to 500 characters. TED JD ignores it from an application. |

A call from an application is the decision of the partner, and the record shows `resolutionOrigin` `PARTNER`. A call from a person is a decision of your back office, with `resolutionOrigin` `OPERATOR`. `resolvedBy` is the subject of the token. The caller must be identified: a token that names neither a person nor an application gets `403`.

`DENY` rejects the transfer and releases the hold and the usage limit. `ALLOW` resumes it. The answer carries the status of the transfer. A held TED that the partner decides here is credited or returned at the next re-drive.

| Status and code | Meaning |
| - | - |
| `400` `BTF-0001` | `X-Idempotency` is missing, or it is not 1 to 255 printable characters with no spaces. |
| `409` `BTF-0128` | The transfer is not open for this decision. It is already final, it waits on another side or another `analysisId`, or `decideBy` passed. The first final decision wins, whoever sends it. |
| `422` `BTF-0129` | The decision is not `ALLOW` or `DENY`, the `analysisId` is not valid, or a person sent no justification. |
| `503` `BTF-0130` | TED JD has not applied the decision, and repeating it is safe. Retry after the `Retry-After` time. |
| `404` `BTF-0200` | The transfer is unknown, or the `evaluationKey` has neither form. |
| `403` `BTF-0405` | The caller lacks the permission, the token names no person or application, or a person decides a received TED here. |
| `500` `BTF-9000` | The outcome is unknown. Send the decision again: it answers what the transfer became. |

A cross-core credit is never decided on this route, because it never waits.

## The outcome of each screened transfer

***

When the route of a flow has a `feedbackEndpoint`, TED JD reports how each screened transfer ended, once for each side that the partner evaluated. The `Idempotency-Key` is the evaluation key, a colon and the `outcome`. TED JD repeats a report after a transient failure for up to 24 hours after the last change of the transfer, and the partner must apply each outcome once.

| How the transfer ended | `outcome` |
| - | - |
| Completed | `SETTLED` |
| Cancelled | `CANCELLED` |
| Cut at `decideBy` after a `REVIEW` that nobody decided | `EXPIRED` |
| A received TED denied after its review ran past `decideBy` | `EXPIRED` |
| Any other rejection or failure, and a refused cross-core credit | `REJECTED` |

## Events

***

| Event | Fires when |
| - | - |
| `transfer.fraud_analysis` | The partner answered `REVIEW` on a TED OUT, a cross-core TED or a P2P transfer. It fires again when the recipient side of a P2P transfer opens its own analysis. `fraudCheck` carries the answer. Deduplicate on the tenant, `transferId` and `fraudCheck.analysisId`. |
| `transfer_incoming.fraud_analysis` | A received TED waits for the partner or for the desk. `retentionReason` is `FRAUD_REVIEW_PENDING` or `FRAUD_REVIEW_DESK`. It carries `creditDeadlineAt`. It fires again, as `FRAUD_REVIEW_DESK`, when a pending hold goes to the desk. Deduplicate on the tenant, `transferId` and `retentionReason`. |
| `transfer_incoming.refused` | TED JD refused a cross-core credit and booked nothing. `reason` is `antifraud`, `ledger_refused` or another refusal, and `fraudCheck` is present when the partner was asked. |

`transfer.fraud_analysis` and `transfer_incoming.fraud_analysis` carry no party name, document or account. `transfer_incoming.refused` carries the payer's name, document, ISPB, branch and account and the payee's document, ISPB, branch and account, as the paying core sent them. Send it to a destination that handles personal data. See [Webhooks](https://docs.lerian.studio/en/interfaces/ted-jd/ted-webhooks.md) for the other events of a transfer.

## What the partner implements

***

TED JD sends the evaluation as described in [What the partner receives](https://docs.lerian.studio/en/interfaces/ted-jd/ted-configuration.md#what-the-partner-receives): the schema, the headers, the signature and the answer rules. For the full contract the partner implements, see [Antifraud partner contract](https://docs.lerian.studio/en/reference/antifraud-partner-contract.md).


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