notchpay-client
v0.3.0-beta
Published
The notchpay javascript client for your saas
Readme
Notchpay API Client
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
- Node 12 or higher
- 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-client3. 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: "[email protected]",
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 paymentInitialize Payment (Legacy Method)
const legacyPaymentData = {
amount: 5000,
currency: "XAF",
description: "Payment for product/service",
email: "[email protected]",
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 paymentGet Payment Details
const paymentDetails = await notchpay.payments.get(transactionReference);
console.log(paymentDetails.transaction.status); // Check payment statusList All Payments
const payments = await notchpay.payments.getAll();
console.log(payments.items); // Array of payment transactions
console.log(payments.totals); // Total number of paymentsDirect Charge (Mobile Money)
// First create a payment
const paymentData = {
amount: 5000,
currency: "XAF",
description: "Mobile money payment",
customer: {
email: "[email protected]",
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 processingInitialize 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 processingRecipient Operations
Create a Recipient
const recipientData = {
email: "[email protected]",
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 recipientsWebhook operations
// CREATE
const webhook = await notchpay.webhooks.create({
url: 'https://example.com/webhooks',
events: [
NotchPayWebhookEventType.PAYMENT_COMPLETE,
NotchPayWebhookEventType.PAYMENT_FAILED
],
description: 'Payment notifications for my e-commerce site',
active: true
});
// LIST
const webhooks = await notchpay.webhooks.list(30, 1);
// RETRIEVE
const webhook = await notchpay.webhooks.retrieve('webhook_id');
// UPDATE
const updatedWebhook = await notchpay.webhooks.update('webhook_id', {
active: false,
events: [NotchPayWebhookEventType.PAYMENT_COMPLETE]
});
// DELETE
await client.webhooks.delete('webhook_id');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 Unauthorizederrors, check your API keys - For
422 Validationerrors, 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
