debitech 1.3.0 → 1.6.1

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
- SHA1:
3
- metadata.gz: 80a1113ae193781f0000c1c5ce7d5dff6d4a8ef7
4
- data.tar.gz: f129e8f59589dc5a53d1d16d51030599f3926e34
2
+ SHA256:
3
+ metadata.gz: 448697aa6d7c6fec201cbca4371590832853ab761f32fde54fa510a85598611a
4
+ data.tar.gz: 475d18a41fbfbf71660dc6e897721fda5b83aea1127609be20954de89894330b
5
5
  SHA512:
6
- metadata.gz: f747691d6e2a953583edc59bd4e1f6189ab5d93aa2c4772357687d94b83c7c552590fd959f12a54ed395644f67a4e962deddc75f63fd1149ed2068eaff54a477
7
- data.tar.gz: 46d07f8d33c8ccd8ad81822074cc029886acbac904bcec55161d9b2e0580692c882fec6e21a986efcdc8045e846c07364122c1b94c5915de607dc257037d88f6
6
+ metadata.gz: '09ed9bdb56735924483932fa52135f19dc60235e9302814dfe2620509746cb6d008c64ea92d6aa19b298db53933ffdd2daf1a8deab97f453e057a0f57fa025a1'
7
+ data.tar.gz: '08b6a7ab5517031de70b1bf98e63c9a71b86baa570db26c948717552541039a9c856ce62053d997c70accea43a0a1a1b60a1051f75668957dd0bad3abd9a6ab1'
@@ -0,0 +1,26 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ matrix:
16
+ ruby-version: ["3.0", "2.7", "2.6", "2.5", "jruby-head"]
17
+
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Set up Ruby ${{ matrix.ruby-version }}
21
+ uses: ruby/setup-ruby@ae9cb3b565e36682a2c6045e4f664388da4c73aa
22
+ with:
23
+ ruby-version: ${{ matrix.ruby-version }}
24
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
25
+ - name: Run tests
26
+ run: bundle exec rake
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "tmp/**/*"
4
+ inherit_gem:
5
+ barsoom_utils: shared_rubocop.yml
data/Gemfile CHANGED
@@ -1,2 +1,10 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
+
3
+ gem "rexml" if RUBY_VERSION.start_with?("3")
4
+
2
5
  gemspec
6
+
7
+ group :development do
8
+ gem "barsoom_utils", github: "barsoom/barsoom_utils"
9
+ gem "rubocop"
10
+ end
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Debitech
2
2
 
