This is the official TypeScript SDK for integrating with the Airtel API.
- Create a Airtel money developer account: https://developers.airtel.africa/user/signup
- Get your client id and client secret from the developer portal.
- If using the disbursements API, you will need to generate a public key and a PIN from the developer portal.
npm install @osenco/airtelyarn add @osenco/airtelpnpm add @osenco/airtelbun add @osenco/airtelimport { Airtel } from '@osenco/airtel';
const client_id =""
const client_secret = ""
const country = "KE"
const currency = "KES"
const env = "live"
const pin = ""
const public_key = ""const airtel = new Airtel(client_id, client_secret, country, currency, env);const airtel = new Airtel(client_id, client_secret, country, currency, env, pin, public_key);Use the authorize method to generate a token. The token is valid for 1 hour.
await airtel.authorize();Use the prompt method to send a USSD push to a customer to complete the payment by entering their PIN.
try {
const amount = 1000;
const reference = '1234567890';
const phone = '254732345678';
airtel.authorize().then(({ prompt }) => {
const res = prompt(phone, amount, reference)
console.info(res);
})
// OR
await airtel.authorize();
const res = await airtel.prompt(phone, amount, reference);
console.info(res);
} catch (error) {
console.error(error);
}