npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

accept-admin

v0.6.1

Published

A package for managing integration with accept payment service

Downloads

15

Readme

Accept Admin

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

Build Status Coverage Status NSP Status

Getting Started

npm install accept-admin

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

// config.js
module.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

import AcceptAdmin from "accept-admin"
// or in node < 10 you can
// const { Accept } = require("accept-admin")
// const AcceptAdmin = require("accept-admin").default

AcceptAdmin.config(ACCEPT_CONFIG)

//... later in your code

await AcceptAdmin.pay({
  // credentials: ACCEPT_CREDENTIALS, // include if you want to pay having not called configuration prior
  amount: 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.js
const express = require("express")
const { AcceptRouter } = require("accept-admin")
// or
// const { AcceptRouter } = require("accept-admin/lib/express_router")

const app = express()

app.use(AcceptRouter({
  hmac_secret: process.env.ACCEPT_HMAC_SECRET, // or get from a config file
  notificationEndpoint: '/accept/notifaction', // default
  responseEndpoint: '/accept/response', // default
  onNotification(req, res) { // if not set will default to simply responding with 200
    console.log("Notification", req.body)
  },
  onResponse(req, res) { // if not set will default to simply responding with 200
    console.log("Response", req.query)
    return { message: "success" } // instead of res.status(200).send({ message: "success" })
  },
}))

and when starting your server

// server.js
const app = require("./app")
const { Accept } = require("./accept-admin")
const ACCEPT_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 configured
  await Accept.init()
  // then start app
  app.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