> 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="https://2211683957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9XBN1F9dv7Dl1ggilGWC%2Fuploads%2F9VtaAWuBZyWk0eQmn4d8%2FFlow%20-%20Payment%20Flow%20with%20TAF.svg?alt=media&amp;token=1d1a6ec9-cd89-4354-97c2-e0319a831860" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
