qr-bills 0.1.2 → 1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e156aa65cb4788eff6c5450aee6dd63f69090432e4f4182d304a31aac808ebe6
4
- data.tar.gz: 3f928ff3b0213a3509f161e4ba2a56e480830e78181740835d294fd087d6e943
3
+ metadata.gz: 5b13afc587aab384d5e9a030f42108e2b9110fcc7990e6f1ae0b7ce94069d04c
4
+ data.tar.gz: 8052cd236374ecf1bc14ba7f41b7cd42295fc983a3034e3dec39b23af794c862
5
5
  SHA512:
6
- metadata.gz: d61b9da6f1620aa1c8f8d05a9d460105087076c96568e061fa3f16d09cfb697c16ffd34084513b4ba397a73b61ba104cf2b5562f380f4d71bf4a3604c3c984a7
7
- data.tar.gz: 88d1f1c246014a9f6f2837d9d6c20760d0fb759fc0c3484e0c5f561a6e4f31622935ddda9a55dcdb25a9888b159b4a2d9918f76fced28118541396174a88b0ef
6
+ metadata.gz: f513cd9212d3469f6be2b9b254b7fd39fb3b61d712896d90f70250c5e05426d8bf87800940288c699649b19d3ae3cc71d6e17726e9a9ddbc15f49614402291a2
7
+ data.tar.gz: 455577fd45fcc3fe7be24f14ee32275e2d5e6e8d5257f4c7eeaee184616596f6a5f42c09e72d2fe01fe42d3ccf774a0711e0e60516e46438216fefad453d1967
@@ -0,0 +1,17 @@
1
+ de:
2
+ qrbills:
3
+ payment_part: Zahlteil
4
+ account: Konto
5
+ payable_to: Zahlbar an
6
+ reference: Referenz
7
+ additional_information: zusätzliche Informationen
8
+ further_information: weitere Informationen
9
+ currency: Währung
10
+ amount: Betrag
11
+ receipt: Empfangsschein
12
+ acceptance_point: Annahmestelle
13
+ separate_before_paying_in: Vor der Einzahlung abzutrennen
14
+ payable_by: Zahlbar durch
15
+ payable_by_name_addr: Zahlbar durch (Name/Adresse)
16
+ in_favour_of: Zugunsten
17
+ name: Name
@@ -0,0 +1,17 @@
1
+ en:
2
+ qrbills:
3
+ payment_part: payment part
4
+ account: account
5
+ payable_to: payable to
6
+ reference: reference
7
+ additional_information: additional information
8
+ further_information: further information
9
+ currency: currency
10
+ amount: amount
11
+ receipt: receipt
12
+ acceptance_point: acceptance point
13
+ separate_before_paying_in: separate before paying in
14
+ payable_by: payable by
15
+ payable_by_name_addr: payable by (name/address)
16
+ in_favour_of: in favour of
17
+ name: nom
@@ -0,0 +1,17 @@
1
+ fr:
2
+ qrbills:
3
+ payment_part: section paiement
4
+ account: compte
5
+ payable_to: payable à
6
+ reference: référence
7
+ additional_information: informations additionnelles
8
+ further_information: informations supplémentaires
9
+ currency: monnaie
10
+ amount: montant
11
+ receipt: récépissé
12
+ acceptance_point: èpomt de dépôt
13
+ separate_before_paying_in: à détacher avant le versement
14
+ payable_by: payable par
15
+ payable_by_name_addr: payable par (nom/adresse)
16
+ in_favour_of: en faveur de
17
+ name: name
@@ -0,0 +1,17 @@
1
+ it:
2
+ qrbills:
3
+ payment_part: "sezione pagamento"
4
+ account: conto
5
+ payable_to: "pagabile a"
6
+ reference: riferimento
7
+ additional_information: "informazioni aggiuntive"
8
+ further_information: "informazioni supplementari"
9
+ currency: valuta
10
+ amount: importo
11
+ receipt: ricevuta
12
+ acceptance_point: "punto di accettazione"
13
+ separate_before_paying_in: "da staccare prima del versamento"
14
+ payable_by: pagabile da
15
+ payable_by_name_addr: pagabile da (nome/indirizzo)
16
+ in_favour_of: a favore di
17
+ name: nome
data/lib/qr-bills.rb CHANGED
@@ -2,38 +2,34 @@ require 'i18n'
2
2
  require 'qr-bills/qr-exceptions'
