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

# PrimerHeadlessUniversalCheckoutRawDataManagerDelegate

## Overview

Set the `PrimerHeadlessUniversalCheckoutRawDataManagerDelegate` in order to receive different callbacks from your `RawDataManager`.

### primerRawDataManager(\_:dataIsValid:)

Returns whether the `rawData` set is valid, and all the errors that occurred during validation.

```swift SWIFT theme={"dark"}
func primerRawDataManager(_ rawDataManager: PrimerHeadlessUniversalCheckout.RawDataManager, dataIsValid isValid: Bool, errors: [Error]?)
```

#### Parameters

<Expandable defaultOpen title="Parameters">
  <ResponseField name="rawDataManager" type="PrimerHeadlessUniversalCheckout.RawDataManager">
    The instance of the raw data manager calling this delegate method
  </ResponseField>

  <ResponseField name="isValid" type="Bool">
    Whether the data is valid
  </ResponseField>

  <ResponseField name="errors" type="Array<Error>">
    The errors that occurred during the validation
  </ResponseField>
</Expandable>

### primerRawDataManager(\_:willFetchMetadataForState:)

Called when we begin to fetch metadata for the current `rawData`. Changing `rawData` triggers this callback.
Some time after this is called, `primerRawDataManager(_:didReceiveMetadata:forState:)` will be called with the relevant metadata for the state.

Use this method to indicate to the user that metadata is being fetched; for example, by showing a loading spinner or other UI until the metadata has been returned.

```swift SWIFT theme={"dark"}
func primerRawDataManager(_ rawDataManager: PrimerHeadlessUniversalCheckout.RawDataManager,
                          willFetchMetadataForState state: PrimerValidationState)
```

#### Parameters

<Expandable defaultOpen title="Parameters">
  <ResponseField name="rawDataManager" type="PrimerHeadlessUniversalCheckout.RawDataManager">
    The instance of the raw data manager calling this delegate method.
  </ResponseField>

  <ResponseField name="state" type="PrimerValidationState">
    An object containing the state that triggered the metadata fetch. For example, for
    card number entry, this will be an instance of `PrimerCardNumberEntryState`

    <Expandable title="Implementations" defaultOpen>
      <ResponseField name="class PrimerCardNumberEntryState">
        Used when `rawData` is set to `PrimerCardData`

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="cardNumber" type="String" required>
            The card number set on `rawData` that triggered the metadata fetch
          </ResponseField>
        </Expandable>
      </ResponseField>
    </Expandable>
  </ResponseField>
</Expandable>

### primerRawDataManager(\_:didReceiveMetadata:forState:)

Called when new validation metadata relating to the current validation state is received. This will always be
called some time after `primerRawDataManager(_:willFetchMetadataForState:)` is called.

Use this method to query new validation metadata, add informational UI, or allow the user to add
additional payment information required to make a payment.

```swift SWIFT theme={"dark"}
func primerRawDataManager(_ rawDataManager: PrimerHeadlessUniversalCheckout.RawDataManager,
                          didReceiveMetadata metadata: PrimerPaymentMethodMetadata,
                          forState state: PrimerValidationState)
```

#### Parameters

