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

# Troubleshooting — React Native

> Fix hooks that throw outside `PrimerCheckoutProvider` or `PrimerCardFormProvider`, a checkout that fails to start, and a custom Pay button that does nothing.

## Quick diagnosis

| Symptom | Likely Cause | Solution |
| - | - | - |
| Error `usePrimerCheckout must be used within a <PrimerCheckoutProvider>` | A Primer component or hook is rendered outside `PrimerCheckoutProvider` | Render it below `PrimerCheckoutProvider`, in a child component |
| Error `usePrimerCardForm must be used within a <PrimerCardFormProvider>` | `PrimerCardForm`, a card input or `usePrimerCardForm` is rendered outside `PrimerCardFormProvider` | Wrap your card UI in `PrimerCardFormProvider` |
| The sheet shows its error screen as soon as it opens, or `isReady` never becomes `true` | Invalid or expired client token, or another failure while the checkout starts | Read `usePrimerCheckout().error` and start again with a fresh client token |
| The checkout starts again from the loading screen | The `clientToken` value changed, or the provider mounted again | Keep the client token in state and keep the provider mounted during the checkout |
| The sheet doesn't close | `onRequestDismiss` is missing, or doesn't set `visible` to `false` | Pass `onRequestDismiss={() => setVisible(false)}` |
| Apple Pay or Google Pay is missing or fails to start | Apple Pay is available on iOS only, and Google Pay on Android only | Check `isAvailable` before you start a wallet, and follow [Native setup](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/guides/native-setup.md) |
| Your own Pay button does nothing | The card payment method wasn't started, the checkout isn't ready, or the card data isn't valid | Call `start()` from `usePrimerPaymentMethod('PAYMENT_CARD')` once `isReady` is `true`, and gate the button on `isValid` |
| Payment fails after submission | Declined card, 3DS failure, or network issue | Handle `paymentOutcome` with `status: 'error'` and log `errorId` and `diagnosticsId` |
| The app throws `'NativePrimer' could not be found`, or `pod install` or the Android build fails | Installation or build issue | See [Troubleshooting](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/troubleshooting.md) in the React Native SDK reference |

## Provider setup

### Hook used outside PrimerCheckoutProvider

**Cause:** Primer components and hooks read the checkout session from the nearest [`PrimerCheckoutProvider`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/primer-checkout-provider) above them. Outside one, they throw:

```text theme={"dark"}
usePrimerCheckout must be used within a <PrimerCheckoutProvider>. Wrap your component tree with <PrimerCheckoutProvider clientToken="...">.
```

`PrimerCardFormProvider` also needs `PrimerCheckoutProvider` above it.

A common cause is calling a hook in the same component that renders the provider. The hook then runs above the provider, not inside it.

**Solution:** Call the hooks in a child component of `PrimerCheckoutProvider`:

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

// WRONG
export function BrokenCheckoutScreen({ clientToken }: { clientToken: string }) {
  const { isReady } = usePrimerCheckout();
  return (
    <PrimerCheckoutProvider clientToken={clientToken}>
      <Text>{isReady ? 'Ready' : 'Loading'}</Text>
    </PrimerCheckoutProvider>
  );
}

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

function CheckoutStatus() {
  const { isReady } = usePrimerCheckout();
  return <Text>{isReady ? 'Ready' : 'Loading'}</Text>;
}
```

### Card form used outside PrimerCardFormProvider

**Cause:** [`PrimerCardForm`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/primer-card-form), the [card inputs](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-inputs.md) and [`usePrimerCardForm`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/use-primer-card-form) read the card form state from `PrimerCardFormProvider`. Without it, they throw:

```text theme={"dark"}
usePrimerCardForm must be used within a <PrimerCardFormProvider>. The built-in <PrimerCheckoutSheet>/<CheckoutFlow> wires this automatically.
```

`PrimerCheckoutSheet` sets up its own card form state, so this error comes from a layout you build yourself.

**Solution:** Put `PrimerCardFormProvider` inside `PrimerCheckoutProvider`, around your card UI. [Your own Pay button does nothing](#your-own-pay-button-does-nothing) shows the full setup.

## Configuration and initialization

### Checkout fails to start

**Cause:** The checkout can't start, for example because of an invalid or expired client token, a network issue, or an incorrect API key when your server created the client session. `usePrimerCheckout().isReady` stays `false` and `usePrimerCheckout().error` is set.

`PrimerCheckoutSheet` moves from its loading screen to its error screen.

**Solution:** Generate a fresh client token on your server for each checkout attempt. Read the ID and message of [`usePrimerCheckout().error`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/use-primer-checkout#reading-a-start-error) and show your own message:

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

type StartError = { errorId?: string; code?: string; description?: string; message?: string };

export function StartErrorNotice() {
  const { error } = usePrimerCheckout();

  useEffect(() => {
    if (!error) return;
    const e = error as StartError;
    console.warn('[Primer] Checkout failed to start', e.errorId ?? e.code, e.description ?? e.message);
  }, [error]);

  if (!error) return null;
  return <Text>We couldn't load the checkout. Try again later.</Text>;
}
```