3
- [![Build Status](https://travis-ci.org/barsoom/debitech.png?branch=master)](https://travis-ci.org/barsoom/debitech)
3
+ [![Ruby CI](https://github.com/barsoom/debitech/actions/workflows/ci.yml/badge.svg)](https://github.com/barsoom/debitech/actions/workflows/ci.yml)
4
4
 
5
5
  This is a DebiTech payment library extracted from production code.
6
6
 
7
7
  You can use this to do subscription payments without needing to handle any credit card information yourself.
8
8
 
9
- If you want something more low level, check the [debitech_soap](https://github.com/joakimk/debitech_soap) gem, which this library uses for API access.
9
+ If you want something more low-level, check the [debitech_soap](https://github.com/joakimk/debitech_soap) gem, which this library uses for API access.
10
10
 
11
11
  Setting up payments using DebiTech (one of the two payment systems run by DIBS) is not trivial,
12
12
  but it seems there are not many good options in Sweden yet. Atleast using this you don't need to
@@ -22,7 +22,9 @@ Todo:
22
22
 
23
23
  Add this line to your application's Gemfile:
24
24
 
25
- gem 'debitech'
25
+ ```ruby
26
+ gem 'debitech'
27
+ ```
26
28
 
27
29
  And then execute:
28
30
 
@@ -41,68 +43,77 @@ Get the API docs in DIBS manager, setup the account.
41
43
 
42
44
  ## Usage: Adding a credit card
43
45
 
44
- # MAC: Secret key shared by your app and DIBS, get it from the DIBS manager
45
- # METHOD: Something like cc.cekab, check the docs or ask support.
46
- debitech_web_config = {
47
- :merchant => "ACCOUNT_NAME",
48
- :secret_key => "MAC",
49
- :fields => { :method => "METHOD", pageSet: "my-default-pageset" }
50
- }
51
-
52
- # In the view: form to redirect the user to DIBS
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?`.
56
- <% custom_fields = { pageSet: "my-custom-pageset" } %>
57
- <form accept-charset="iso-8859-1" action="<%= api.form_action %>" method="post">
58
- <% api.form_fields(custom_fields).each do |name, value| %>
59
- <input name="<%= name %>" type="hidden" value="<%= value %>">
60
- <% end %>
61
-
62
- <!-- send translation strings, redirect back urls, etc here -->
63
- <input name="redirect_back_url" type="hidden" value="https://yourapp/credit_cards">
64
- </form>
65
-
66
- # When you get the response back (TODO: add example templates)
67
- api.valid_response?(mac, sum, reply, verify_id) # is the response from DIBS?
68
- api.approved_reply?(reply) # was the card added successfully?
69
-
70
- # Store verify_id as your reference to the card.
46
+ ```erb
47
+ # MAC: Secret key shared by your app and DIBS, get it from the DIBS manager
48
+ # METHOD: Something like cc.cekab, check the docs or ask support.
49
+ debitech_web_config = {
50
+ :merchant => "ACCOUNT_NAME",
51
+ :secret_key => "MAC",
52
+ :fields => { :method => "METHOD", pageSet: "my-default-pageset" }
53
+ }
54
+
55
+ # In the view: form to redirect the user to DIBS
56
+ <% api = Debitech::WebApi.new(debitech_web_config) %>
57
+ # You can optionally pass a hash of further custom fields.
58
+ # Note that if you override the "currency" here, you will also need to pass it explicitly into `valid_response?`.
59
+ <% custom_fields = { pageSet: "my-custom-pageset" } %>
60
+ <form accept-charset="iso-8859-1" action="<%= api.form_action %>" method="post">
61
+ <% api.form_fields(custom_fields).each do |name, value| %>
62
+ <input name="<%= name %>" type="hidden" value="<%= value %>">
63
+ <% end %>
64
+
65
+ <!-- send translation strings, redirect back urls, etc here -->
66
+ <input name="redirect_back_url" type="hidden" value="https://yourapp/credit_cards">
67
+ </form>
68
+ ```
69
+
70
+ ```ruby
71
+ # When you get the response back (TODO: add example templates)
72
+ api.valid_response?(mac, sum, reply, verify_id) # is the response from DIBS?
73
+ api.valid_response?(mac, sum, reply, verify_id, currency, reference_number) # if the request included "referenceNo", do this instead
74
+ api.approved_reply?(reply) # was the card added successfully?
75
+
76
+ # Store verify_id as your reference to the card.
77
+ ```
71
78
 
72
79
  ## Usage: Charging a credit card
73
80
 
74
81
  Configuration:
75
82
 
76
- # METHOD, MAC, ACCOUNT_NAME: Just like with the Web Api.
77
- # API_USER, API_PASSWORD: A API user you can create in DIBS manager.
78
- debitech_server_config = {
79
- :method => "METHOD",
80
- :secret_key => "MAC",
81
- :soap_opts => {
82
- :merchant => "ACCOUNT_NAME",
83
- :username => "API_USER",
84
- :password => "API_PASSWORD"
85
- }
86
- }
83
+ ```ruby
84
+ # METHOD, MAC, ACCOUNT_NAME: Just like with the Web Api.
85
+ # API_USER, API_PASSWORD: A API user you can create in DIBS manager.
86
+ debitech_server_config = {
87
+ :method => "METHOD",
88
+ :secret_key => "MAC",
89
+ :soap_opts => {
90
+ :merchant => "ACCOUNT_NAME",
91
+ :username => "API_USER",
92
+ :password => "API_PASSWORD"
93
+ }
94
+ }
95
+ ```
87
96
 
88
97
  First try to get "valid_credentials?" to return true using [debitech_soap](https://github.com/joakimk/debitech_soap). If it does not work, try to regenerate the password for the API user. Some characters are not possible with the SOAP library.
89
98
 
90
99
  Charging a credit card:
91
100
 
92
- debitech = Debitech::ServerApi.new(debitech_server_config)
93
-
94
- # VERIFY_ID: The id you get back when registering a card.
95
- # AMOUNT: The amount to charge, must be in cents (1 SEK = 100).
96
- # IP: The ip, can be "127.0.0.1", but the request ip is probably more useful.
97
- # UNIQUE_REFERENCE: A unique reference, you want this to be something like invoice-NUM, so that you can search for it
98
- # in DIBS manager with "invoice*". This is required so that you don't charge more than once for a
99
- # single payment by accident. Must be atleast 5 characters long.
100
-
101
- debitech.charge(:verify_id => verify_id,
102
- :amount => AMOUNT,
103
- :unique_reference => "UNIQUE_REFERENCE",
104
- :currency => "SEK",
105
- :ip => "IP")
101
+ ```ruby
102
+ debitech = Debitech::ServerApi.new(debitech_server_config)
103
+
104
+ # VERIFY_ID: The id you get back when registering a card.
105
+ # AMOUNT: The amount to charge, must be in cents (1 SEK = 100).
106
+ # IP: The ip, can be "127.0.0.1", but the request ip is probably more useful.
107
+ # UNIQUE_REFERENCE: A unique reference, you want this to be something like invoice-NUM, so that you can search for it
108
+ # in DIBS manager with "invoice*". This is required so that you don't charge more than once for a
109
+ # single payment by accident. Must be atleast 5 characters long.
110
+
111
+ debitech.charge(:verify_id => verify_id,
112
+ :amount => AMOUNT,
113
+ :unique_reference => "UNIQUE_REFERENCE",
114
+ :currency => "SEK",
115
+ :ip => "IP")
116
+ ```
106
117
 
107
118
  This returns a Debitech::ServerApi::ChargeResult, check [server_api.rb](https://github.com/barsoom/debitech/blob/master/lib/debitech/server_api.rb).
108
119
 
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env rake
2
- require 'bundler/gem_tasks'
3
- require 'rspec/core/rake_task'
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
4
 
5
5
  desc "Run all specs"
6
- RSpec::Core::RakeTask.new('spec') do |t|
7
- t.pattern = 'spec/**/*.rb'
6
+ RSpec::Core::RakeTask.new("spec") do |t|
7
+ t.pattern = "spec/**/*.rb"
8
8
  end
9
9
 
10
- task :default => :spec
10
+ task default: :spec
11
11
 
data/debitech.gemspec CHANGED
@@ -1,15 +1,16 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/debitech/version', __FILE__)
2
+ require File.expand_path("../lib/debitech/version", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.platform = Gem::Platform::RUBY
6
- s.authors = ["Joakim Kolsjö"]
7
- s.email = ["joakim@barsoom.se"]
6
+ s.authors = [ "Joakim Kolsjö" ]
7
+ s.email = [ "joakim@barsoom.se" ]
8
8
  s.description = %q{Library for doing payments using DebiTech (DIBS)}
9
9
  s.summary = %q{Library for doing payments using DebiTech (DIBS)}
10
10
  s.homepage = "https://github.com/barsoom/debitech"
11
11
  s.name = "debitech"
12
12
  s.version = Debitech::VERSION
13
+ s.metadata = { "rubygems_mfa_required" => "true" }
13
14
 
14
15
  s.required_ruby_version = ">= 1.8.7"
15
16
 
@@ -20,5 +21,5 @@ Gem::Specification.new do |s|
20
21
 
21
22
  s.files = `git ls-files`.split("\n")
22
23
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
23
- s.require_paths = ["lib"]
24
+ s.require_paths = [ "lib" ]
24
25
  end
@@ -13,7 +13,7 @@ module Debitech
13
13
  end
14
14
 
15
15
  def success?
16
- @response.result_code.to_s[0,1] == "1"
16
+ @response.result_code.to_s[0, 1] == "1"
17
17
  end
18
18
 
19
19
  def pending?
@@ -44,7 +44,7 @@ module Debitech
44
44
  data = "001:payment:1:#{opts[:amount].to_i}:"
45
45
  mac = Mac.build [ data, opts[:currency], opts[:unique_reference], @config[:secret_key] ]
46
46
  extra = "&method=#{@config[:method]}&currency=#{opts[:currency]}&MAC=#{mac}&referenceNo=#{opts[:unique_reference]}"
47
- response = @soap_api.subscribe_and_settle(:verifyID => opts[:verify_id], :ip => opts[:ip], :data => data, :extra => extra)
47
+ response = @soap_api.subscribe_and_settle(verifyID: opts[:verify_id], ip: opts[:ip], data: data, extra: extra)
48
48
  ChargeResult.new(response)
49
49
  end
50
50
  end
@@ -1,4 +1,4 @@
1
1
  module Debitech
2
2
  # try to follow http://semver.org/
3
- VERSION = "1.3.0"
3
+ VERSION = "1.6.1"
4
4
  end
@@ -13,19 +13,21 @@ module Debitech
13
13
 
14
14
  # you probably want to encode these when posting to dibs, for example HTMLEntities.new.encode(v, :named) (gem: htmlentities)
15
15
  def form_fields(more_custom_fields = {})
16
- # Overriding via the initializer may be more convenient for per-env stuff like "method"".
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
18
  all_fields_except_mac = custom_fields.merge(more_custom_fields)
19
19
  mac = request_mac(all_fields_except_mac)
20
- all_fields_except_mac.merge(:MAC => mac)
20
+ all_fields_except_mac.merge(MAC: mac)
21
21
  end
22
22
 
23
23
  def form_action
24
24
  "https://securedt.dibspayment.com/verify/bin/#{@merchant}/index"
25
25
  end
26
26
 
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
27
+ # If the currency was passed into form_fields (and thus isn't known on an instance level),
28
+ # you will need to pass it in explicitly here.
29
+ def valid_response?(mac, sum, reply, verify_id, currency = custom_fields[:currency], reference_number = nil)
30
+ response_mac(sum, reply, verify_id, currency, reference_number) == mac.upcase.split("=").last
29
31
  end
30
32
 
31
33
  def approved_reply?(reply)
@@ -40,30 +42,41 @@ module Debitech
40
42
 
41
43
  def base_fields
42
44
  {
43
- :currency => "SEK",
44
- :method => "cc.test",
45
- :amount => "100",
46
- :authOnly => "true",
47
- :pageSet => "creditcard",
48
- :data => "001:auth:1:100:",
49
- :uses3dsecure => "false",
50
- :billingFirstName => "First name",
51
- :billingLastName => "Last name",
52
- :billingAddress => "Address",
53
- :billingCity => "City",
54
- :billingCountry => "Country",
55
- :eMail => "email@example.com",
45
+ currency: "SEK",
46
+ method: "cc.test",
47
+ amount: "100",
48
+ authOnly: "true",
49
+ pageSet: "creditcard",
50
+ data: "001:auth:1:100:",
51
+ billingFirstName: "First name",
52
+ billingLastName: "Last name",
53
+ billingAddress: "Address",
54
+ billingCity: "City",
55
+ billingCountry: "Country",
56
+ eMail: "email@example.com",
56
57
  }
57
58
  end
58
59
 
59
60
  private
60
61
 
61
62
  def request_mac(fields)
62
- Mac.build [ fields[:data], fields[:currency], fields[:method], @secret_key ]
63
+ verify_id = fields[:verifyID]
64
+
65
+ if verify_id
66
+ Mac.build [ fields[:data], fields[:currency], fields[:method], @secret_key, verify_id ]
67
+ else
68
+ Mac.build [ fields[:data], fields[:currency], fields[:method], @secret_key ]
69
+ end
63
70
  end
64
71
 
65
- def response_mac(sum, reply, verify_id, currency)
66
- Mac.build [ sum, currency, reply, verify_id, @secret_key ]
72
+ def response_mac(sum, reply, verify_id, currency, reference_number)
73
+ # Reference number is optional, but if it's passed in when making the payment it
74
+ # needs to be part of the response_mac calculation to verify the payment result.
75
+ if reference_number
76
+ Mac.build [ sum, currency, reply, verify_id, reference_number, @secret_key ]
77
+ else
78
+ Mac.build [ sum, currency, reply, verify_id, @secret_key ]
79
+ end
67
80
  end
68
81
  end
69
82
  end
data/lib/debitech.rb CHANGED
@@ -1,3 +1,3 @@
1
- require 'debitech/version'
2
- require 'debitech/server_api'
3
- require 'debitech/web_api'
1
+ require "debitech/version"
2
+ require "debitech/server_api"
3
+ require "debitech/web_api"
@@ -2,51 +2,51 @@ require "debitech"
2
2
 
3
3
  describe Debitech::ServerApi, "charge" do
4
4
  let(:unique_reference) {
5
- { :unique_reference => "some_unique_ref" }
5
+ { unique_reference: "some_unique_ref" }
6
6
  }
7
7
 
8
8
  let(:transaction) {
9
- { :verify_id => 1234567, :amount => 2235, :currency => "SEK", :ip => "127.0.0.1" }.merge(unique_reference)
9
+ { verify_id: 1234567, amount: 2235, currency: "SEK", ip: "127.0.0.1" }.merge(unique_reference)
10
10
  }
11
11
 
12
12
  it "should perform a subscribe_and_settle call" do
13
13
  settings = {
14
- :secret_key => "112756FC8C60C5603C58DA6E0A4844ACFDB60525",
15
- :method => "cc.cekab",
16
- :soap_opts => {
17
- :merchant => "store",
18
- :username => "api_user",
19
- :password => "api_password",
20
- }
14
+ secret_key: "112756FC8C60C5603C58DA6E0A4844ACFDB60525",
15
+ method: "cc.cekab",
16
+ soap_opts: {
17
+ merchant: "store",
18
+ username: "api_user",
19
+ password: "api_password",
20
+ },
21
21
  }
22
22
 
23
23
  soap_api = double
24
- allow(DebitechSoap::API).to receive(:new).
25
- with({ :merchant => "store", :username => "api_user", :password => "api_password" }).
26
- and_return(soap_api)
24
+ allow(DebitechSoap::API).to receive(:new)
25
+ .with({ merchant: "store", username: "api_user", password: "api_password" })
26
+ .and_return(soap_api)
27
27
  expect(soap_api).to receive(:subscribe_and_settle).with(
28
- :verifyID => 1234567,
29
- :data => "001:payment:1:10000:",
30
- :ip => "127.0.0.1",
31
- :extra => "&method=cc.cekab&currency=SEK&MAC=1931EE498A77F6B12B2C2D2EC8599719EF9CE419&referenceNo=some_unique_ref",
28
+ verifyID: 1234567,
29
+ data: "001:payment:1:10000:",
30
+ ip: "127.0.0.1",
31
+ extra: "&method=cc.cekab&currency=SEK&MAC=1931EE498A77F6B12B2C2D2EC8599719EF9CE419&referenceNo=some_unique_ref",
32
32
  )
33
33
 
34
34
  server_api = Debitech::ServerApi.new(settings)
35
- server_api.charge(transaction.merge(:amount => 10000))
35
+ server_api.charge(transaction.merge(amount: 10000))
36
36
  end
37
37
 
38
38
  it "should convert the amount to a integer to avoid 500 errors" do
39
39
  soap_api = double
40
40
  allow(DebitechSoap::API).to receive(:new).and_return(soap_api)
41
41
  expect(soap_api).to receive(:subscribe_and_settle).with(
42
- :verifyID => 1234567,
43
- :data => "001:payment:1:2235:",
44
- :ip => "127.0.0.1",
45
- :extra => "&method=&currency=SEK&MAC=78B1144270B1A74A55539FAEB81BB49EC39B90DF&referenceNo=some_unique_ref",
42
+ verifyID: 1234567,
43
+ data: "001:payment:1:2235:",
44
+ ip: "127.0.0.1",
45
+ extra: "&method=&currency=SEK&MAC=78B1144270B1A74A55539FAEB81BB49EC39B90DF&referenceNo=some_unique_ref",
46
46
  )
47
47
 
48
48
  server_api = Debitech::ServerApi.new({})
49
- server_api.charge(transaction.merge(:amount => 2235.0))
49
+ server_api.charge(transaction.merge(amount: 2235.0))
50
50
  end
51
51
 
52
52
  it "should raise an error if the amount has a fraction" do
@@ -54,7 +54,7 @@ describe Debitech::ServerApi, "charge" do
54
54
  allow(DebitechSoap::API).to receive(:new).and_return(soap_api)
55
55
  server_api = Debitech::ServerApi.new({})
56
56
  expect {
57
- server_api.charge(transaction.merge(:amount => 2235.55))
57
+ server_api.charge(transaction.merge(amount: 2235.55))
58
58
  }.to raise_error("The amount (2235.55) contains fractions (for example 10.44 instead of 10), amount should specified in cents.")
59
59
  end
60
60
 
@@ -63,7 +63,7 @@ describe Debitech::ServerApi, "charge" do
63
63
  allow(DebitechSoap::API).to receive(:new).and_return(soap_api)
64
64
  server_api = Debitech::ServerApi.new({})
65
65
  expect {
66
- server_api.charge(transaction.merge(:unique_reference => nil))
66
+ server_api.charge(transaction.merge(unique_reference: nil))
67
67
  }.to raise_error(Debitech::ServerApi::ValidUniqueReferenceRequired)
68
68
  end
69
69
 
@@ -72,7 +72,7 @@ describe Debitech::ServerApi, "charge" do
72
72
  allow(DebitechSoap::API).to receive(:new).and_return(soap_api)
73
73
  server_api = Debitech::ServerApi.new({})
74
74
  expect {
75
- server_api.charge(transaction.merge(:unique_reference => "1234"))
75
+ server_api.charge(transaction.merge(unique_reference: "1234"))
76
76
  }.to raise_error(Debitech::ServerApi::ValidUniqueReferenceRequired)
77
77
  end
78
78
 
@@ -81,14 +81,14 @@ describe Debitech::ServerApi, "charge" do
81
81
  allow(DebitechSoap::API).to receive(:new).and_return(soap_api)
82
82
  allow(soap_api).to receive(:subscribe_and_settle)
83
83
  server_api = Debitech::ServerApi.new({})
84
- server_api.charge(transaction.merge(:unique_reference => "12345"))
84
+ server_api.charge(transaction.merge(unique_reference: "12345"))
85
85
  end
86
86
 
87
87
  [ 100, 101, 150, 199 ].each do |result_code|
88
88
  it "should return success for result_code #{result_code}" do
89
89
  soap_api = double
90
90
  allow(DebitechSoap::API).to receive(:new).and_return(soap_api)
91
- response = double(:result_code => result_code)
91
+ response = double(result_code: result_code)
92
92
  allow(soap_api).to receive(:subscribe_and_settle).and_return(response)
93
93
 
94
94
  server_api = Debitech::ServerApi.new({})
@@ -104,7 +104,7 @@ describe Debitech::ServerApi, "charge" do
104
104
  it "should not be successful for result_code #{result_code}" do
105
105
  soap_api = double
106
106
  allow(DebitechSoap::API).to receive(:new).and_return(soap_api)
107
- response = double(:result_code => result_code)
107
+ response = double(result_code: result_code)
108
108
  allow(soap_api).to receive(:subscribe_and_settle).and_return(response)
109
109
 
110
110
  server_api = Debitech::ServerApi.new({})
@@ -119,7 +119,7 @@ describe Debitech::ServerApi, "charge" do
119
119
  it "should return pending and not be successful for 403" do
120
120
  soap_api = double
121
121
  allow(DebitechSoap::API).to receive(:new).and_return(soap_api)
122
- response = double(:result_code => 403)
122
+ response = double(result_code: 403)
123
123
  allow(soap_api).to receive(:subscribe_and_settle).and_return(response)
124
124
  server_api = Debitech::ServerApi.new({})
125
125
  result = server_api.charge(unique_reference)
@@ -3,7 +3,7 @@ require "debitech"
3
3
 
4
4
  describe Debitech::WebApi do
5
5
  let(:secret_key) {
6
- { :secret_key => "secretkey" }
6
+ { secret_key: "secretkey" }
7
7
  }
8
8
 
9
9
  describe "form_fields" do
@@ -14,32 +14,38 @@ describe Debitech::WebApi do
14
14
  end
15
15
 
16
16
  it "is possible to override the values via the initializer" do
17
- fields = Debitech::WebApi.new(secret_key.merge(:fields => { :method => "cc.cekab" })).form_fields
17
+ fields = Debitech::WebApi.new(secret_key.merge(fields: { method: "cc.cekab" })).form_fields
18
18
  expect(fields[:method]).to eq "cc.cekab"
19
19
  end
20
20
 
21
21
  it "is possible to override the values via method parameters" do
22
- api = Debitech::WebApi.new(secret_key.merge(:fields => { :pageSet => "mydefault" }))
22
+ api = Debitech::WebApi.new(secret_key.merge(fields: { pageSet: "mydefault" }))
23
23
 
24
24
  expect(api.form_fields.fetch(:pageSet)).to eq "mydefault"
25
25
  expect(api.form_fields(pageSet: "override").fetch(:pageSet)).to eq "override"
26
26
  end
27
27
 
28
28
  it "calculates MAC" do
29
- expect(Debitech::WebApi.new({ :secret_key => "secretkey1" }).form_fields[:MAC]).to match /DF253765337968C5ED7E6EA530CD692942416ABE/
30
- expect(Debitech::WebApi.new({ :secret_key => "secretkey2" }).form_fields[:MAC]).to match /BEB3C370E37837734642111D44CA7E304A0F45F2/
29
+ expect(Debitech::WebApi.new({ secret_key: "secretkey1" }).form_fields[:MAC]).to match /DF253765337968C5ED7E6EA530CD692942416ABE/
30
+ expect(Debitech::WebApi.new({ secret_key: "secretkey2" }).form_fields[:MAC]).to match /BEB3C370E37837734642111D44CA7E304A0F45F2/
31
31
  end
32
32
 
33
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)
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
36
  expect(mac_without_override).not_to eq(mac_with_override)
37
37
  end
38
+
39
+ it "includes verify_id in the MAC if provided" do
40
+ mac_without_verify_id = Debitech::WebApi.new({ secret_key: "secretkey1" }).form_fields.fetch(:MAC)
41
+ mac_with_verify_id = Debitech::WebApi.new({ secret_key: "secretkey1" }).form_fields(verifyID: "123456").fetch(:MAC)
42
+ expect(mac_without_verify_id).not_to eq(mac_with_verify_id)
43
+ end
38
44
  end
39
45
 
40
46
  describe "form_action" do
41
47
  it "return the url based on shop" do
42
- api = Debitech::WebApi.new({ :merchant => "myshop" })
48
+ api = Debitech::WebApi.new({ merchant: "myshop" })
43
49
  expect(api.form_action).to include "https://securedt.dibspayment.com/verify/bin/myshop/index"
44
50
  end
45
51
  end
@@ -72,11 +78,11 @@ describe Debitech::WebApi do
72
78
  end
73
79
 
74
80
  it "is not true if the secretkey is different" do
75
- api = Debitech::WebApi.new({ :secret_key => "secretkey2" })
81
+ api = Debitech::WebApi.new({ secret_key: "secretkey2" })
76
82
  expect(api.valid_response?("MAC=667026AD7692F9AFDA362919EA72D8E6A250A849", "1,00", "A", "1234567")).to be false
77
83
  end
78
84
 
79
- it "handle if verify_id is an int" do
85
+ it "handles if verify_id is an integer" do
80
86
  api = Debitech::WebApi.new(secret_key)
81
87
  expect(api.valid_response?("MAC=667026AD7692F9AFDA362919EA72D8E6A250A849", "1,00", "A", 1234567)).to be true
82
88
  end
@@ -86,5 +92,10 @@ describe Debitech::WebApi do
86
92
  expect(api.valid_response?("MAC=667026AD7692F9AFDA362919EA72D8E6A250A849", "1,00", "A", 1234567, "SEK")).to be true
87
93
  expect(api.valid_response?("MAC=667026AD7692F9AFDA362919EA72D8E6A250A849", "1,00", "A", 1234567, "EUR")).to be false
88
94
  end
95
+
96
+ it "handles MAC based on reference_number" do
97
+ api = Debitech::WebApi.new(secret_key)
98
+ expect(api.valid_response?("MAC=AB4698D21798C6F3A1EA25CD67590A072211123D", "1,00", "A", "1234567", "SEK", "ref-123")).to be true
99
+ end
89
100
  end
90
101
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debitech
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Kolsjö
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-26 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debitech_soap
@@ -59,9 +59,9 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".github/workflows/ci.yml"
62
63
  - ".gitignore"
63
- - ".rvmrc"
64
- - ".travis.yml"
64
+ - ".rubocop.yml"
65
65
  - Gemfile
66
66
  - README.md
67
67
  - Rakefile
@@ -75,7 +75,8 @@ files:
75
75
  - spec/debitech/web_api_spec.rb
76
76
  homepage: https://github.com/barsoom/debitech
77
77
  licenses: []
78
- metadata: {}
78
+ metadata:
79
+ rubygems_mfa_required: 'true'
79
80
  post_install_message:
80
81
  rdoc_options: []
81
82
  require_paths:
@@ -91,8 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  - !ruby/object:Gem::Version
92
93
  version: '0'
93
94
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.4.8
95
+ rubygems_version: 3.2.28
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Library for doing payments using DebiTech (DIBS)
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use --create ruby-1.9.3@debitech
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.0
4
- - 1.9.3
5
- - jruby-19mode
6
- - rbx-19mode
7
- - ruby-head
8
- - jruby-head
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