Gathering detailed insights and metrics for pesapal3-sdk
Gathering detailed insights and metrics for pesapal3-sdk
Gathering detailed insights and metrics for pesapal3-sdk
Gathering detailed insights and metrics for pesapal3-sdk
npm install pesapal3-sdk
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A Node.js library for integrating PesaPal payment services into your applications. It provides a comprehensive, type-safe interface for payment-related operations
This project connects to the PesaPal API to handle payments. Here’s what it does:
The project relies on several important packages:
axios
: Used to send HTTP requests.axios-mock-adapter
: Helps in testing by mocking requests.log4js
: Used for logging messages.tracer
: Assists with debugging.supertest
and vitest
.The application logs important information using log4js
. You can find these logs in the pesapal.log
file, which helps in debugging issues.
Make sure to set up your IPN URL in your PesaPal account settings so that the application can receive payment notifications.
with npm
1npm install pesapal3-sdk
with yarn
1yarn add pesapal3-sdk
1import { initialisePesapal, Iconfig, IpayDetails } from "pesapal3-sdk"; 2 3// this credentials are from your PesaPal account, login or register here: https://pesapal.com/ 4const config: Iconfig = { 5 PESAPAL_ENVIRONMENT: "live", // or "sandbox" 6 PESAPAL_CONSUMER_KEY: "your-consumer-key", 7 PESAPAL_CONSUMER_SECRET: "your-consumer-secret", 8 PESAPAL_IPN_URL: "https://yourserverdomain/pesapal/ipn", 9}; 10 11const paymentInstance = initialisePesapal(config); 12 13const details: IpayDetails = { 14 amount: 1000, 15 currency: "USD", 16 description: "This is a test payment", 17 // ...other_details 18}; 19 20const ordered = await paymentInstance.submitOrder( 21 details, 22 "ProductId", 23 "description" 24); 25 26if (ordered.success) { 27 console.log(ordered.response); 28} else { 29 console.error(ordered.error); 30} 31 32// Handle IPN callback, this is the endpoint that PesaPal will call when a payment is completed and must be registered in your PesaPal account 33// for express.js 34app.get("/ipn", async (req, res) => { 35 const currntUrl = new URL(req.url); 36 const searchParams = currntUrl.searchParams; 37 38 const orderTrackingId = searchParams.get("OrderTrackingId") as string; 39 const orderNotificationType = searchParams.get( 40 "OrderNotificationType" 41 ) as string; 42 const orderMerchantReference = searchParams.get( 43 "OrderMerchantReference" 44 ) as string; 45 46 if (!paymentInstance) { 47 // choose how to handle this error 48 // may be just return a response 49 return res 50 .status(500) 51 .send({ success: false, err: "internal server error or something else" }); 52 } 53 54 const response = await paymentInstance.getTransactionStatus(orderTrackingId); 55 return response; 56});
Complete documentation is available on PESAPAL3.
pesapal3-sdk is licensed under the MIT License.
No vulnerabilities found.
No security vulnerabilities found.