> 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="/files/MHfrYIQsyOIS6LFgJU4x" 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 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/mastercard-taf/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.
