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

node-otpbank

v2.0.1

Published

Hungarian OTP Bank easy-to-integrate Node payment module, demo app included.

Downloads

26

Readme

node-otpbank

Hungarian OTP Bank easy-to-integrate Node payment module, demo app included.

Demo online

Available at: https://frozen-ravine-69013.herokuapp.com/app/

Features

  • Three-party Scheme: your app redirects to OTP Bank's site where you can enter the card information. After verification, OTP Bank redirects the user back to your app.

Requirements

  • Node 4+

Install

npm install node-otpbank -S

Usage

Setup

const { Otpbank } = require('node-otpbank');
const otpbank = new Otpbank(yourPosId, yourPrivateKey);

In your transaction starter endpoint

const amount = req.body.amount;

// you can create your own logic, but the library ships with a default
const transactionId = Otpbank.generateTransactionId();

// this will be the OTP Bank's URL, where the client must navigate
const redirectUrl = otpbank.getOtpRedirectUrl(transactionId);

// return the URL
// this is an early response as the startWorkflowSynch method resolves only when
// the user completes the payment form on OTP Bank's website
res.send(redirectUrl);

// this will be called by OTP Bank after they verified your payment
const callbackUrl = `http://yourwebshop.com/app?transaction=${transactionId}`;

// initiates a SOAP message to OTP Bank
otpbank.startTransaction(
  transactionId,
  callbackUrl,
  amount,
  'HUF',
  `A shop comment which will appear on the OTP Bank's site`
)
  .then((result) => /* transaction started, yay */)
  .catch((error) => /* there was a problem with the request */);

In your redirect endpoint (where the transaction is checked)

// After redirection to the site of the merchant
otpbank.getTransaction(transactionId)
  .then((result) => /* get payment data, yay */)
  .catch((error) => /* cannot get payment data */);

API

Otpbank class

This is the Otpbank export of the module.

static generateTransactionId()

Returns a unique ID, that can be passed to the payment method.

The transaction ID must be exactly 32 characters long. This method creates an Object ID (using bson package) and concats enough random bytes in order to reach the 32 characters length.

This is the default strategy and can be ignored, so you can ship your own ID generation algorithm.

getOtpRedirectUrl(transactionId: string)

Returns a URL which will redirect the user to the OTP Bank's website. This URL contains the POS ID (which is received when making a contract with OTP), and the current transaction ID.

startTransaction(transactionId: string, callbackUrl: string, amount: number, currency: string, shopComment: string, optionals?: { consumerRegistrationId: string } = { consumerRegistrationId: '' })

Creates a SOAP request to the OTP Bank's payment server. If succeeded, the transaction just started. You may now redirect the customer to the payment site.

getTransaction(transactionId: string)

Creates a SOAP request to the OTP Bank's payment server. If succeeded, the state of the transaction was retrieved by the request.

Demo

The lib ships with a demo application. When running npm start an Express backend initializes, and a small frontend opens in your default browser.

In the demo app you can enter an arbitrary amount and click the Pay button. This will initiate a request to the OTP Bank's website through the Express backend.

When at the OTP Bank's website, you can fill out the payment form by using the dummy card data provided by OTP Bank on their website. These card informations can be seen on the console when the Express backend initializes.

After the payment form is submitted, the bank redirects the user to the frontend, where details can be seen about the transaction.

The sequence diagram of the demo flow:

Alt Sequence diagram

Notes

All used resources (always-working & always-failing bank card infos, dummy private keys, dummy POS number, documentations) are available at the OTP Bank website.

In order to integrate OTP Bank's payment system, you must first make a contract with OTP, then you will receive your own POS number, which can be configured through the module.

Improvements

  • Implement two-party scheme
  • Add tests

Development notes

  • Upon master commit, the Heroku app will automatically redeploy itself with the newest changes.
  • Upon master commit, TravisCI will publish the package to NPM.