To try again, close the sheet and pass a new client token to the provider, or mount a new provider.

### Checkout restarts unexpectedly

**Cause:** The provider starts a new session whenever the `clientToken` value changes, and ends the session when it unmounts. A client token fetched again on a re-render, or a provider inside a component that unmounts and mounts again, restarts the checkout from the loading screen and resets its state, including `paymentOutcome`.

**Solution:** Fetch one client token per checkout attempt, keep it in state, and render the provider in a component that stays mounted for the whole checkout:

```tsx theme={"dark"}
import { useState } from 'react';
import { Button } from 'react-native';
import { PrimerCheckoutProvider, PrimerCheckoutSheet } from '@primer-io/react-native';

export function CheckoutButton({ fetchClientToken }: { fetchClientToken: () => Promise<string> }) {
  const [clientToken, setClientToken] = useState<string | null>(null);
  const [visible, setVisible] = useState(false);

  const openCheckout = async () => {
    setClientToken(await fetchClientToken());
    setVisible(true);
  };

  return (
    <>
      <Button title="Checkout" onPress={openCheckout} />
      {clientToken !== null && (
        <PrimerCheckoutProvider clientToken={clientToken}>
          <PrimerCheckoutSheet
            visible={visible}
            onRequestDismiss={() => setVisible(false)}
            onDismiss={() => setClientToken(null)}
          />
        </PrimerCheckoutProvider>
      )}
    </>
  );
}
```

To reload the session after your backend updates the client session, pass a new client token.

## Prebuilt sheet

### The sheet doesn't close

**Cause:** You control [`PrimerCheckoutSheet`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/primer-checkout-sheet) with its `visible` prop. The sheet calls `onRequestDismiss` when the shopper taps the backdrop or Cancel, swipes the drag handle down, or presses the Android back button on a screen without a Back button, and when the success screen has been shown for 3 seconds. Without `onRequestDismiss`, none of these close the sheet: a swipe springs back, and the backdrop and Cancel do nothing.

**Solution:** Set `visible` to `false` in `onRequestDismiss`:

```tsx theme={"dark"}
<PrimerCheckoutSheet visible={visible} onRequestDismiss={() => setVisible(false)} />
```

## Payment methods

### Payment method missing

**Cause:** Multiple possible causes:

