Project

swish_qr

0.0
No commit activity in last 3 years
No release in over 3 years
An interface for the public Swish QR API, and generator of Swish payment URIs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.15
~> 12.0
~> 3.0
~> 4.0

Runtime

~> 0.15
 Project Readme

Ruby SwishQr / SwishUri

A Ruby Gem for generating Swish QR codes and Swish URIs Gem Version

What is it?

Swish is a Swedish mobile payment system.

This gem generates a QR code or URI with encoded recipient, amount, message, and other selected properties.

For QR images, it uses the Swish QR API, and gets an officially branded QR code.

The Swish QR API is documented here:
https://developer.getswish.se/qr-api-manual/4-create-qr-codes-using-swish-qr-code-generator-apis/#4-1-1-prefilled

Swish URIs are just a URI with payment details, which a user can click on their mobile to open up the payment app.

Installation

The gem contains both classes, SwishQr and SwishUri

gem 'swish_qr', '~> 0.0.3'
bundle
require 'swish_qr'

Example usage

Inline SVG

This puts the SVG image within your HTML

Controller

@qr = SwishQr.new(
  editable: [ :message, :amount],
  format: "svg",
  payee: 1234567890,
  amount: 6789,
  message: "Invoice X from Company Y",
)

View

- if @qr.success?
  =raw @qr.image
- else
  Problem loading QR image

Render a JPG, which can be loaded from an HTML page

Controller

def render_qr
  @qr = SwishQr.new(
    editable: [ :message, :amount],
    format: "png",
    size: "400",
    payee: 1234567890,
    amount: 6789,
    message: "Invoice X from Company Y",
  )
  if @qr.success?
    send_data(@qr.image, type: 'image/png', disposition: 'inline')
  else
    # Handle error - maybe render a placeholder image?
  end

View

=image_tag '/path_for_controller/render_qr.png'

URI Scheme

SwishUri takes the same arguments as SwishQr, except for the image related ones - size/transparent/format/border

SwishUri.new({payee: 1234567890, amount: 1234, message: 'Hello, World!'}).uri

Generates a URL, such as:
swish://payment?data={"version":1,"payee":{"value":1234567890,"editable":false},"amount":{"value":1234,"editable":false},"message":{"value":"Hello, World!","editable":false}}

Options

| Option name | Type | Function | Valid options | required | | format | string | Sets the image format | jpg, svg, png | yes | | size | number | Horizontal/vertical image dimension (it's square)| Number >= 300 | for jpg and png | | transparent | bool | Sets if the image is transparent | true, false, blank (not valid for JPEG) | no | | border | number | Size of border around image. | number <= 4 | no | | payee | number | The Swish number of the payee | A valid Swish number | no | | amount | number | Amount in SEK | A valid amount | no | | message | string | A prefilled message | Any string | no | | editable | symbol | Sets which fields are editable in the Swish mobile app | :message, :amount, :payee | no |