usePrimerCheckout reads the checkout session of the nearest PrimerCheckoutProvider. Use it to follow the checkout as it starts, to read the client session and to react to the result of each payment through paymentOutcome.
Signature
PrimerCheckoutContextValue is exported from @primer-io/react-native as a type. The hook re-renders your component whenever the checkout state changes.
Outside a PrimerCheckoutProvider, the hook throws:
Checkout state
Derive the checkout state fromisReady, error and paymentOutcome:
Returns
Session
Payment result
PaymentOutcome
paymentOutcome is shared by all payment methods of the provider. Each new result replaces the previous one. A failed payment doesn’t end the session: the shopper can try again, and the next attempt sets a new outcome.
Use paymentOutcome as your main result signal. See Results and callbacks.
PrimerCheckoutSheet clears paymentOutcome when its success or pending screen auto-closes after 3 seconds, when it skips a result screen because it is turned off in settings, and when the shopper leaves the error screen to choose another payment method. Closing the sheet by hand does not clear it. React to the outcome when it changes, for example in an effect, rather than reading it later.Lower-level state and actions
The value also carries the state and actions behind the other hooks. UseusePrimerPaymentMethod, usePrimerCardForm and usePrimerVaultManager instead of calling them directly.
Card and raw data
Native UI payment methods
Bank selection
Klarna
Stripe ACH
Saved payment methods
Usage
Showing the start of the checkout
Reading a start error
Read the ID and message of a start error as in the example above. To try again, pass a new client token to the provider or mount a new provider.Reacting to the payment outcome
PaymentOutcomeHandler anywhere inside the provider. See Handle the payment result for the full walkthrough.
Reading the client session
formatCurrency takes the amount in minor units and formats it in the device language.
See also
PrimerCheckoutProvider
Start the session and set the callbacks.
Checkout data
The fields of CheckoutData, PaymentOutcome and ClientSession.
PrimerError
Error fields and the error ids Primer Checkout raises.
Handle the payment result
React to successful, pending and failed payments.