2.1.1 • Published 9 months ago

paychangu v2.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

paychangu

A Node.js service for interacting with the PayChangu API, enabling payments and mobile money payouts in Malawi.

Table of Contents

Introduction

paychangu provides a simple interface for integrating with the PayChangu API, allowing for payment processing and mobile money payouts specifically in Malawi. This service helps developers easily connect to PayChangu's payment solutions, supporting both payment initiation and verification, as well as mobile money transfers.

Installation

To install the package, run:

npm install paychangu

Usage

Initialization

To start using paychangu, import the service and initialize it with your API credentials:

const PaymentsService = require('paychangu');

const paymentService = new PaymentsService({
  apiKey: 'YOUR_API_KEY', // Replace with your actual API key
  baseURL: 'https://api.paychangu.com', // Optional, defaults to this URL
});

Methods

initiatePayment

Initiates a payment transaction.

await paymentService.initiatePayment({
  amount: 1000,             // Amount in MWK
  email: 'user@example.com', // Payer's email address(Optional)
  first_name,         // Payer's first name(Optional)
  last_name,         // Payer's last name (Optional)
  description: 'Test Payment', // Description of the payment
  callbackUrl: 'https://your-callback-url.com', // URL for payment completion callback
  returnUrl: 'https://your-return-url.com',     // URL to redirect after payment
});

This method returns a response with details about the initiated payment.

verifyPayment

Verifies the status of a payment using its transaction reference.

await paymentService.verifyPayment(txRef);

Parameters:

  • txRef (string): Transaction reference of the payment.

This method returns the payment verification details.

initiateMobileMoneyPayout

Initiates a payout to a mobile money account.

await paymentService.initiateMobileMoneyPayout({
  mobile: '801234567', // Mobile number to receive payout
  amount: 500,         // Amount to payout in MWK
});

This method returns a response with details about the initiated payout.

Error Handling

Each method throws an error if the API call fails. The error includes a message to assist with debugging.

Examples

Here's an example of initiating a payment:

try {
  const paymentResponse = await paymentService.initiatePayment({
    amount: 1000,
    first_name:'Roberto',
    last_name:'Bitah',
    email: 'user@example.com',
    description: 'Sample Payment',
    callbackUrl: 'https://your-callback-url.com',
    returnUrl: 'https://your-return-url.com',
  });
  console.log('Payment initiated:', paymentResponse);
} catch (error) {
  console.error('Error initiating payment:', error.message);
}

License

This project is licensed under the MIT License.

2.1.1

9 months ago

1.1.1

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago