Logo Lanfrica

papakowdadson/dadson-momo-stk

Domaine:

digital infrastructure

Type de record:

software
Créateur:
pap
Hôte:
Software toolkit for momo payment in Ghana # dadson-momo-stk A simple Mobile money toolkit with reusable middleware and utilities for Express applications. ## Table of Contents - Installation - Usage - Middleware - createAccessToken - initializePayment - verifyPayment - Utilities - logger - Routes - License ## Installation To install this toolkit, you can use npm: ```sh npm install @papakowdadson/dadson-momo-stk ``` ## USAGE Here’s an example of how to use the toolkit in an Express application-MVC: - Create a .env file with the PORT value //Sample .env ```sh PORT=5000 MTN_BASE_URL_SANDBOX=sandbox.momodeveloper.mtn.c… // Textbed URL MTN_BASIC_AUTH=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX MTN_BASE_URL=proxy.momoapi.mtn.com // Production url MTN_OCP_COLLECTION_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ``` - Create index.js file ```sh //Sample index.js const express = require("express"); const cors = require("cors"); const app = express(); const { urlencoded } = require("express"); const dotenv = require("dotenv"); dotenv.config(); const port = process.env.PORT; const paymentRoute = require("./routes/paymentroute"); app.use(cors()); app.options("*", cors()); app.use(express.json()); app.use(urlencoded({ extended: true })); app.use("/@your url/payment", paymentRoute);//sample route, change to any route of your choice app.listen(port, () => { console.log(`server is running on ${port}`); }); ``` - Create Route file - Create Controller file ## Middleware createAccessToken Generates access token for each request from `MTN_BASIC_AUTH`. Call this method to generate access token before making any request.It accepts a callback function. Usage Example ```sh const mtnMomo = require('dadson-momo-stk'); const _Momo = mtnMomo(process.env.MTN_BASIC_AUTH,process.env.MTN_OCP_COLLECTION_KEY); const { createAccessToken } = _Momo; const GenerateAccessToken = (req, res, next) => { console.log("====creating access token===="); createAccessToken((error, body) => { if (body) { const _body = JSON.parse( …