npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

paychangu-ts

v1.0.0

Published

TypeScript library for PayChangu payment integration

Readme

PayChangu TypeScript Library

npm version

A TypeScript library for integrating with the PayChangu payment gateway, supporting online payments and mobile money transactions in Malawi.

Installation

npm install paychangu-ts --save

or using yarn:

yarn add paychangu-ts

Usage

Initialize the PayChangu Service

import { PaymentsService } from 'paychangu-ts';

const paymentsService = new PaymentsService({
  apiKey: 'your-api-key-here',
  // Optional: override the base URL
  // baseURL: 'https://api.paychangu.com'
});

Initiate a Payment

const initiatePayment = async () => {
  try {
    const response = await paymentsService.initiatePayment({
      amount: 1000,
      email: '[email protected]',
      first_name: 'John',
      last_name: 'Doe',
      description: 'Payment for order #123',
      callbackUrl: 'https://your-website.com/callback',
      returnUrl: 'https://your-website.com/thank-you'
    });
    
    console.log('Payment initiated:', response);
    console.log('Checkout URL:', response.data.link);
    
    // Redirect the user to the checkout page
    // window.location.href = response.data.link;
  } catch (error) {
    console.error('Payment initiation failed:', error);
  }
};

Verify a Payment

const verifyPayment = async (txRef) => {
  try {
    const response = await paymentsService.verifyPayment(txRef);
    console.log('Payment verification:', response);
    
    if (response.data.status === 'successful') {
      // Payment was successful
      console.log('Payment was successful!');
    } else {
      // Payment failed or is pending
      console.log('Payment status:', response.data.status);
    }
  } catch (error) {
    console.error('Payment verification failed:', error);
  }
};

Inline Checkout

Important Note: The PayChangu inline checkout has specific requirements and limitations:

  1. jQuery must be included on your page before the PayChangu script
  2. A container element must exist on the page for the checkout to append to
  3. If inline checkout fails, consider using standard checkout as a fallback
// 1. First include jQuery in your HTML
// <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

// 2. Make sure you have a container in your HTML
// <div id="paychangu-checkout-container"></div>

// 3. Generate the configuration for inline checkout
const checkoutConfig = paymentsService.generateInlineCheckoutConfig({
  amount: 500,
  currency: 'MWK',
  customer: {
    email: '[email protected]',
    first_name: 'John',
    last_name: 'Doe'
  },
  callback_url: 'https://example.com/webhook',
  return_url: 'https://example.com/return',
  customization: {
    title: 'Purchase',
    description: 'Purchase description'
  }
});

// 4. Load the script and use the checkout function
import { loadPayChanguCheckoutScript } from 'paychangu-ts';

async function initiateCheckout() {
  try {
    await loadPayChanguCheckoutScript();
    
    // Use the configuration with the PayChangu checkout function
    window.PaychanguCheckout(checkoutConfig);
  } catch (error) {
    console.error('Error with inline checkout:', error);
    
    // Fallback to standard checkout if inline fails
    const standardCheckoutResponse = await paymentsService.initiatePayment({
      // Same parameters as above...
    });
    
    // Redirect to the standard checkout URL
    window.location.href = standardCheckoutResponse.data.checkout_url;
  }
}

Initiate a Mobile Money Payout

Note: Mobile money functionality may not be fully operational in the current PayChangu API. The library includes these methods for future compatibility, but they may not work as expected at this time.

Test Mobile Numbers

For testing mobile money functionality, PayChangu provides these test mobile numbers:

| Provider | Mobile Number | Result | |----------|--------------|--------| | Airtel Money | 990000000 | SUCCESS | | Airtel Money | 990000001 | FAILED | | TNM Mpamba | 899817565 | SUCCESS | | TNM Mpamba | 899817566 | FAILED |

const initiatePayout = async () => {
  try {
    const response = await paymentsService.initiateMobileMoneyPayout({
      mobile: '899817565', // TNM Mpamba test number (SUCCESS)
      amount: 500
    });
    
    console.log('Payout initiated:', response);
  } catch (error) {
    console.error('Payout initiation failed:', error);
  }
};

API Reference

PaymentsService

The main class for interacting with the PayChangu API.

Constructor

new PaymentsService(config: PayChanguConfig)
  • config.apiKey (string, required): Your PayChangu API key
  • config.baseURL (string, optional): Override the default API base URL

Methods

initiatePayment(params: PaymentInitParams): Promise<PaymentResponse>

Initiates a payment transaction.

verifyPayment(txRef: string): Promise<PaymentVerificationResponse>

Verifies the status of a payment transaction.

initiateMobileMoneyPayout(params: MobileMoneyPayoutParams): Promise<MobileMoneyPayoutResponse>

Initiates a mobile money payout.

License

ISC