Card payments
Accept credit and debit cards with secure, PCI-compliant input elements.
PaymentKit.js renders card inputs inside isolated iframes, ensuring sensitive card data never touches your servers.
Setup
CDN
NPM/ES Modules
Create and mount card elements
Unmount elements
Each mount() call returns a handle with an unmount() method. Call it when the card form is removed from the page while the rest of your checkout stays alive — for example, when a modal closes or the user switches to another payment method. Always unmount the three card elements together; they are provisioned as a set.
Calling unmount():
- Removes the secure input iframes from your containers and disconnects their message channels.
- Cancels the mount if it hasn’t finished yet, so it is safe to call immediately after
mount()(for example, in a React effect cleanup). - Leaves the element reusable — calling
mount()on it again renders a fresh input.
unmount() tears down individual inputs; it does not replace the instance-wide paymentKit.cleanup(). When you are done with the PaymentKit instance entirely (for example, navigating away from checkout), still call paymentKit.cleanup() to release remaining SDK resources such as hidden helper iframes and injected scripts. Calling cleanup() after elements have been unmounted is safe.
Element options
Pass options to createElement to customize appearance and behavior:
Styling
The style object applies CSS properties directly to the input element inside the iframe. For layout properties like height, border, and background, style the parent container in your HTML instead:
PaymentKit.js automatically reads your container’s padding and applies it to the input inside the iframe, so text alignment and vertical centering match your container’s styling.
Submit payment
Submit options
By default, submit() validates the customer fields on the client before anything is sent:
customer_name— required, 4–40 characterscustomer_email— required, must be a valid email formatcustomer_country— requiredcustomer_zip_code— required
If any of these checks fail, onError is called with per-field errors ("required" or "invalid") and the payment is not submitted.
Set skipCustomerValidation: true when you validate customer details in your own form logic, or when the built-in rules don’t fit your data (for example, customer names shorter than 4 characters). The field values are then sent to the checkout API as-is.
skipCustomerValidation only skips the customer field checks. Card field validation (card number, expiry, CVC) always runs and cannot be skipped.
3D Secure
3D Secure (3DS) authentication is handled automatically by PaymentKit.js when required by the card issuer or payment processor.
When 3DS is required, PaymentKit.js displays a Stripe.js authentication modal. The customer completes authentication (entering a code or biometric), and PaymentKit.js verifies the result and completes the payment. No additional code is required in your submit() call.
For 3DS to work, include Stripe.js in your page: <script src="https://js.stripe.com/v3/"></script>
Error codes
Payment failure details: errors.checkout_response
When a card payment fails after the card details were submitted successfully — that is, the failure comes from the payment itself rather than from form validation — the error object passed to onError contains two extra keys:
errors.root— a customer-facing error message you can display directly (falls back to"Payment failed"when the backend provides none).errors.checkout_response— the full checkout response object from the API, so you can inspect the exact failure reason programmatically.
checkout_response is present in these cases:
- The charge was declined (checkout concluded in a
payment_failedorcheckout_failedstate). - 3D Secure authentication failed and no fallback processor was available.
- 3D Secure authentication passed, but the charge was subsequently declined.
It is not present for validation errors (the per-field codes in the table above), iframe connection errors, or when too many authentication attempts were made — so always guard for it before use.
Useful fields on checkout_response: