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

# PrimerCardForm

> Component that renders the card fields in a fixed layout for a checkout UI you build yourself.

> [!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.

`PrimerCardForm` renders the card fields in a fixed layout: the card number, the expiry date and CVV, and the cardholder name. Place it inside [`PrimerCardFormProvider`](#primercardformprovider) and add your own Pay button that calls [`usePrimerCardForm().submit()`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/use-primer-card-form).

[`PrimerCheckoutSheet`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/primer-checkout-sheet) already renders a card form with its own Pay button and mounts its own `PrimerCardFormProvider`. Use `PrimerCardForm` and `PrimerCardFormProvider` only in a layout you build yourself.

## Usage

A custom card layout needs four parts:

1. `PrimerCheckoutProvider` at the root.
2. `PrimerCardFormProvider` around everything that reads the card form.
3. A call to `start()` on [`usePrimerPaymentMethod('PAYMENT_CARD')`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/payment-methods/use-primer-payment-method), which activates the card form.
4. Your own Pay button that calls `submit()`.

```tsx theme={"dark"}
import { useEffect } from 'react';
import { Button, View } from 'react-native';
import {
  PrimerCardForm,
  PrimerCardFormProvider,
  PrimerCheckoutProvider,
  usePrimerCardForm,
  usePrimerPaymentMethod,
} from '@primer-io/react-native';

export function CheckoutScreen({ clientToken }: { clientToken: string }) {
  return (
    <PrimerCheckoutProvider clientToken={clientToken}>
      <PrimerCardFormProvider>
        <CardPayment />
      </PrimerCardFormProvider>
    </PrimerCheckoutProvider>
  );
}

function CardPayment() {
  const card = usePrimerPaymentMethod('PAYMENT_CARD');
  const cardForm = usePrimerCardForm();
  const startCard = card.kind === 'card' && card.isAvailable ? card.start : undefined;

  useEffect(() => {
    startCard?.();
  }, [startCard]);

  if (!card.isAvailable) return null;

  return (
    <View>
      <PrimerCardForm onSubmit={() => cardForm.submit()} />
      <Button
        title="Pay"
        disabled={!cardForm.isValid || cardForm.isSubmitting}
        onPress={() => cardForm.submit()}
      />
    </View>
  );
}
```

The payment result arrives in [`usePrimerCheckout().paymentOutcome`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/use-primer-checkout). See [Handle the payment result](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/guides/handle-payment-result.md).

> [!NOTE]
>
> To keep the form locked after the tap, set your own paying flag on the tap and pass `editable={false}` while it is set. Clear it only if the payment fails, and read the result from `paymentOutcome`.

## Props

| Prop | Type | Default | Description |
| - | - | - | - |
| `onSubmit` | `() => void` | — | Called when the shopper presses the return key on the last field: the cardholder name, or the CVV when the cardholder name is hidden. Route it to the same handler as your Pay button. |
| `autoFocus` | `boolean` | `false` | Focuses the card number field 300 ms after mount. |
| `editable` | `boolean` | `true` | Whether the fields accept input. Pass `false` while a payment runs. The fields are also disabled while `usePrimerCardForm().isSubmitting` is `true`. |
| `style` | `StyleProp<ViewStyle>` | — | Style for the outer container. |
| `testID` | `string` | `'primer-card-form'` | Test ID of the container. The nested elements get IDs derived from it. |

The props type is exported as `PrimerCardFormProps`.

## Layout

| Order | Content |
| - | - |
| 1 | [`PrimerCardNumberInput`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-inputs#primercardnumberinput), which shows the co-badged network selector when a card has more than one network. |
| 2 | [`PrimerExpiryDateInput`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-inputs#primerexpirydateinput) and [`PrimerCVVInput`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-inputs#primercvvinput), side by side. |
| 3 | [`PrimerCardholderNameInput`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-inputs#primercardholdernameinput), only when `usePrimerCardForm().isCardholderNameVisible` is `true`. |

* The CVV field's label follows the detected network: `CVV`, `CVC`, `CID`, `CVN`, `CVE` or `CVP2`.
* The return key moves the focus from the card number to the expiry date, the CVV and the cardholder name. On the last field it calls `onSubmit`.
* The cardholder name field is hidden when the client session's `CARD_INFORMATION` checkout module turns off the cardholder name.
* To show the card networks the session accepts, add [`PrimerAcceptedCardNetworks`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-networks#primeracceptedcardnetworks) to your layout.
* Nested test IDs: `<testID>-card-number`, `<testID>-expiry`, `<testID>-cvv` and `<testID>-cardholder-name`.

The fields take their look from the [`theme`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/theming/primer-theme-override) prop of `PrimerCheckoutProvider`. To change labels, order or layout, compose the [card inputs](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-inputs.md) yourself.

## PrimerCardFormProvider

`PrimerCardFormProvider` holds the card form state: the field values, which fields the shopper has visited, and the submit state. Every `usePrimerCardForm()` call, card input and `PrimerCardForm` below it reads the same state.

```tsx theme={"dark"}
function PrimerCardFormProvider(props: { children: ReactNode }): React.JSX.Element;
```

| Prop | Type | Default | Description |
| - | - | - | - |
| `children` | `ReactNode` | Required | The components that use the card form. |

* Place it inside `PrimerCheckoutProvider`. Outside it, it throws.
* `usePrimerCardForm`, `PrimerCardForm` and the card inputs throw when no `PrimerCardFormProvider` is above them.
* Entered values are kept while the provider is mounted, also when the components that show them unmount. They are cleared when the provider unmounts.

## See also

> [card] [usePrimerCardForm](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/use-primer-card-form.md)
>
> Field values, validation and `submit()` for your own Pay button.

> [card] [Card inputs](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-inputs.md)
>
> The individual card fields, for a layout of your own.

> [card] [Card networks](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-networks.md)
>
> Detected network, co-badged selection and the accepted networks row.

> [card] [usePrimerPaymentMethod](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/payment-methods/use-primer-payment-method.md)
>
> Start the card method and other payment methods.


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