<Expandable defaultOpen title="Parameters">
  <ResponseField name="rawDataManager" type="PrimerHeadlessUniversalCheckout.RawDataManager">
    The instance of the raw data manager calling this delegate method.
  </ResponseField>

  <ResponseField name="metadata" type="PrimerPaymentMethodMetadata">
    An object containing metadata for the relevant `state` also returned with this method.

    <Expandable defaultOpen title="Implementations">
      <ResponseField name="class PrimerCardNumberEntryState">
        Used when `rawData` is set to `PrimerCardData`

        <Expandable defaultOpen title="Properties">
          <ResponseField name="cardNumber" type="String" required>
            The card number set on `rawData` that triggered the metadata fetch
          </ResponseField>
        </Expandable>
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="state" type="PrimerValidationState">
    An object containing the state that triggered the metadata fetch. For example, for
    card number entry, this will be an instance of `PrimerCardNumberEntryState`

    <Expandable title="Implementations" defaultOpen>
      <ResponseField name="class PrimerCardNumberEntryMetadata">
        Card network metadata including selectable card networks and detected card
        networks.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="source" type="PrimerCardValidationSource" required>
            Enum value indicating the source of the validation.

            <Expandable title="cases" defaultOpen>
              <ResponseField name=".remote">
                Indicates that remote validation occurred using Primer APIs.
              </ResponseField>

              <ResponseField name=".localFallback">
                Indicates that remote validation was attempted but could not be
                completed, causing a fallback to local validation.
              </ResponseField>

              <ResponseField name=".local">
                Indicates that the validation occurred locally, usually leveraging
                the first few digits of the card number.
              </ResponseField>
            </Expandable>
          </ResponseField>

          <ResponseField name="selectableCardNetworks" type="PrimerCardNetworksMetadata?">
            Card networks for the given card number that can be selected by the user
            prior to payment. This will be null in the case that a network is
            co-badged, or we are unable to remotely validate the given card number.

            <Expandable title="Properties">
              <ResponseField name="items" type="[PrimerCardNetwork]" required>
                <Expandable title="Element">
                  <ResponseField name="cardNetwork" type="PrimerCardNetwork">
                    Represents a card network and includes metadata about that network relative to
                    a specific card BIN.

                    <Expandable defaultOpen>
                      <ResponseField name="network" type="CardNetwork" required>
                        An enum value for the card network (e.g. `.visa`, `.mastercard`)
                      </ResponseField>

                      <ResponseField name="displayName" type="String" required>
                        The human-readable name of the card network (e.g., Visa, Mastercard).
                      </ResponseField>

                      <ResponseField name="allowed" type="Bool" required>
                        A boolean indicating whether this card network is allowed.
                      </ResponseField>
                    </Expandable>
                  </ResponseField>
                </Expandable>
              </ResponseField>

              <ResponseField name="preferred" type="PrimerCardNetwork?">
                The preferred card network. Use this to pre-select a network if there are multiple.

                <Expandable defaultOpen>
                  <ResponseField name="network" type="CardNetwork" required>
                    An enum value for the card network (e.g. `.visa`, `.mastercard`)
                  </ResponseField>

                  <ResponseField name="displayName" type="String" required>
                    The human-readable name of the card network (e.g., Visa, Mastercard).
                  </ResponseField>

                  <ResponseField name="allowed" type="Bool" required>
                    A boolean indicating whether this card network is allowed.
                  </ResponseField>
                </Expandable>
              </ResponseField>
            </Expandable>
          </ResponseField>

          <ResponseField name="detectedCardNetworks" type="PrimerCardNetworksMetadata">
            All detected card networks for the given card number. This will include
            networks even if they are not merchant-supported.

            <Expandable title="Properties">
              <ResponseField name="items" type="[PrimerCardNetwork]" required>
                <Expandable title="Element">
                  <ResponseField name="cardNetwork" type="PrimerCardNetwork">
                    Represents a card network and includes metadata about that network relative to
                    a specific card BIN.

                    <Expandable defaultOpen>
                      <ResponseField name="network" type="CardNetwork" required>
                        An enum value for the card network (e.g. `.visa`, `.mastercard`)
                      </ResponseField>

                      <ResponseField name="displayName" type="String" required>
                        The human-readable name of the card network (e.g., Visa, Mastercard).
                      </ResponseField>

                      <ResponseField name="allowed" type="Bool" required>
                        A boolean indicating whether this card network is allowed.
                      </ResponseField>
                    </Expandable>
                  </ResponseField>
                </Expandable>
              </ResponseField>

              <ResponseField name="preferred" type="PrimerCardNetwork?">
                The preferred card network. Use this to pre-select a network if there are multiple.

                <Expandable defaultOpen>
                  <ResponseField name="network" type="CardNetwork" required>
                    An enum value for the card network (e.g. `.visa`, `.mastercard`)
                  </ResponseField>

                  <ResponseField name="displayName" type="String" required>
                    The human-readable name of the card network (e.g., Visa, Mastercard).
                  </ResponseField>

                  <ResponseField name="allowed" type="Bool" required>
                    A boolean indicating whether this card network is allowed.
                  </ResponseField>
                </Expandable>
              </ResponseField>
            </Expandable>
          </ResponseField>
        </Expandable>
      </ResponseField>
    </Expandable>
  </ResponseField>
</Expandable>

### primerRawDataManager(\_:didReceiveBinData:)

Called when the SDK detects BIN data from the card number entered by the user.
This callback provides detailed information about the card including issuer details and card attributes.
It delivers BIN data independently from the metadata state callbacks and has a default no-op implementation, so overriding it is optional.

