PaymentKit.js
Accept payments directly on your website with secure, PCI-compliant payment elements powered by PaymentKit.js.
PaymentKit.js is a lightweight JavaScript library that lets you securely collect payment information on your website. It renders payment inputs inside isolated iframes, ensuring sensitive card data never touches your servers and keeping you PCI compliant.
Before you begin
To accept payments with PaymentKit.js, you’ll need:
- A PaymentKit account with at least one payment processor connected
- A backend server to create checkout sessions and handle payment confirmation
- Your API keys from the PaymentKit dashboard under Developers > API Keys
Try it out
See PaymentKit.js in action with our demo application:
A complete working example showing card payments, PayPal, and Google Pay integration.
Installation
Choose your preferred installation method:
CDN
NPM
YARN
PNPM
Load PaymentKit.js directly from a CDN without any build step. Perfect for HTML-based projects or quick prototyping.
unpkg (recommended):
jsDelivr:
The CDN bundle exposes a global PaymentKit object with all payment methods included (~29 KB minified). Access payment methods via PaymentKit.PaymentMethods.card, .paypal, and .googlePay.
How it works
Accepting a payment with PaymentKit.js involves three steps:
- Create a checkout session on your server to get a secure token
- Initialize PaymentKit.js on your frontend with the token
- Collect and submit payment details from your customer
Step 1: Create a checkout session
Before collecting payment details, create a checkout session on your server. This generates a secure token that authorizes the frontend to process the payment.
Replace {account_id} with your account’s external ID (e.g., acc_dev_abc123).
The response includes a secure_token that you’ll pass to PaymentKit.js:
Step 2: Initialize PaymentKit
Import PaymentKit and the payment methods you want to support, then initialize with your configuration:
CDN
NPM/ES Modules
The CDN bundle includes all payment methods pre-loaded. Access them via PaymentKit.PaymentMethods.
Use 'sandbox' during development and testing. Switch to 'production' when deploying to your live environment.
Step 3: Collect payment details
How you collect payment details depends on which payment method you’re using. PaymentKit.js supports multiple payment methods that you can enable based on your needs.
Available payment methods
Accept credit and debit cards with PCI-compliant inputs and automatic 3D Secure handling.
Let customers pay with their PayPal account using a popup-based authentication flow.
Accept Google Pay on supported devices for fast, secure checkout.
Using multiple payment methods
You can enable multiple payment methods in a single PaymentKit instance. This lets customers choose their preferred way to pay:
CDN
NPM/ES Modules
Submitting a payment
Regardless of which payment method you use, payments are submitted using the submit() method. This method validates the payment details, processes the payment, and calls your success or error callbacks.
Customer fields
PaymentKit collects customer information to help with fraud prevention and compliance. The following fields are required for card payments:
Success response
When a payment succeeds, the onSuccess callback receives a result object:
Handling errors
Payment errors are returned to the onError callback as an object with field-specific error codes:
Error types
Form field errors
Card input errors
Payment method errors
Cleaning up
When your checkout component unmounts or the user navigates away, always clean up PaymentKit resources to prevent memory leaks:
In React, use a cleanup function in your effect:
Failing to call cleanup() can leave orphaned iframes and event listeners, which may cause issues if the user returns to checkout.