Notch Pay JavaScript sdk for easy payment integrations
npm install notchpay-apibash
npm install notchpay-api
`
Configurations
Configure your Notch Pay API keys easily either through environment variables or directly within your application.
`bash
export NOTCHPAY_PUBLIC_KEY=your_public_key
export NOTCHPAY_PRIVATE_KEY=your_private_key
`
Features
This package offers a comprehensive solution for seamlessly integrating Notch Pay APIs, covering essential functionalities grouped into distinct modules:
- Payment APIs: Streamline Notch Pay payment integration with a user-friendly TypeScript and JavaScript function call signature.
- Transfer APIs: Facilitate seamless transfer handling through Notch Pay with dedicated TypeScript and JavaScript functions, ensuring a smooth integration experience.
- MIscellaneous APIs: Access various Notch Pay functionalities effortlessly using TypeScript and JavaScript function call signatures, providing a unified and intuitive interface.
- Webhooks: Simplify webhook implementation with a single function call, enhancing developer efficiency in setup and management.
Usage
Integrating Notch Pay into your Node.js application is as easy as importing the NotchPay class and accessing the desired API functionalities:
`typescript
// Your application code
import { NotchPay, NotchPayConfig } from 'notchpay-api';
const notchPayConfig: NotchPayConfig = {
endpoint: 'api.notchpay.co',
publicKey: 'your_public_key',
secretKey: 'your_secret_key',
};
const notchPay = new NotchPay(notchPayConfig);
// Now, you can use the notchPay instance to make API requests
notchPay.payments
.initialize({
amount: 500,
currency: 'XAF',
phone: '+237691622731',
})
.then(response => {
// Handle the payment response
console.log(response);
})
.catch(error => {
// Handle errors
console.error(error);
});
`
$3
Handle notchpay webhooks event just by passing your callback handler to the desired event
`typescript
app.post('/webhooks', (req: Request, res: Response) => {
const completePaymentCallback = (eventId: string, data: any) => {
console.log(✔️ NotchPay completed payment event ${eventId} was received)
}
const failedPaymentCallback = (eventId: string, data: any) => {
console.log(✔️ NotchPay failed payment event ${eventId} was received)
}
return notchPay.webhooks.handleEvent(req, res, {
'payment.complete': completePaymentCallback,
'payment.failed': failedPaymentCallback,
})
})
`
Tests
To ensure the reliability of the library, run the included test suite with the following command:
`bash
npm test
``