* No payment methods configured in the [Primer Dashboard](https://dashboard.primer.io) for the client session's currency and country
* Client session missing the `currencyCode` or `countryCode` field
* A native dependency that the payment method needs isn't installed, for example the `PrimerKlarnaSDK` pod for Klarna on iOS

**Solution:** Verify your Dashboard configuration and make sure your client session includes the correct `currencyCode` and `countryCode`. Add the native dependencies as described in [Native setup](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/guides/native-setup.md). To see which payment methods the session returned, use the snippet in [Inspect available payment methods](#inspect-available-payment-methods).

### Apple Pay or Google Pay not available

**Cause:** Apple Pay is available on iOS only, and Google Pay on Android only. On the other platform, `usePrimerPaymentMethod(type).isAvailable` is `false`. When the wallet is in the session as a native UI method, for example Google Pay on iOS, `availabilityError.code` is `PLATFORM_NOT_SUPPORTED` and `start()` rejects with a `PrimerError` whose `errorId` is `google-pay-unavailable` or `apple-pay-unavailable`.

**Solution:** Check `isAvailable` before you show or start a wallet. Enable Apple Pay or Google Pay for your session in the Dashboard. For Apple Pay, add the Apple Pay capability to your iOS app and pass `paymentMethodOptions.applePayOptions.merchantIdentifier`. See [Native setup](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/guides/native-setup.md#apple-pay).

### Shopper doesn't return to your app after a redirect

**Cause:** Payment methods that leave your app, such as PayPal and Klarna, return to it through a URL. On iOS, that needs a URL scheme registered in your app and `paymentMethodOptions.iOS.urlScheme`. On Android, Klarna needs `paymentMethodOptions.klarnaOptions.returnIntentUrl`. Without it, selecting a Klarna payment category ends the attempt with the `errorId` `klarna-return-url-missing`.

**Solution:** Register the URL and pass it in `settings`, as described in [Native setup](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/guides/native-setup.md#register-a-url-scheme-on-ios). For Klarna on Android, also add the return activity from the [Klarna section](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/guides/native-setup.md#klarna).

## Card form

### Your own Pay button does nothing

**Cause:** `usePrimerCardForm().submit()` never rejects. It returns without submitting when:

* The checkout isn't ready yet (`isReady` is `false`)
* The card payment method wasn't started with `start()` from `usePrimerPaymentMethod('PAYMENT_CARD')`
* A submit is already running
* `isValid` is `false`

In each case, it marks the submit as attempted, so the card fields show their errors. Until you call `start()`, the SDK validates nothing, `isValid` stays `false`, and typing in the card fields logs a warning:

```text theme={"dark"}
[PrimerCheckoutProvider] setRawData: no manager (activeMethod=null)
```

**Solution:** Start the card payment method once the checkout is ready, gate your button on `isValid`, keep your own flag from the tap until `paymentOutcome` arrives, then show the result in place of the form:

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

function CardPayment() {
  const { isReady, paymentOutcome } = usePrimerCheckout();
  const card = usePrimerPaymentMethod('PAYMENT_CARD');
  const cardForm = usePrimerCardForm();
  const [isPaying, setIsPaying] = useState(false);

  const start = isReady && card.kind === 'card' && card.isAvailable ? card.start : undefined;

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

  useEffect(() => {
    if (paymentOutcome) setIsPaying(false);
  }, [paymentOutcome]);

  const pay = () => {
    if (!cardForm.isValid || isPaying) return;
    setIsPaying(true);
    void cardForm.submit();
  };

  if (paymentOutcome) {
    return <Text>{paymentOutcome.status === 'error' ? 'Payment failed' : 'Payment complete'}</Text>;
  }

  return (
    <View>
      <PrimerCardForm editable={!isPaying} onSubmit={pay} />
      {isPaying ? (
        <ActivityIndicator />
      ) : (
        <Button title="Pay" disabled={!cardForm.isValid} onPress={pay} />
      )}
    </View>
  );
}

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

### Form shows invalid despite all visible fields being filled

**Cause:** `isValid` comes from the native SDK. A card field you left out of your own layout stays empty, so when the session requires it, `isValid` stays `false`. `requiredFields` lists the fields the native SDK requires. The cardholder name is hidden only when the client session's `CARD_INFORMATION` checkout module turns it off, which `isCardholderNameVisible` reports.

A field's error shows only after the shopper focuses the field and leaves it with a value in it, or after a submit attempt. Fields you build yourself must call `markFieldFocused` and `markFieldBlurred`, or their errors stay hidden until a submit attempt.

**Solution:** Render `PrimerCardForm`, which shows the cardholder name field whenever `isCardholderNameVisible` is `true`, or render every card input yourself. Inspect `errors` and `requiredFields` with the snippet in [Log card form validation errors](#log-card-form-validation-errors). See [When errors show](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/use-primer-card-form.md#when-errors-show).

## Installation

For installation and build issues, such as `'NativePrimer' could not be found` when the app imports `@primer-io/react-native`, `pod install` failing on `PrimerSDK`, or Android `Unresolved reference` errors, see [Troubleshooting](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/troubleshooting.md) in the React Native SDK reference.

## Validation vs payment errors

Understanding the difference helps with proper error handling:

| Error Type | When It Occurs | How It's Handled |
| - | - | - |
| **Validation errors** | During input (invalid format, missing fields) | Shown by the card inputs from `usePrimerCardForm().errors`; `submit()` does nothing while `isValid` is `false` |
| **Payment failures** | After form submission (declined card, 3DS failure, network issues) | Delivered as `paymentOutcome` with `status: 'error'`. `PrimerCheckoutSheet` shows its error screen unless `uiOptions.isErrorScreenEnabled` is `false` |

> [!WARNING]
>
> Don't confuse these two error types. Validation errors prevent form submission and are shown inline. Payment failures occur after the form is submitted and require explicit handling.

## Debugging tips

### Log the payment outcome

[`usePrimerCheckout().paymentOutcome`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/use-primer-checkout#paymentoutcome) carries the result of every payment attempt. Render this component anywhere inside `PrimerCheckoutProvider`:

```tsx theme={"dark"}
import { useEffect } from 'react';
import { usePrimerCheckout } from '@primer-io/react-native';

export function PaymentOutcomeLogger() {
  const { paymentOutcome } = usePrimerCheckout();

  useEffect(() => {
    if (!paymentOutcome) return;
    if (paymentOutcome.status === 'error') {
      const { errorId, errorCode, description, diagnosticsId } = paymentOutcome.error;
      console.warn('[Primer] Payment failed', { errorId, errorCode, description, diagnosticsId });
    } else {
      console.log('[Primer] Payment', paymentOutcome.status, paymentOutcome.data.payment?.id);
    }
  }, [paymentOutcome]);

  return null;
}
```

### Check checkout readiness

If `isReady` stays `false`, the checkout is either still starting or failed to start, so check `error`:

```tsx theme={"dark"}
import { useEffect } from 'react';
import { usePrimerCheckout } from '@primer-io/react-native';

export function ReadinessLogger() {
  const { isReady, isLoadingResources, error } = usePrimerCheckout();

  useEffect(() => {
    console.log('[Primer] Ready:', isReady, 'Loading resources:', isLoadingResources, 'Start error:', error != null);
  }, [isReady, isLoadingResources, error]);

  return null;
}
```

### Inspect available payment methods

Read the payment methods of the session from [`usePrimerPaymentMethods`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/payment-methods/primer-payment-method-list) once they have loaded:

```tsx theme={"dark"}
import { useEffect } from 'react';
import { usePrimerPaymentMethods } from '@primer-io/react-native';

export function PaymentMethodsLogger() {
  const { paymentMethods, isLoading } = usePrimerPaymentMethods();

  useEffect(() => {
    if (isLoading) return;
    paymentMethods.forEach((method) => {
      console.log(`[Primer] Available: ${method.type} (${method.name})`);
    });
  }, [isLoading, paymentMethods]);

  return null;
}
```

### Log card form validation errors

Render this component inside `PrimerCardFormProvider`. It logs field names and validation messages:

```tsx theme={"dark"}
import { useEffect } from 'react';
import { usePrimerCardForm } from '@primer-io/react-native';

export function CardFormLogger() {
  const { isValid, errors, requiredFields } = usePrimerCardForm();

  useEffect(() => {
    console.log('[Primer] Card form', { isValid, requiredFields, errors });
  }, [isValid, requiredFields, errors]);

  return null;
}
```

### Read the SDK's console messages

The React Native layer of the SDK writes warnings and errors to the JavaScript console, which you can read in React Native DevTools. Each message starts with a prefix that names its source, for example:

| Prefix | Source |
| - | - |
| `[PrimerCheckoutProvider]` | The provider: starting the session, payment method managers, and card data sent before the card payment method was started |
| `[CardFormState]` | The card form state, for example a submit that failed |
| `[MethodSelectionScreen]` | The payment method list of `PrimerCheckoutSheet` |

For the native SDKs, check the Xcode console on iOS and Logcat on Android.

## Getting help

When contacting Primer support, include:

1. The `diagnosticsId` from the error
2. The `errorId` and `description` of the error
3. Your `@primer-io/react-native` version, React Native version, platform and OS version
4. Steps to reproduce the issue

```tsx theme={"dark"}
if (paymentOutcome?.status === 'error') {
  const { error, data } = paymentOutcome;
  console.log('Include in support request:', {
    errorId: error.errorId,
    description: error.description,
    diagnosticsId: error.diagnosticsId,
    recoverySuggestion: error.recoverySuggestion,
    paymentId: data?.payment?.id,
  });
}
```

> [!WARNING]
>
> Never include card numbers, expiry dates or security codes in logs, screenshots or support requests.

## See also

> [card] [Events guide](https://primer.io/docs/checkout/primer-checkout/configuration/events.md)
>
> Event handling patterns

> [card] [Build a custom card form](https://primer.io/docs/checkout/primer-checkout/guides-and-recipes/build-custom-card-form.md)
>
> Card form tutorial

> [card] [Installation troubleshooting](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/troubleshooting.md)
>
> Fix installation, build and native setup issues

> [card] [PrimerError](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/common/primer-error.md)
>
> Error fields and the error IDs the SDK raises


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