3
3
  require 'qr-bills/qr-params'
4
4
  require 'qr-bills/qr-html-layout'
5
+ require 'qr-bills/qr-creditor-reference'
5
6
 
6
- class QRBills
7
+ module QRBills
7
8
  def self.generate(qr_params)
8
- # init translator sets
9
- I18n.load_path << "#{File.expand_path("#{File.dirname(__FILE__)}/../config/locales/it.yml")}"
10
- I18n.load_path << "#{File.expand_path("#{File.dirname(__FILE__)}/../config/locales/en.yml")}"
11
- I18n.load_path << "#{File.expand_path("#{File.dirname(__FILE__)}/../config/locales/de.yml")}"
12
- I18n.load_path << "#{File.expand_path("#{File.dirname(__FILE__)}/../config/locales/fr.yml")}"
13
- I18n.default_locale = :it
14
-
15
- bill = {
16
- params: qr_params,
17
- output: nil
18
- }
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)
19
11
 
20
- if qr_params.has_key?(:bill_type)
21
-
22
- if !QRParams.valid?(qr_params)
23
- raise QRExceptions::INVALID_PARAMETERS + ": params validation check failed"
24
- 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")
25
15
 
26
- if qr_params[:output_params][:format] == "html"
27
- bill[:output] = QRHTMLLayout.create(qr_params)
28
- else
29
- raise QRExceptions::NOT_SUPPORTED + ": html is the only output format supported so far"
30
- end
16
+ I18n.load_path << locale_file
17
+ end
31
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])
32
24
  else
33
- raise QRExceptions::INVALID_PARAMETERS + ": bill type param not set"
25
+ raise ArgumentError, "#{QRExceptions::NOT_SUPPORTED}: #{qr_params[:output_params][:format]} is not yet supported"
34
26
  end
35
27
 
36
- return bill
28
+ { params: qr_params, output: output }
29
+ end
30
+
31
+ def self.create_creditor_reference(reference)
32
+ QRCreditorReference.create(reference)
37
33
  end
38
34
 
39
35
  def self.get_qr_params
@@ -0,0 +1,78 @@
1
+ require 'qr-bills/qr-exceptions'
2
+
3
+ # implement Creditor Reference ISO 11649 generator
4
+ module QRCreditorReference
5
+ PREFIX = "RF"
6
+
7
+ # chars values to calculate the check code
8
+ @char_values = {
9
+ "A": 10,
10
+ "B": 11,
11
+ "C": 12,
12
+ "D": 13,
13
+ "E": 14,
14
+ "F": 15,
15
+ "G": 16,
16
+ "H": 17,
17
+ "I": 18,
18
+ "J": 19,
19
+ "K": 20,
20
+ "L": 21,
21
+ "M": 22,
22
+ "N": 23,
23
+ "O": 24,
24
+ "P": 25,
25
+ "Q": 26,
26
+ "R": 27,
27
+ "S": 28,
28
+ "T": 29,
29
+ "U": 30,
30
+ "V": 31,
31
+ "W": 32,
32
+ "X": 33,
33
+ "Y": 34,
34
+ "Z": 35
35
+ }
36
+
37
+ def self.create(reference)
38
+ reference = reference.delete(' ')
39
+ chars = reference.split('')
40
+
41
+ if chars.size == 0
42
+ raise QRExceptions::INVALID_PARAMETERS + ": provided reference too short: must be at least one char"
43
+ end
44
+
45
+ # max 25 chars: 2 chars (RF) + 2 chars (check code) + 21 chars (reference)
46
+ if chars.size > 21
47
+ raise QRExceptions::INVALID_PARAMETERS + ": provided reference too long: must be less than 21 chars"
48
+ end
49
+
50
+ reference_val = ""
51
+
52
+ chars.each do |c|
53
+ reference_val += get_char_value(c).to_s
54
+ end
55
+
56
+ # put RF+00 at the end to resolve check code
57
+ reference_val += @char_values["R".to_sym].to_s + @char_values["F".to_sym].to_s + "00"
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
62
+ check_code = 98 - (reference_val.to_i % 97)
63
+
64
+ if check_code < 10
65
+ check_code = "0" + check_code.to_s
66
+ end
67
+
68
+ return PREFIX + check_code.to_s + reference
69
+ end
70
+
71
+ def self.get_char_value(char)
72
+ if char =~ /[0-9]/
73
+ return char.to_i
74
+ end
75
+
76
+ return @char_values[char.upcase.to_sym]
77
+ end
78
+ end
@@ -1,4 +1,4 @@
1
- class QRExceptions
1
+ module QRExceptions
2
2
  EXCEPTION_PREFIX = "QR-bill"
