debitech_soap 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ tools
2
+ .bundle
3
+ pkg
4
+ todo.txt
5
+ */*.swp
6
+ *.swp
7
+ */**/.*.swp
8
+ */**/*.swp
9
+ */*/*/*.swp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ree@debitech_soap
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in debitech_soap.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ debitech_soap (0.0.1)
5
+ activesupport
6
+ i18n
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ ZenTest (4.4.2)
12
+ activesupport (3.0.3)
13
+ autotest (4.4.6)
14
+ ZenTest (>= 4.4.1)
15
+ diff-lcs (1.1.2)
16
+ i18n (0.5.0)
17
+ rspec (2.3.0)
18
+ rspec-core (~> 2.3.0)
19
+ rspec-expectations (~> 2.3.0)
20
+ rspec-mocks (~> 2.3.0)
21
+ rspec-core (2.3.1)
22
+ rspec-expectations (2.3.0)
23
+ diff-lcs (~> 1.1.2)
24
+ rspec-mocks (2.3.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ autotest
31
+ debitech_soap!
32
+ rspec
data/LICENCE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 Joakim Kolsjö
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,61 @@
1
+ Work in progress!
2
+ ----
3
+
4
+ This is **work in progress and not usable yet**. [Readme Driven Development](http://tom.preston-werner.com/2010/08/23/readme-driven-development.html)...
5
+
6
+ WIP docs below
7
+ ----
8
+
9
+ This is a wrapper of the DebiTech SOAP API. It's intended to be API compatible with the DebiTech Java client but also supports a more developer friendly syntax :).
10
+
11
+ Installing
12
+ ----
13
+
14
+ gem install debitech_soap
15
+
16
+ Usage
17
+ ----
18
+
19
+ This is how you would have used the DebiTech Java API:
20
+
21
+ include_class "com.verifyeasy.server.VEServer"
22
+ veserver = VEServer.get_instance("https://secure.incab.se/verify/server/merchant_name")
23
+
24
+ This is how you use DebitechSoap:
25
+
26
+ require 'debitech_soap'
27
+ veserver = DebitechSoap::API.new(:merchant => "merchant_name", :username => "api_user_name", :password => "api_user_password")
28
+
29
+ Supported arguments
30
+ ----
31
+
32
+ Java style (see DebitechSoap::API::PARAMS.keys in lib/debitech_soap.rb):
33
+
34
+ veserver.refund(1234567, 23456, 100, "extra")
35
+
36
+ Hash:
37
+
38
+ veserver.refund(:verifyID => 1234567, :transID => 23456, :amount => 100, :extra => "extra")
39
+
40
+ Custom methods
41
+ ----
42
+
43
+ **valid_credentials?**: Returns **true** if the credentials work (calls "checkSwedishPersNo").
44
+
45
+ Return data
46
+ ----
47
+
48
+ - An object with methods for each attribute (See DebitechSoap::RETURN_DATA).
49
+ - Each attribute has serveral methods, for example "infoCode" can also be "getInfoCode" or "get_info_code".
50
+ - If the return value is a number it will be converted to an integer.
51
+
52
+ API docs
53
+ ----
54
+
55
+ Get DIBSServerManual.pdf from the DIBS Manager.
56
+
57
+ Known issues
58
+ ----
59
+
60
+ - Does not work with Ruby 1.9 (does not have "soap/wsdlDriver"). We have not been able to get "savon" to work.
61
+
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ desc "Run all specs"
7
+
8
+ RSpec::Core::RakeTask.new('spec') do |t|
9
+ t.pattern = 'spec/**/*.rb'
10
+ end
11
+
12
+ task :default => :spec
13
+
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "debitech_soap/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "debitech_soap"
7
+ s.version = DebitechSoap::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Joakim Kolsjö", 'Niklas Holmgren']
10
+ s.email = ["joakim.kolsjo@gmail.com", 'niklas.holmgren@bukowskis.com']
11
+ s.homepage = "http://github.com/joakimk/debitech_soap"
12
+ s.summary = %q{A pure ruby way to make payments with DebiTech}
13
+ s.description = %q{An implementation of the DebiTech Java API using pure ruby and the SOAP API.}
14
+
15
+ s.add_dependency "activesupport"
16
+ s.add_dependency "i18n" # Because of activesupport infections
17
+ s.add_development_dependency 'rspec'
18
+ s.add_development_dependency 'autotest'
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,3 @@
1
+ module DebitechSoap
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,105 @@
1
+ require 'soap/wsdlDriver'
2
+ require 'ostruct'
3
+ require 'rubygems'
4
+ require 'active_support'
5
+
6
+ begin
7
+ # Required for active_support 3+
8
+ require 'active_support/core_ext/string/inflections'
9
+ rescue LoadError
10
+ end
11
+
12
+ module DebitechSoap
13
+ class API
14
+
15
+ RETURN_DATA = %w{aCSUrl acquirerAddress acquirerAuthCode acquirerAuthResponseCode acquirerCity acquirerConsumerLimit acquirerErrorDescription acquirerFirstName acquirerLastName acquirerMerchantLimit acquirerZipCode amount errorMsg infoCode infoDescription pAReqMsg resultCode resultText verifyID}
16
+
17
+ PARAMS = { "settle" => ["verifyID", "transID", "amount", "extra"],
18
+ "subscribe_and_settle" => ["verifyID", "transID", "data", "ip", "extra"],
19
+ "authorize" => ["billingFirstName", "billingLastName", "billingAddress", "billingCity",
20
+ "billingCountry", "cc", "expM", "expY", "eMail", "ip", "data", "currency", "transID", "extra"],
21
+ "authorizeAndSettle3DS" => ["verifyID", "paRes", "extra"],
22
+ "refund" => ["verifyID", "transID", "amount", "extra"],
23
+ "askIf3DSEnrolled" => ["billingFirstName", "billingLastName", "billingAddress", "billingCity",
24
+ "billingCountry", "cc", "expM", "expY", "eMail", "ip", "data", "currency", "transID",
25
+ "httpAcceptHeader", "httpUserAgentHeader", "method", "referenceNo", "extra"],
26
+ "auth_reversal" => ["verifyID", "amount", "transID", "extra"],
27
+ "authorize3DS" => ["verifyID", "paRes", "extra"],
28
+ "subscribe" => ["verifyID", "transID", "data", "ip", "extra"],
29
+ "authorize_and_settle" => ["billingFirstName", "billingLastName", "billingAddress", "billingCity", "billingCountry",
30
+ "cc", "expM", "expY", "eMail", "ip", "data", "currency", "transID", "extra"] }
31
+
32
+ def initialize(opts = {})
33
+ @api_credentials = {}
34
+ @api_credentials[:shopName] = opts[:merchant]
35
+ @api_credentials[:userName] = opts[:username]
36
+ @api_credentials[:password] = opts[:password]
37
+
38
+ disable_stderr do
39
+ @client = SOAP::WSDLDriverFactory.new('https://secure.incab.se/axis2/services/DTServerModuleService_v1?wsdl').create_rpc_driver
40
+ end
41
+
42
+ define_java_wrapper_methods!
43
+ end
44
+
45
+ def valid_credentials?
46
+ disable_stderr do
47
+ @client.checkSwedishPersNo(@api_credentials.merge({ :persNo => "555555-5555" })).return == "true"
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def define_java_wrapper_methods!
54
+ PARAMS.keys.each { |method|
55
+ (class << self; self; end).class_eval do # Doc:
56
+ define_method(method) do |*args| # def refund(*args)
57
+ attributes = @api_credentials.clone
58
+
59
+ if args.first.is_a?(Hash)
60
+ attributes.merge!(args.first)
61
+ else
62
+ parameter_order = PARAMS[method.to_s]
63
+ args.each_with_index { |argument, i|
64
+ attributes[parameter_order[i].to_sym] = argument
65
+ }
66
+ end
67
+
68
+ return_data @client.send(method, attributes).return
69
+ end # end
70
+ end
71
+ }
72
+ end
73
+
74
+ def return_data(results)
75
+ hash = {}
76
+
77
+ RETURN_DATA.each { |attribute|
78
+ result = results.send(attribute)
79
+ unless result.is_a?(SOAP::Mapping::Object)
80
+ result = result.to_i if integer?(result)
81
+ hash[attribute] = result
82
+ hash["get_" + attribute.underscore] = result
83
+ hash["get" + attribute.camelcase] = result
84
+ hash[attribute.underscore] = result
85
+ end
86
+ }
87
+
88
+ OpenStruct.new(hash)
89
+ end
90
+
91
+ def integer?(result)
92
+ result.to_i != 0 || result == "0"
93
+ end
94
+
95
+ def disable_stderr
96
+ begin
97
+ $stderr = File.open('/dev/null', 'w')
98
+ yield
99
+ ensure
100
+ $stderr = STDERR
101
+ end
102
+ end
103
+
104
+ end
105
+ end
@@ -0,0 +1,139 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../lib/debitech_soap'))
2
+
3
+ class MockSoapResult
4
+ class MockReturn
5
+ def method_missing(*opts)
6
+ SOAP::Mapping::Object.new
7
+ end
8
+ end
9
+
10
+ def return
11
+ @return ||= MockReturn.new
12
+ end
13
+ end
14
+
15
+ describe DebitechSoap::API, "valid_credentials?" do
16
+
17
+ before do
18
+ @client = mock(Object)
19
+ SOAP::WSDLDriverFactory.stub!(:new).and_return(mock(Object, :create_rpc_driver => @client))
20
+ end
21
+
22
+ it "should call checkSwedishPersNo with the credentials and a valid swedish social security number" do
23
+ @client.should_receive(:checkSwedishPersNo).with(:shopName => "merchant_name", :userName => "api_user_name",
24
+ :password => "api_user_password", :persNo => "555555-5555").
25
+ and_return(mock(Object, :return => "true"))
26
+
27
+ api = DebitechSoap::API.new(:merchant => "merchant_name", :username => "api_user_name", :password => "api_user_password")
28
+ api.valid_credentials?.should == true
29
+ end
30
+
31
+ it "should return false if the service returns false" do
32
+ @client.stub!(:checkSwedishPersNo).and_return(mock(Object, :return => "false"))
33
+ api = DebitechSoap::API.new(:merchant => "merchant_name", :username => "api_user_name", :password => "api_user_password")
34
+ api.valid_credentials?.should == false
35
+ end
36
+
37
+ end
38
+
39
+ describe DebitechSoap::API, "calling a method with java-style arguments" do
40
+
41
+ before do
42
+ @client = mock(Object)
43
+ SOAP::WSDLDriverFactory.stub!(:new).and_return(mock(Object, :create_rpc_driver => @client))
44
+ end
45
+
46
+ it "should map the arguments to a hash and call the corresponding SOAP method" do
47
+ api = DebitechSoap::API.new(:merchant => "merchant_name", :username => "api_user_name", :password => "api_user_password")
48
+ @client.should_receive("refund").with(:verifyID => 1234567, :transID => 23456, :amount => 100, :extra => "extra",
49
+ :shopName => "merchant_name", :userName => "api_user_name", :password => "api_user_password").
50
+ and_return(MockSoapResult.new)
51
+ api.refund(1234567, 23456, 100, "extra")
52
+ end
53
+
54
+ it "should not keep old attributes when making subsequent api calls" do
55
+ api = DebitechSoap::API.new(:merchant => "merchant_name", :username => "api_user_name", :password => "api_user_password")
56
+ @client.should_receive("refund").with(:verifyID => 1234567, :transID => 23456, :amount => 100, :extra => "extra",
57
+ :shopName => "merchant_name", :userName => "api_user_name", :password => "api_user_password").
58
+ and_return(MockSoapResult.new)
59
+ @client.should_receive("authorize3DS").with(:verifyID => 1234567, :paRes => "RES", :extra => "extra",
60
+ :shopName => "merchant_name", :userName => "api_user_name", :password => "api_user_password").
61
+ and_return(MockSoapResult.new)
62
+
63
+ api.refund(1234567, 23456, 100, "extra")
64
+ api.authorize3DS(1234567, "RES", "extra")
65
+ end
66
+
67
+ it "should create a return object" do
68
+ api = DebitechSoap::API.new
69
+ mock_soap_result = MockSoapResult.new
70
+ mock_soap_result.return.stub!(:resultText).and_return("success")
71
+ @client.stub!("refund").and_return(mock_soap_result)
72
+ api.refund(1234567, 23456, 100, "extra").resultText.should == "success"
73
+ end
74
+
75
+ it "should return nil when there is no data" do
76
+ api = DebitechSoap::API.new
77
+ mock_soap_result = MockSoapResult.new
78
+ @client.stub!("refund").and_return(mock_soap_result)
79
+ api.refund(1234567, 23456, 100, "extra").resultCode.should be_nil
80
+ end
81
+
82
+ it "should be able to access the data using getCamelCase, get_underscore and underscore methods" do
83
+ api = DebitechSoap::API.new
84
+ mock_soap_result = MockSoapResult.new
85
+ mock_soap_result.return.stub!(:resultText).and_return("success")
86
+ @client.stub!("refund").and_return(mock_soap_result)
87
+ result = api.refund(1234567, 23456, 100, "extra")
88
+ result.getResultText.should == "success"
89
+ result.get_result_text.should == "success"
90
+ result.result_text.should == 'success'
91
+ end
92
+
93
+ it "should convert the result to an integer when its a number" do
94
+ api = DebitechSoap::API.new
95
+ mock_soap_result = MockSoapResult.new
96
+ mock_soap_result.return.stub!(:resultCode).and_return("100")
97
+ @client.stub!("refund").and_return(mock_soap_result)
98
+ result = api.refund(1234567, 23456, 100, "extra")
99
+ result.resultCode.should == 100
100
+ result.getResultCode.should == 100
101
+ result.get_result_code.should == 100
102
+ end
103
+
104
+ it "should convert the result to an integer when its zero" do
105
+ api = DebitechSoap::API.new
106
+ mock_soap_result = MockSoapResult.new
107
+ mock_soap_result.return.stub!(:resultCode).and_return("0")
108
+ @client.stub!("refund").and_return(mock_soap_result)
109
+ result = api.refund(1234567, 23456, 100, "extra")
110
+ result.resultCode.should == 0
111
+ end
112
+
113
+ end
114
+
115
+ describe DebitechSoap::API, "calling a method with hash-style arguments" do
116
+
117
+ before do
118
+ @client = mock(Object)
119
+ SOAP::WSDLDriverFactory.stub!(:new).and_return(mock(Object, :create_rpc_driver => @client))
120
+ end
121
+
122
+ it "should call the corresponding soap method" do
123
+ api = DebitechSoap::API.new(:merchant => "merchant_name", :username => "api_user_name", :password => "api_user_password")
124
+ @client.should_receive("refund").with(:verifyID => 1234567, :transID => 23456, :amount => 100, :extra => "extra",
125
+ :shopName => "merchant_name", :userName => "api_user_name", :password => "api_user_password").
126
+ and_return(MockSoapResult.new)
127
+ api.refund(:verifyID => 1234567, :transID => 23456, :amount => 100, :extra => "extra")
128
+ end
129
+
130
+ it "should return data" do
131
+ api = DebitechSoap::API.new
132
+ mock_soap_result = MockSoapResult.new
133
+ mock_soap_result.return.stub!(:resultText).and_return("success")
134
+ @client.stub!("refund").and_return(mock_soap_result)
135
+ api.refund(:verifyID => 1234567, :transID => 23456, :amount => 100, :extra => "extra").getResultText.should == "success"
136
+ end
137
+
138
+ end
139
+
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: debitech_soap
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "Joakim Kolsj\xC3\xB6"
14
+ - Niklas Holmgren
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-01-27 00:00:00 +01:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: activesupport
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: i18n
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: autotest
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ description: An implementation of the DebiTech Java API using pure ruby and the SOAP API.
79
+ email:
80
+ - joakim.kolsjo@gmail.com
81
+ - niklas.holmgren@bukowskis.com
82
+ executables: []
83
+
84
+ extensions: []
85
+
86
+ extra_rdoc_files: []
87
+
88
+ files:
89
+ - .gitignore
90
+ - .rvmrc
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENCE
94
+ - README.markdown
95
+ - Rakefile
96
+ - autotest/discover.rb
97
+ - debitech_soap.gemspec
98
+ - lib/debitech_soap.rb
99
+ - lib/debitech_soap/version.rb
100
+ - spec/debitech_soap_spec.rb
101
+ has_rdoc: true
102
+ homepage: http://github.com/joakimk/debitech_soap
103
+ licenses: []
104
+
105
+ post_install_message:
106
+ rdoc_options: []
107
+
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 3
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ requirements: []
129
+
130
+ rubyforge_project:
131
+ rubygems_version: 1.3.7
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: A pure ruby way to make payments with DebiTech
135
+ test_files:
136
+ - spec/debitech_soap_spec.rb