debitech 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24d3837cce2fed9f2d327af0a5e14a45956a7826
4
- data.tar.gz: 9353b96c987b1314af7487cdd795ef54d9b4ebb5
3
+ metadata.gz: 80a1113ae193781f0000c1c5ce7d5dff6d4a8ef7
4
+ data.tar.gz: f129e8f59589dc5a53d1d16d51030599f3926e34
5
5
  SHA512:
6
- metadata.gz: 7c309871d7f6a87f2e3abb27fe4a50cbaf137a19f22b923e536dcdc7bbacfc9854a65c3cdde6d0d1600b66ff09d37e9c3464351ee07e5e32850260c37edb0f7d
7
- data.tar.gz: 15e0e23ba1d96ab869b5ce09985cafb68000969ed781be8b32d229592f4e0491781bb30a0dcdd74fc999dec7cb537201051a4f17884967cd908d6266aa2c1dc6
6
+ metadata.gz: f747691d6e2a953583edc59bd4e1f6189ab5d93aa2c4772357687d94b83c7c552590fd959f12a54ed395644f67a4e962deddc75f63fd1149ed2068eaff54a477
7
+ data.tar.gz: 46d07f8d33c8ccd8ad81822074cc029886acbac904bcec55161d9b2e0580692c882fec6e21a986efcdc8045e846c07364122c1b94c5915de607dc257037d88f6
data/README.md CHANGED
@@ -50,8 +50,9 @@ Get the API docs in DIBS manager, setup the account.
50
50
  }
51
51
 
52
52
  # In the view: form to redirect the user to DIBS
53
- # You can optionally pass a hash of further custom fields.
54
53
  <% api = Debitech::WebApi.new(debitech_web_config) %>
54
+ # You can optionally pass a hash of further custom fields.
55
+ # Note that if you override the "currency" here, you will also need to pass it explicitly into `valid_response?`.
55
56
  <% custom_fields = { pageSet: "my-custom-pageset" } %>
56
57
  <form accept-charset="iso-8859-1" action="<%= api.form_action %>" method="post">
57
58
  <% api.form_fields(custom_fields).each do |name, value| %>
@@ -1,4 +1,4 @@
1
1
  module Debitech
2
2
  # try to follow http://semver.org/
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
@@ -15,18 +15,17 @@ module Debitech
15
15
  def form_fields(more_custom_fields = {})
16
16
  # Overriding via the initializer may be more convenient for per-env stuff like "method"".
17
17
  # Overriding via the method argument may be more convenient for per-request stuff like multiple pageSets.
18
- base_fields.
19
- merge(@custom_fields).
20
- merge(more_custom_fields).
21
- merge(:MAC => request_mac)
18
+ all_fields_except_mac = custom_fields.merge(more_custom_fields)
19
+ mac = request_mac(all_fields_except_mac)
20
+ all_fields_except_mac.merge(:MAC => mac)
22
21
  end
23
22
 
24
23
  def form_action
25
24
  "https://securedt.dibspayment.com/verify/bin/#{@merchant}/index"
26
25
  end
27
26
 
28
- def valid_response?(mac, sum, reply, verify_id)
29
- response_mac(sum, reply, verify_id) == mac.upcase.split("=").last
27
+ def valid_response?(mac, sum, reply, verify_id, currency = custom_fields[:currency])
28
+ response_mac(sum, reply, verify_id, currency) == mac.upcase.split("=").last
30
29
  end
31
30
 
32
31
  def approved_reply?(reply)
@@ -35,6 +34,10 @@ module Debitech
35
34
 
36
35
  private
37
36
 
37
+ def custom_fields
38
+ base_fields.merge(@custom_fields)
39
+ end
40
+
38
41
  def base_fields
39
42
  {
40
43
  :currency => "SEK",
@@ -53,12 +56,14 @@ module Debitech
53
56
  }
54
57
  end
55
58
 
56
- def request_mac
57
- Mac.build [ base_fields[:data], base_fields[:currency], base_fields[:method], @secret_key ]
59
+ private
60
+
61
+ def request_mac(fields)
62
+ Mac.build [ fields[:data], fields[:currency], fields[:method], @secret_key ]
58
63
  end
59
64
 
60
- def response_mac(sum, reply, verify_id)
61
- Mac.build [ sum, base_fields[:currency], reply, verify_id, @secret_key ]
65
+ def response_mac(sum, reply, verify_id, currency)
66
+ Mac.build [ sum, currency, reply, verify_id, @secret_key ]
62
67
  end
63
68
  end
64
69
  end
@@ -25,10 +25,16 @@ describe Debitech::WebApi do
25
25
  expect(api.form_fields(pageSet: "override").fetch(:pageSet)).to eq "override"
26
26
  end
27
27
 
28
- it "calculate mac" do
28
+ it "calculates MAC" do
29
29
  expect(Debitech::WebApi.new({ :secret_key => "secretkey1" }).form_fields[:MAC]).to match /DF253765337968C5ED7E6EA530CD692942416ABE/
30
30
  expect(Debitech::WebApi.new({ :secret_key => "secretkey2" }).form_fields[:MAC]).to match /BEB3C370E37837734642111D44CA7E304A0F45F2/
31
31
  end
32
+
33
+ it "accounts for overrides in the MAC" do
34
+ mac_without_override = Debitech::WebApi.new({ :secret_key => "secretkey1" }).form_fields.fetch(:MAC)
35
+ mac_with_override = Debitech::WebApi.new({ :secret_key => "secretkey1" }).form_fields(method: "other-method").fetch(:MAC)
36
+ expect(mac_without_override).not_to eq(mac_with_override)
37
+ end
32
38
  end
33
39
 
34
40
  describe "form_action" do
@@ -74,5 +80,11 @@ describe Debitech::WebApi do
74
80
  api = Debitech::WebApi.new(secret_key)
75
81
  expect(api.valid_response?("MAC=667026AD7692F9AFDA362919EA72D8E6A250A849", "1,00", "A", 1234567)).to be true
76
82
  end
83
+
84
+ it "lets you pass currency explicitly" do
85
+ api = Debitech::WebApi.new(secret_key)
86
+ expect(api.valid_response?("MAC=667026AD7692F9AFDA362919EA72D8E6A250A849", "1,00", "A", 1234567, "SEK")).to be true
87
+ expect(api.valid_response?("MAC=667026AD7692F9AFDA362919EA72D8E6A250A849", "1,00", "A", 1234567, "EUR")).to be false
88
+ end
77
89
  end
78
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debitech
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Kolsjö