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
- Node 12 or higher
- NotchPay API Keys
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
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.
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
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
const paymentDetails = await notchpay.payments.get(transactionReference);
console.log(paymentDetails.transaction.status); // Check payment status
const payments = await notchpay.payments.getAll();
console.log(payments.items); // Array of payment transactions
console.log(payments.totals); // Total number of payments
// 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
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
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);
const recipients = await notchpay.recipients.getAll();
console.log(recipients.items); // Array of recipients
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.
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
});
By contributing to this library, you agree that your contributions may be placed under the MIT license. Copyright (c) Notchpay Sarl.
See CHANGELOG.md for details of changes in each release.
Made with 😍 by Daniel Leussa