spayd
TypeScript icon, indicating that this package has built-in type declarations

3.0.4 • Public • Published

build status dependencies npm version

spayd-js

An implementation of Short-Payment-Descriptor library in JavaScript/TypeScript. Primarily used for generating QR-Payments.

Installation

# yarn
yarn add spayd

# npm
npm install spayd --save

Usage

import spayd from 'spayd';

const payment = {
  acc: 'CZ2806000000000168540115',
  am: '450.00',
  cc: 'CZK',
  msg: 'Payment for some stuff',
  xvs: '1234567890'
};

// print just the SPAYD string
console.log(spayd(payment));
import qrcode from 'qrcode';
import spayd from 'spayd';

const qrCodeEl = document.getElementById('qr');

const payment = {
  acc: 'CZ2806000000000168540115',
  am: '450.00',
  cc: 'CZK',
  msg: 'Payment for some stuff',
  xvs: '1234567890'
};

const spaydString = spayd(payment);

// generate and assign qr-payment to an image element
qrcode.toDataURL(spaydString)
  .then((url) => {
    qrCodeEl.setAttribute('src', url);
  })
  .catch(console.error);

Options

Required Descriptor Format Description Example
acc string account number in IBAN format or IBAN+BIC format "CZ5855000000001265098001+RZBCCZPP"
altAcc string[] array of alternative accounts (usage of these accounts depends on the bank app implementation) [ "CZ5855000000001265098001+RZBCCZPP", "CZ5855000000001265098001" ]
am string amount of money to transfer in floating point number string "480.55"
cc string currency in ISO 4217 format "CZK"
rf number payment identifier for the receiver 1234567890123456
rn string receiver's name "PETR DVORAK"
dt Date due date new Date(2018, 3, 20)
pt string payment type "P2P"
msg string message for receiver "Payment for some stuff"
crc32 string CRC32 hashsum of this SPAYD payment "1234ABCD"
xper string number of days to retry the payment "7"
xvs string variable symbol "1234567890"
xss string specific symbol "1234567890"
xks string constant symbol "1234567890"
xid string payment identifier for the payer "ABCDEFGHIJ1234567890"

For more info about SPAYD descriptors, see:

Package variants

As of version >=3.0, the default export is in the UMD format. This enables you to use the package both in the browser and in nodejs. Plus, it allows it to target legacy browsers, like IE11. If you encounter no troubles with the default export, feel free to keep using it.

If you wanted import specifically an ES6 or CommonJS version of spayd, use the "/esm" or "/cjs" subpath respectively.

// pure ES6 version
import spayd from "spayd/esm";

// CommonJS version
const spayd = require("spayd/cjs");

Readme

Keywords

none

Package Sidebar

Install

npm i spayd

Weekly Downloads

771

Version

3.0.4

License

MIT

Unpacked Size

258 kB

Total Files

24

Last publish

Collaborators

  • tajnymag