Skip to content

notchpay/notchpay-client

 
 

Repository files navigation

Notchpay API Client

NPM Version NPM Downloads NPM License

Introduction

This JavaScript library simplifies the integration with NotchPay API in your JavaScript applications. It handles the complexity of direct API integration, enabling quick and efficient API calls.

Available functionalities include:

  • Payments (Mobile Money, Direct Charges)
  • Recipients
  • Account Management

Table of Content

  1. Requirements
  2. Installation
  3. Initialization
  4. Usage
  5. Support
  6. Debugging Errors
  7. License
  8. Changelog

1. Requirements

  1. Node 12 or higher
  2. NotchPay API Keys

2. Installation

To install the package, run the following command:

# Using npm
npm install notchpay-client@latest

# Using yarn
yarn add notchpay-client

# Using pnpm
pnpm add notchpay-client

3. Initialization

import { NotchpayClient } from 'notchpay-client';

const notchpay = new NotchpayClient({
    publicKey: 'YOUR_PUBLIC_KEY',
    privateKey: 'YOUR_PRIVATE_KEY', // optional
    hashKey: 'YOUR_HASH_KEY', // optional
    debug: true // Set to false in production
});

For testing, use the Sandbox Public Keys. For production, use Live Public Keys. You can obtain your API keys from the NotchPay dashboard: https://business.notchpay.co/developer/api-keys.

4. Usage

Payment Operations

Create Payment (Modern Method)

const paymentData = {
  amount: 5000,
  currency: "XAF",
  description: "Payment for product/service",
  customer: {
    email: "customer@example.com",
    name: "Customer Name",
    phone: "+237600000000" // optional
  }
};

const response = await notchpay.payments.create(paymentData);

console.log(response.transaction.reference); // Save this reference for future operations
console.log(response.authorization_url); // Redirect user to this URL to complete payment

Initialize Payment (Legacy Method)

const legacyPaymentData = {
  amount: 5000,
  currency: "XAF",
  description: "Payment for product/service",
  email: "customer@example.com",
  callback: "https://your-website.com/callback" // URL to redirect after payment
};

const response = await notchpay.payments.initialize(legacyPaymentData);

console.log(response.transaction.reference); // Save this reference for future operations
console.log(response.authorization_url); // Redirect user to this URL to complete payment

Get Payment Details

const paymentDetails = await notchpay.payments.get(transactionReference);

console.log(paymentDetails.transaction.status); // Check payment status

List All Payments

const payments = await notchpay.payments.getAll();

console.log(payments.items); // Array of payment transactions
console.log(payments.totals); // Total number of payments

Direct Charge (Mobile Money)

// First create a payment
const paymentData = {
  amount: 5000,
  currency: "XAF",
  description: "Mobile money payment",
  customer: {
    email: "customer@example.com",
    name: "Customer Name"
  }
};
const response = await notchpay.payments.create(paymentData);

// Then charge directly with mobile money
const chargeData = {
  channel: NotchPayChannel.MOBILE, // or NotchPayChannel.MTN, NotchPayChannel.ORANGE
  data: {
    phone: "+237600000000" // Customer's mobile money number
  }
};
const chargeResponse = await notchpay.payments.directCharge(
  response.transaction.reference,
  chargeData
);

console.log(chargeResponse.code); // 202 indicates successful processing

Initialize Mobile Money Payment (Convenience Method)

You can also initiate a mobile money payment in one step:

const response = await notchpay.payments.initializeMobileMoneyPayment(
  paymentData,
  "+237600000000", // Phone number for mobile money
  NotchPayChannel.MOBILE // or specific provider: NotchPayChannel.MTN, NotchPayChannel.ORANGE
);

console.log(response.code); // 202 indicates successful processing

Recipient Operations

Create a Recipient

const recipientData = {
  email: "recipient@example.com",
  name: "Recipient Name",
  channel: NotchPayChannel.MOBILE,
  country: "CM",
  number: "+237600000000",
  description: "Vendor payment recipient"
};

const response = await notchpay.recipients.create(recipientData);

List All Recipients

const recipients = await notchpay.recipients.getAll();

console.log(recipients.items); // Array of recipients

5. Support

For additional help with using this library, contact the technical team via email or on Telegram. You can also follow us on Twitter and provide feedback.

6. Debugging Errors

When integrating, you may encounter various errors:

  • For 401 Unauthorized errors, check your API keys
  • For 422 Validation errors, check the request parameters
  • For server errors, contact our support team

Enable debug mode during development to see detailed error information:

const notchpay = new NotchpayClient({
    // ...other options
    debug: true
});

7. License

By contributing to this library, you agree that your contributions may be placed under the MIT license. Copyright (c) Notchpay Sarl.

8. Changelog

See CHANGELOG.md for details of changes in each release.

Made with 😍 by Daniel Leussa

About

The notchpay javascript client for your saas

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%