> 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/mastercard-taf/implement-taf/authenticate-a-transaction.md).

# Authenticate a transaction

Use the Thales SDK to authenticate a transaction with Mastercard Token Authentication Framework (TAF).

This call generates a Mastercard payload. Use it to retrieve a TAF eligible transaction cryptogram.

## Authentication flow

<figure><img src="https://1873847743-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>Mastercard TAF authentication flow at checkout.</p></figcaption></figure>

## SDK integration

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

Start device authentication in `onDeviceAuthentication`.

You can customize the biometric UI strings.

Handle the final result in `onSuccess` or `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 = "Title";
            CharSequence subTitle = "Subtitle";
            CharSequence description = "Description";
            CharSequence negativeButtonText = "Negative Button";
            deviceAuthentication.startAuthentication(fragmentActivity,
                    title,
                    subTitle,
                    description,
                    negativeButtonText);
        }

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

        @Override
        public void onSuccess(String payload) {
            // Decode the Mastercard Payload and verify the Transaction assertion
        }
    });
}
```

`onSuccess` returns the Mastercard payload.

`onError` returns a `TMGClientException` with an error code and message.
{% endtab %}

{% tab title="iOS" %}
Call `authenticateTransaction` with a `TransactionContext`.

Start device authentication in `deviceAuthenticationHandler`.

```swift
let tokenID = ""
let transContext = MastercardTAFHelper.TransactionContext(merchantName: "ABC", amount: "100", currencyCode: "USD")
// 1. Start authenticate transaction
mastercardTAFHelper.authenticateTransaction(forTokenID: tokenID, context: transContext,
    deviceAuthenticationHandler: { auth in
        // 2. Start user authentication
        let customMessage = "" // Pass in the custom message. e.g: "Authenticate with Face ID"
        auth.startAuthentication(withMessage: customMessage)
    },
    completionHandler: { (mastercardPayload, error) in
        // 3. Success in generating payload
        if error == nil {
        
        } else {
            // Handle 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/mastercard-taf/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.
