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.
- Checkout pay step
- Add a card
- Upgrade a plan
- One-off purchase
Examples
Installation
npx knowns-ui@latest add payment-formPaste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install Payment form from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/payment-form
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add payment-form
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- components/ui/knowns/spinner.tsx
- components/ui/knowns/button.tsx
- components/ui/knowns/alert.tsx
- components/ui/knowns/kbd.tsx
- components/ui/knowns/field-class.ts
- components/ui/knowns/textarea.tsx
- components/ui/knowns/chat-composer/use-autosize.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/use-floating.ts
- components/ui/knowns/tooltip.tsx
- components/ui/knowns/tooltip-utils.ts
- components/ui/knowns/input.tsx
- components/ui/knowns/card-input/card-input.tsx
- components/ui/knowns/card-input/card-brand-glyph.tsx
- components/ui/knowns/card-input/card-input-utils.ts
- components/ui/knowns/blocks/checkout/payment-form.tsx
- components/ui/knowns/blocks/checkout/checkout-utils.ts
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0, class-variance-authority@^0.7.1.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/payment-form, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "payment-form" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.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- Default
true / 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- Default
Date.now() - For the expiry check.
| Prop | Type | Default | Description |
|---|---|---|---|
| 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" | "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 | - / "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 | true / 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 | Date.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
- 01Spaces the card number the brand's way as it is typed and shows the brand as a neutral text glyph, never a logo.
- 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.
- 03Shows a field's error once it was left or the form was sent, and puts focus on the first wrong field.
- 04Disables the fields and spins the button while the payment is processing; a second press does nothing.
- 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.
- 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
| State | What moves | Timing |
|---|---|---|
| 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" }).