Skip to content
Knowns UI
Get ProSign in

Payment Form

The pay step of a checkout: email for the receipt, the card number with brand detection, expiry and security code, a slot for wallet buttons, and a pay button with the total. It shows the processing state and a declined payment with a retry that keeps what was typed.

On this page
Used for
  • Checkout pay step
  • Add a card
  • Upgrade a plan
  • One-off purchase

Examples

State

Installation

npx knowns-ui@latest add payment-form
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

value / onChange
CardDraft / (draft) => void
{ email, number, expiry, cvc, name, postal? }. Controlled; the form formats as it goes.
onSubmit
(draft) => void
Called only with a draft that passed every check. Start the payment and set status to processing.
status
"form" | "processing" | "failed"
Default"form"
Processing disables the fields and spins the button; failed shows the decline and Try again.
error
{ code?, message? } | null
The decline. Known codes (card_declined, insufficient_funds, expired_card, incorrect_cvc, incorrect_number, processing_error, authentication_required) get their own words; message replaces them.
amount / payLabel
string
Default - / "Pay {amount}"
The total on the button.
wallets
ReactNode
Buttons above the card fields, with an or pay with card rule under them. Two per row from 448px.
askEmail / askPostal
boolean
Defaulttrue / false
Ask for the receipt email, and a postal code.
footnote / title / surface
ReactNode | null / ReactNode | null / boolean
The line under the button, the heading, and whether it draws its own card.
now
number
DefaultDate.now()
For the expiry check.

Accessibility

  • Each field has a label and the autocomplete the browser and password managers expect (email, cc-number, cc-exp, cc-csc, cc-name, postal-code).
  • Errors are tied to their field (aria-describedby, aria-invalid); sending a wrong form focuses the first wrong field.
  • The decline is an alert. A decline that points at a field (a wrong security code) focuses that field.
  • While processing, the form is aria-busy and the fields are disabled.

What it handles

  1. 01Spaces the card number the brand's way as it is typed and shows the brand as a neutral text glyph, never a logo.
  2. 02Checks the number (length and Luhn), the expiry against this month and the security code length for the brand, in words a person can act on.
  3. 03Shows a field's error once it was left or the form was sent, and puts focus on the first wrong field.
  4. 04Disables the fields and spins the button while the payment is processing; a second press does nothing.
  5. 05Shows a decline above the button with Try again, keeps every field as typed, focuses the field the bank pointed at and offers Use another card when that is the way out.
  6. 06Takes wallet or saved-method buttons in a slot above the card fields.

States

First render
Nothing moves
none
Processing
The button spins, the fields dim
until onPay settles
Declined
The reason shows above the button; Try again
none
Reduced motion
The spinner stays, nothing else moves
none

Works with

When to use

When to use

  • Collecting a card with brand detection and checks before handing it to your provider's tokeniser.
  • Adding or replacing a card in billing, with a decline shown in words.

When not to use

  • The whole checkout with the summary and the receipt: use Checkout.
  • Only the card number, expiry and code in your own form: use Card Input.
  • Showing the card on file: use Settings.

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Payment Form to my app and wire it to my own data.
  • I need collecting a card with brand detection and checks before handing it to your provider's tokeniser. Set that up with the Knowns UI Payment Form.
  • Which Payment Form props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "payment-form" }) and search_docs({ query: "payment form" }).

Need help?

Stuck on Payment Form, or found something off? We read every message.