Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.payx.company/llms.txt

Use this file to discover all available pages before exploring further.

The payx-js SDK allows you to accept payments directly on your website without redirecting your customers. It opens a secure, high-conversion checkout modal as an overlay.

Installation

Via NPM

npm install payx-js@latest

Via CDN

For simple HTML sites, you can include the script via our CDN:
<script src="https://payx.company/js/v1/payx.js"></script>

Basic Usage

To start a payment, initialize the PayX object and call the setup method.
import { PayX } from 'payx-js';

const payment = PayX.setup({
  key: 'pk_test_your_public_key',
  email: 'customer@example.com',
  amount: 100.00,
  currency: 'GHS',
  onSuccess: (response) => {
    console.log('Payment successful!', response.transactionId);
    alert('Thank you for your payment!');
  },
  onCancel: () => {
    console.log('Customer closed the modal');
  }
});

// Open the checkout modal
payment.open();

Configuration Options

key
string
required
Your PayX Public Key (starts with pk_).
email
string
required
The customer’s email address.
amount
number
required
The amount to charge in GHS.
currency
string
default:"GHS"
The currency code. Currently only GHS is supported.
firstname
string
Customer’s first name.
lastname
string
Customer’s last name.
phoneNumber
string
Customer’s mobile money number.
metadata
object
A JSON object containing custom data you want to associate with the transaction.

Callbacks

onSuccess
function
Called when the payment is completed successfully. Returns a response object with the transactionId.
onCancel
function
Called if the customer closes the modal without completing the payment.
onError
function
Called if an error occurs during the checkout process.