@zimatech/swiss-qr-bill
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

This file was auto-generated with zdoccer.js 2.0.3

Index


original Markdown from src/_preamble.md

@zimatech/swiss-qr-bill

Provides functions to create QR bills according to Swiss Payment Standards in browsers.

Features:

  • generates bills as SVG (210 x 110mm)
  • generates bills as PDF (A4)
  • optional input values validation
  • four languages: DE, FR, IT, EN

Usage

Example:

const qrBill = new SwissQrBill({
  creditor: {
    IBAN: 'CH5204835012345671000',
    creditor: {
      type: 'S',
      name: 'Stiftung Bessere Welt',
      streetOrLine1: 'Postfach',
      postCode: '3011',
      town: 'Bern',
      country: 'CH'
    }
  },
  amount: {
    currency: 'CHF',
    amount: 420.69
  },
  additional: {
    data: 'Rechnung 200',
  },
}, SwissQrBillLang.DE)

console.log(qrBill.getErrors())

qrBill.render2PDF('dataurlstring', {
  title: 'Swiss QR Bill',
  subject: 'Rechnung 200',
  author: 'ZimaTech GmbH',
  creator: 'ZimaTech GmbH'
}).then((data) => {
  const a = document.createElement('a')
  a.setAttribute('download', 'bill.pdf')
  a.setAttribute('href', data)
  a.click()
})

transformed Javadoc from src/swiss-qr-bill-format.ts

enum SwissQrBillFormat

Available output formats for QR bill

PerforatedPaper,

Bill will be printed on perforated paper, so no cut lines are drawn.

LinesWithScissors,

Bill will be electronicly transmitted. Include cut lines with scissor symbol.

LinesWithText,

Bill will be electronicly transmitted. Include cut lines with 'seperate before paying' text.

DashedLinesWithScissors,

Bill will be electronicly transmitted. Include dashed cut lines with scissor symbol.

DashedLinesWithText

Bill will be electronicly transmitted. Include dashed cut lines with 'seperate before paying' text.


transformed Javadoc from src/swiss-qr-bill-lang.ts

enum SwissQrBillLang

Available QR bill languages

DE,

Deutsch

FR,

Français

IT,

Italiano

EN

English


transformed Javadoc from src/swiss-qr-bill-validator.ts

class SwissQrBillValidator

Validator for QR bill values

constructor(values: SQBValues, lang: SwissQrBillLang = SwissQrBillLang.DE)

Creates validator with given values

  • param values — @param lang

public setValues(values: SQBValues, lang: SwissQrBillLang = SwissQrBillLang.DE)

Set new QR bill values

public getErrors(format: 'array'): SwissQrBillValidationError[]|null

Get errors in array format

public getErrors(format?: 'object'): Record<SwissQrBillKeys, SwissQrBillValidationError[]>|null

Get errors in object format

  • param format'object' or undefined
  • returns — object SwissQrBillKeys: SwissQrBillValidationError[] or null if no errors occured

interface SwissQrBillValidationError

Object definition for raised validation errors

field: SwissQrBillKeys

Descriptor of the field containing the error, e.g. 'amount.currency'

errno: SwissQrBillValidationErrno

Error number

error: string

Initial error message text

enum SwissQrBillValidationErrno

Validation error numbers

MayNotBeEmpty = 1000,

Value may not be empty

MustBeEmpty = 1001,

Value must be empty

TooLong = 9000,

Value was too long. The code won't be exactly 9000 but 9000 + maxLength

CountryCodeNotCHOrLI = 2000,

Value must contain CH or LI country code (i.e. an IBAN)

InvalidIBAN = 2001,

IBAN not valid, i.e. checksum fail or wrong length

InvalidAddressType = 3000,

Invalid address type specified

InvalidCountryCode = 3001,

Invalid country code

InvalidAmount = 4000,

Invalid amount, i.e. not in range 0.01 ... 999999999.99

InvalidCurrency = 4001,

Invalid currency, i.e. not 'CHF' or 'EUR'

InvalidReferenceType = 5000,

Invalid reference type specified

InvalidReference = 5001,

Invalid reference, i.e. checksum fail or wrong length

NotAQRIBAN = 5002

QR refernce used without QR IBAN


transformed Javadoc from src/swiss-qr-bill.ts

class SwissQrBill

QR bill class

constructor(values: SwissQrBillOptions, lang: SwissQrBillLang = SwissQrBillLang.DE)

Create QR bill with given values

public setValues(values: SwissQrBillOptions, lang: SwissQrBillLang = SwissQrBillLang.DE)

Updates QR bill values

public getErrors(format: 'array'): SwissQrBillValidationError[]|null

Get errors in array format

public getErrors(format?: 'object'): Record<SwissQrBillKeys, SwissQrBillValidationError[]>|null

Get errors in object format

  • param format'object' or undefined
  • returns — object SwissQrBillKeys: SwissQrBillValidationError[] or null if no errors occured

public render2PDF(output: 'arraybuffer'|'blob'|'dataurlstring'|'pdfobjectnewwindow', properties?: DocumentProperties, format: SwissQrBillFormat = SwissQrBillFormat.DashedLinesWithScissors): Promise<unknown>