3
3
 
4
4
  INVALID_PARAMETERS = EXCEPTION_PREFIX + " invalid parameters"
@@ -1,8 +1,6 @@
1
1
  require 'rqrcode'
2
- require 'RMagick'
3
- include Magick
4
2
 
5
- class QRGenerator
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][:alternative_scheme_paramters]}\r\n"
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
- IO.binwrite(qrcode_path, png.to_s)
97
- end
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
- class QRHTMLLayout
3
+ module QRHTMLLayout
4
4
 
5
5
  def self.create(params)
6
6
  QRGenerator.create(params, params[:qrcode_filepath])
@@ -10,25 +10,25 @@ class QRHTMLLayout
10
10
  def self.html_layout(params)
11
11
  layout = "<div class=\"bill_container\">\n"
12
12
  layout += " <div class=\"receipt_section\">\n"
13
- layout += " <div class=\"title\">#{I18n.t(:receipt).capitalize}</div>\n"
14
- layout += " <div class=\"subtitle payable_to\">#{I18n.t(:account).capitalize} / #{I18n.t(:payable_to).capitalize}</div>\n"
13
+ layout += " <div class=\"title\">#{I18n.t("qrbills.receipt").capitalize}</div>\n"
14
+ layout += " <div class=\"subtitle payable_to\">#{I18n.t("qrbills.account").capitalize} / #{I18n.t("qrbills.payable_to").capitalize}</div>\n"
15
15
  layout += " <div class=\"qrcontent\">\n"
16
16
  layout += " #{params[:bill_params][:creditor][:iban]}<br/>\n"
17
17
  layout += " #{params[:bill_params][:creditor][:address][:name]}<br/>\n"
18
18
  layout += " #{params[:bill_params][:creditor][:address][:line1]} #{params[:bill_params][:creditor][:address][:line2]}<br/>\n"
19
19
  layout += " #{params[:bill_params][:creditor][:address][:postal_code]} #{params[:bill_params][:creditor][:address][:town]}<br/>\n"
20
- layout += " </div>"
21
- layout += " <div><br/></div>"
20
+ layout += " </div>\n"
21
+ layout += " <div><br/></div>\n"
22
22
 
23
23
  if !params[:bill_params][:reference].nil? && !params[:bill_params][:reference].empty?
24
- layout += " <div class=\"subtitle reference\">#{I18n.t(:reference).capitalize}</div>\n"
24
+ layout += " <div class=\"subtitle reference\">#{I18n.t("qrbills.reference").capitalize}</div>\n"
25
25
  layout += " <div class=\"reference\">\n"
26
26
  layout += " #{params[:bill_params][:reference]}<br/>\n"
27
27
  layout += " </div>\n"
28
28
  layout += " <div><br/></div>\n"
29
29
  end
30
30
 
31
- layout += " <div class=\"subtitle payable_by\">#{I18n.t(:payable_by).capitalize}</div>\n"
31
+ layout += " <div class=\"subtitle payable_by\">#{I18n.t("qrbills.payable_by").capitalize}</div>\n"
32
32
  layout += " <div class=\"payable_by\">\n"
33
33
  layout += " #{params[:bill_params][:debtor][:address][:name]}<br/>\n"
34
34
  layout += " #{params[:bill_params][:debtor][:address][:line1]} #{params[:bill_params][:debtor][:address][:line2]}<br/>\n"
@@ -37,33 +37,33 @@ class QRHTMLLayout
37
37
 
38
38
  layout += " <div class=\"amount\">\n"
39
39
  layout += " <div class=\"currency\">\n"
40
- layout += " <span class=\"amount_header subtitle\">#{I18n.t(:currency).capitalize}</span><br/>\n"
40
+ layout += " <span class=\"amount_header subtitle\">#{I18n.t("qrbills.currency").capitalize}</span><br/>\n"
41
41
  layout += " #{params[:bill_params][:currency]}<br/>\n"
42
42
  layout += " </div>\n"
43
43
 
44
44
  layout += " <div class=\"amount_value\">\n"
