swish_qr 0.0.2 → 0.0.3
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 +22 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d74217fa684799cd15d8abc1ae3e64a7a6bb192d
|
|
4
|
+
data.tar.gz: f9bf83f426042ca00e4f8ec8cbb941d40efa4b7c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3b047569b1630493a0631c8a2784efc264e2faf1f8011346cfa5d4a4695089fc4e633697141d419e34046b8e4ce3bf59525c920d4df45c2efe68b1d4710a934e
|
|
7
|
+
data.tar.gz: 178d855fdc6bfd4cdfbc439cd3b47a54aca8b04e9cfe0bd0b4f8f7770bc0e477526345353826d7c052fa1e949c838faffac13c06eccc92064b8738e45e42894d
|
data/lib/swish_qr.rb
CHANGED
|
@@ -49,11 +49,21 @@ class SwishQr
|
|
|
49
49
|
@image_format = args[:format]
|
|
50
50
|
@request_hash = get_simple_values_from_args(args)
|
|
51
51
|
@request_hash.merge!(get_complex_values_from_args(args))
|
|
52
|
-
|
|
53
|
-
#puts @request_hash
|
|
52
|
+
sanitise_amount
|
|
54
53
|
@request_hash.to_json
|
|
55
54
|
end
|
|
56
55
|
|
|
56
|
+
def sanitise_amount
|
|
57
|
+
return unless @request_hash[:amount]
|
|
58
|
+
# Delete amount if it's blank / 0, to ensure that the request is valid
|
|
59
|
+
if @request_hash[:amount][:value].to_i == 0
|
|
60
|
+
@request_hash.delete(:amount)
|
|
61
|
+
return
|
|
62
|
+
end
|
|
63
|
+
# This is to support BigDecimal, which would otherwise get misrepresented as a string in the JSON
|
|
64
|
+
@request_hash[:amount][:value] = @request_hash[:amount][:value].to_f unless @request_hash[:amount][:value].is_a?(Integer)
|
|
65
|
+
end
|
|
66
|
+
|
|
57
67
|
def get_simple_values_from_args(args)
|
|
58
68
|
args.select{|k,v| SIMPLE_VALUES.include?(k)}
|
|
59
69
|
end
|
|
@@ -65,5 +75,15 @@ class SwishQr
|
|
|
65
75
|
end
|
|
66
76
|
ret
|
|
67
77
|
end
|
|
78
|
+
end
|
|
68
79
|
|
|
80
|
+
class SwishUri < SwishQr
|
|
81
|
+
def initialize(args)
|
|
82
|
+
build_request_body(args)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def uri
|
|
86
|
+
"swish://payment?data=#{{version: 1}.merge(@request_hash).to_json}"
|
|
87
|
+
end
|
|
69
88
|
end
|
|
89
|
+
|