payx-js SDK allows you to accept payments directly on your website using a secure, modal checkout experience without redirecting your customers.
How It Works (Scoped Token Model)
To protect your account, never embed secret API keys in client-side code. PayX uses a secure 2-step token flow:- Server-Side Token Generation: Your backend server calls
POST /api/v1/checkoutusing your secret API key (px_live_v2_...orpx_test_v2_...) to create a 30-minute scoped checkout token (px_checkout_...). - Client-Side Initialization: Your frontend receives the scoped token and initializes
PayX.checkout({ token })to render the payment modal.
Installation
Via CDN (Recommended)
Include the PayX JS script tag before the closing</body> tag or in the <head> of your page:
Via NPM
Usage Example
Step 1: Generate Scoped Token on Backend (Node.js)
Step 2: Launch Checkout in Frontend
Configuration Options
string
required
The 30-minute scoped checkout token (
px_checkout_...) generated server-side by POST /api/v1/checkout.Callbacks
function
required
Callback triggered when the transaction is completed successfully. Receives a response object containing
reference and transaction metadata.function
Callback triggered when the customer dismisses or closes the modal without completing payment.
function
Callback triggered if an unexpected error occurs during initialization or processing.