# 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.
3. Retrieve the verification result from the *Get 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:

```typescript
import { PxpCheckout } from "@pxpio/web-components-sdk";

const pxpCheckout = PxpCheckout.initialize({
  environment: "test",
  session: sessionData,
  ownerId: "your-owner-id",
  ownerType: "MerchantGroup",
  transactionData: {
    amount: 100.00,
    currency: "USD",
    entryType: "Ecom",
    intent: {
      card: "authorisation"
    },
    merchantTransactionId: crypto.randomUUID(),
    merchantTransactionDate: () => new Date().toISOString()
  },
  onGetShopper: async () => {
    return {
      firstName: "John",
      lastName: "Doe",
    };
  },
});
```

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

### Shopper type reference

| Parameter | 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 the SDK's `onPostAuthorisation` callback.

/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. |


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",
    "stateMessage": "Transaction Authorised",
    "transactionMethod": {
      "intent": "Authorisation",
      "fundingType": "Card",
      "entryType": "Ecom"
    },
    "merchant": "MERCHANT-1",
    "site": "SITE-1",
    "merchantTransactionId": "ECOM-001",
    "merchantTransactionDate": "2024-01-27T08:51:02.826Z",
    "amounts": {
      "transactionValue": 50.05,
      "currencyCode": "EUR"
    },
    "fundingData": {
        "providerResponse": {
          "nameVerificationResult": "NoInformationAvailable" // The name verification result
        }
      }
    }
  }
]
```

## 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:

```typescript
// Backend: Create session with name verification enabled
const sessionResponse = await fetch('/api/sessions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    merchant: 'merchant-01',
    site: 'site-01',
    merchantTransactionId: crypto.randomUUID(),
    amounts: {
      currencyCode: 'USD',
      transactionValue: 100.00
    },
    transactionMethod: {
      intent: {
        card: 'authorisation'
      }
    },
    identityVerification: {
      nameVerification: true
    }
  })
});

const sessionData = await sessionResponse.json();

// Frontend: Initialize SDK with onGetShopper callback
const pxpCheckout = PxpCheckout.initialize({
  environment: 'test',
  session: sessionData,
  ownerId: 'owner-123',
  ownerType: 'MerchantGroup',
  transactionData: {
    amount: 100.00,
    currency: 'USD',
    entryType: 'Ecom',
    intent: {
      card: 'authorisation'
    },
    merchantTransactionId: crypto.randomUUID(),
    merchantTransactionDate: () => new Date().toISOString()
  },
  onGetShopper: async () => {
    // Return shopper details from your system
    const shopper = await fetchShopperDetails();
    return {
      firstName: shopper.firstName,
      lastName: shopper.lastName
    };
  }
});

// Create and mount the new card component
const newCard = pxpCheckout.create('new-card', {
  onPostAuthorisation: async (data) => {
    console.log('Transaction completed:', data.merchantTransactionId);
    
    // Backend: Retrieve transaction details including name verification result
    const transactionDetails = await fetch(
      `/api/v1/transactions/merchant-01/site-01?merchantTransactionId=${data.merchantTransactionId}&systemTransactionId=${data.systemTransactionId}`
    );
    
    const transactions = await transactionDetails.json();
    const latestTransaction = transactions[transactions.length - 1];
    const verificationResult = latestTransaction.fundingData?.providerResponse?.nameVerificationResult;
    
    console.log('Name verification result:', verificationResult);
    
    // Handle the verification result
    if (verificationResult === 'FirstNameMatchedLastNameMatched') {
      console.log('Name verification successful');
    } else if (verificationResult === 'NoInformationAvailable') {
      console.log('Name verification information not available');
    } else {
      console.log('Name verification failed or partially matched');
    }
  }
});

newCard.mount('new-card-container');
```