ideal 0.2.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.
data/test/helper.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'mocha'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+
8
+ require 'ideal'
9
+
10
+ $stdout.sync = true
11
+
12
+ module Test
13
+ module Unit
14
+ class TestCase
15
+ HOME_DIR = RUBY_PLATFORM =~ /mswin32/ ? ENV['HOMEPATH'] : ENV['HOME'] unless defined?(HOME_DIR)
16
+ LOCAL_CREDENTIALS = File.join(HOME_DIR.to_s, '.ideal/fixtures.yml') unless defined?(LOCAL_CREDENTIALS)
17
+ DEFAULT_CREDENTIALS = File.join(File.dirname(__FILE__), 'fixtures.yml') unless defined?(DEFAULT_CREDENTIALS)
18
+
19
+ private
20
+
21
+ def all_fixtures
22
+ @fixtures ||= load_fixtures
23
+ end
24
+
25
+ def fixtures(key)
26
+ data = all_fixtures[key] || raise(StandardError, "No fixture data was found for '#{key}'")
27
+ data.dup
28
+ end
29
+
30
+ def load_fixtures
31
+ file = File.exists?(LOCAL_CREDENTIALS) ? LOCAL_CREDENTIALS : DEFAULT_CREDENTIALS
32
+ YAML.load(File.read(file))
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,203 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../helper', __FILE__)
4
+
5
+ class IdealTest < Test::Unit::TestCase
6
+ def setup
7
+ setup_ideal_gateway(fixtures('default'))
8
+ Ideal::Gateway.environment = :test
9
+
10
+ @gateway = Ideal::Gateway.new
11
+
12
+ @valid_options = {
13
+ :issuer_id => '0151',
14
+ :expiration_period => 'PT10M',
15
+ :return_url => 'http://return_to.example.com',
16
+ :order_id => '123456789012',
17
+ :currency => 'EUR',
18
+ :description => 'A classic Dutch windmill',
19
+ :entrance_code => '1234'
20
+ }
21
+ end
22
+
23
+ def test_making_test_requests
24
+ assert @gateway.issuers.test?
25
+ end
26
+
27
+ def test_setup_purchase_with_valid_options
28
+ response = @gateway.setup_purchase(550, @valid_options)
29
+ assert_success response
30
+ assert_not_nil response.service_url
31
+ assert_not_nil response.transaction_id
32
+ assert_equal @valid_options[:order_id], response.order_id
33
+ end
34
+
35
+ def test_setup_purchase_with_invalid_amount
36
+ response = @gateway.setup_purchase(0.5, @valid_options)
37
+
38
+ assert_failure response
39
+ assert_equal "BR1210", response.error_code
40
+ assert_not_nil response.error_message
41
+ assert_not_nil response.consumer_error_message
42
+ end
43
+
44
+ # TODO: Should we raise a SecurityError instead of setting success to false?
45
+ def test_status_response_with_invalid_signature
46
+ Ideal::StatusResponse.any_instance.stubs(:signature).returns('db82/jpJRvKQKoiDvu33X0yoDAQpayJOaW2Y8zbR1qk1i3epvTXi+6g+QVBY93YzGv4w+Va+vL3uNmzyRjYsm2309d1CWFVsn5Mk24NLSvhYfwVHEpznyMqizALEVUNSoiSHRkZUDfXowBAyLT/tQVGbuUuBj+TKblY826nRa7U=')
47
+ response = capture_transaction(:success)
48
+
49
+ assert_failure response
50
+ assert !response.verified?
51
+ end
52
+
53
+ ###
54
+ #
55
+ # These are the 7 integration tests of ING which need to be ran sucessfuly
56
+ # _before_ you'll get access to the live environment.
57
+ #
58
+ # See test_transaction_id for info on how the remote tests are ran.
59
+ #
60
+
61
+ def test_retrieval_of_issuers
62
+ assert_equal [{ :id => '0151', :name => 'Issuer Simulator' }], @gateway.issuers.list
63
+ end
64
+
65
+ def test_successful_transaction
66
+ capture_transaction(:success)
67
+ assert_success capture_transaction(:success)
68
+ end
69
+
70
+ def test_cancelled_transaction
71
+ captured_response = capture_transaction(:cancelled)
72
+
73
+ assert_failure captured_response
74
+ assert_equal :cancelled, captured_response.status
75
+ end
76
+
77
+ def test_expired_transaction
78
+ captured_response = capture_transaction(:expired)
79
+
80
+ assert_failure captured_response
81
+ assert_equal :expired, captured_response.status
82
+ end
83
+
84
+ def test_still_open_transaction
85
+ captured_response = capture_transaction(:open)
86
+
87
+ assert_failure captured_response
88
+ assert_equal :open, captured_response.status
89
+ end
90
+
91
+ def test_failed_transaction
92
+ captured_response = capture_transaction(:failure)
93
+
94
+ assert_failure captured_response
95
+ assert_equal :failure, captured_response.status
96
+ end
97
+
98
+ def test_internal_server_error
99
+ captured_response = capture_transaction(:server_error)
100
+
101
+ assert_failure captured_response
102
+ assert_equal 'SO1000', captured_response.error_code
103
+ end
104
+
105
+ private
106
+
107
+ # Shortcut method which does a #setup_purchase through #test_transaction and
108
+ # captures the resulting transaction and returns the capture response.
109
+ def capture_transaction(type)
110
+ @gateway.capture test_transaction(type).transaction_id
111
+ end
112
+
113
+ # Calls #setup_purchase with the amount corresponding to the named test and
114
+ # returns the response. Before returning an assertion will be ran to test
115
+ # whether or not the transaction was successful.
116
+ def test_transaction(type)
117
+ amount = case type
118
+ when :success then 100
119
+ when :cancelled then 200
120
+ when :expired then 300
121
+ when :open then 400
122
+ when :failure then 500
123
+ when :server_error then 700
124
+ end
125
+
126
+ response = @gateway.setup_purchase(amount, @valid_options)
127
+ assert response.success?
128
+ response
129
+ end
130
+
131
+ # Setup the gateway by providing a hash of attributes and values.
132
+ def setup_ideal_gateway(fixture)
133
+ fixture = fixture.dup
134
+ # The passphrase needs to be set first, otherwise the key won't initialize properly
135
+ if passphrase = fixture.delete('passphrase')
136
+ Ideal::Gateway.passphrase = passphrase
137
+ end
138
+ fixture.each { |key, value| Ideal::Gateway.send("#{key}=", value) }
139
+ Ideal::Gateway.live_url = nil
140
+ end
141
+
142
+ # Allows the testing of you to check for negative assertions:
143
+ #
144
+ # # Instead of
145
+ # assert !something_that_is_false
146
+ #
147
+ # # Do this
148
+ # assert_false something_that_should_be_false
149
+ #
150
+ # An optional +msg+ parameter is available to help you debug.
151
+ def assert_false(boolean, message = nil)
152
+ message = build_message message, '<?> is not false or nil.', boolean
153
+
154
+ clean_backtrace do
155
+ assert_block message do
156
+ not boolean
157
+ end
158
+ end
159
+ end
160
+
161
+ # A handy little assertion to check for a successful response:
162
+ #
163
+ # # Instead of
164
+ # assert response.success?
165
+ #
166
+ # # DRY that up with
167
+ # assert_success response
168
+ #
169
+ # A message will automatically show the inspection of the response
170
+ # object if things go afoul.
171
+ def assert_success(response)
172
+ clean_backtrace do
173
+ assert response.success?, "Response failed: #{response.inspect}"
174
+ end
175
+ end
176
+
177
+ # The negative of +assert_success+
178
+ def assert_failure(response)
179
+ clean_backtrace do
180
+ assert_false response.success?, "Response expected to fail: #{response.inspect}"
181
+ end
182
+ end
183
+
184
+ def assert_valid(validateable)
185
+ clean_backtrace do
186
+ assert validateable.valid?, "Expected to be valid"
187
+ end
188
+ end
189
+
190
+ def assert_not_valid(validateable)
191
+ clean_backtrace do
192
+ assert_false validateable.valid?, "Expected to not be valid"
193
+ end
194
+ end
195
+
196
+ private
197
+ def clean_backtrace(&block)
198
+ yield
199
+ rescue Test::Unit::AssertionFailedError => e
200
+ path = File.expand_path(__FILE__)
201
+ raise Test::Unit::AssertionFailedError, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ }
202
+ end
203
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ideal
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - Soemirno Kartosoewito
14
+ - Matthijs Kadijk
15
+ - Eloy Duran
16
+ - Manfred Stienstra
17
+ - Frank Oxener
18
+ autorequire:
19
+ bindir: bin
20
+ cert_chain: []
21
+
22
+ date: 2012-01-03 00:00:00 Z
23
+ dependencies:
24
+ - !ruby/object:Gem::Dependency
25
+ name: builder
26
+ prerelease: false
27
+ requirement: &id001 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ hash: 3
33
+ segments:
34
+ - 0
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: nap
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: mocha
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :development
65
+ version_requirements: *id003
66
+ description: iDEAL payment gateway (see http://www.ideal.nl and http://www.activemerchant.org/)
67
+ email: manfred@fngtps.com
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ extra_rdoc_files:
73
+ - LICENSE
74
+ - README.textile
75
+ files:
76
+ - .document
77
+ - .gitignore
78
+ - .travis.yml
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE
82
+ - README.textile
83
+ - Rakefile
84
+ - ideal.gemspec
85
+ - init.rb
86
+ - lib/ideal.rb
87
+ - lib/ideal/acquirers.rb
88
+ - lib/ideal/gateway.rb
89
+ - lib/ideal/response.rb
90
+ - lib/ideal/version.rb
91
+ - test/fixtures.yml
92
+ - test/gateway_test.rb
93
+ - test/helper.rb
94
+ - test/remote_test.rb
95
+ homepage: http://github.com/Fingertips/ideal
96
+ licenses: []
97
+
98
+ post_install_message:
99
+ rdoc_options: []
100
+
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project:
124
+ rubygems_version: 1.8.13
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: iDEAL payment gateway
128
+ test_files:
129
+ - test/fixtures.yml
130
+ - test/gateway_test.rb
131
+ - test/helper.rb
132
+ - test/remote_test.rb