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.
usePrimerPaymentMethod gives you the state and actions for one payment method, by its type (for example 'PAYMENT_CARD', 'KLARNA' or 'ADYEN_BLIK'). The return value depends on how the method is driven, so check its kind first, then render the UI that kind needs and call its actions. The native SDK runs the payment, and the result arrives in usePrimerCheckout().paymentOutcome. Call it in a component inside PrimerCheckoutProvider; it throws outside one. Rendering the hook does no native work: native calls start when you call an action such as start().

Signature

UsePrimerPaymentMethodReturn is a union. Narrow it on kind:
The package exports the variant types NativeUiPaymentMethod, CardPaymentMethod, StripeAchPaymentMethod and UnsupportedPaymentMethod.

Kinds

The kind comes from the method’s manager category in the session, checked in this order. PAYMENT_CARD is always card. A type that isn’t in the session is unsupported, except PAYMENT_CARD, which is card with isAvailable: false.
Every variant has isAvailable. When it is false, render nothing for that method: its actions can’t take a payment.

Fields every kind shares

Native UI

kind: 'nativeUi' (type NativeUiPaymentMethod). The native SDK presents the payment sheet or opens the browser. PaymentMethodAvailabilityError is { code: string; message: string }. code is PLATFORM_NOT_SUPPORTED for a wallet the device’s platform doesn’t support, NOT_READY for Google Pay on an Android device that isn’t ready to pay, and NOT_AVAILABLE otherwise. message is for your logs.
PrimerPaymentMethodList draws Apple’s own Apple Pay button on iOS and Google’s own Google Pay button on Android.

Card

kind: 'card' (type CardPaymentMethod). The card form is yours to render: see PrimerCardForm and usePrimerCardForm. The result of the card payment arrives in usePrimerCheckout().paymentOutcome.

Bank selection

kind: 'bankSelection'. The shopper picks a bank, then the native SDK redirects to it. IssuingBank:

Raw-data form

kind: 'rawDataForm', for ADYEN_BANCONTACT_CARD, ADYEN_MBWAY and ADYEN_BLIK. You collect a few values and send them to the native SDK. Before start() has activated the method, setData and submit do nothing. Wait until requiredInputs is filled before you collect data.

Klarna

kind: 'klarna'. The shopper picks a Klarna payment category, Klarna’s own view loads inside your screen, and the shopper authorizes. KlarnaPaymentCategory:
Set settings.paymentMethodOptions.klarnaOptions.returnIntentUrl and handle that URL in your app, as described in Native setup.

PrimerKlarnaPaymentView

PrimerKlarnaPaymentView is the native view that shows Klarna’s content for the selected category. Render it once isViewLoaded is true. Start from a fixed height, such as 250, and update it from onContentHeightChange.

Stripe ACH

kind: 'stripeAch' (type StripeAchPaymentMethod). The shopper enters the account holder’s details, links a bank account in Stripe’s screen, then accepts a mandate. It needs the Stripe dependency from Native setup and these settings on the provider:
  • settings.paymentMethodOptions.stripeOptions.publishableKey: your Stripe publishable key.
  • settings.paymentMethodOptions.stripeOptions.mandateData: either { merchantName }, which fills the SDK’s mandate text (in the device language), or { fullMandateText }, your own text, shown as it is. Without either, the attempt ends with the error stripe-ach-mandate-config.
See Handle the payment result for the outcomes.

Unsupported

kind: 'unsupported' (type UnsupportedPaymentMethod) is { kind: 'unsupported'; isAvailable: false }. The method can’t be used in this session. Render nothing for it.

End a flow

When the shopper leaves your screen for a bank-selection, Klarna or Stripe ACH method, end the flow with stopBanks(), stopKlarna() or stopAch() from usePrimerCheckout(), as the prebuilt sheet does when the shopper goes back to its method list. Then start() begins a new flow the next time your screen opens.

Errors

Payment failures, such as a declined card, a 3DS failure or a network error, arrive in paymentOutcome. The hook also ends attempts with its own errors. The *-start-failed, *-submit-failed, *-mandate-failed and *-decline-failed ids wrap a failure that didn’t come as a PrimerError; when it did, you get that error instead. See PrimerError for its fields.

See also

PrimerPaymentMethodList

List the session’s payment methods.

usePrimerCheckout

The payment outcome and checkout state.

Native setup

URL schemes, wallets and the Klarna and Stripe dependencies.

PrimerError

Error fields and where errors arrive.