45
- layout += " <span class=\"amount_header subtitle\">#{I18n.t(:amount).capitalize}</span><br/>\n"
45
+ layout += " <span class=\"amount_header subtitle\">#{I18n.t("qrbills.amount").capitalize}</span><br/>\n"
46
46
  layout += " #{params[:bill_params][:amount]}<br/>\n"
47
47
  layout += " </div>\n"
48
48
  layout += " </div>\n"
49
49
 
50
50
  layout += " <div class=\"acceptance_point\">\n"
51
- layout += " #{I18n.t(:acceptance_point).capitalize}<br/>\n"
51
+ layout += " #{I18n.t("qrbills.acceptance_point").capitalize}<br/>\n"
52
52
  layout += " </div>\n"
53
53
 
54
54
  layout += " </div>\n"
55
55
  layout += " <div class=\"payment_section\">\n"
56
56
  layout += " <div class=\"left_column\">\n"
57
- layout += " <div class=\"title\">#{I18n.t(:payment_part).capitalize}</div>\n"
57
+ layout += " <div class=\"title\">#{I18n.t("qrbills.payment_part").capitalize}</div>\n"
58
58
  layout += " <div class=\"qr_code\"><img src=\"#{params[:qrcode_filepath]}\" /></div>\n"
59
59
  layout += " <div class=\"amount\">\n"
60
60
  layout += " <div class=\"currency\">\n"
61
- layout += " <span class=\"amount_header subtitle\">#{I18n.t(:currency).capitalize}</span><br/>\n"
61
+ layout += " <span class=\"amount_header subtitle\">#{I18n.t("qrbills.currency").capitalize}</span><br/>\n"
62
62
  layout += " #{params[:bill_params][:currency]}<br/>\n"
63
63
  layout += " </div>\n"
64
64
 
65
65
  layout += " <div class=\"amount_value\">\n"
66
- layout += " <span class=\"amount_header subtitle\">#{I18n.t(:amount).capitalize}</span><br/>\n"
66
+ layout += " <span class=\"amount_header subtitle\">#{I18n.t("qrbills.amount").capitalize}</span><br/>\n"
67
67
  layout += " #{params[:bill_params][:amount]}<br/>\n"
68
68
  layout += " </div>\n"
69
69
  layout += " </div>\n"
@@ -71,17 +71,17 @@ class QRHTMLLayout
71
71
  layout += " <div class=\"further_information\">\n"
72
72
 
73
73
  if !params[:bill_params][:bill_information_coded].nil? && !params[:bill_params][:bill_information_coded].empty?
74
- layout += " <span class=\"finfo_header\">Name AV1:</span> #{params[:bill_params][:bill_information_coded]}\n"
74
+ layout += " <span class=\"finfo_header\">#{I18n.t("qrbills.name").capitalize} AV1:</span> #{params[:bill_params][:bill_information_coded]}\n"
75
75
  end
76
76
 
77
- if !params[:bill_params][:alternative_scheme_paramters].nil? && !params[:bill_params][:alternative_scheme_paramters].empty?
78
- layout += " <span class=\"finfo_header\">Name AV2:</span> #{params[:bill_params][:alternative_scheme_paramters]}\n"
77
+ if !params[:bill_params][:alternative_scheme_parameters].nil? && !params[:bill_params][:alternative_scheme_parameters].empty?
78
+ layout += " <span class=\"finfo_header\">#{I18n.t("qrbills.name").capitalize} AV2:</span> #{params[:bill_params][:alternative_scheme_parameters]}\n"
79
79
  end
80
80
 
81
81
  layout += " </div>\n"
82
82
  layout += " </div>\n"
83
83
  layout += " <div class=\"right_column\">\n"
84
- layout += " <div class=\"subtitle payable_to\">#{I18n.t(:account).capitalize} / #{I18n.t(:payable_to).capitalize}</div>\n"
84
+ layout += " <div class=\"subtitle payable_to\">#{I18n.t("qrbills.account").capitalize} / #{I18n.t("qrbills.payable_to").capitalize}</div>\n"
85
85
  layout += " <div class=\"qrcontent\">\n"
86
86
  layout += " #{params[:bill_params][:creditor][:iban]}<br/>\n"
87
87
  layout += " #{params[:bill_params][:creditor][:address][:name]}<br/>\n"
@@ -91,7 +91,7 @@ class QRHTMLLayout
91
91
  layout += " <div><br/></div>\n"
92
92
 
93
93
  if !params[:bill_params][:reference].nil? && !params[:bill_params][:reference].empty?
