debitech 1.2.0 → 1.3.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 +4 -4
- data/README.md +2 -1
- data/lib/debitech/version.rb +1 -1
- data/lib/debitech/web_api.rb +15 -10
- data/spec/debitech/web_api_spec.rb +13 -1
- 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: 80a1113ae193781f0000c1c5ce7d5dff6d4a8ef7
|
4
|
+
data.tar.gz: f129e8f59589dc5a53d1d16d51030599f3926e34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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| %>
|
data/lib/debitech/version.rb
CHANGED
data/lib/debitech/web_api.rb
CHANGED
@@ -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
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
57
|
-
|
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,
|
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 "
|
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
|