2.0.1 • Published 6 years ago

maksunappi v2.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

maksunappi

Build Status

A Node.js library for online payments in Finland. Includes test configurations for Nordea, DanskeBank, Handelsbanken, OP, Aktia, Ålandsbanken, S-Pankki, Säästöpankki and POP Pankki.

Currently requires Express.

About

Reaktor

From Reaktor with love.

Apply for juicy positions at reaktor.com/careers and prepare for The Culling.

Install

npm install maksunappi

Testing

Run tests with grunt.

Usage and configuration

Basic usage (using default configurations)

var generalOptions = {
  appHandler: app, // an Express application
  hostUrl: 'http://domain.here.com:port', // required for return URLs
  logger : logger //optional winston logger instance
};

var maksunappi = require('maksunappi').create(generalOptions);

Bank configuration

Changing configurations (code example)

var bankOptions = [
  {
    id : 'nordea',
    imgPath : '/path/to/my/image.png',
    vendorId : 'production id',
    checksumKey : 'production key'
  },
  {
    id : 'op',
    name: 'Osuuspankki',
    algorithmType: 'sha256'
  }
];

var maksunappi = require('maksunappi').create(generalOptions, bankOptions);

The following options can only be configured in this initial configuration phase (see "Bank configuration options" below for other options that can be configured either here on on a per-request basis):

  • id - identifier for the bank (this identifies the bank you are about to configure, see below for options)
  • paymentUrl - url for the online payments service
  • imgPath - path for the image used for the HTML form (or "button")
  • checksumKey - vendor specific key used in computing the MAC

Possible values for id are:

BankID
Aktiaaktia
Danskebankdanskebank
Handelsbankenhandelsbanken
Nordeanordea
Osuuspankkiop
POP Pankkipoppankki
S-Pankkispankki
Säästöpankkisaastopankki
Ålandsbankenalandsbanken

Configuration options with an unrecognized id are ignored.

Bank configuration options

The following table describes the different options you can use to configure banks. These options are then mapped to bank specific form fields. E.g paymentVersion is mapped to 'NET_VERSION' in Aktia's case and to 'VERSIO' in DanskeBank's.

Any of these options may be either set as general options for a bank in the initial configuration or overridden in button options on a per-request basis.

The library performs minimal checks on inputs. Required fields are checked but reference numbers and input lengths are generally not. Depending on the field and bank, not observing the length limits specified in bank specific interface specification documents may or may not have an effect on the success of the request. Failure to provide an input for a required field results in an exception.

M = mandatory, O = optional, - = not in use

FieldAktiaÅlandsbankenDanskebankHandelsbankenNordeaOsuuspankkiPOP PankkiS-PankkiSäästöpankki
paymentVersionMMMMMMMMM
requestIdMM-MMMMMM
vendorIdMMMMMMMMM
vendorAccount-M--O--M-
vendorName-M--O--M-
language-MO-O--M-
amountMMMMMMMMM
currencyMMMMMMMMM
referenceMMMMOMMMM
dueDateMMMMMOMMM
messageForBankStatement----OO---
confirmMM-MOOMMM
keyVersion-M--MM-M-
cookie-M-------
algorithmType--M------
mobile----O----
messageForWebFormOO-O-OOOO

Notice that Aktia and Handelsbanken share the same mandatory and optional fields.

Do remember to configure vendorName and vendorAccount for all banks which require them when not using the test credentials (vendorId, checksumKey)!

Input formatting

Option values should be in the following formats:

FieldFormatExampleNotes
paymentVersion(convertible to) integer3 / "3" / "003"Is automatically formatted to comply with bank specifications.
requestIdstring of numbers"201401301400391"Integer values are fine too (watch out for floating point precision problems).
vendorIdstring"TAPESHOPID" / "12345678"
vendorAccountstring"448710-126"
vendorNamestring"TESTIKAUPPA"
languageISO 693-1 (string)"FI" / "SV" / "EN"Note that some banks only support a subset of these languages ("FI"/"SV").
amountfloating point / integer25 / 50.5
currencystring"EUR"
referencestring"2014013014003919"See "Generating reference numbers" below.
dueDatestring / JavaScript Date"EXPRESS" / new Date()See "Additional notes" below
messageForBankStatementstringIs automatically split into rows according to bank specifications. The message may be clipped if too long. Message is shown in the bank statement
confirmbooleantrue / false
keyVersion(convertible to) integerSimilar to paymentVersion.
cookieboolean
algorithmTypestring'md5' / 'sha256''md5' is the default for most banks.
mobileboolean
messageForWebFormstringmessage is only shown to the buyer in the webform

Additional notes concerning due dates:

Always use either "EXPRESS" or a JavaScript Date object, not e.g. date strings. "EXPRESS" works with all banks (for DanskeBank, the library converts it into a date). Dates in the past are automatically converted into today's date.

Note that some banks (namely Ålandsbanken and S-Pankki) only allow EXPRESS payments.

Mapping to form fields

The following table describes the mapping from options to bank specific form fields, if you need to refer to the original specifications for help with parameters.