94
- layout += " <div class=\"subtitle reference\">#{I18n.t(:reference).capitalize}</div>\n"
94
+ layout += " <div class=\"subtitle reference\">#{I18n.t("qrbills.reference").capitalize}</div>\n"
95
95
  layout += " <div class=\"reference\">\n"
96
96
  layout += " #{params[:bill_params][:reference]}<br/>\n"
97
97
  layout += " </div>\n"
@@ -99,14 +99,14 @@ class QRHTMLLayout
99
99
  end
100
100
 
101
101
  if !params[:bill_params][:additionally_information].nil? && !params[:bill_params][:additionally_information].empty?
102
- layout += " <div class=\"subtitle additional_information\">#{I18n.t(:additional_information).capitalize}</div>\n"
102
+ layout += " <div class=\"subtitle additional_information\">#{I18n.t("qrbills.additional_information").capitalize}</div>\n"
103
103
  layout += " <div class=\"additional_information\">\n"
104
104
  layout += " #{params[:bill_params][:additionally_information]}<br/>\n"
105
105
  layout += " </div>\n"
106
106
  layout += " <div><br/></div>\n"
107
107
  end
108
108
 
109
- layout += " <div class=\"subtitle payable_by\">#{I18n.t(:payable_by).capitalize}</div>\n"
109
+ layout += " <div class=\"subtitle payable_by\">#{I18n.t("qrbills.payable_by").capitalize}</div>\n"
110
110
  layout += " <div class=\"payable_by\">\n"
111
111
  layout += " #{params[:bill_params][:debtor][:address][:name]}<br/>\n"
112
112
  layout += " #{params[:bill_params][:debtor][:address][:line1]} #{params[:bill_params][:debtor][:address][:line2]}<br/>\n"
@@ -1,7 +1,7 @@
1
- class QRParams
1
+ module QRParams
2
2
  QR_BILL_WITH_QR_REFERENCE = "orange_with_reference"
3
3
  QR_BILL_WITH_CREDITOR_REFERENCE = "red_with_reference"
4
- QR_BILL_WITOUTH_REFERENCE = "red_without_reference"
4
+ QR_BILL_WITHOUT_REFERENCE = "red_without_reference"
5
5
 
6
6
  def self.get_qr_params
7
7
  {
@@ -13,6 +13,9 @@ class QRParams
13
13
  ttf: File.expand_path("#{File.dirname(__FILE__)}/../../web/assets/fonts/LiberationSans-Regular.ttf"),
14
14
  svg: File.expand_path("#{File.dirname(__FILE__)}/../../web/assets/fonts/LiberationSans-Regular.svg")
15
15
  },
