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

ipizza

v0.3.0

Published

Node.js implementation for Estonian(and some other) banklink payments.

Downloads

5

Readme

Build Status

What?

Node.js module for payment processing with Estonian (and other iPizza based) banks. It currently supports Swedbank, SEB, Sampo, Krediidipank, LHV, Nordea and Estcard. Testing is provided by awesome Pangalink.net service.

###Install

npm install ipizza

Run tests:

npm test
node casperjs/runner.js       # requires CasperJS

Sample:

node sample/sample_express.js
node sample/sample_http.js

Basic usage

var ipizza = require('ipizza')

Setup

// General options.
ipizza.set({
  hostname: 'http://my.domain.com:4000' // used in return URL.
, appHandler: app //if you use Express.
, logLevel: 'verbose'
, env: 'development'
})

// Common options for providers(banks).
ipizza.provider({
  provider: 'swedbank'
, clientId: 'uid202196'
, privateKey: 'keys/swedbank.key.pem'
, certificate: 'keys/swedbank.cert.pem'
}

Making a payment.

var payment = ipizza.payment({
  provider: 'swedbank'
, id: 10
, msg: 'Stuff'
, amount: 8.99
})

// Pipe into response. Redirects to bank site.
payment.pipe(resp)

// or get raw values
var params = payment.json()
var gateway = payment.get('gateway')

// or just get the HTML form
var html = payment.html()

Response handling

Note that after success event you also have to check that the amount matches the Order ID/Reference number based on your stored request data. If you don't do this payment response could potentially be faked.

ipizza.on('success', function (reply, req, resp) {
  /*
  reply:
    { transactionId: '1602',
      amount: 2.95,
      curr: 'EUR',
      receiver: '10002050618003',
      receiverName: 'ALLAS ALLAR',
      sender: '10010046155012',
      senderName: 'TÕÄGER Leõpäöld¸´¨¦',
      date: '16.09.2012',
      provider: 'seb',
      bankId: 'EYP',
      clientId: 'testvpos',
      id: '123',
      ref: '',
      msg: 'Goods üÜõÕöÖäÄ',
      lang: 'ENG',
      isAuto: false }
  */
})

ipizza.on('error', function (reply, req, resp) {
  /*
  reply:
    { type: 'not paid',
      provider: 'seb',
      bankId: 'EYP',
      clientId: 'testvpos',
      id: '123',
      ref: '',
      msg: 'Goods üÜõÕöÖäÄ',
      lang: 'ENG',
      isAuto: false }
    { type: 'not verified',
      provider: 'seb' }
  */
})

ipizza.get(key), ipizza.set(key, value)

Supported syntax:

// Support both camelCase and spaced keys.
ipizza.get('logLevel')
ipizza.get('log level')
ipizza.set('logLevel', 'info')
ipizza.set('log level', 'info')
// and objects.
ipizza.set({logLevel: 'info', env: 'production'})

Options:

  • appHandler - Middleware for automatic response handling. If you use Express you can set it to your application instance. Otherwise it returns a function that you can use as a middleware.
  • env - Environment mode. (Usually) development or production. This is used for getting the right gateway URL and you should use it for specifying different configurations. Default: $NODE_ENV.
  • hostname - Base URL that is used when creating return URLs. Should point to your server from network.
  • logLevel - Log level. Options: silly, verbose, info, warn, error. Default: info.
  • logStream - Log stream. Default: stdout.
  • returnRoute - Route that is used in automatic response handling. You can optionally specify provider position with :provider. Defaults to /api/payment/response/:provider.
  • throwOnErrors - Should ipizza throw on error cases? Default: true.

ipizza.provider([provider], opt)

Used to set common properties(like keys) for a specific provider. These can be overwritten with ipizza.payment().

Supported syntax:

// With a provider name key.
ipizza.provider('swedbank', {
  clientId: 'uid202196'
, privateKey: __dirname + '/keys/swedbank.key.pem'
, certificate: __dirname + '/keys/swedbank.cert.pem'
}

// With option block only.
ipizza.provider({
  provider: 'swedbank'
, clientId: 'uid202196'
, privateKey: __dirname + '/keys/swedbank.key.pem'
, certificate: __dirname + '/keys/swedbank.cert.pem'
}

// Array of providers.
ipizza.provider(
  [ { provider: 'swedbank'
    , clientId: 'uid202196'
    , privateKey: __dirname + '/keys/swedbank.key.pem'
    , certificate: __dirname + '/keys/swedbank.cert.pem'
    }
  , { provider: 'seb'
    , clientId: 'uid203519'
    , privateKey: __dirname + '/keys/seb.key.pem'
    , certificate: __dirname + '/keys/seb.cert.pem'
    }
  ]);

Options:

  • alias - Clone a provider with specified name. Useful when you need to use different configurations for same payment gateway.
  • all options for ipizza.payment().

ipizza.payment([provider], opt)

// With a provider name key.
var p = ipizza.payment('swedbank', {
  id: 123
, amount: 3.99
})

// With option block only.
var p = ipizza.payment({
  provider: 'swedbank'
, id: 123
, amount: 3.99
})

Options:

  • provider - Bank name.

  • clientId - Merchant ID. Usually VK_SND_ID.

  • privateKey - Merchant private key file. This can be path, buffer of string contents of the key.

  • certificate - Bank public certificate file. This can be path, buffer of string contents of the key.

  • mac - Password used for Nordea.

  • algorithm - Algoritm used for Nordea. SHA1, SHA256 or MD5. Default: SHA1.

  • id - Order ID.

  • amount - Amount to pay.

  • ref - Order refernce number. Optional.

  • msg - Payment message.

  • curr - Currency. Default: EUR.

  • lang - Language for bank interface. Default: ENG.

  • encoding - Encoding used. UTF-8 or ISO-8859-1. Only used when supported by provider. Default: UTF-8.

  • account - Receiver account number. Optional.

  • accountName - Receiver name. Optional.

  • gateway - URL for the provider gateway. Optional. Automatically based on environment.

  • return - Return URL sent to the bank. Optional. Automatically generated based on returnRoute.

Methods:

  • pipe(response) - Redirect payment directly to the response object. Client that made the request is automatically sent to the bank's website. Note that payment is not really a stream (you can't listen data events on it) and this is just a syntactic sugar.
  • json() - Return object with raw parameters that should be sent to the bank. Including calculated MAC values.
  • html() - Return HTML form with all payment info filled in that posts to bank website.
  • set(key, value), get(key) - Getter/setters for overwriting options.

Automatic response handling

This module will automatically make return URLs and set up listeners for matching routes. You can change the format of that route by changing the returnRoute option.

To connect it to your server you need to include the middleware function that you get from appHandler option.

var f = ipizza.get('appHandler')
// Returns: function(request, response, next) {...}

app.use(f)

If you use Express you can just set the application instance as appHandler.

var app = express()
ipizza.set('appHandler', app)

Manual response handling

If you don't like automatic response handling you can do it all manually. When making a payment you need to set the return option that is then sent to bank as RETURN_URL.

It's up to you then to have something listening on that URL. When you have captured a request from bank you need to call ipizza.response(provider, request, response) to verify the request and dispatch success and error events.

Error handling

By default ipizza throws on errors. That is correct behaviour as the API is synchronous. If you don't like it in your production environment you can disable it by calling ipizza.set('throwOnErrors', false). Still, if your not sure if your data can produce errors you should put the function calls inside a try/catch block or set up a domain. Chances are, your own code will throw if it doesn't get any reasonable data back because of an error.

Contributing

This repo uses npm coding style.