0.0.3 • Published 9 months ago

@spayd/core v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@spayd/core

NPM version License

A TypeScript library for generating Short Payment Descriptor (SPAYD) strings, a standardized format for encoding payment information into QR codes.

What is SPAYD?

SPAYD (Short Payment Descriptor) is a standardized format for encoding payment information into QR codes. It was developed by the Czech Banking Association and is widely used in Central European countries for initiating bank transfers via QR codes.

Installation

# npm
npm install @spayd/core

# yarn
yarn add @spayd/core

# pnpm
pnpm add @spayd/core

Usage

import { createShortPaymentDescriptor } from '@spayd/core'

// Create a payment descriptor
const spayd = createShortPaymentDescriptor({
  acc: 'CZ6508000000192000145399+GIBACZPX',
  am: '123.45',
  cc: 'CZK',
  msg: 'Payment for services',
  rf: '1234567890',
  rn: 'John Doe',
  dt: new Date('2024-12-31'),
  x: {
    vs: '1234567890', // Variable symbol (specific to Czech/Slovak payments)
    ss: '0987654321', // Specific symbol
    ks: '0308' // Constant symbol
  }
})

console.log(spayd)
// Output: SPD*1.0*ACC:CZ6508000000192000145399+GIBACZPX*AM:123.45*CC:CZK*MSG:Payment for services*RF:1234567890*RN:John Doe*DT:20241231*X-VS:1234567890*X-SS:0987654321*X-KS:0308

API

createShortPaymentDescriptor(attributes: SpaydPaymentAttributes, transliterateParams?: boolean): string

Creates a SPAYD string from the provided payment attributes.

Parameters

ParameterTypeDescription
attributesSpaydPaymentAttributesPayment information object. See below for structure.
transliterateParamsbooleanOptional. Whether to transliterate special characters in text fields.

Returns

Returns a SPAYD-formatted string that can be encoded into a QR code.

Payment Attributes (SpaydPaymentAttributes)

AttributeTypeRequiredDescriptionFormat/Validation
accstringYesPrimary account number (IBAN + optional BIC/SWIFT)'CZ6508000000192000145399+GIBACZPX' or IBAN only
altAccstring[]NoAlternative account numbersSame format as acc. Max 2 recommended.
amstringNoPayment amountDecimal with 2 places (max 10 chars). e.g., '123.45'
ccstringNoCurrency codeISO 4217 code (3 chars). e.g., 'CZK'
rfstringNoPayment referenceMax 16 digits. e.g., '1234567890'
rnstringNoRecipient nameMax 35 chars. e.g., 'John Doe'
dtDateNoDue dateJavaScript Date object
ptstringNoPayment typeMax 3 chars. 'IP' for immediate payment
msgstringNoMessage for recipientMax 60 chars
nt'E'\|'P'NoNotification type'E' for email, 'P' for phone
ntastringNoNotification addressEmail or phone number (max 320 chars)

Extended Attributes (x)

Czech-specific payment attributes:

AttributeTypeDescriptionFormat/Validation
x.perstringPayment retry period0-30 days. e.g., '7'
x.vsstringVariable symbolMax 10 digits
x.ssstringSpecific symbolMax 10 digits
x.ksstringConstant symbolMax 10 digits
x.idstringPayment identifierMax 20 chars
x.urlstringRelated URLMax 140 chars, valid HTTP(S) URL

Validation

The library includes built-in validation for all fields:

  • IBAN validation using ibantools
  • Currency code validation against ISO 4217
  • Length and format validation for all fields
  • URL validation for x.url
  • Notification format validation (email/phone)
0.0.3

9 months ago

0.0.2

9 months ago