The official JavaScript SDK for integrating PayChangu payment gateway into your web applications.
Install the package using npm:
npm install paychangu-js
Or using yarn:
yarn add paychangu-js
Import the necessary modules from the SDK:
import { PopupSDK, LevelSDK, VerificationSDK, generateTxRef } from 'paychangu-js';
The Popup SDK allows you to integrate an inline popup payment flow.
const popupSDK = PopupSDK;
// Configure and initiate the popup
popupSDK.initiate(config);
The Level SDK provides functionality for level-based payments.
const levelSDK = LevelSDK;
// Make a level-based payment
const response = await levelSDK.makePayment(levelConfig);
The Verification SDK allows you to verify transactions.
const verificationSDK = VerificationSDK;
// Verify a transaction
const verificationResponse = await verificationSDK.verifyTransaction(txRef);
interface PaychanguConfig {
public_key: string;
tx_ref: string;
amount: number;
currency: string;
callback_url: string;
return_url: string;
customer: Customer;
customization: Customization;
meta?: Record<string, unknown>;
}
interface LevelConfig {
amount: number;
currency: string;
email: string;
first_name: string;
last_name: string;
callback_url: string;
return_url: string;
tx_ref: string;
customization?: {
title?: string;
description?: string;
};
meta?: Record<string, unknown>;
}
Generate a unique transaction reference:
const txRef = generateTxRef();
The SDK exports the following types for TypeScript users:
PaychanguConfig
LevelConfig
LevelResponse
VerificationResponse
Customer
Customization
import { PopupSDK, generateTxRef } from 'paychangu-js';
const config = {
public_key: 'your_public_key',
tx_ref: generateTxRef(),
amount: 1000,
currency: 'MWK',
callback_url: 'https://your-callback-url.com',
return_url: 'https://your-return-url.com',
customer: {
email: 'customer@example.com',
first_name: 'John',
last_name: 'Doe'
},
customization: {
title: 'Payment for Product X',
description: 'This is a test payment'
}
};
PopupSDK.initiate(config);
import { LevelSDK, generateTxRef } from 'paychangu-js';
const levelConfig = {
amount: 1000,
currency: 'MWK',
email: 'customer@example.com',
first_name: 'John',
last_name: 'Doe',
callback_url: 'https://your-callback-url.com',
return_url: 'https://your-return-url.com',
tx_ref: generateTxRef()
};
const response = await LevelSDK.makePayment(levelConfig);
console.log(response);
import { VerificationSDK } from 'paychangu-js';
const txRef = 'your_transaction_reference';
const verificationResponse = await VerificationSDK.verifyTransaction(txRef);
console.log(verificationResponse);
For support or questions, please contact our support team at dev@paychangu.com.