Skip to main content
Primer Checkout React Native SDK is currently in beta (v3.0.0-beta.1). The API is subject to change before the stable release.
PrimerCheckoutProvider starts the native SDK with your client token and makes the checkout session available to every Primer component and hook below it. It also applies your theme and calls your callbacks. It renders only its children and draws no UI of its own.

Props

PrimerCheckoutProviderProps, CheckoutData, CheckoutPaymentMethodData, PaymentCreationHandler, PrimerSettings, PrimerThemeOverride and PrimerError are exported from @primer-io/react-native as types.

Results and callbacks

Read the result of each payment from usePrimerCheckout().paymentOutcome. It reports the success, pending and failure results.

onCheckoutComplete

Called when the checkout completed and a payment was created. checkoutData.payment has the payment id and orderId.

onError

Called with the PrimerError of a payment error, for example a declined payment, a 3DS failure or a network error. The second argument carries the payment data when the native SDK sends it. Read it with optional chaining. Read errors that stop the checkout from starting from usePrimerCheckout().error.

onBeforePaymentCreate

Called before the native SDK creates the payment. checkoutPaymentMethodData.paymentMethod is the payment method type. Answer through the handler:

Callbacks in settings

settings.headlessUniversalCheckoutCallbacks accepts more callbacks: Without an onCheckoutAdditionalInfo callback, additional info that Primer Checkout doesn’t handle itself sets paymentOutcome to an error with the errorId 'additional-info-unhandled' once the checkout is ready.

Session lifecycle

The clientToken prop controls the session: To reload the session, for example after your backend updates the client session, pass a new client token.

Theme updates

The provider merges theme.light and theme.dark over the default tokens and applies the result on the next render. Define the theme outside your component or memoize it, so the provider doesn’t merge it again on every render.

Placement

Put PrimerCheckoutProvider above every Primer component and hook that reads the checkout session. Outside it, usePrimerCheckout throws:
The components and hooks that need the provider include PrimerCheckoutSheet, PrimerCardFormProvider, PrimerPaymentMethodList, PrimerAcceptedCardNetworks, PrimerCardNetworkSelector, usePrimerPaymentMethod, usePrimerPaymentMethods and usePrimerVaultManager. usePrimerTheme and usePrimerLocalization also work outside the provider.

Usage

With the prebuilt sheet

This example creates a new client token, and so a new session, for each checkout attempt.

Logging errors

Watch paymentOutcome as well, as shown on the usePrimerCheckout page.

See also

usePrimerCheckout

Read the checkout state and the payment outcome.

PrimerCheckoutSheet

Run the whole checkout in a prebuilt bottom sheet.

PrimerSettings

Configure payment methods and UI options.

PrimerThemeOverride

Override design tokens for light and dark mode.