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
onCheckoutComplete
Called when the checkout completed and a payment was created.checkoutData.payment has the payment id and orderId.
onError
Called with thePrimerError 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
TheclientToken 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 mergestheme.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
PutPrimerCheckoutProvider above every Primer component and hook that reads the checkout session. Outside it, usePrimerCheckout throws:
PrimerCheckoutSheet, PrimerCardFormProvider, PrimerPaymentMethodList, PrimerAcceptedCardNetworks, PrimerCardNetworkSelector, usePrimerPaymentMethod, usePrimerPaymentMethods and usePrimerVaultManager. usePrimerTheme and usePrimerLocalization also work outside the provider.
Usage
With the prebuilt sheet
Logging errors
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.