swish_qr 0.0.3 → 0.0.4
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/lib/swish_qr.rb +15 -13
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 74229711ef84fe4804407236ca30b50e7e611956
|
|
4
|
+
data.tar.gz: e3a7ea9ecd2484575dd8a86741d101246c090dba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8417ba48f25b053d6e02a2ffebaf77f894718630e0b9d8d360b94365021bc0b5dab7785e17399f65f2b170478a4e69b3dbe22379920f5116b765937d1270093d
|
|
7
|
+
data.tar.gz: 06eb8c88934a31e33a5aee3526247646dd9735fb9fbc79100a0cb94fa8579be34548ec5be41b77ea8f641b20d4eaa776edf89a80d9012c72276c7fa256fbd894
|
data/lib/swish_qr.rb
CHANGED
|
@@ -7,9 +7,9 @@ class SwishQr
|
|
|
7
7
|
|
|
8
8
|
SWISH_QR_API_ENDPOINT="https://www.swish.bankgirot.se/qrg-swish/api/v1/prefilled"
|
|
9
9
|
@result = {}
|
|
10
|
-
@
|
|
10
|
+
@data_hash = {}
|
|
11
11
|
@image_format
|
|
12
|
-
attr_accessor :
|
|
12
|
+
attr_accessor :data_hash
|
|
13
13
|
|
|
14
14
|
SIMPLE_VALUES = [ :format, :size, :border, :transparent ]
|
|
15
15
|
COMPLEX_VALUES = [ :payee, :amount, :message ]
|
|
@@ -18,7 +18,7 @@ class SwishQr
|
|
|
18
18
|
def initialize(args)
|
|
19
19
|
check_args(args)
|
|
20
20
|
@result = HTTParty.post(SWISH_QR_API_ENDPOINT,
|
|
21
|
-
:body =>
|
|
21
|
+
:body => build_data_hash(args),
|
|
22
22
|
:headers => { 'Content-Type' => 'application/json' } )
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -38,6 +38,8 @@ class SwishQr
|
|
|
38
38
|
@result.parsed_response['error']
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
+
private
|
|
42
|
+
|
|
41
43
|
def check_args(args)
|
|
42
44
|
raise ArgumentError, "Invalid format: '#{args[:format]}', must specify one of: #{VALID_FORMATS}" unless VALID_FORMATS.include?(args[:format])
|
|
43
45
|
raise ArgumentError, "Size (minimum 300) must be specified for #{args[:format]}" unless (args[:format] == 'svg' || args[:size].to_i >= 300)
|
|
@@ -45,23 +47,23 @@ class SwishQr
|
|
|
45
47
|
raise ArgumentError, "Max border is 4" if (args[:border].to_i > 4)
|
|
46
48
|
end
|
|
47
49
|
|
|
48
|
-
def
|
|
50
|
+
def build_data_hash(args)
|
|
49
51
|
@image_format = args[:format]
|
|
50
|
-
@
|
|
51
|
-
@
|
|
52
|
+
@data_hash = get_simple_values_from_args(args)
|
|
53
|
+
@data_hash.merge!(get_complex_values_from_args(args))
|
|
52
54
|
sanitise_amount
|
|
53
|
-
@
|
|
55
|
+
@data_hash.to_json
|
|
54
56
|
end
|
|
55
57
|
|
|
56
58
|
def sanitise_amount
|
|
57
|
-
return unless @
|
|
59
|
+
return unless @data_hash[:amount]
|
|
58
60
|
# Delete amount if it's blank / 0, to ensure that the request is valid
|
|
59
|
-
if @
|
|
60
|
-
@
|
|
61
|
+
if @data_hash[:amount][:value].to_i == 0
|
|
62
|
+
@data_hash.delete(:amount)
|
|
61
63
|
return
|
|
62
64
|
end
|
|
63
65
|
# This is to support BigDecimal, which would otherwise get misrepresented as a string in the JSON
|
|
64
|
-
@
|
|
66
|
+
@data_hash[:amount][:value] = @data_hash[:amount][:value].to_f unless @data_hash[:amount][:value].is_a?(Integer)
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
def get_simple_values_from_args(args)
|
|
@@ -79,11 +81,11 @@ end
|
|
|
79
81
|
|
|
80
82
|
class SwishUri < SwishQr
|
|
81
83
|
def initialize(args)
|
|
82
|
-
|
|
84
|
+
build_data_hash(args)
|
|
83
85
|
end
|
|
84
86
|
|
|
85
87
|
def uri
|
|
86
|
-
"swish://payment?data=#{{version: 1}.merge(@
|
|
88
|
+
"swish://payment?data=#{{version: 1}.merge(@data_hash).to_json}"
|
|
87
89
|
end
|
|
88
90
|
end
|
|
89
91
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: swish_qr
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Linus Corin
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-12-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|
|
@@ -80,7 +80,8 @@ dependencies:
|
|
|
80
80
|
- - "~>"
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
|
-
description: An interface for the public Swish QR API
|
|
83
|
+
description: An interface for the public Swish QR API, and generator of Swish payment
|
|
84
|
+
URIs
|
|
84
85
|
email:
|
|
85
86
|
- noreply+see_website_for_email@corin.net
|
|
86
87
|
executables: []
|
|
@@ -111,5 +112,5 @@ rubyforge_project:
|
|
|
111
112
|
rubygems_version: 2.5.2
|
|
112
113
|
signing_key:
|
|
113
114
|
specification_version: 4
|
|
114
|
-
summary: QR code generator for Swish
|
|
115
|
+
summary: QR code and URI generator for Swish
|
|
115
116
|
test_files: []
|