qr-bills 0.2.2 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/locales/qrbills.fr.yml +2 -2
- data/lib/qr-bills/qr-creditor-reference.rb +4 -1
- data/lib/qr-bills/qr-exceptions.rb +1 -1
- data/lib/qr-bills/qr-generator.rb +5 -17
- data/lib/qr-bills/qr-html-layout.rb +5 -4
- data/lib/qr-bills/qr-params.rb +54 -27
- data/lib/qr-bills.rb +18 -27
- metadata +6 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc357870d91f0b58fb6ea0895b8093cdff66fe9488080263cf9c50600b7bfb66
|
4
|
+
data.tar.gz: a1239f2e9aa5e25ddf01db1c8d1372be14809bf69b7a877074c9fd70c07e5780
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c950153805c26782e33f8a029b35a2610f6b5ac9030718836fb8bb06657d1d157ae6bf73dcfdb48e7ad796e21af006518cfb2cde15dc501adfdecb78f3ced28a
|
7
|
+
data.tar.gz: a995e3a5e7d45d6050214107d0f5db07937055e9db5daf204ba1550152a59cdb6b8f9417a512efc4618e2f79fcf8d79f98191d53431d63a198bb60fbc6d4f261
|
@@ -9,9 +9,9 @@ fr:
|
|
9
9
|
currency: monnaie
|
10
10
|
amount: montant
|
11
11
|
receipt: récépissé
|
12
|
-
acceptance_point:
|
12
|
+
acceptance_point: point de dépôt
|
13
13
|
separate_before_paying_in: à détacher avant le versement
|
14
14
|
payable_by: payable par
|
15
15
|
payable_by_name_addr: payable par (nom/adresse)
|
16
16
|
in_favour_of: en faveur de
|
17
|
-
name: name
|
17
|
+
name: name
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'qr-bills/qr-exceptions'
|
2
2
|
|
3
3
|
# implement Creditor Reference ISO 11649 generator
|
4
|
-
|
4
|
+
module QRCreditorReference
|
5
5
|
PREFIX = "RF"
|
6
6
|
|
7
|
+
# chars values to calculate the check code
|
7
8
|
@char_values = {
|
8
9
|
"A": 10,
|
9
10
|
"B": 11,
|
@@ -56,6 +57,8 @@ class QRCreditorReference
|
|
56
57
|
reference_val += @char_values["R".to_sym].to_s + @char_values["F".to_sym].to_s + "00"
|
57
58
|
|
58
59
|
# get check code
|
60
|
+
# when performing the validation of the check code (n % 97)
|
61
|
+
# the remainder must be equal to 1, thus the 98
|
59
62
|
check_code = 98 - (reference_val.to_i % 97)
|
60
63
|
|
61
64
|
if check_code < 10
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'rqrcode'
|
2
|
-
require 'rmagick'
|
3
|
-
include Magick
|
4
2
|
|
5
|
-
|
3
|
+
module QRGenerator
|
6
4
|
# payload:
|
7
5
|
# "SPC\r\n" + # indicator for swiss qr code: SPC (swiss payments code)
|
8
6
|
# "0200\r\n" + # version of the specifications, 0200 = v2.0
|
@@ -39,11 +37,6 @@ class QRGenerator
|
|
39
37
|
# "eBill/B/41010560425610173"; # alternative scheme paramaters, max 100 chars
|
40
38
|
|
41
39
|
def self.create(params, qrcode_path)
|
42
|
-
create_qr(params, qrcode_path)
|
43
|
-
add_swiss_cross(qrcode_path, qrcode_path)
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.create_qr(params, qrcode_path)
|
47
40
|
payload = "SPC\r\n"
|
48
41
|
payload += "0200\r\n"
|
49
42
|
payload += "1\r\n"
|
@@ -76,7 +69,7 @@ class QRGenerator
|
|
76
69
|
payload += "#{params[:bill_params][:additionally_information]}\r\n"
|
77
70
|
payload += "EPD\r\n"
|
78
71
|
payload += "#{params[:bill_params][:bill_information_coded]}\r\n"
|
79
|
-
payload += "#{params[:bill_params][:
|
72
|
+
payload += "#{params[:bill_params][:alternative_scheme_parameters]}\r\n"
|
80
73
|
|
81
74
|
qrcode = RQRCode::QRCode.new(payload)
|
82
75
|
|
@@ -93,13 +86,8 @@ class QRGenerator
|
|
93
86
|
size: 1024,
|
94
87
|
)
|
95
88
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
def self.add_swiss_cross(qrcode_path, final_path)
|
100
|
-
qr_image = Image.read(qrcode_path)[0]
|
101
|
-
swiss_cross = Image.read(File.expand_path("#{File.dirname(__FILE__)}/../../web/assets/images/swiss_cross.png"))[0]
|
102
|
-
final_qr = qr_image.composite(swiss_cross, CenterGravity, OverCompositeOp)
|
103
|
-
final_qr.write(final_path)
|
89
|
+
swiss_cross = ChunkyPNG::Image.from_file(File.expand_path("#{File.dirname(__FILE__)}/../../web/assets/images/swiss_cross.png"))
|
90
|
+
final_qr = png.compose!(swiss_cross, (png.width - swiss_cross.width) / 2, (png.height - swiss_cross.height) / 2)
|
91
|
+
final_qr.save(qrcode_path)
|
104
92
|
end
|
105
93
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'qr-bills/qr-generator'
|
2
2
|
|
3
|
-
|
3
|
+
module QRHTMLLayout
|
4
4
|
|
5
5
|
def self.create(params)
|
6
6
|
QRGenerator.create(params, params[:qrcode_filepath])
|
@@ -8,6 +8,7 @@ class QRHTMLLayout
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.html_layout(params)
|
11
|
+
I18n.locale = params[:bill_params][:language]
|
11
12
|
layout = "<div class=\"bill_container\">\n"
|
12
13
|
layout += " <div class=\"receipt_section\">\n"
|
13
14
|
layout += " <div class=\"title\">#{I18n.t("qrbills.receipt").capitalize}</div>\n"
|
@@ -74,8 +75,8 @@ class QRHTMLLayout
|
|
74
75
|
layout += " <span class=\"finfo_header\">#{I18n.t("qrbills.name").capitalize} AV1:</span> #{params[:bill_params][:bill_information_coded]}\n"
|
75
76
|
end
|
76
77
|
|
77
|
-
if !params[:bill_params][:
|
78
|
-
layout += " <span class=\"finfo_header\">#{I18n.t("qrbills.name").capitalize} AV2:</span> #{params[:bill_params][:
|
78
|
+
if !params[:bill_params][:alternative_scheme_parameters].nil? && !params[:bill_params][:alternative_scheme_parameters].empty?
|
79
|
+
layout += " <span class=\"finfo_header\">#{I18n.t("qrbills.name").capitalize} AV2:</span> #{params[:bill_params][:alternative_scheme_parameters]}\n"
|
79
80
|
end
|
80
81
|
|
81
82
|
layout += " </div>\n"
|
@@ -232,4 +233,4 @@ class QRHTMLLayout
|
|
232
233
|
|
233
234
|
return layout
|
234
235
|
end
|
235
|
-
end
|
236
|
+
end
|
data/lib/qr-bills/qr-params.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
module QRParams
|
2
2
|
QR_BILL_WITH_QR_REFERENCE = "orange_with_reference"
|
3
3
|
QR_BILL_WITH_CREDITOR_REFERENCE = "red_with_reference"
|
4
|
-
|
4
|
+
QR_BILL_WITHOUT_REFERENCE = "red_without_reference"
|
5
5
|
|
6
6
|
def self.get_qr_params
|
7
7
|
{
|
@@ -24,7 +24,7 @@ class QRParams
|
|
24
24
|
reference: "", # qr reference or creditor reference (iso-11649)
|
25
25
|
additionally_information: "",
|
26
26
|
bill_information_coded: "",
|
27
|
-
|
27
|
+
alternative_scheme_parameters: "",
|
28
28
|
creditor: {
|
29
29
|
address: {
|
30
30
|
type: "S",
|
@@ -56,43 +56,70 @@ class QRParams
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def self.valid?(params)
|
59
|
-
|
59
|
+
return false unless params.key?(:bill_type)
|
60
|
+
return false unless QRParams.base_params_valid?(params)
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
return QRParams.qr_bill_with_creditor_reference_valid?(params)
|
69
|
-
elsif params[:bill_type] == QR_BILL_WITOUTH_REFERENCE
|
70
|
-
return QRParams.qr_bill_without_reference_valid?(params)
|
71
|
-
else
|
72
|
-
return false
|
73
|
-
end
|
62
|
+
case params[:bill_type]
|
63
|
+
when QRParams::QR_BILL_WITH_QR_REFERENCE
|
64
|
+
QRParams.qr_bill_with_qr_reference_valid?(params)
|
65
|
+
when QRParams::QR_BILL_WITH_CREDITOR_REFERENCE
|
66
|
+
QRParams.qr_bill_with_creditor_reference_valid?(params)
|
67
|
+
when QRParams::QR_BILL_WITHOUT_REFERENCE
|
68
|
+
QRParams.qr_bill_without_reference_valid?(params)
|
74
69
|
else
|
75
|
-
|
70
|
+
false
|
76
71
|
end
|
77
72
|
end
|
78
|
-
|
73
|
+
|
79
74
|
def self.base_params_valid?(params)
|
80
|
-
|
81
|
-
|
75
|
+
if params[:bill_type] == "" || params[:bill_type] == nil
|
76
|
+
raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: bill type cannot be blank"
|
77
|
+
end
|
78
|
+
|
79
|
+
if params[:qrcode_filepath] == "" || params[:qrcode_filepath] == nil
|
80
|
+
raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: qrcode_filepath cannot be blank"
|
81
|
+
end
|
82
|
+
|
83
|
+
if params[:bill_params][:currency] == "" || params[:bill_params][:currency] == nil
|
84
|
+
raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: currency cannot be blank"
|
85
|
+
end
|
86
|
+
|
87
|
+
true
|
82
88
|
end
|
83
89
|
|
84
90
|
def self.qr_bill_with_qr_reference_valid?(params)
|
85
|
-
|
86
|
-
|
91
|
+
if params[:bill_params][:reference_type] != "QRR"
|
92
|
+
raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: reference type must be 'QRR' for QR bill with standard reference"
|
93
|
+
end
|
94
|
+
|
95
|
+
if params[:bill_params][:reference] == "" || params[:bill_params][:reference] == nil
|
96
|
+
raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: reference cannot be blank for QR bill with standard reference"
|
97
|
+
end
|
98
|
+
|
99
|
+
true
|
87
100
|
end
|
88
101
|
|
89
102
|
def self.qr_bill_with_creditor_reference_valid?(params)
|
90
|
-
|
91
|
-
|
103
|
+
if params[:bill_params][:reference_type] != "SCOR"
|
104
|
+
raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: reference type must be 'SCOR' for QR bill with (new) creditor reference"
|
105
|
+
end
|
106
|
+
|
107
|
+
if params[:bill_params][:reference] == "" || params[:bill_params][:reference] == nil
|
108
|
+
raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: reference cannot be blank for QR bill with (new) creditor reference"
|
109
|
+
end
|
110
|
+
|
111
|
+
true
|
92
112
|
end
|
93
113
|
|
94
114
|
def self.qr_bill_without_reference_valid?(params)
|
95
|
-
|
96
|
-
|
115
|
+
if params[:bill_params][:reference_type] != "NON"
|
116
|
+
raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: reference type must be 'NON' for QR bill without reference"
|
117
|
+
end
|
118
|
+
|
119
|
+
if params[:bill_params][:reference] != ""
|
120
|
+
raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: reference must be blank for QR bill without reference"
|
121
|
+
end
|
122
|
+
|
123
|
+
true
|
97
124
|
end
|
98
125
|
end
|
data/lib/qr-bills.rb
CHANGED
@@ -4,41 +4,32 @@ require 'qr-bills/qr-params'
|
|
4
4
|
require 'qr-bills/qr-html-layout'
|
5
5
|
require 'qr-bills/qr-creditor-reference'
|
6
6
|
|
7
|
-
|
7
|
+
module QRBills
|
8
8
|
def self.generate(qr_params)
|
9
|
+
raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: bill type param not set" unless qr_params.has_key?(:bill_type)
|
10
|
+
raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: validation failed" unless QRParams.valid?(qr_params)
|
9
11
|
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
if !QRParams.valid?(qr_params)
|
14
|
-
raise QRExceptions::INVALID_PARAMETERS + ": params validation check failed"
|
15
|
-
end
|
12
|
+
# init translator sets
|
13
|
+
%i[it en de fr].each do |locale|
|
14
|
+
locale_file = File.join(qr_params[:locales][:path], "qrbills.#{locale}.yml")
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
I18n.load_path << locale_file
|
17
|
+
end
|
20
18
|
|
19
|
+
output = case qr_params[:output_params][:format]
|
20
|
+
when 'html'
|
21
|
+
QRHTMLLayout.create(qr_params)
|
22
|
+
when 'qrcode_png'
|
23
|
+
QRGenerator.create(qr_params, qr_params[:qrcode_filepath])
|
21
24
|
else
|
22
|
-
raise QRExceptions::
|
25
|
+
raise ArgumentError, "#{QRExceptions::NOT_SUPPORTED}: #{qr_params[:output_params][:format]} is not yet supported"
|
23
26
|
end
|
24
27
|
|
25
|
-
|
26
|
-
I18n.load_path << File.join(qr_params[:locales][:path], "qrbills.it.yml")
|
27
|
-
I18n.load_path << File.join(qr_params[:locales][:path], "qrbills.en.yml")
|
28
|
-
I18n.load_path << File.join(qr_params[:locales][:path], "qrbills.de.yml")
|
29
|
-
I18n.load_path << File.join(qr_params[:locales][:path], "qrbills.fr.yml")
|
30
|
-
I18n.default_locale = :it
|
31
|
-
|
32
|
-
bill = {
|
33
|
-
params: qr_params,
|
34
|
-
output: QRHTMLLayout.create(qr_params)
|
35
|
-
}
|
36
|
-
|
37
|
-
return bill
|
28
|
+
{ params: qr_params, output: output }
|
38
29
|
end
|
39
30
|
|
40
31
|
def self.create_creditor_reference(reference)
|
41
|
-
|
32
|
+
QRCreditorReference.create(reference)
|
42
33
|
end
|
43
34
|
|
44
35
|
def self.get_qr_params
|
@@ -54,6 +45,6 @@ class QRBills
|
|
54
45
|
end
|
55
46
|
|
56
47
|
def self.get_qrbill_without_reference_type
|
57
|
-
QRParams::
|
48
|
+
QRParams::QR_BILL_WITHOUT_REFERENCE
|
58
49
|
end
|
59
|
-
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qr-bills
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damiano Radice
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -50,26 +50,6 @@ dependencies:
|
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '2'
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: rmagick
|
55
|
-
requirement: !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: 4.1.2
|
60
|
-
- - "<"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '5'
|
63
|
-
type: :runtime
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 4.1.2
|
70
|
-
- - "<"
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: '5'
|
73
53
|
- !ruby/object:Gem::Dependency
|
74
54
|
name: rspec
|
75
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,7 +80,7 @@ dependencies:
|
|
100
80
|
version: '13.0'
|
101
81
|
description: 'QR-bills support for swiss payments, for full documentation please refer
|
102
82
|
to github repo: https://github.com/damoiser/qr-bills'
|
103
|
-
email:
|
83
|
+
email: dam.radice@gmail.com
|
104
84
|
executables: []
|
105
85
|
extensions: []
|
106
86
|
extra_rdoc_files: []
|
@@ -133,7 +113,7 @@ metadata:
|
|
133
113
|
homepage_uri: https://github.com/damoiser/qr-bills
|
134
114
|
source_code_uri: https://github.com/damoiser/qr-bills
|
135
115
|
wiki_uri: https://github.com/damoiser/qr-bills
|
136
|
-
post_install_message:
|
116
|
+
post_install_message:
|
137
117
|
rdoc_options: []
|
138
118
|
require_paths:
|
139
119
|
- lib
|
@@ -149,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
129
|
version: '0'
|
150
130
|
requirements: []
|
151
131
|
rubygems_version: 3.1.2
|
152
|
-
signing_key:
|
132
|
+
signing_key:
|
153
133
|
specification_version: 4
|
154
134
|
summary: QR-bills support for swiss payments
|
155
135
|
test_files: []
|