Skip to content

Communicate with Finnish banks using Web Services

License

Notifications You must be signed in to change notification settings

hyrsky/pankkiyhteys

Repository files navigation

Build Status

Pankkiyhteys

This library is an implementation of Web Services API, a standardised solution used for automated communications between banks and corporate customers.

Currently only Osuuspankki is supported.

For in depth technical documentation about Web Services click here.

Install

Install with npm:

  npm install pankkiyhteys

Usage

Autogenerated docs at: https://hyrsky.github.io/pankkiyhteys

Request certificate with transfer key

import { promises as fs } from "fs";

const client = new Osuuspankki('1234567890', undefined, 'FI')
const privateKey = await Key.generateKey();

await fs.writeFile(`private-key-${new Date().toISOString()}.key`, privateKey);

const cert = await client.getInitialCertificate(privateKey, "0123456789ABCDEF");

await fs.writeFile(`certificate-${new Date().toISOString()}.pem`, cert);

Renewing certificate

function isAboutToExpire(key) {
  const dateToCheck = new Date()
  dateToCheck.setMonth(dateToCheck.getMonth() + 2)
  return key.expires() < dateToCheck
}

const key = new Key(oldPrivateKey, oldCert)
const client = new Osuuspankki('1234567890', key, 'FI')

if (key.isAboutToExpire()) {
  /**
   * You have to:
   *   * generate new key.
   *   * save key to persistent storage before renewal.
   */
  const keys = await Key.generateKey()
  await writeFile('./newkey.pem', keys.privateKey)
  const certificate = await client.getCertificate(keys.privateKey)
  await writeFile('./newcert.pem', certificate)
}