> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/merchant-tokenization/es/taf-de-mastercard/implement-taf/authenticate-a-transaction.md).

# Autenticar una transacción

Usa el SDK de Thales para autenticar una transacción con Mastercard Token Authentication Framework (TAF).

Esta llamada genera un payload de Mastercard. Úsalo para recuperar un criptograma de transacción elegible para TAF.

## Flujo de autenticación

<figure><img src="/files/e82fc008f15a3962208fb3c3cd9ea7fc333889a2" alt=""><figcaption><p>Flujo de autenticación de Mastercard TAF en el proceso de pago.</p></figcaption></figure>

## Integración del SDK

{% tabs %}
{% tab title="Android" %}
Llamada `MastercardTAFHelper.authenticateTransaction`.

Iniciar autenticación del dispositivo en `onDeviceAuthentication`.

Puedes personalizar las cadenas de la interfaz biométrica.

Gestiona el resultado final en `onSuccess` o `onError`.

```java
public void mastercard_AuthenticateTransaction(@NonNull final String tokenID, @NonNull TransactionContext transactionContext, @NonNull MastercardTAFHelper masterCardTAFHelper, @NonNull FragmentActivity fragmentActivity) {
    masterCardTAFHelper.authenticateTransaction(tokenID, transactionContext, new TransactionListener() {
        @Override
        public void onDeviceAuthentication(DeviceAuthentication deviceAuthentication) {
            CharSequence title = "Título";
            CharSequence subTitle = "Subtítulo";
            CharSequence description = "Descripción";
            CharSequence negativeButtonText = "Botón negativo";
            deviceAuthentication.startAuthentication(fragmentActivity,
                    title,
                    subTitle,
                    description,
                    negativeButtonText);
        }

        @Override
        public void onError(TMGClientException exception) {
            // Verifica el error
            int errorCode = exception.getErrorCode();
            String errorMessage = exception.getMessage();
        }

        @Override
        public void onSuccess(String payload) {
            // Decodifica el payload de Mastercard y verifica la aserción de la transacción
        }
    });
}
```

`onSuccess` devuelve el payload de Mastercard.

`onError` devuelve un `TMGClientException` con un código de error y un mensaje.
{% endtab %}

{% tab title="iOS" %}
Llamada `authenticateTransaction` con un `TransactionContext`.

Iniciar autenticación del dispositivo en `deviceAuthenticationHandler`.

```swift
let tokenID = ""
let transContext = MastercardTAFHelper.TransactionContext(merchantName: "ABC", amount: "100", currencyCode: "USD")
// 1. Iniciar la autenticación de la transacción
mastercardTAFHelper.authenticateTransaction(forTokenID: tokenID, context: transContext,
    deviceAuthenticationHandler: { auth in
        // 2. Iniciar la autenticación del usuario
        let customMessage = "" // Pasa el mensaje personalizado. p. ej.: "Autenticar con Face ID"
        auth.startAuthentication(withMessage: customMessage)
    },
    completionHandler: { (mastercardPayload, error) in
        // 3. Éxito al generar el payload
        if error == nil {
        
        } else {
            // Gestionar error
        }
    }
)
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.payments.thalescloud.io/merchant-tokenization/es/taf-de-mastercard/implement-taf/authenticate-a-transaction.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
