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:PrimerCheckoutProviderat the root.PrimerCardFormProvideraround everything that reads the card form.- A call to
start()onusePrimerPaymentMethod('PAYMENT_CARD'), which activates the card form. - Your own Pay button that calls
submit().
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,CVEorCVP2. - 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_INFORMATIONcheckout module turns off the cardholder name. - To show the card networks the session accepts, add
PrimerAcceptedCardNetworksto your layout. - Nested test IDs:
<testID>-card-number,<testID>-expiry,<testID>-cvvand<testID>-cardholder-name.
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,PrimerCardFormand the card inputs throw when noPrimerCardFormProvideris 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.