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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/swish_qr.rb +22 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93326fd5d9efd57f41c00e3c72d66ae379a7326b
4
- data.tar.gz: 5fb2b8a6e5d5231f02ed1611f61ec2a247224bf8
3
+ metadata.gz: d74217fa684799cd15d8abc1ae3e64a7a6bb192d
4
+ data.tar.gz: f9bf83f426042ca00e4f8ec8cbb941d40efa4b7c
5
5
  SHA512:
6
- metadata.gz: 21778b12357f0b50ee25a56121beb6d8ec61f25291b662399bff4f02acb83d1983f5bf2ceb3fbab482857d99a35f887fd130abf8bc469e0c9f4dc1e81b4a4187
7
- data.tar.gz: d9b41f3149996f00179a28e7df6caf94e933e18f2f202639044871690f054a90a7231f75081dc3fe20fbb3ee95b8566e29392349bb22cc7c243be6c49a9427a6
6
+ metadata.gz: 3b047569b1630493a0631c8a2784efc264e2faf1f8011346cfa5d4a4695089fc4e633697141d419e34046b8e4ce3bf59525c920d4df45c2efe68b1d4710a934e
7
+ data.tar.gz: 178d855fdc6bfd4cdfbc439cd3b47a54aca8b04e9cfe0bd0b4f8f7770bc0e477526345353826d7c052fa1e949c838faffac13c06eccc92064b8738e45e42894d
@@ -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
- @request_hash.delete(:amount) if @request_hash[:amount] && @request_hash[:amount][:value].to_i == 0
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
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swish_qr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Linus Corin