Create SEPA XML for business transactions
npm install sepaWelcome to sepa.js
==================
This library can be used to generate the XML structure used
for SEPA payment
transfers. It is currently in its early stages and mostly geared towards German
batched direct debit transactions.
It will work in the browser or using node.js. To use it in the browser, just
include it via script-tag and access through the SEPA variable. There are a
few examples below.
You can also try the live online generator.
If you are worried about account number safety, be assured that everything is
calculated client side. Check the source code if you don't trust me.
If you have extended sepa.js for a different purpose, please contribute the code
either via email or ideally as a pull request.
If you are missing something, please create an issue.
* Each SEPA document contains exactly one group header, accessible via the grpHdr property.
* You can add multiple paymentInfo blocks to a document, i.e one per sequenceType (FRST/RCUR)
* A payment info block can contain multiple transactions.
Validating an IBAN or Creditor ID
---------------------------------
You can use sepa.js to validate IBAN and Creditor ID numbers or calculate their checksum. Here is an example:
``javascript
var SEPA = require("sepa");
// Validating this IBAN returns true.
SEPA.validateIBAN("DE40987654329876543210");
// Passing this IBAN with "00" as the checksum returns the
// IBAN with the correct checksum, "DE87123456781234567890".
SEPA.checksumIBAN("DE00123456781234567890");
// Validating this Creditor ID returns true.
SEPA.validateCreditorID("DE98ZZZ09999999999");
// Passing this Creditor ID with "00" as the checksum returns the
// Creditor ID with the correct checksum, "DE98ZZZ09999999999".
SEPA.checksumCreditorID("DE00ZZZ09999999999");
`
Creating an XML DirectDebit Document
---------------------------------
The main use case for sepa.js is creating an XML Document based on the
EBICS Specification.
Here is a simple node.js example. If you want to use the browser instead, just
omit the first line and include via script-tag or module loader instead.
`javascript
var SEPA = require("sepa");
var doc = new SEPA.Document('pain.008.001.08');
doc.grpHdr.id = "XMPL.20140201.TR0";
doc.grpHdr.created = new Date();
doc.grpHdr.initiatorName = "Example LLC";
var info = doc.createPaymentInfo();
info.collectionDate = new Date();
info.creditorIBAN = "DE87123456781234567890";
info.creditorBIC = "XMPLDEM0XXX";
info.creditorName = "Example LLC";
info.creditorId = "DE98ZZZ09999999999";
info.originalCreditorId = "IT66ZZZA1B2C3D4E5F6G7H8"; //optional
info.batchBooking = true; //optional
doc.addPaymentInfo(info);
var tx = info.createTransaction();
tx.debtorName = "Example Customer";
tx.debtorIBAN = "DE40987654329876543210";
tx.debtorBIC = "CUSTDEM0XXX";
tx.mandateId = "XMPL.CUST487.2014";
tx.mandateSignatureDate = new Date("2014-02-01");
tx.amount = 50.23;
tx.currency = 'EUR'; //optional
tx.remittanceInfo = "INVOICE 54";
tx.end2endId = "XMPL.CUST487.INVOICE.54";
info.addTransaction(tx);
console.log(doc.toString());
`
Creating an XML Transfer Document
---------------------------------
`javascript
var SEPA = require("sepa");
var doc = new SEPA.Document('pain.001.001.09');
doc.grpHdr.id = "XMPL.20140201.TR0";
doc.grpHdr.created = new Date();
doc.grpHdr.initiatorName = "Example LLC";
var info = doc.createPaymentInfo();
info.requestedExecutionDate = new Date();
info.debtorIBAN = "DE87123456781234567890";
info.debtorBIC = "XMPLDEM0XXX";
info.debtorName = "Example LLC";
doc.addPaymentInfo(info);
var tx = info.createTransaction();
tx.creditorName = "Example Customer";
tx.creditorIBAN = "DE40987654329876543210";
tx.creditorBIC = "CUSTDEM0XXX";
tx.amount = 50.23;
tx.remittanceInfo = "INVOICE 54";
tx.end2endId = "XMPL.CUST487.INVOICE.54";
info.addTransaction(tx);
console.log(doc.toString());
`
xml
xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.008.001.08 pain.008.001.08.xsd"
xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.08">
XMPL.20140201.TR0
2024-07-05T11:44:23
1
50.23
Example LLC
XMPL.20140201.TR0.0
DD
true
1
50.23
SEPA
CORE
FRST
2024-07-05
Example LLC
DE98ZZZ09999999999
DE87123456781234567890
XMPLDEM0XXX
SLEV
DE98ZZZ09999999999
SEPA
XMPL.20140201.TR0.0.0
XMPL.CUST487.INVOICE.54
50.23
XMPL.CUST487.2014
2014-02-01
false
CUSTDEM0XXX
Example Customer
DE40987654329876543210
INVOICE 54
``