```swift SWIFT theme={"dark"}
func primerRawDataManager(_ rawDataManager: PrimerHeadlessUniversalCheckout.RawDataManager,
                          didReceiveBinData binData: PrimerBinData)
```

#### Parameters

<Expandable defaultOpen title="Parameters">
  <ResponseField name="rawDataManager" type="PrimerHeadlessUniversalCheckout.RawDataManager">
    The instance of the raw data manager calling this delegate method.
  </ResponseField>

  <ResponseField name="binData" type="PrimerBinData">
    <Expandable title="Properties" defaultOpen>
      <ResponseField name="preferred" type="PrimerCardNetwork?">
        The recommended card network to use, based on the order specified in `orderedAllowedCardNetworks` in the Client Session. `nil` if no network is allowed or data is not yet resolved.

        <Expandable title="PrimerCardNetwork Properties">
          <ResponseField name="network" type="CardNetwork" required>
            An enum value for the card network (e.g. `.visa`, `.mastercard`).
          </ResponseField>

          <ResponseField name="displayName" type="String" required>
            A human-readable name for the card network (e.g., "Visa", "Mastercard").
          </ResponseField>

          <ResponseField name="issuerCountryCode" type="String?">
            The ISO 3166-1 alpha-2 country code of the card issuer.
          </ResponseField>

          <ResponseField name="issuerName" type="String?">
            The name of the card issuer (e.g., bank name).
          </ResponseField>

          <ResponseField name="accountFundingType" type="String?">
            The type of account funding (e.g., "CREDIT", "DEBIT", "PREPAID").
          </ResponseField>

          <ResponseField name="prepaidReloadableIndicator" type="String?">
            Indicates whether a prepaid card is reloadable.
          </ResponseField>

          <ResponseField name="productUsageType" type="String?">
            The usage type of the card product (e.g., "CONSUMER", "COMMERCIAL").
          </ResponseField>

          <ResponseField name="productCode" type="String?">
            The product code assigned by the card network.
          </ResponseField>

          <ResponseField name="productName" type="String?">
            The product name assigned by the card network (e.g., "Visa Signature").
          </ResponseField>

          <ResponseField name="issuerCurrencyCode" type="String?">
            The ISO 4217 currency code associated with the card issuer.
          </ResponseField>

          <ResponseField name="regionalRestriction" type="String?">
            Regional restrictions that apply to the card.
          </ResponseField>

          <ResponseField name="accountNumberType" type="String?">
            The type of account number (e.g., "PAN", "TOKEN").
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="alternatives" type="[PrimerCardNetwork]" required>
        All detected card networks, including ones that are not allowed. For co-badged cards, this list contains multiple networks. Each element has the same properties as `preferred` above.
      </ResponseField>

      <ResponseField name="status" type="PrimerBinDataStatus" required>
        The status of the BIN data retrieval.

        <Expandable title="Cases" defaultOpen>
          <ResponseField name=".complete">
            This happens when 8 digits or more are entered in the card number field. The SDK retrieved the BIN data using Primer's BIN data service, providing the most accurate information including issuer details.
          </ResponseField>

          <ResponseField name=".partial">
            This happens when fewer than 8 digits are entered in the card number field, or when the SDK fails to contact Primer's BIN data service. The SDK retrieved the card networks using static information bundled with the SDK. This can only identify international card networks and does not include issuer details.
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="firstDigits" type="String?">
        The first digits (BIN prefix) of the card number, when available.
      </ResponseField>
    </Expandable>
  </ResponseField>
</Expandable>

### primerRawDataManager(\_:metadataDidChange:)

<Warning>
  This method is deprecated. Please use `primerRawDataManager(_:willFetchMetadataForState:)` and
  `primerRawDataManager(_:didReceiveMetadata:forState:)`.
</Warning>

Returns validation metadata for the current validation state, triggered by using `rawData`. Check the section below for the metadata types that can be returned.

```swift SWIFT theme={"dark"}
func primerRawDataManager(_ rawDataManager: PrimerHeadlessUniversalCheckout.RawDataManager, metadataDidChange metadata: [String: Any]?)
```

#### Parameters

<Expandable defaultOpen title="Parameters">
  <ResponseField name="rawDataManager" type="PrimerHeadlessUniversalCheckout.RawDataManager">
    The instance of the raw data manager calling this delegate method.
  </ResponseField>

  <ResponseField name="metadata" type="Dictionary<String:Any>">
    The metadata associated with the validation state.
  </ResponseField>
</Expandable>
