pesapal-hono
Version:
A lightweight Pesapal payment gateway integration using Hono.js
33 lines (32 loc) • 1.35 kB
JavaScript
// src/pesapal.ts
import { createAxiosInstance } from './utils/axios.js';
export class Pesapal {
config;
axiosInstance;
constructor(config) {
this.config = config;
this.axiosInstance = createAxiosInstance(config);
}
async getAuthToken() {
const response = await this.axiosInstance.post('/Auth/RequestToken', {
consumer_key: this.config.consumerKey,
consumer_secret: this.config.consumerSecret,
});
return response.data.token;
}
async registerIPN(data) {
const token = await this.getAuthToken();
const response = await this.axiosInstance.post('/URLSetup/RegisterIPN', data, { headers: { Authorization: `Bearer ${token}` } });
return response.data;
}
async submitOrder(data) {
const token = await this.getAuthToken();
const response = await this.axiosInstance.post('/Transactions/SubmitOrderRequest', data, { headers: { Authorization: `Bearer ${token}` } });
return response.data;
}
async getTransactionStatus(orderTrackingId) {
const token = await this.getAuthToken();
const response = await this.axiosInstance.get(`/Transactions/GetTransactionStatus?orderTrackingId=${orderTrackingId}`, { headers: { Authorization: `Bearer ${token}` } });
return response.data;
}
}