# Name verification

Verify cardholder names match registered address information.

## Overview

Name verification checks whether the cardholder's name matches the name associated with the registered address on file. This feature helps reduce fraud by validating the identity of the person making the payment.

To enable name verification, you need to:

1. Configure your backend to request name verification during session creation.
2. Implement the `onGetShopper` callback in your SDK configuration to provide shopper details (`firstName` and `lastName`). The SDK uses these values for name verification — not the cardholder name field automatically.
3. Retrieve the verification result from the transaction details API after payment.


## Step 1: Enable name verification in your session

When creating a checkout session on your backend, include the `identityVerification` object in your API request:

```json
{
  "merchant": "merchant-01",
  "site": "site-01",
  "merchantTransactionId": "txn-001",
  "amounts": {
    "currencyCode": "USD",
    "transactionValue": 100.00
  },
  "transactionMethod": {
    "intent": {
      "card": "Authorisation"
    }
  },
  "identityVerification": {
    "nameVerification": true
  }
}
```

| Parameter | Description |
|  --- | --- |
| `identityVerification.nameVerification`boolean | Set to `true` to enable name verification for the transaction. |


## Step 2: Provide shopper details

Implement the `onGetShopper` callback in your SDK configuration to provide the cardholder's first and last name:

```kotlin
import com.pxp.PxpCheckout
import com.pxp.checkout.components.newCard.NewCardComponent
import com.pxp.checkout.components.newCard.NewCardComponentConfig
import com.pxp.checkout.models.*
import com.pxp.checkout.services.models.transaction.Shopper
import com.pxp.checkout.types.ComponentType

val pxpSdkConfig = PxpSdkConfig(
    environment = Environment.TEST,
    session = sessionConfig,
    clientId = "your-client-id",
    ownerType = "MerchantGroup",
    ownerId = "your-owner-id",
    transactionData = TransactionData(
        amount = 100.0,
        currency = "USD",
        merchant = "merchant-01",
        entryType = EntryType.Ecom,
        intent = TransactionIntentData(card = CardIntentType.Authorisation),
        merchantTransactionId = UUID.randomUUID().toString(),
        merchantTransactionDate = { Instant.now().toString() }
    ),
    onGetShopper = {
        Shopper(
            firstName = "John",
            lastName = "Doe"
        )
    }
)

val pxpCheckout = PxpCheckout.builder()
    .withConfig(pxpSdkConfig)
    .withContext(context)
    .build()
```

Use a real `SessionConfig` from your session API response (include `data` and `locale`, not only `sessionId` / `hmacKey` / `encryptionKey`).

For name verification, the SDK sends `firstName` and `lastName` from `onGetShopper` on the transaction request. If you collect a cardholder name in the UI, return those values from `onGetShopper`. Optionally set `Shopper.id` when storing cards or deleting tokens after failed payments.

