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.
PrimerCardForm renders the card fields in a fixed layout: the card number, the expiry date and CVV, and the cardholder name. Place it inside PrimerCardFormProvider and add your own Pay button that calls usePrimerCardForm().submit(). PrimerCheckoutSheet already renders a card form with its own Pay button and mounts its own PrimerCardFormProvider. Use PrimerCardForm and PrimerCardFormProvider only in a layout you build yourself.

Usage

A custom card layout needs four parts:
  1. PrimerCheckoutProvider at the root.
  2. PrimerCardFormProvider around everything that reads the card form.
  3. A call to start() on usePrimerPaymentMethod('PAYMENT_CARD'), which activates the card form.
  4. Your own Pay button that calls submit().
The payment result arrives in usePrimerCheckout().paymentOutcome. See Handle the payment result.
To keep the form locked after the tap, set your own paying flag on the tap and pass editable={false} while it is set. Clear it only if the payment fails, and read the result from paymentOutcome.

Props

The props type is exported as PrimerCardFormProps.

Layout

  • The CVV field’s label follows the detected network: CVV, CVC, CID, CVN, CVE or CVP2.
  • The return key moves the focus from the card number to the expiry date, the CVV and the cardholder name. On the last field it calls onSubmit.
  • The cardholder name field is hidden when the client session’s CARD_INFORMATION checkout module turns off the cardholder name.
  • To show the card networks the session accepts, add PrimerAcceptedCardNetworks to your layout.
  • Nested test IDs: <testID>-card-number, <testID>-expiry, <testID>-cvv and <testID>-cardholder-name.
The fields take their look from the theme prop of PrimerCheckoutProvider. To change labels, order or layout, compose the card inputs yourself.

PrimerCardFormProvider

PrimerCardFormProvider holds the card form state: the field values, which fields the shopper has visited, and the submit state. Every usePrimerCardForm() call, card input and PrimerCardForm below it reads the same state.
  • Place it inside PrimerCheckoutProvider. Outside it, it throws.
  • usePrimerCardForm, PrimerCardForm and the card inputs throw when no PrimerCardFormProvider is above them.
  • Entered values are kept while the provider is mounted, also when the components that show them unmount. They are cleared when the provider unmounts.

See also

usePrimerCardForm

Field values, validation and submit() for your own Pay button.

Card inputs

The individual card fields, for a layout of your own.

Card networks

Detected network, co-badged selection and the accepted networks row.

usePrimerPaymentMethod

Start the card method and other payment methods.