debitech_soap 1.0.0 → 1.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/lib/debitech_soap.rb +2 -115
- data/lib/debitech_soap/api.rb +121 -0
- data/lib/debitech_soap/version.rb +1 -1
- metadata +20 -19
data/lib/debitech_soap.rb
CHANGED
@@ -1,117 +1,4 @@
|
|
1
|
-
require 'soap/wsdlDriver'
|
2
|
-
require 'ostruct'
|
3
|
-
require 'debitech_soap/string_extensions'
|
4
|
-
|
5
1
|
module DebitechSoap
|
6
|
-
|
7
|
-
|
8
|
-
RETURN_DATA = %w{aCSUrl acquirerAddress acquirerAuthCode acquirerAuthResponseCode acquirerCity acquirerConsumerLimit acquirerErrorDescription acquirerFirstName acquirerLastName acquirerMerchantLimit acquirerZipCode amount errorMsg infoCode infoDescription pAReqMsg resultCode resultText verifyID}
|
9
|
-
|
10
|
-
PARAMS = { %w(settle) => ["verifyID", "transID", "amount", "extra"],
|
11
|
-
%w(subscribeAndSettle subscribe_and_settle) \
|
12
|
-
=> ["verifyID", "transID", "data", "ip", "extra"],
|
13
|
-
%w(authorize) => ["billingFirstName", "billingLastName", "billingAddress", "billingCity",
|
14
|
-
"billingCountry", "cc", "expM", "expY", "eMail", "ip", "data", "currency", "transID", "extra"],
|
15
|
-
%w(authorizeAndSettle3DS authorize_and_settle_3ds) \
|
16
|
-
=> ["verifyID", "paRes", "extra"],
|
17
|
-
%w(refund) => ["verifyID", "transID", "amount", "extra"],
|
18
|
-
%w(askIf3DSEnrolled ask_if_3ds_enrolled) \
|
19
|
-
=> ["billingFirstName", "billingLastName", "billingAddress", "billingCity",
|
20
|
-
"billingCountry", "cc", "expM", "expY", "eMail", "ip", "data", "currency", "transID",
|
21
|
-
"httpAcceptHeader", "httpUserAgentHeader", "method", "referenceNo", "extra"],
|
22
|
-
%w(authReversal auth_reversal) => ["verifyID", "amount", "transID", "extra"],
|
23
|
-
%w(authorize3DS authorize_3ds) => ["verifyID", "paRes", "extra"],
|
24
|
-
%w(subscribe) => ["verifyID", "transID", "data", "ip", "extra"],
|
25
|
-
%w(authorizeAndSettle authorize_and_settle) \
|
26
|
-
=> ["billingFirstName", "billingLastName", "billingAddress", "billingCity", "billingCountry",
|
27
|
-
"cc", "expM", "expY", "eMail", "ip", "data", "currency", "transID", "extra"] }
|
28
|
-
|
29
|
-
def initialize(opts = {})
|
30
|
-
@api_credentials = {}
|
31
|
-
@api_credentials[:shopName] = opts[:merchant]
|
32
|
-
@api_credentials[:userName] = opts[:username]
|
33
|
-
@api_credentials[:password] = opts[:password]
|
34
|
-
|
35
|
-
disable_stderr do
|
36
|
-
@client = SOAP::WSDLDriverFactory.new(File.join(File.dirname(__FILE__), "service.wsdl")).create_rpc_driver
|
37
|
-
end
|
38
|
-
|
39
|
-
define_java_wrapper_methods!
|
40
|
-
end
|
41
|
-
|
42
|
-
def valid_credentials?
|
43
|
-
disable_stderr do
|
44
|
-
return_value(@client.checkSwedishPersNo(@api_credentials.merge({ :persNo => "5555555555" }))) == "true"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
# We use mumboe-soap4r for Ruby 1.9 compatibility, but if you use this library in 1.8 without using that lib
|
51
|
-
# (e.g. without bundle exec) then you might get the standard library SOAP lib instead.
|
52
|
-
# The standard library SOAP lib uses "return" here, and mumboe-soap4r uses "m_return".
|
53
|
-
def return_value(object)
|
54
|
-
object.respond_to?(:m_return) ? object.m_return : object.return
|
55
|
-
end
|
56
|
-
|
57
|
-
def define_java_wrapper_methods!
|
58
|
-
PARAMS.keys.flatten.each { |method|
|
59
|
-
(class << self; self; end).class_eval do # Doc:
|
60
|
-
define_method(method) do |*args| # def refund(*args)
|
61
|
-
attributes = @api_credentials.clone
|
62
|
-
|
63
|
-
if args.first.is_a?(Hash)
|
64
|
-
attributes.merge!(args.first)
|
65
|
-
else
|
66
|
-
parameter_order = api_signature(method).last
|
67
|
-
args.each_with_index { |argument, i|
|
68
|
-
attributes[parameter_order[i].to_sym] = argument
|
69
|
-
}
|
70
|
-
end
|
71
|
-
begin
|
72
|
-
client_result = return_value(@client.send(api_signature(method).first.first, attributes))
|
73
|
-
rescue Timeout::Error
|
74
|
-
client_result = OpenStruct.new(:resultCode => 403, :resultText => "SOAP Timeout")
|
75
|
-
return return_data(client_result)
|
76
|
-
end
|
77
|
-
return_data(client_result)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
}
|
81
|
-
end
|
82
|
-
|
83
|
-
def return_data(results)
|
84
|
-
hash = {}
|
85
|
-
|
86
|
-
RETURN_DATA.each { |attribute|
|
87
|
-
result = results.send(attribute)
|
88
|
-
unless result.is_a?(SOAP::Mapping::Object)
|
89
|
-
result = result.to_i if integer?(result)
|
90
|
-
hash[attribute] = result
|
91
|
-
hash["get_" + attribute.underscore] = result
|
92
|
-
hash["get" + attribute.camelcase] = result
|
93
|
-
hash[attribute.underscore] = result
|
94
|
-
end
|
95
|
-
}
|
96
|
-
OpenStruct.new(hash)
|
97
|
-
end
|
98
|
-
|
99
|
-
def integer?(result)
|
100
|
-
result.to_i != 0 || result == "0"
|
101
|
-
end
|
102
|
-
|
103
|
-
def disable_stderr
|
104
|
-
begin
|
105
|
-
$stderr = File.open('/dev/null', 'w')
|
106
|
-
yield
|
107
|
-
ensure
|
108
|
-
$stderr = STDERR
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def api_signature(method)
|
113
|
-
PARAMS.find {|key,value| key.include?(method.to_s) }
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
2
|
+
# It takes a little while to load, so don't load it when rails loads.
|
3
|
+
autoload :API, File.expand_path(File.join(File.dirname(__FILE__), 'debitech_soap/api'))
|
117
4
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
$previous_stderr = $stderr
|
3
|
+
$stderr = StringIO.new
|
4
|
+
require 'soap/wsdlDriver'
|
5
|
+
$stderr = $previous_stderr
|
6
|
+
require 'ostruct'
|
7
|
+
require 'debitech_soap/string_extensions'
|
8
|
+
|
9
|
+
module DebitechSoap
|
10
|
+
class API
|
11
|
+
|
12
|
+
RETURN_DATA = %w{aCSUrl acquirerAddress acquirerAuthCode acquirerAuthResponseCode acquirerCity acquirerConsumerLimit acquirerErrorDescription acquirerFirstName acquirerLastName acquirerMerchantLimit acquirerZipCode amount errorMsg infoCode infoDescription pAReqMsg resultCode resultText verifyID}
|
13
|
+
|
14
|
+
PARAMS = { %w(settle) => ["verifyID", "transID", "amount", "extra"],
|
15
|
+
%w(subscribeAndSettle subscribe_and_settle) \
|
16
|
+
=> ["verifyID", "transID", "data", "ip", "extra"],
|
17
|
+
%w(authorize) => ["billingFirstName", "billingLastName", "billingAddress", "billingCity",
|
18
|
+
"billingCountry", "cc", "expM", "expY", "eMail", "ip", "data", "currency", "transID", "extra"],
|
19
|
+
%w(authorizeAndSettle3DS authorize_and_settle_3ds) \
|
20
|
+
=> ["verifyID", "paRes", "extra"],
|
21
|
+
%w(refund) => ["verifyID", "transID", "amount", "extra"],
|
22
|
+
%w(askIf3DSEnrolled ask_if_3ds_enrolled) \
|
23
|
+
=> ["billingFirstName", "billingLastName", "billingAddress", "billingCity",
|
24
|
+
"billingCountry", "cc", "expM", "expY", "eMail", "ip", "data", "currency", "transID",
|
25
|
+
"httpAcceptHeader", "httpUserAgentHeader", "method", "referenceNo", "extra"],
|
26
|
+
%w(authReversal auth_reversal) => ["verifyID", "amount", "transID", "extra"],
|
27
|
+
%w(authorize3DS authorize_3ds) => ["verifyID", "paRes", "extra"],
|
28
|
+
%w(subscribe) => ["verifyID", "transID", "data", "ip", "extra"],
|
29
|
+
%w(authorizeAndSettle authorize_and_settle) \
|
30
|
+
=> ["billingFirstName", "billingLastName", "billingAddress", "billingCity", "billingCountry",
|
31
|
+
"cc", "expM", "expY", "eMail", "ip", "data", "currency", "transID", "extra"] }
|
32
|
+
|
33
|
+
def initialize(opts = {})
|
34
|
+
@api_credentials = {}
|
35
|
+
@api_credentials[:shopName] = opts[:merchant]
|
36
|
+
@api_credentials[:userName] = opts[:username]
|
37
|
+
@api_credentials[:password] = opts[:password]
|
38
|
+
|
39
|
+
disable_stderr do
|
40
|
+
@client = SOAP::WSDLDriverFactory.new(File.join(File.dirname(__FILE__), "service.wsdl")).create_rpc_driver
|
41
|
+
end
|
42
|
+
|
43
|
+
define_java_wrapper_methods!
|
44
|
+
end
|
45
|
+
|
46
|
+
def valid_credentials?
|
47
|
+
disable_stderr do
|
48
|
+
return_value(@client.checkSwedishPersNo(@api_credentials.merge({ :persNo => "5555555555" }))) == "true"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# We use mumboe-soap4r for Ruby 1.9 compatibility, but if you use this library in 1.8 without using that lib
|
55
|
+
# (e.g. without bundle exec) then you might get the standard library SOAP lib instead.
|
56
|
+
# The standard library SOAP lib uses "return" here, and mumboe-soap4r uses "m_return".
|
57
|
+
def return_value(object)
|
58
|
+
object.respond_to?(:m_return) ? object.m_return : object.return
|
59
|
+
end
|
60
|
+
|
61
|
+
def define_java_wrapper_methods!
|
62
|
+
PARAMS.keys.flatten.each { |method|
|
63
|
+
(class << self; self; end).class_eval do # Doc:
|
64
|
+
define_method(method) do |*args| # def refund(*args)
|
65
|
+
attributes = @api_credentials.clone
|
66
|
+
|
67
|
+
if args.first.is_a?(Hash)
|
68
|
+
attributes.merge!(args.first)
|
69
|
+
else
|
70
|
+
parameter_order = api_signature(method).last
|
71
|
+
args.each_with_index { |argument, i|
|
72
|
+
attributes[parameter_order[i].to_sym] = argument
|
73
|
+
}
|
74
|
+
end
|
75
|
+
begin
|
76
|
+
client_result = return_value(@client.send(api_signature(method).first.first, attributes))
|
77
|
+
rescue Timeout::Error
|
78
|
+
client_result = OpenStruct.new(:resultCode => 403, :resultText => "SOAP Timeout")
|
79
|
+
return return_data(client_result)
|
80
|
+
end
|
81
|
+
return_data(client_result)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def return_data(results)
|
88
|
+
hash = {}
|
89
|
+
|
90
|
+
RETURN_DATA.each { |attribute|
|
91
|
+
result = results.send(attribute)
|
92
|
+
unless result.is_a?(SOAP::Mapping::Object)
|
93
|
+
result = result.to_i if integer?(result)
|
94
|
+
hash[attribute] = result
|
95
|
+
hash["get_" + attribute.underscore] = result
|
96
|
+
hash["get" + attribute.camelcase] = result
|
97
|
+
hash[attribute.underscore] = result
|
98
|
+
end
|
99
|
+
}
|
100
|
+
OpenStruct.new(hash)
|
101
|
+
end
|
102
|
+
|
103
|
+
def integer?(result)
|
104
|
+
result.to_i != 0 || result == "0"
|
105
|
+
end
|
106
|
+
|
107
|
+
def disable_stderr
|
108
|
+
begin
|
109
|
+
$stderr = File.open('/dev/null', 'w')
|
110
|
+
yield
|
111
|
+
ensure
|
112
|
+
$stderr = STDERR
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def api_signature(method)
|
117
|
+
PARAMS.find {|key,value| key.include?(method.to_s) }
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debitech_soap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Joakim Kolsj\xC3\xB6"
|
@@ -18,11 +18,12 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2013-05-
|
21
|
+
date: 2013-05-21 00:00:00 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: mumboe-soap4r
|
25
|
-
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
27
|
none: false
|
27
28
|
requirements:
|
28
29
|
- - ~>
|
@@ -34,12 +35,12 @@ dependencies:
|
|
34
35
|
- 8
|
35
36
|
- 4
|
36
37
|
version: 1.5.8.4
|
37
|
-
prerelease: false
|
38
38
|
type: :runtime
|
39
|
-
|
39
|
+
version_requirements: *id001
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rake
|
42
|
-
|
42
|
+
prerelease: false
|
43
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
44
|
none: false
|
44
45
|
requirements:
|
45
46
|
- - ">="
|
@@ -48,12 +49,12 @@ dependencies:
|
|
48
49
|
segments:
|
49
50
|
- 0
|
50
51
|
version: "0"
|
51
|
-
prerelease: false
|
52
52
|
type: :development
|
53
|
-
|
53
|
+
version_requirements: *id002
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: rspec
|
56
|
-
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
58
|
none: false
|
58
59
|
requirements:
|
59
60
|
- - ">="
|
@@ -62,12 +63,12 @@ dependencies:
|
|
62
63
|
segments:
|
63
64
|
- 0
|
64
65
|
version: "0"
|
65
|
-
prerelease: false
|
66
66
|
type: :development
|
67
|
-
|
67
|
+
version_requirements: *id003
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
69
|
name: guard
|
70
|
-
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
72
|
none: false
|
72
73
|
requirements:
|
73
74
|
- - ">="
|
@@ -76,12 +77,12 @@ dependencies:
|
|
76
77
|
segments:
|
77
78
|
- 0
|
78
79
|
version: "0"
|
79
|
-
prerelease: false
|
80
80
|
type: :development
|
81
|
-
|
81
|
+
version_requirements: *id004
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: guard-rspec
|
84
|
-
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
86
|
none: false
|
86
87
|
requirements:
|
87
88
|
- - ">="
|
@@ -90,9 +91,8 @@ dependencies:
|
|
90
91
|
segments:
|
91
92
|
- 0
|
92
93
|
version: "0"
|
93
|
-
prerelease: false
|
94
94
|
type: :development
|
95
|
-
|
95
|
+
version_requirements: *id005
|
96
96
|
description: An implementation of the DebiTech Java API using pure ruby and the SOAP API.
|
97
97
|
email:
|
98
98
|
- joakim.kolsjo@gmail.com
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- Rakefile
|
118
118
|
- debitech_soap.gemspec
|
119
119
|
- lib/debitech_soap.rb
|
120
|
+
- lib/debitech_soap/api.rb
|
120
121
|
- lib/debitech_soap/string_extensions.rb
|
121
122
|
- lib/debitech_soap/version.rb
|
122
123
|
- lib/service.wsdl
|