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

# Card networks

> Hooks and components for the detected card network, co-badged network selection and the accepted networks row.

> [!WARNING]
>
> Primer Checkout React Native SDK is currently in **beta** (v3.0.0-beta.1).
> The API is subject to change before the stable release.

The card form detects the card network from the digits the shopper types. The hooks and components on this page read the detected network, let the shopper choose a network on a co-badged card, and show the networks your session accepts.

| API | Use it to |
| - | - |
| [`usePrimerCardNetwork`](#useprimercardnetwork) | Read the detected network, its traits and its icon. |
| [`usePrimerCardNetworkSelection`](#useprimercardnetworkselection) | Read the networks of a co-badged card and record the shopper's choice. |
| [`PrimerCardNetworkSelector`](#primercardnetworkselector) | Show the SDK's co-badged network selector. |
| [`PrimerAcceptedCardNetworks`](#primeracceptedcardnetworks) | Show a row of the networks the session accepts. |

All of them must be inside `PrimerCheckoutProvider`. They don't need `PrimerCardFormProvider`. The detected network comes from the native SDK's BIN data, which exists only while the card form is active: after `start()` on [`usePrimerPaymentMethod('PAYMENT_CARD')`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/payment-methods/use-primer-payment-method), or inside `PrimerCheckoutSheet`.

## usePrimerCardNetwork

Returns the detected network with its traits and icon.

```tsx theme={"dark"}
function usePrimerCardNetwork(): UseCardNetworkReturn;
```

The return type is exported as `UseCardNetworkReturn`.

| Field | Type | Description |
| - | - | - |
| `network` | `string \| null` | The detected network as the native SDK reports it, for example `'VISA'`. `null` before a network is detected. It can be a value outside [`CardNetworkId`](#cardnetworkid). |
| `descriptor` | object | Traits of the detected network: card number lengths, gap pattern, CVV length and CVV label. Same shape as [`usePrimerCardForm().descriptor`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/use-primer-card-form#network-descriptor). |
| `iconSource` | `ImageSourcePropType \| null` | An image source (`{ uri }`) for the detected network's icon. `null` while it loads, when the network is `OTHER` or unknown, or when the lookup fails. |

* `descriptor` starts as the default descriptor on every network change and updates when the native SDK returns the traits. It stays the default when the native SDK has no traits for the network or the lookup fails.
* `iconSource` is only for the detected network. For the icons of other networks, use `PrimerCardNetworkSelector` or `PrimerAcceptedCardNetworks`.

```tsx theme={"dark"}
import { Image, Text } from 'react-native';
import { usePrimerCardNetwork } from '@primer-io/react-native';

function DetectedNetwork() {
  const { network, descriptor, iconSource } = usePrimerCardNetwork();

  if (!network) return null;
  if (iconSource) return <Image source={iconSource} style={{ width: 28, height: 20 }} resizeMode="contain" />;
  return <Text>{descriptor.displayName}</Text>;
}
```

## usePrimerCardNetworkSelection

Returns the networks of a co-badged card and lets you record the shopper's choice.

```tsx theme={"dark"}
function usePrimerCardNetworkSelection(): UsePrimerCardNetworkSelectionReturn;
```

The return type is exported as `UsePrimerCardNetworkSelectionReturn`.

| Field | Type | Description |
| - | - | - |
| `availableNetworks` | `ReadonlyArray<CardNetworkDetails>` | The detected networks that are allowed: the preferred network first, then the alternatives. Empty before BIN data arrives. |
| `selectedNetwork` | `CardNetworkDetails \| null` | The shopper's choice. `null` until the shopper chooses, and when the chosen network is not in `availableNetworks`. |
| `selectedIdentifier` | `CardNetworkId \| null` | Identifier of the shopper's choice, or `null`. |
| `displayedNetwork` | `CardNetworkDetails \| null` | The network to show: `selectedNetwork`, otherwise the first of `availableNetworks`, otherwise `null`. |
| `displayedIdentifier` | `CardNetworkId \| null` | Identifier of `displayedNetwork`. |
| `isSelectorVisible` | `boolean` | `true` when two or more networks are available and the shopper may choose any of them. |
| `isDualBadge` | `boolean` | `true` when two or more networks are available and at least one doesn't allow a choice. EFTPOS is the only such network. |

| Method | Description |
| - | - |
| `selectNetwork(identifier: CardNetworkId): Promise<void>` | Records the shopper's choice and sends it to the native SDK with the card data. Resolves once it is applied. Rejects with a `PrimerError` with `errorId` `NO_ACTIVE_CARD_FORM` when no card form is active, and rejects when sending the card data fails. |

* The choice is sent with the card data until the shopper changes the card number to one whose detected networks no longer include it. The SDK then drops the choice and `selectedNetwork` returns to `null`.
* Without a choice, no network is sent with the card data.
* The choice is also dropped when the card form stops being active.

### Building your own selector

```tsx theme={"dark"}
import { Pressable, Text, View } from 'react-native';
import { usePrimerCardNetworkSelection } from '@primer-io/react-native';

function NetworkPicker() {
  const { availableNetworks, displayedIdentifier, isSelectorVisible, selectNetwork } =
    usePrimerCardNetworkSelection();

  if (!isSelectorVisible) return null;

  return (
    <View>
      {availableNetworks.map((network) => (
        <Pressable
          key={network.identifier}
          onPress={() => selectNetwork(network.identifier).catch(() => {})}
        >
          <Text>
            {network.displayName}
            {network.identifier === displayedIdentifier ? ' (selected)' : ''}
          </Text>
        </Pressable>
      ))}
    </View>
  );
}
```

> [!WARNING]
>
> `PrimerCardNumberInput`, and so `PrimerCardForm`, already contains the co-badged selector. Build your own selector, or use `PrimerCardNetworkSelector`, only in a layout with your own card number field. Otherwise the shopper sees two selectors.

## CardNetworkDetails

A network in `usePrimerCardNetworkSelection`. All fields are read-only.

| Field | Type | Description |
| - | - | - |
| `identifier` | `CardNetworkId` | The network identifier, for example `'CARTES_BANCAIRES'`. |
| `displayName` | `string` | The network name, for example `"Cartes Bancaires"`. |
| `allowed` | `boolean` | `true` unless the native SDK reports the network as not allowed. Networks in `availableNetworks` always have `true`. |
| `allowsUserSelection` | `boolean` | `false` for EFTPOS, `true` for every other network. |

## PrimerCardNetworkSelector

The co-badged network selector that `PrimerCardNumberInput` shows inside the card number field. Render it yourself only next to your own card number field.

| Prop | Type | Default | Description |
| - | - | - | - |
| `testID` | `string` | — | Test ID root. A dual badge gets the ID itself and `<testID>-badge-<NETWORK>` on each badge. The selectable selector gets `<testID>-trigger`, `<testID>-popover` and `<testID>-option-<NETWORK>`. |

The props type is exported as `PrimerCardNetworkSelectorProps`. The selector reads `usePrimerCardNetworkSelection()` and renders one of three states:

| State | Renders |
| - | - |
| Fewer than two available networks | Nothing. |
| `isDualBadge` | A badge for each network side by side, with no choice. |
| `isSelectorVisible` | The badge of `displayedNetwork` and a chevron. A tap opens a list of the networks, with a check mark on the displayed one. Choosing a network calls `selectNetwork`. |

A badge shows the network's icon. Without an icon it shows a two-letter abbreviation, for example `CB` for Cartes Bancaires, or a generic card image when there is no abbreviation.

## PrimerAcceptedCardNetworks

A horizontal row of small chips for the card networks your session accepts. Add it to your own layout, for example above the card number.

| Prop | Type | Default | Description |
| - | - | - | - |
| `networks` | `string[]` | `usePrimerCheckout().acceptedCardNetworks` | The networks to show, for example `['VISA', 'MASTERCARD']`. Overrides the session's list. |
| `style` | `StyleProp<ViewStyle>` | — | Style for the row. |
| `testID` | `string` | `'primer-accepted-card-networks'` | Test ID of the row. Each chip gets `<testID>-chip-<NETWORK>`. |

* Without `networks`, it shows `acceptedCardNetworks` from [`usePrimerCheckout()`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/use-primer-checkout): the networks the session accepts, in order. The SDK loads them when the checkout is ready and again when the client session changes.
* Each chip shows the network's icon, or a two-letter abbreviation while there is no icon.
* It renders nothing while the list is empty or not loaded yet.
* Duplicate networks are shown once, in the order given.

The props type is exported as `PrimerAcceptedCardNetworksProps`.

## CardNetworkId

The identifiers of the networks the SDK knows:

```tsx theme={"dark"}
type CardNetworkId =
  | 'VISA'
  | 'MASTERCARD'
  | 'AMEX'
  | 'DINERS_CLUB'
  | 'DISCOVER'
  | 'JCB'
  | 'UNIONPAY'
  | 'MAESTRO'
  | 'ELO'
  | 'MIR'
  | 'HIPER'
  | 'HIPERCARD'
  | 'DANKORT'
  | 'BANCONTACT'
  | 'CARTES_BANCAIRES'
  | 'EFTPOS'
  | 'OTHER';
```

## BinData

The BIN data the native SDK reports for the card number. Read it from `usePrimerCardForm().binData` or the `onBinDataChange` option of [`usePrimerCardForm`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/use-primer-card-form). The type is exported as `BinData`.

| Field | Type | Description |
| - | - | - |
| `preferred` | `CardNetwork \| null` | The preferred detected network, or `null`. |
| `alternatives` | `CardNetwork[]` | The other detected networks, for example the second network of a co-badged card. |
| `status` | `BinDataStatus` (`'PARTIAL' \| 'COMPLETE'`) | Whether the BIN lookup is partial or complete. |
| `firstDigits` | `string \| null` | The leading digits of the card number as the native SDK reports them, or `null`. |

`BinDataStatus` is also exported.

`CardNetwork`, also exported, describes one detected network:

| Field | Type | Description |
| - | - | - |
| `network` | `string` | The network identifier, for example `'VISA'`. |
| `displayName` | `string` | The network name. |
| `allowed` | `boolean` (optional) | Whether the session allows the network. |
| `issuerCountryCode`, `issuerName`, `accountFundingType`, `prepaidReloadableIndicator`, `productUsageType`, `productCode`, `productName`, `issuerCurrencyCode`, `regionalRestriction`, `accountNumberType` | `string \| null` (optional) | Issuer and product details. Filled only when `status` is `'COMPLETE'`. |

## See also

> [card] [usePrimerCardForm](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/use-primer-card-form.md)
>
> Card form state, including `binData` and `descriptor`.

> [card] [Card inputs](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-inputs.md)
>
> `PrimerCardNumberInput` and its built-in selector.

> [card] [PrimerCardForm](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/primer-card-form.md)
>
> The card fields in a fixed layout.

> [card] [Display card network](https://primer.io/docs/checkout/primer-checkout/guides-and-recipes/display-card-network.md)
>
> Show the detected card network as the shopper types.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.