Giter Club home page Giter Club logo

qr-bills's Introduction

CircleCI Gem Version Donate

QR-Bills gem for implementing Swiss payments.

Notes

Please note that no checks are performed to validate IBAN and references (like Creditor Reference) when submitting the params. These checks are required to be performed by the application.

Deprecation warnings ⚠️

⚠️ 🔥 If you are using qrcode_filepath please switch and start using qrcode_format as qrcode_filepath will be deprecated and removed!

Installation

Gem installation

gem install qr-bills

Locales / Translations

To support translations, copy/paste the 4 languages code into your I18n engine: config/locales/*.yml

Usage

Generate a creditor reference (ISO-11649) number

The creditor reference is composed as follow:

  • RF + 2 check digits + reference

Max reference length is 21 chars.

QRBills.create_creditor_reference("MTR81UUWZYO48NY55NP3")
# => "RF89MTR81UUWZYO48NY55NP3"

Availables outputs formats

params[:output_params][:format] = "html"
# OR
params[:output_params][:format] = "prawn"
# OR
params[:output_params][:format] = "png"
# OR
params[:output_params][:format] = "svg"
  • html returns a full qr-bill as a html-template string, uses params[:qrcode_format] for the qrcode format which supports png and svg. Defaults to png.
  • prawn returns a full qr-bill in pure Ruby for inclusion in a Prawn PDF template, uses params[:qrcode_format] for the qrcode format which supports svg ONLY.
  • png returns the qrcode of the qr-bill as a ChunkyPNG::Image object.
  • svg returns the qrcode of the qr-bill as a svg string.

Availables qr-bill types formats

QR bill with (new) creditor reference

This is a new bill type introduced with the new qr bills format

params[:bill_type]                      = QRBills.get_qrbill_with_creditor_reference_type
params[:bill_params][:reference_type]   = "SCOR" # fixed type for bill with creditor reference
params[:bill_params][:reference]        = "RF89MTR81UUWZYO48NY55NP3" # example

QR bill with creditor reference

QR bill with (old) reference type

This can be compared to the (old) orange bill type

params[:bill_type]                      = QRBills.get_qrbill_with_qr_reference_type
params[:bill_params][:reference_type]   = "QRR" # fixed type for bill with qr reference
params[:bill_params][:reference]        = "00 00037 01588 13258 31366 09972" # example

QR bill with (old) reference type

QR bill without reference

This can be compared to the (old) red bill type

params[:bill_type]                      = QRBills.get_qrbill_without_reference_type
params[:bill_params][:reference_type]   = "NON" # fixed type for bill without reference

QR bill without reference

Generate a QR-Bill

# get the QR params, so you will get the full hash structure and as well some default values
params = QRBills.get_qr_params

# fill the params, for example
params[:bill_type]                                      = QRBills.get_qrbill_with_creditor_reference_type
params[:qrcode_filepath]                                = "#{Dir.pwd}/tmp/qrcode-html.png"
params[:qrcode_format]                                  = "svg" # use qrcode_format with "svg" / "png" instead of qrcode_filepath to use a data url encoded qr code
params[:output_params][:format]                         = "html"
params[:bill_params][:creditor][:iban]                  = "CH93 0076 2011 6238 5295 7"
params[:bill_params][:creditor][:address][:type]        = "S" # or type "K"
params[:bill_params][:creditor][:address][:name]        = "Compagnia di assicurazione forma & scalciante"
params[:bill_params][:creditor][:address][:line1]       = "Via cantonale"
params[:bill_params][:creditor][:address][:line2]       = "24"
params[:bill_params][:creditor][:address][:postal_code] = "3000"
params[:bill_params][:creditor][:address][:town]        = "Lugano"
params[:bill_params][:creditor][:address][:country]     = "CH"
params[:bill_params][:amount]                           = 12345.15
params[:bill_params][:currency]                         = "CHF"
params[:bill_params][:debtor][:address][:type]          = "S"
params[:bill_params][:debtor][:address][:name]          = "Foobar Barfoot"
params[:bill_params][:debtor][:address][:line1]         = "Via cantonale"
params[:bill_params][:debtor][:address][:line2]         = "25"
params[:bill_params][:debtor][:address][:postal_code]   = "3001"
params[:bill_params][:debtor][:address][:town]          = "Comano"
params[:bill_params][:debtor][:address][:country]       = "CH"
# you can get the new creditor reference using QRBills.create_creditor_reference("your_reference") 
params[:bill_params][:reference]                        = "RF89MTR81UUWZYO48NY55NP3" 
params[:bill_params][:reference_type]                   = "SCOR"
params[:bill_params][:additionally_information]         = "pagamento riparazione monopattino"

# generate the QR Bill
bill = QRBills.generate(params)

# if params[:output_params][:format] == "prawn" pass `pdf` to QRBills.generate to get a Prawn::Document object
bill = QRBills.generate(params, pdf)


# bill format is given in the params, default is html
# bill has the following format:
#    bill = {
#      params: params,
#      output: "output"
#    }

References

TODO

  • add other outputs formats
  • add "empty" QR-Bill QR bill empty

License

BSD-3

qr-bills's People

Contributors

800a7b32 avatar alexanderadam avatar damoiser avatar danielpuglisi avatar kaktusyaka avatar randiem avatar solaris007 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.