FieldAktiaÅlandsbankenDanskebankHandelsbankenNordeaOsuuspankkiPOP PankkiS-PankkiSäästöpankki
paymentVersionNET_VERSIONAAB_VERSIONVERSIONET_VERSIONSOLOPMT_VERSIONVERSIONET_VERSIONAAB_VERSIONNET_VERSION
requestIdNET_STAMPAAB_STAMP-NET_STAMPSOLOPMT_STAMPMAKSUTUNNUSNET_STAMPAAB_STAMPNET_STAMP
vendorIdNET_SELLER_IDAAB_RCV_IDKNRONET_SELLER_IDSOLOPMT_RCV_IDMYYJANET_SELLER_IDAAB_RCV_IDNET_SELLER_ID
vendorAccount-AAB_RCV_ACCOUNT--SOLOPMT_RCV_ACCOUNT--AAB_RCV_ACCOUNT-
vendorName-AAB_RCV_NAME--SOLOPMT_RCV_NAME--AAB_RCV_NAME-
language-AAB_LANGUAGElng-SOLOPMT_LANGUAGE--AAB_LANGUAGE-
amountNET_AMOUNTAAB_AMOUNTSUMMANET_AMOUNTSOLOPMT_AMOUNTSUMMANET_AMOUNTAAB_AMOUNTNET_AMOUNT
currencyNET_CURAAB_CURVALUUTTANET_CURSOLOPMT_CURVALUUTTALAJINET_CURAAB_CURNET_CUR
referenceNET_REFAAB_REFVIITENET_REFSOLOPMT_REFVIITENET_REFAAB_REFNET_REF
dueDateNET_DATEAAB_DATEERAPAIVANET_DATESOLOPMT_DATEERAPVMNET_DATEAAB_DATENET_DATE
messageForBankStatement----SOLOPMT_MSGVIEST1 / VIEST2---
confirmNET_CONFIRMAAB_CONFIRM-NET_CONFIRMSOLOPMT_CONFIRMVAHVISTUSNET_CONFIRMAAB_CONFIRMNET_CONFIRM
keyVersion-AAB_KEYVERS--SOLOPMT_KEYVERSTARKISTE-VERSIO-AAB_KEYVERS-
cookie-BC_UseBVCookie-------
algorithmType--ALG------
mobile----SOLOPMT_PMTTYPE----
messageForWebFormNET_MSGAAB_MSG-NET_MSG-VIESTINET_MSGAAB_MSGNET_MSG

Create payment HTML forms for configured banks

var requestId = "123456789876543";
var referenceNum = <generate reference here>; // see "Generating reference numbers" below
var options = {
                requestId: requestId,
                amount: 25,
                messageForBankStatement: "Lorem ipsum dolor sit amet...",
                reference: referenceNum,
                language: 'FI'
              };

var buttonHtml = maksunappi.paymentButton('nordea', options);

...or if you just want the request parameters without generating any HTML:

var params = maksunappi.buildRequestParams('nordea', options);

Generating reference numbers / check numbers

Finnish reference number:

var numericIdentifier = '1234556789'; // e.g. a timestamp + an id
var referenceNumber = maksunappi.referenceNumbers.toFinnishPaymentReference(numericIdentifier);

International RF reference number (might not be supported by all banks):

var referenceNumber = maksunappi.referenceNumbers.toRFReference(finnishReferenceNumber);

Usually if the bank requires both a requestId and a reference, you should use the requestId as the basis (numericIdentifier) for the reference number.

Get a listing of all configured banks (IDs)

var banks = maksunappi.banks
// => ['danskebank', 'handelsbanken', 'nordea',
//     'op', 'aktia', 'alandsbanken', 'spankki']

Response handling

The module binds paths /epayments/ok/<bank id> (GET and POST, for all bank ids), /epayments/cancel (only GET) and /epayments/reject (only GET) to the given Express app for use as return urls.

Response handling is event based.

maksunappi.on('success', function (request, response, data) {
  // Payment was successful and the customer returned to the site.
  // Normalized query data can be accessed in the data parameter.
  // Note: for many banks, the query string is empty unless the "confirm"
  // parameter is set to true.
});

maksunappi.on('mac-check-failed', function (request, response, data) {
  // Same as above but MAC check failed, so the data was faulty.
});

maksunappi.on('cancel', function (request, response) {
  // User cancelled the payment.
});

maksunappi.on('reject', function (request, response) {
  // The payment was rejected by the bank.
});

Normalized response data

The normalized query string data contains the following fields:

X = present, - = not present

FieldAktiaÅlandsbankenDanskebankHandelsbankenNordeaOsuuspankkiPOP PankkiS-PankkiSäästöpankki
versionXXXXXXXXX
requestIdXX-XXXXXX
referenceXXXXXXXXX
archivedIdXX-XXXXXX
macXXXXXXXXX
algorithmX--X--X-X
macVersion-----X---
currency--X------
vendorId--X------
dueDate--X------
paymentStatus--X------
paymentSum--X------
paymentMethod--X------

Version numbers (version, macVersion) are converted to integers in the normalized data.

Sample application

See sample/app.js for a simple usage example. Run the sample app locally with node sample/start-sample.js.

2.0.1

6 years ago

2.0.0

6 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

9 years ago

1.0.1

10 years ago

0.1.3

10 years ago

1.0.0

10 years ago

0.1.2

10 years ago

0.1.0

10 years ago