Skip to content

niho/bankgirot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bankgirot

Generate payment files for Bankgirot.

What is Bankgirot?

Bankgirot is a Swedish automated clearing house (ACH) for batch processing of high volume domestic low value payments. It facilitates credit and direct debit transfers between Swedish bank accounts. It is commonly used for things like payroll, vendor payments, consumer payments (such as utility bills, insurance premiums, etc.).

How does Bankgirot work?

Bankgirot uses simple payment files that batches together a group of payments. The payment file is generated by the payment initiator, signed with a digital signature and then uploaded to Bankgirot, typically using SFTP. Bankgirot will then clear the payments described in the file on regular intervals throughout the day. There are multiple ways that the actual transfer of funds can happen. It can for example be a direct transfer between accounts, which is the most common and convenient method. It can also be done by mailing a cheque through ordinary postal service. The reciever can then withdraw the money at a postal office, convenience store or supermarket.

Technical documentation

Example usage (in Typescript)

import * as fs from "fs";
import * as bankgirot from "bankgirot";

const customerNumber = "123456";
const secretKey = "1234567890ABCDEF1234567890ABCDEF";
const keyDate = new Date("2019-02-18");

// The Seal object creates the tamper proof electronic seal (HMAC) that
// protects the file while in transit.
const seal = new bankgirot.Seal(
  bankgirot.HashType.HMAC_SHA_256,
  keyDate,
  secretKey
);

// A list of Payment objects. Each payment specifies a destination Bankgiro
// account number, an OCR reference number, the amount in SEK, and an optional
// payment date and text message.
const payments = [
  new bankgirot.Payment("123-4567", "99991234567890001", 1000),
  new bankgirot.Payment("123-8901", "99991234567890002", 1230)
];

// Payment lists are grouped into Order objects. Each order specifies a source
// account and a list of payments from that account. The order object can also
// override the payment date on its contained payments, as well as specify a
// longer text message to include on all payment specifications sent as part of
// the order.
const orders = [new bankgirot.Order("999-1234", payments)];

// Multiple orders are grouped together in a File object. A file is a Readable stream and can be piped to a Writeable destination (like a file, stdout or a socket). A file also has a specific filename given by the `filename` property.
const file = new bankgirot.File(customerNumber, seal, orders);

// Write the file to the file system (in the current directory).
file.pipe(fs.createWriteStream(file.filename));

Payroll och direct payments

The example above shows a normal payment between one Bankgiro account and another. But Bankgirot also supports payments directly to all Swedish bank accounts, as well as payment by cheque if the receiver does not have a bank account or the account number is unknown. Direct deposit and cheque payments are commonly used for payroll payments to individuals.

You can create direct deposit and cheque payments by using the bankgirot.PaymentCheque and bankgirot.PaymentDeposit classes.

const payments = [
  new bankgirot.PaymentCheque(
    1, // This is a unique serial number for this payment receiver.
    "John Doe", // Name of the receiver.
    {
      street: "Sveavägen 1",
      postalCode: "100 21",
      city: "Stockholm"
    },
    "99991234567890001", // OCR reference
    1000 // Amount
  ),
  new bankgirot.PaymentDeposit(
    1, // Serial number. It is important that these are unique per receiver.
    "1234", // Clearing number for the bank.
    "9988776655", // Bank account number.
    "99991234567890001", // OCR reference
    1000, // Amount
    "Hello" // A message shown on the receivers account statement.
  )
];

Getting started

make          # Build the project and run tests
make format   # Format code according to style guide
make test     # Run tests