16
+ locales: {
17
+ path: File.expand_path("#{File.dirname(__FILE__)}/../../config/locales")
18
+ },
16
19
  bill_params: {
17
20
  language: "it",
18
21
  amount: 0.0,
@@ -21,7 +24,7 @@ class QRParams
21
24
  reference: "", # qr reference or creditor reference (iso-11649)
22
25
  additionally_information: "",
23
26
  bill_information_coded: "",
24
- alternative_scheme_paramters: "",
27
+ alternative_scheme_parameters: "",
25
28
  creditor: {
26
29
  address: {
27
30
  type: "S",
@@ -53,43 +56,70 @@ class QRParams
53
56
  end
54
57
 
55
58
  def self.valid?(params)
56
- if params.has_key?(:bill_type)
57
-
58
- if !QRParams.base_params_valid?(params)
59
- return false
60
- end
59
+ return false unless params.key?(:bill_type)
60
+ return false unless QRParams.base_params_valid?(params)
61
61
 
62
- if params[:bill_type] == QR_BILL_WITH_QR_REFERENCE
63
- return QRParams.qr_bill_with_qr_reference_valid?(params)
64
- elsif params[:bill_type] == QR_BILL_WITH_CREDITOR_REFERENCE
65
- return QRParams.qr_bill_with_creditor_reference_valid?(params)
66
- elsif params[:bill_type] == QR_BILL_WITOUTH_REFERENCE
67
- return QRParams.qr_bill_without_reference_valid?(params)
68
- else
69
- return false
70
- 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)
71
69
  else
72
- return false
70
+ false
73
71
  end
74
72
  end
75
-
73
+
76
74
  def self.base_params_valid?(params)
77
- # todo
78
- return true
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
79
88
  end
80
89
 
81
90
  def self.qr_bill_with_qr_reference_valid?(params)
82
- # todo
83
- return true
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
84
100
  end
85
101
 
86
102
  def self.qr_bill_with_creditor_reference_valid?(params)
87
- # todo
88
- return true
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
89
112
  end
90
113
 
91
114
  def self.qr_bill_without_reference_valid?(params)
92
- # todo
93
- return true
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
94
124
  end
95
125
  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.1.2
4
+ version: '1.0'
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: 2020-07-05 00:00:00.000000000 Z
11
+ date: 2021-04-08 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,16 +80,17 @@ 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: damoiser+qrbill@gmail.com
83
+ email: dam.radice@gmail.com
104
84
  executables: []
105
85
  extensions: []
106
86
  extra_rdoc_files: []
107
87
  files:
108
- - config/locales/de.yml
109
- - config/locales/en.yml
110
- - config/locales/fr.yml
111
- - config/locales/it.yml
88
+ - config/locales/qrbills.de.yml
89
+ - config/locales/qrbills.en.yml
90
+ - config/locales/qrbills.fr.yml
91
+ - config/locales/qrbills.it.yml
112
92
  - lib/qr-bills.rb
93
+ - lib/qr-bills/qr-creditor-reference.rb
113
94
  - lib/qr-bills/qr-exceptions.rb
114
95
  - lib/qr-bills/qr-generator.rb
115
96
  - lib/qr-bills/qr-html-layout.rb
@@ -132,7 +113,7 @@ metadata:
132
113
  homepage_uri: https://github.com/damoiser/qr-bills
133
114
  source_code_uri: https://github.com/damoiser/qr-bills
134
115
  wiki_uri: https://github.com/damoiser/qr-bills
135
- post_install_message:
116
+ post_install_message:
136
117
  rdoc_options: []
137
118
  require_paths:
138
119
  - lib
@@ -148,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
129
  version: '0'
149
130
  requirements: []
150
131
  rubygems_version: 3.1.2
151
- signing_key:
132
+ signing_key:
152
133
  specification_version: 4
153
134
  summary: QR-bills support for swiss payments
154
135
  test_files: []
@@ -1,15 +0,0 @@
1
- de:
2
- payment_part: Zahlteil
3
- account: Konto
4
- payable_to: Zahlbar an
5
- reference: Referenz
6
- additional_information: zusätzliche Informationen
7
- further_information: weitere Informationen
8
- currency: Währung
9
- amount: Betrag
10
- receipt: Empfangsschein
11
- acceptance_point: Annahmestelle
12
- separate_before_paying_in: Vor der Einzahlung abzutrennen
13
- payable_by: Zahlbar durch
14
- payable_by_name_addr: Zahlbar durch (Name/Adresse)
15
- in_favour_of: Zugunsten
@@ -1,15 +0,0 @@
1
- en:
2
- payment_part: payment part
3
- account: account
4
- payable_to: payable to
5
- reference: reference
6
- additional_information: additional information
7
- further_information: further information
8
- currency: currency
9
- amount: amount
10
- receipt: receipt
11
- acceptance_point: acceptance point
12
- separate_before_paying_in: separate before paying in
13
- payable_by: payable by
14
- payable_by_name_addr: payable by (name/address)
15
- in_favour_of: in favour of
@@ -1,15 +0,0 @@
1
- fr:
2
- payment_part: section paiement
3
- account: compte
4
- payable_to: payable à
5
- reference: référence
6
- additional_information: informations additionnelles
7
- further_information: informations supplémentaires
8
- currency: monnaie
9
- amount: montant
10
- receipt: récépissé
11
- acceptance_point: èpomt de dépôt
12
- separate_before_paying_in: à détacher avant le versement
13
- payable_by: payable par
14
- payable_by_name_addr: payable par (nom/adresse)
15
- in_favour_of: en faveur de
@@ -1,15 +0,0 @@
1
- it:
2
- payment_part: "sezione pagamento"
3
- account: conto
4
- payable_to: "pagabile a"
5
- reference: riferimento
6
- additional_information: "informazioni aggiuntive"
7
- further_information: "informazioni supplementari"
8
- currency: valuta
9
- amount: importo
10
- receipt: ricevuta
11
- acceptance_point: "punto di accettazione"
12
- separate_before_paying_in: "da staccare prima del versamento"
13
- payable_by: pagabile da
14
- payable_by_name_addr: pagabile da (nome/indirizzo)
15
- in_favour_of: a favore di