The `firstName` and `lastName` fields are required for name verification to work. Learn more about the [onGetShopper callback](/guides/checkout/components/android/card/events#sdk-data-callbacks).

### Shopper type reference

| Field | Description |
|  --- | --- |
| `firstName`String? | The cardholder's first name. |
| `lastName`String? | The cardholder's last name. |


## Step 3: Retrieve the verification result

After a transaction is completed, retrieve the name verification result by calling the [Get transaction details API](https://developer.pxp.io/apis/transaction/other/get-transaction-details) on your backend.

The name verification result isn't returned in the SDK transaction response. You must retrieve it from the API using the `merchantTransactionId` and `systemTransactionId` received in `CardSubmitComponentConfig.onPostAuthorisation` (via `NewCardComponentConfig.submit`).

/v1/transactions/{merchant}/{site}

### Request example

To get a transaction's details, you'll need to supply the `merchant` and `site` associated with the transaction, and either its `merchantTransactionId` or its `systemTransactionId`.

Use the following request example to get a transaction's details using a merchant transaction ID.

```curl
curl --request GET \
     --url https://api-services.pxp.io/api/v1/transactions/MERCHANT-1/SITE-1?merchantTransactionId=ECOM-001 \
     --header 'accept: application/json'
```

#### Path parameters

| Parameter | Description |
|  --- | --- |
| `merchant`string (≤ 10 characters) | The unique merchant identifier associated with this transaction, as assigned by PXP. |
| `site`string (≤ 10 characters) | The unique site identifier associated with this transaction, as assigned by PXP. |


#### Query parameters

| Parameter | Description |
|  --- | --- |
| `merchantTransactionId`string (≤ 50 characters) | The unique identifier that you assigned to this transaction. |
| `systemTransactionId`string (≤ 40 characters) | The unique identifier assigned to this transaction by PXP. |


### Response example

If your request is successful, you'll receive a `200` response containing an array of transaction records. The last element of the array contains the most recent transaction state. The name verification result is returned in the  `fundingData.providerResponse.nameVerificationResult` field.

```json
[
  {
    "systemTransactionId": "1ed768bb-e88a-4636-91ae-67927ccbb02b",
    "state": "Authorised",
    "merchantTransactionId": "ECOM-001",
    "fundingData": {
      "providerResponse": {
        "nameVerificationResult": "NoInformationAvailable"
      }
    }
  }
]
```

## Verification result values

The following table describes the possible verification result values and their meaning.

| Value | Description |
|  --- | --- |
| `NoInformationAvailable` | No verification information was available from the card issuer. |
| `FirstNameMatchedLastNameMatched` | Both first and last names matched the registered information. |
| `FirstNameMatchedLastNameNotMatched` | First name matched, but last name did not match. |
| `FirstNameMatchedLastNameNotChecked` | First name matched, but last name was not checked. |
| `FirstNameMatchedLastNamePartialMatch` | First name matched, last name partially matched. |
| `FirstNameNotMatchedLastNameMatched` | First name did not match, but last name matched. |
| `FirstNameNotMatchedLastNameNotMatched` | Neither first name nor last name matched. |
| `FirstNameNotMatchedLastNameNotChecked` | First name did not match, last name was not checked. |
| `FirstNameNotMatchedLastNamePartialMatch` | First name did not match, last name partially matched. |
| `FirstNameNotCheckedLastNameMatched` | First name was not checked, but last name matched. |
| `FirstNameNotCheckedLastNameNotMatched` | First name was not checked, last name did not match. |
| `FirstNameNotCheckedLastNameNotChecked` | Neither first name nor last name was checked. |
| `FirstNameNotCheckedLastNamePartialMatch` | First name was not checked, last name partially matched. |
| `FirstNamePartialMatchLastNameMatched` | First name partially matched, last name matched. |
| `FirstNamePartialMatchLastNameNotMatched` | First name partially matched, last name did not match. |
| `FirstNamePartialMatchLastNameNotChecked` | First name partially matched, last name was not checked. |
| `FirstNamePartialMatchLastNamePartialMatch` | Both first and last names partially matched. |


## Complete example

Here's a complete example showing how to implement name verification:

```kotlin
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import com.pxp.PxpCheckout
import com.pxp.checkout.components.newCard.NewCardComponent
import com.pxp.checkout.components.newCard.NewCardComponentConfig
import com.pxp.checkout.models.*
import com.pxp.checkout.services.models.transaction.Shopper
import com.pxp.checkout.types.ComponentType
import kotlinx.coroutines.launch
import java.time.Instant
import java.util.UUID

class CheckoutActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        setContent {
            CheckoutScreen()
        }
    }
}

@Composable
fun CheckoutScreen() {
    val context = LocalContext.current
    val scope = rememberCoroutineScope()
    
    var pxpCheckout by remember { mutableStateOf<PxpCheckout?>(null) }
    var newCardComponent by remember { mutableStateOf<NewCardComponent?>(null) }
    var sessionConfig by remember { mutableStateOf<SessionConfig?>(null) }
    
    // Step 1: Create session with name verification enabled (backend)
    LaunchedEffect(Unit) {
        try {
            sessionConfig = createSessionWithNameVerification()
            
            // Step 2: Initialize SDK with onGetShopper callback
            val pxpSdkConfig = PxpSdkConfig(
                environment = Environment.TEST,
                session = sessionConfig!!,
                clientId = "your-client-id",
                ownerType = "MerchantGroup",
                ownerId = "owner-123",
                transactionData = TransactionData(
                    amount = 100.0,
                    currency = "USD",
                    merchant = "merchant-01",
                    entryType = EntryType.Ecom,
                    intent = TransactionIntentData(card = CardIntentType.Authorisation),
                    merchantTransactionId = UUID.randomUUID().toString(),
                    merchantTransactionDate = { Instant.now().toString() }
                ),
                onGetShopper = {
                    // Return shopper details from your system
                    val shopper = fetchShopperDetails()
                    Shopper(
                        firstName = shopper.firstName,
                        lastName = shopper.lastName
                    )
                }
            )
            
            pxpCheckout = PxpCheckout.builder()
                .withConfig(pxpSdkConfig)
                .withContext(context)
                .build()
            
            // Create and configure the new card component
            val newCardConfig = NewCardComponentConfig().apply {
                submit = CardSubmitComponentConfig().apply {
                    onPreAuthorisation = { _ ->
                        TransactionInitiationData()
                    }
                    onPostAuthorisation = { submitResult ->
                        when (submitResult) {
                            is MerchantSubmitResult -> {
                                scope.launch {
                                    retrieveVerificationResult(
                                        merchantTransactionId = submitResult.merchantTransactionId,
                                        systemTransactionId = submitResult.systemTransactionId
                                    )
                                }
                            }
                            is FailedSubmitResult -> {
                                // handle via onSubmitError in practice
                            }
                            else -> { /* other HTTP 200 outcomes */ }
                        }
                    }
                }
            }
            
            newCardComponent = pxpCheckout?.createComponent<NewCardComponent>(
                ComponentType.NEW_CARD,
                newCardConfig
            )
            
        } catch (e: Exception) {
            println("Failed to initialize checkout: ${e.message}")
        }
    }
    
    // Render the component
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp)
    ) {
        if (newCardComponent != null) {
            newCardComponent?.Content(modifier = Modifier.fillMaxWidth())
        } else {
            CircularProgressIndicator()
        }
    }
}

suspend fun createSessionWithNameVerification(): SessionConfig {
    // Backend API call to create session with identity verification
    val sessionRequest = mapOf(
        "merchant" to "merchant-01",
        "site" to "site-01",
        "merchantTransactionId" to UUID.randomUUID().toString(),
        "amounts" to mapOf(
            "currencyCode" to "USD",
            "transactionValue" to 100.0
        ),
        "transactionMethod" to mapOf(
            "intent" to mapOf(
                "card" to "Authorisation"
            )
        ),
        "identityVerification" to mapOf(
            "nameVerification" to true
        )
    )
    
    // Make your API call and return session data
    // This is placeholder - implement your actual API call
    return SessionConfig(
        sessionId = "session-123",
        hmacKey = "hmac-key",
        encryptionKey = "encryption-key",
        data = "{}",
        locale = "en-US"
    )
}

suspend fun fetchShopperDetails(): ShopperDetails {
    // Fetch shopper details from your backend
    // This is placeholder - implement your actual data fetch
    return ShopperDetails(
        firstName = "John",
        lastName = "Doe"
    )
}

suspend fun retrieveVerificationResult(
    merchantTransactionId: String,
    systemTransactionId: String
) {
    try {
        // Backend API call to get transaction details
        val url = "https://your-api.com/api/v1/transactions/merchant-01/site-01?merchantTransactionId=$merchantTransactionId&systemTransactionId=$systemTransactionId"
        
        // Make your API call - this is placeholder
        // val response = httpClient.get(url)
        // val transactions = response.body<List<Transaction>>()
        
        // Parse the response and extract verification result from the last transaction
        // val latestTransaction = transactions.lastOrNull()
        // val verificationResult = latestTransaction?.fundingData?.providerResponse?.nameVerificationResult
        
        val verificationResult = "FirstNameMatchedLastNameMatched" // Placeholder
        
        println("Name verification result: $verificationResult")
        
        // Handle the verification result
        when (verificationResult) {
            "FirstNameMatchedLastNameMatched" -> {
                println("Name verification successful")
            }
            "NoInformationAvailable" -> {
                println("Name verification information not available")
            }
            else -> {
                println("Name verification failed or partially matched")
            }
        }
    } catch (e: Exception) {
        println("Failed to retrieve verification result: ${e.message}")
    }
}

// Helper data classes
data class ShopperDetails(
    val firstName: String,
    val lastName: String
)

data class Transaction(
    val systemTransactionId: String,
    val merchantTransactionId: String,
    val fundingData: FundingData?
)

data class FundingData(
    val providerResponse: ProviderResponse?
)

data class ProviderResponse(
    val nameVerificationResult: String?
)
```