UNPKG

daraja-pie

Version:

A simple JS API built on top of M-Pesa's daraja

22 lines (19 loc) 522 B
import axios from "axios"; import { SB_END_POINTS, LIVE_END_POINTS } from "./constants.js"; export async function getAccessToken() { const END_POINT = process.env.ENVIRONMENT == "production" ? LIVE_END_POINTS.GET_TOKEN : SB_END_POINTS.GET_TOKEN; const config = { headers: { Authorization: `Basic ${process.env.MPESA_CREDS}`, }, }; try { const { data } = await axios.get(END_POINT, config); return data; } catch (err) { throw new Error(err); } }