Renders the QR bill to an A4 pdf

  • param output — what to output, either 'arraybufer', 'blob, 'dataurlstring' or 'pdfobjectnewwindow'
  • param properties — jsPDF DocumentProperties
  • param format — the format of the bill itself. See SwissQrBillFormat 🡵
  • returns — a promise resolving once the object is ready

public render2SVG(format: SwissQrBillFormat = SwissQrBillFormat.DashedLinesWithScissors): SVGElement

Renders the QR bill to a 210 x 110 mm svg

  • param format — the format of the bill itself. See SwissQrBillFormat 🡵
  • returnsSVGElement containing the QR bill

public getQRCode(): QRCode

Create qr code for this bill

  • returns — QRCode object

public getQRData(): string

Create qr code data for this bill

  • returns — string (CR+LF delimited) containing all data

public static friendlyFormatIBAN(iban: string): string

Format IBAN in human friendly way

  • param iban — IBAN
  • returns — formatted IBAN

public static machineFormatIBAN(iban: string): string

Removes spaces from human friendly formatted IBAN

  • param iban — formatted IBAN
  • returns — IBAN

public static friendlyFormatQRR(qrr: string): string

Format a QR reference in human friendly way

  • param qrr — QR reference
  • returns — formatted QR reference

public static machineFormatQRR(qrr: string): string

Removes spaces from human friendly formatted QR reference

  • param qrr — formatted QR reference
  • returns — QR reference

public static friendlyFormatSCOR(scor: string): string

Format a creditor reference in human friendly way

  • param scor — creditor reference
  • returns — formatted creditor reference

public static machineFormatSCOR(scor: string): string

Removes spaces from human friendly formatted creditor reference

  • param scor — formatted creditor reference
  • returns — creditor reference

public static friendlyFormatAmount(amount: string): string

Format amount in human friendly way

  • param amount — amount
  • returns — formatted amount

public static machineFormatAmount(amount: string): string

Removes spaces from human friendly formatted amount

  • param amount — formatted amount
  • returns — amount

interface SwissQrBillOptions

Options for SwissQrBill 🡵

creditor: SQBCreditorInfo // CdtrInf

SQBCreditorInfo 🡵 object describing the creditor

amount?: SQBAmount // CcyAmt

optional SQBAmount 🡵 object

debitor?: SQBAddress // UltmtDbtr

optional SQBAddress 🡵 object describing the debitor

reference?: SQBReferenceInfo // RmtInf

optional SQBReferenceInfo 🡵 object describing the reference

additional?: SQBAdditionalInfo // AddInf

optional SQBAdditionalInfo 🡵 object describing additional qr bill information

alternative?: SQBAlternativeInfo // AltPmtInf

optional SQBAlternativeInfo 🡵 object describing alternative qr bill billing methods

adviceOnly?: boolean

optional parameter for 'advice only' bills. If set to true, amount will be set to 0.00 and additional information will say DO NOT USE FOR PAYMENT

interface SQBCreditorInfo

Creditor information with IBAN and address

IBAN: string // IBAN

IBAN as string without spaces

creditor: SQBAddress // Cdtr

SQBAddress 🡵 object of creditor

interface SQBAddress

Addresses

type: 'S'|'K' // AdrTp

Address type, either 'S' for structured or 'K' for combined

Note: Several e-Bankings convert combined addresses to structured addresses on scanning. Thus, prefer providing a structured address!

name: string // Name

Name

streetOrLine1?: string // StrtNmOrAdrLine1

  • for structured addresses: street name
  • for combined addresses: line 1 of address

buildingOrLine2?: string // BldgNbOrAdrLine2

  • for structured addresses: building number
  • for combined addresses: line 2 of address

postCode?: string // PstCd

  • for structured addresses: postal code
  • for combined addresses: to be left empty

town?: string // TwnNm

  • for structured addresses: town name
  • for combined addresses: to be left empty

country: string // Ctry

Country code i.e. 'CH'

interface SQBAmount

Amount and currency

amount?: number

Amount from 0.01 to 999999999.99

currency: 'CHF'|'EUR'

Currency, either 'CHF' or 'EUR'

interface SQBReferenceInfo

Reference information

type: 'QRR'|'SCOR'|'NON'

Type, either 'QRR' (QR reference), 'SCOR' (creditor reference) or 'NON' (none)

reference?: string

Reference

interface SQBAdditionalInfo

Additional information

data?: string

Additional payment information, free text, i.e. payment message

bankingInfo?: string

Banking information. Not transmitted.

interface SQBAlternativeInfo

Alternative payment information

parameter1?: string

Value 1, free text

parameter2?: string

Value 2, free text

type SwissQrBillKeys =

All valuable keys in SwissQrBillOptions 🡵

Package Sidebar

Install

npm i @zimatech/swiss-qr-bill

Weekly Downloads

2

Version

2.0.2

License

ISC

Unpacked Size

75.8 kB

Total Files

14

Last publish

Collaborators

  • zimatecholi