tranxs
Version:
Tranxs is a powerful and easy-to-use Node.js library for integrating M-Pesa payment services into your application. It provides seamless support for all major M-Pesa transactions, including STK Push, B2C, B2B, C2B, Reversal, Account Balance, and Transacti
44 lines • 1.53 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AirtelMoney = void 0;
const axios_1 = __importDefault(require("axios"));
class AirtelMoney {
credentials;
environment;
baseURL;
constructor(credentials, environment = "sandbox") {
this.credentials = credentials;
this.environment = environment;
this.baseURL =
this.environment === "production"
? "https://openapi.airtel.africa"
: "https://openapiuat.airtel.africa";
}
async generateAuthToken() {
try {
const response = await axios_1.default.post(`${this.baseURL}/auth/oauth2/token`, {
client_id: this.credentials.clientId,
client_secret: this.credentials.clientSecretKey,
grant_type: "client_credentials",
}, {
headers: {
"Content-Type": "application/json",
Accept: "*/*",
},
});
return response.data.access_token;
}
catch (error) {
console.error("Tranx Error:", error.response ? error.response.data : error.message);
}
return null;
}
async USSDPush() {
console.log(this.generateAuthToken());
}
}
exports.AirtelMoney = AirtelMoney;
//# sourceMappingURL=AirtelMoney.js.map