Skip to content

Repository files navigation

Accept Admin

Package for managing integration with the accept payment service provided by paymobsolutions for lack of an offical one.

Coverage StatusNSP Status

Getting Started

npm install accept-admin

Include your paymob accept credentials in a gitingnored .env or configuration file

// config.jsmodule.exports={credentials: {username: process.env.ACCEPT_USERNAME,password: process.env.ACCEPT_PASSWORD,expiration: 36000,},hmac_secret: process.env.ACCEPT_HMAC_SECRET,integration_id: process.env.ACCEPT_INTEGRATION_ID,host: "https://example.com/api",notification_callback_url: "/accept/notification",response_callback_url: "/accept/response",}

Import the accept admin instance and configure it

importAcceptAdminfrom"accept-admin"// or in node < 10 you can// const { Accept } = require("accept-admin")// const AcceptAdmin = require("accept-admin").defaultAcceptAdmin.config(ACCEPT_CONFIG)//... later in your codeawaitAcceptAdmin.pay({// credentials: ACCEPT_CREDENTIALS, // include if you want to pay having not called configuration prioramount: 20,source: {"identifier": "5123456789012346","sourceholder_name": "Test Account","subtype": "CARD","expiry_month": "05","expiry_year": "21","cvn": "123"}})

Package includes a router and middelware functions to deal with Hmac validation

one possible workflow with express

// app.jsconstexpress=require("express")const{ AcceptRouter }=require("accept-admin")// or// const { AcceptRouter } = require("accept-admin/lib/express_router")constapp=express()app.use(AcceptRouter({hmac_secret: process.env.ACCEPT_HMAC_SECRET,// or get from a config filenotificationEndpoint: '/accept/notifaction',// defaultresponseEndpoint: '/accept/response',// defaultonNotification(req,res){// if not set will default to simply responding with 200console.log("Notification",req.body)},onResponse(req,res){// if not set will default to simply responding with 200console.log("Response",req.query)return{message: "success"}// instead of res.status(200).send({ message: "success" })},}))

and when starting your server

// server.jsconstapp=require("./app")const{ Accept }=require("./accept-admin")constACCEPT_CONFIG=require("./config")Accept.config(ACCEPT_CONFIG)(async()=>{// get auth_token and assign it ot the instance // and set integration callback hooks to// integration.host + integration.response_callback_url as configuredawaitAccept.init()// then start appapp.listen(process.env.PORT,()=>console.log("server started"))})()

See tests for the rest of the available functions, like tokenization, refunding and voiding transactions

This package has partial coverage of the accept admin API but is mainly meant for manging payment and an tokanization of credit cards.

The package is maintianed by DREIDEV and is not an offical paymobsolutions/accept package

Licence MIT

About

A package for managing integration with accept payment service

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages