paychangu-js
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

PayChangu JavaScript SDK

The official JavaScript SDK for integrating PayChangu payment gateway into your web applications.

Installation

Install the package using npm:

npm install paychangu-js

Or using yarn:

yarn add paychangu-js

Usage

Import the necessary modules from the SDK:

import { PopupSDK, LevelSDK, VerificationSDK, generateTxRef } from 'paychangu-js';

Features

Popup SDK

The Popup SDK allows you to integrate an inline popup payment flow.

const popupSDK = PopupSDK;

// Configure and initiate the popup
popupSDK.initiate(config);

Level SDK

The Level SDK provides functionality for level-based payments.

const levelSDK = LevelSDK;

// Make a level-based payment
const response = await levelSDK.makePayment(levelConfig);

Verification SDK

The Verification SDK allows you to verify transactions.

const verificationSDK = VerificationSDK;

// Verify a transaction
const verificationResponse = await verificationSDK.verifyTransaction(txRef);

Configuration

PaychanguConfig

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>;
}

LevelConfig

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>;
}

Helper Functions

generateTxRef

Generate a unique transaction reference:

const txRef = generateTxRef();

Types

The SDK exports the following types for TypeScript users:

  • PaychanguConfig
  • LevelConfig
  • LevelResponse
  • VerificationResponse
  • Customer
  • Customization

Examples

Initiating a Popup Payment

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);

Making a Level-based Payment

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);

Verifying a Transaction

import { VerificationSDK } from 'paychangu-js';

const txRef = 'your_transaction_reference';
const verificationResponse = await VerificationSDK.verifyTransaction(txRef);
console.log(verificationResponse);

Support

For support or questions, please contact our support team at dev@paychangu.com.

Package Sidebar

Install

npm i paychangu-js

Weekly Downloads

5

Version

2.1.2

License

MIT

Unpacked Size

22.2 kB

Total Files

22

Last publish

Collaborators

  • paychangu