debitech 1.1.0 → 1.2.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: 82279dd06b05d239c43e6ff2190190fa8ffd654b
4
- data.tar.gz: 9dd2575228951cce994151aab74f883af3a64f62
3
+ metadata.gz: 24d3837cce2fed9f2d327af0a5e14a45956a7826
4
+ data.tar.gz: 9353b96c987b1314af7487cdd795ef54d9b4ebb5
5
5
  SHA512:
6
- metadata.gz: e9343f83273a827349186aa6b63187eaf54674c5be823c19ad9968bc891979a1d50b0945a14de5fb1749962a71a4547bbf728696f64bb7efd93f5ccf3d6b9ccc
7
- data.tar.gz: e2a9dd971b861a830d0322f88734e304b07e2a6ec2518b71c1280987ce400e02edd0651cb1e29dcaa417c9108f69e78f48ca8cc063df3f9295e6a41d684ff926
6
+ metadata.gz: 7c309871d7f6a87f2e3abb27fe4a50cbaf137a19f22b923e536dcdc7bbacfc9854a65c3cdde6d0d1600b66ff09d37e9c3464351ee07e5e32850260c37edb0f7d
7
+ data.tar.gz: 15e0e23ba1d96ab869b5ce09985cafb68000969ed781be8b32d229592f4e0491781bb30a0dcdd74fc999dec7cb537201051a4f17884967cd908d6266aa2c1dc6
@@ -1,9 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.3.0
4
4
  - 1.9.3
5
5
  - jruby-19mode
6
6
  - rbx-19mode
7
7
  - ruby-head
8
8
  - jruby-head
9
- - ree
9
+
10
+ # Workaround for Travis + Bundler issues. If this ticket has been resolved, maybe we can remove the workaround.
11
+ # https://github.com/travis-ci/travis-ci/issues/3531
12
+ before_install:
13
+ - gem install bundler
data/README.md CHANGED
@@ -46,13 +46,15 @@ Get the API docs in DIBS manager, setup the account.
46
46
  debitech_web_config = {
47
47
  :merchant => "ACCOUNT_NAME",
48
48
  :secret_key => "MAC",
49
- :fields => { :method => "METHOD" }
49
+ :fields => { :method => "METHOD", pageSet: "my-default-pageset" }
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.
53
54
  <% api = Debitech::WebApi.new(debitech_web_config) %>
55
+ <% custom_fields = { pageSet: "my-custom-pageset" } %>
54
56
  <form accept-charset="iso-8859-1" action="<%= api.form_action %>" method="post">
55
- <% api.form_fields.each do |name, value| %>
57
+ <% api.form_fields(custom_fields).each do |name, value| %>
56
58
  <input name="<%= name %>" type="hidden" value="<%= value %>">
57
59
  <% end %>
58
60
 
@@ -1,4 +1,4 @@
1
1
  module Debitech
2
2
  # try to follow http://semver.org/
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
@@ -6,16 +6,23 @@ module Debitech
6
6
  APPROVED_REPLY = "A"
7
7
 
8
8
  def initialize(opts = {})
9
- @opts = opts
9
+ @merchant = opts.fetch(:merchant, nil)
10
+ @secret_key = opts.fetch(:secret_key, nil)
11
+ @custom_fields = opts.fetch(:fields, {})
10
12
  end
11
13
 
12
14
  # you probably want to encode these when posting to dibs, for example HTMLEntities.new.encode(v, :named) (gem: htmlentities)
13
- def form_fields
14
- base_fields.merge(:MAC => request_mac)
15
+ def form_fields(more_custom_fields = {})
16
+ # Overriding via the initializer may be more convenient for per-env stuff like "method"".
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)
15
22
  end
16
23
 
17
24
  def form_action
18
- "https://securedt.dibspayment.com/verify/bin/#{@opts[:merchant]}/index"
25
+ "https://securedt.dibspayment.com/verify/bin/#{@merchant}/index"
19
26
  end
20
27
 
21
28
  def valid_response?(mac, sum, reply, verify_id)
@@ -42,16 +49,16 @@ module Debitech
42
49
  :billingAddress => "Address",
43
50
  :billingCity => "City",
44
51
  :billingCountry => "Country",
45
- :eMail => "email@example.com"
46
- }.merge!(@opts[:fields] || {})
52
+ :eMail => "email@example.com",
53
+ }
47
54
  end
48
55
 
49
56
  def request_mac
50
- Mac.build [ base_fields[:data], base_fields[:currency], base_fields[:method], @opts[:secret_key] ]
57
+ Mac.build [ base_fields[:data], base_fields[:currency], base_fields[:method], @secret_key ]
51
58
  end
52
59
 
53
60
  def response_mac(sum, reply, verify_id)
54
- Mac.build [ sum, base_fields[:currency], reply, verify_id, @opts[:secret_key] ]
61
+ Mac.build [ sum, base_fields[:currency], reply, verify_id, @secret_key ]
55
62
  end
56
63
  end
57
64
  end
@@ -9,13 +9,20 @@ describe Debitech::WebApi do
9
9
  describe "form_fields" do
10
10
  it "include static values" do
11
11
  fields = Debitech::WebApi.new(secret_key).form_fields
12
- expect(fields[:currency]).to match /SEK/
13
- expect(fields[:method]).to match /cc.test/
12
+ expect(fields[:currency]).to eq "SEK"
13
+ expect(fields[:method]).to eq "cc.test"
14
14
  end
15
15
 
16
- it "is possible to override the values" do
16
+ it "is possible to override the values via the initializer" do
17
17
  fields = Debitech::WebApi.new(secret_key.merge(:fields => { :method => "cc.cekab" })).form_fields
18
- expect(fields[:method]).to match /cc.cekab/
18
+ expect(fields[:method]).to eq "cc.cekab"
19
+ end
20
+
21
+ it "is possible to override the values via method parameters" do
22
+ api = Debitech::WebApi.new(secret_key.merge(:fields => { :pageSet => "mydefault" }))
23
+
24
+ expect(api.form_fields.fetch(:pageSet)).to eq "mydefault"
25
+ expect(api.form_fields(pageSet: "override").fetch(:pageSet)).to eq "override"
19
26
  end
20
27
 
21
28
  it "calculate mac" do
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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Kolsjö