> ## 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 `additional payment method data` for a given `vaultedPaymentMethodId`.

```swift SWIFT theme={"dark"}
func validate(
    vaultedPaymentMethodId: String,
    vaultedPaymentMethodAdditionalData: PrimerVaultedPaymentMethodAdditionalData,
    completion: @escaping (_ errors: [Error]?) -> Void
)
```

## Parameters

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

  <ResponseField name="vaultedPaymentMethodAdditionalData" 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 `vaultedPaymentMethodAdditionalData`.
The completion handler will either return an array of errors, or `nil` if validation is successful.

The errors returned can be cast to `PrimerError` or `PrimerValidationError`.

<Expandable defaultOpen title="Returns">
  <ResponseField name="completion">
    Completion will be called when the validation has been completed and the
    result is available.
  </ResponseField>

  <ResponseField name="errors" type="Array<Error>">
    <Expandable title="Errors" defaultOpen>
      <ResponseField name="invalidVaultedPaymentMethodId" type="PrimerError">
        An error that will be thrown in case the you provide a vaulted payment method that doesn't exist.
      </ResponseField>

      <ResponseField name="invalidCvv" type="PrimerValidationError">
        An error that will be thrown in case the CVV/CVC is not valid.
      </ResponseField>
    </Expandable>
  </ResponseField>
</Expandable>

## Example

```swift SWIFT theme={"dark"}
import UIKit
import PrimerSDK

class MerchantHeadlesVaultManagerViewController: UIViewController {

  var vaultManager = PrimerHeadlessUniversalCheckout.VaultManager()

  override func viewDidLoad() {
    super.viewDidLoad()

    do {
      // Before you configure your vault manager you must have started
      // PrimerHeadlessUniversalCheckout with a client token.
      try self.vaultManager.configure()

    } catch {
      // Handler the error
    }
  }

  func validateCVV(_ cvv: String, forVaultedPaymentMethodWithId id: String) {
    let vaultedCardAdditionalData = PrimerVaultedCardAdditionalData(cvv: cvv)
    // 👇 Call validate
    self.vaultManager.validate(vaultedPaymentMethodId: id, vaultedPaymentMethodAdditionalData: vaultedCardAdditionalData, completion: { errors in
      if let errors = errors {
        // Handle validation errors
      }
    })
  }
}
```
