> ## Documentation Index
> Fetch the complete documentation index at: https://primer.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# validate

Perform a validation process on the provided `additionalData` for a given `vaultedPaymentMethodId`.

```kotlin KOTLIN theme={"dark"}
suspend fun validate(
  vaultedPaymentMethodId: String,
  additionalData: PrimerVaultedPaymentMethodAdditionalData
): Result<List<PrimerValidationError>>
```

## Parameters

<Expandable title="Parameters" defaultOpen>
  <ResponseField name="vaultedPaymentMethodId" type="String" required>
    The `id` of a `PrimerVaultedPaymentMethod` previously retrieved with [fetchVaultedPaymentMethods](/sdk/android/v2.x.x/primer-headless-checkout/vault-manager/fetchVaultedPaymentMethods).
  </ResponseField>

  <ResponseField name="additionalData" type="PrimerVaultedPaymentMethodAdditionalData" required>
    <Expandable title="Direct Subclasses">
      <ResponseField name="PrimerVaultedCardAdditionalData">
        <Expandable title="Properties" defaultOpen>
          <ResponseField name="cvv" type="String" required>
            CVV value associated with the vaulted card.
          </ResponseField>
        </Expandable>
      </ResponseField>
    </Expandable>
  </ResponseField>
</Expandable>

## Returns

The `validate` method performs validation operation for the given `vaultedPaymentMethodId` and `additionalData`.
Returns a result object of type [Result](https://kotlinlang.org/api-reference/latest/jvm/stdlib/kotlin/-result/).

The Result class represents the outcome of the operation, indicating `success` or `failure`.

By inspecting the returned Result object, you can determine the success or failure of the validation.
This allows you to handle different scenarios based on the result.

<Expandable title="Results" defaultOpen>
  <ResponseField name="success">
    In case of successful operation result, SDK will return:

    <Expandable title="Return Type" defaultOpen>
      <ResponseField name="List<PrimerValidationError>">
        <Expandable title="Type">
          <ResponseField name="PrimerValidationError">
            <Expandable title="Properties">
              <ResponseField name="errorId" type="String" required>
                A unique error identifier.
              </ResponseField>

              <ResponseField name="description" type="String" required>
                A error description.
              </ResponseField>

              <ResponseField name="diagnosticsId" type="String" required>
                A unique diagnostics id for the given error.
              </ResponseField>
            </Expandable>
          </ResponseField>
        </Expandable>
      </ResponseField>
    </Expandable>

    If the returned list is empty after performing a validation process, it indicates that the data has passed the validation successfully.
    On the other hand, if the validation process encounters any issues or errors, the result object will contain a list of PrimerValidationError objects.
    These objects represent specific validation errors or issues associated with the payment method data.
  </ResponseField>

  <ResponseField name="failure">
    In case of unsuccessful operation result, as part of `Result` object SDK will return:

    <Expandable title="Exceptions" defaultOpen>
      <ResponseField name="InvalidVaultedPaymentMethodIdException">
        In case the id passed does not match any payment method previously retrieved by [fetchVaultedPaymentMethods](/sdk/android/v2.x.x/primer-headless-checkout/vault-manager/fetchVaultedPaymentMethods).
      </ResponseField>
    </Expandable>
  </ResponseField>
</Expandable>

## Example

Refer to the following example for [fetching](/sdk/android/v2.x.x/primer-headless-checkout/vault-manager/fetchVaultedPaymentMethods) vaulted payment methods.

For example, by utilizing the `validate` function, you can validate the CVV collected from the user by passing
`PrimerVaultedCardAdditionalData(cvv: ...)` as the `additionalData` parameter.

```kotlin KOTLIN theme={"dark"}
private fun validateVaultedPaymentMethodAdditionalData(
  vaultedPaymentMethodId: String,
  additionalData: PrimerVaultedPaymentMethodAdditionalData
) {
  // 👇 validate additional data by calling suspend function within the scope
  scope.launch {
    vaultManager.validate(vaultedPaymentMethodId, additionalData).onSuccess { errors ->
      // enable 'Pay' button in case errors list is empty...
    }.onFailure { throwable ->
      // handle error
    }
  }
}
```
