barzahlen 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,86 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Barzahlen::Api::Online::Api do
6
+ context 'request' do
7
+ it 'should call the correct url' do
8
+ http = double('Barzahlen::Online::Api:Http')
9
+ http.should_receive(:request)
10
+ .with(URI('https://api.barzahlen.de/path'), anything)
11
+ .and_return(get_successful_http_response)
12
+
13
+ api = Barzahlen::Api::Online::Api.new http, get_config
14
+ api.request 'path', :payment_key, [], {}
15
+ end
16
+
17
+ it 'should pass the correct parameters' do
18
+ http = double('Barzahlen::Online::Api:Http')
19
+ http.should_receive(:request)
20
+ .with(anything, :foo1 => 'foo1', :foo2 => 'bar2', :foo3 => 'bar3', :shop_id => 12345,
21
+ :hash => '539a7a8cf60febe6865ecb64369e8df819940249cbd6cdbe1a3ff72d3ca7087b1fdcd5c9396f2a0da6bced901364bfc5a2a4430b8dd405b96a4705c533eedeb0')
22
+ .and_return(get_successful_http_response)
23
+
24
+ api = Barzahlen::Api::Online::Api.new(http, get_config)
25
+ api.request 'path', :payment_key, [:foo1, :foo2, :foo3, :payment_key],
26
+ :foo1 => 'foo1', :foo2 => 'bar2', :foo3 => 'bar3'
27
+ end
28
+
29
+ it 'should return the correct result' do
30
+ http = double('Barzahlen::Online::Api:Http')
31
+ allow(http).to receive(:request).and_return(get_successful_http_response)
32
+
33
+ api = Barzahlen::Api::Online::Api.new http, get_config
34
+ result = api.request 'path', :payment_key, [], {}
35
+
36
+ result.should == {
37
+ :transaction_id => '227840174',
38
+ :result => '0',
39
+ :hash => '0714be1522e16fe67f397767c98cf37e37fd9c2a5391f49f8b01cb66642150751c77a0cce1ef7268e7bdeee792ed63eab53ef9b860f721c9d9d47ffc871ee3f9'
40
+ }
41
+ end
42
+
43
+ it 'should raise a runtime error on a response code that different to 200' do
44
+ http = double('Barzahlen::Online::Api:Http')
45
+ allow(http).to receive(:request).and_return(get_http_response('500', 'error'))
46
+
47
+ api = Barzahlen::Api::Online::Api.new http, get_config
48
+ expect { api.request 'path', :payment_key, [], {} }.to raise_error
49
+ end
50
+ end
51
+
52
+ context 'build_hash' do
53
+ it 'should generate hash' do
54
+ http = double('Barzahlen::Online::Api:Http')
55
+
56
+ parameters_order = [:foo1, :foo2, :foo3, :payment_key]
57
+
58
+ api = Barzahlen::Api::Online::Api.new http, get_config
59
+ hash = api.build_hash :payment_key, parameters_order,
60
+ :foo1 => 'foo1', :foo2 => 'bar2', :foo3 => 'bar3'
61
+
62
+ hash.should == '539a7a8cf60febe6865ecb64369e8df819940249cbd6cdbe1a3ff72d3ca7087b1fdcd5c9396f2a0da6bced901364bfc5a2a4430b8dd405b96a4705c533eedeb0'
63
+ end
64
+ end
65
+
66
+ private
67
+ def get_config
68
+ {:host => 'api.barzahlen.de',
69
+ :shop_id => 12345,
70
+ :payment_key => 'foobarfoobar',
71
+ :notification_key => 'barfoobarfoo',
72
+ :language => 'de',}
73
+ end
74
+
75
+ def get_successful_http_response
76
+ get_http_response '200', "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response><transaction-id>227840174</transaction-id><result>0</result><hash>0714be1522e16fe67f397767c98cf37e37fd9c2a5391f49f8b01cb66642150751c77a0cce1ef7268e7bdeee792ed63eab53ef9b860f721c9d9d47ffc871ee3f9</hash></response>"
77
+ end
78
+
79
+ def get_http_response(code, body)
80
+ http_response = double 'Net::HTTPResponse'
81
+ allow(http_response).to receive(:code).and_return(code)
82
+ allow(http_response).to receive(:body).and_return(body)
83
+
84
+ http_response
85
+ end
86
+ end
@@ -0,0 +1,15 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Barzahlen::Api::Online::HashBuilder do
6
+ it 'should generate hash' do
7
+ parameters_order = [:foo1, :foo2, :foo3, :payment_key]
8
+ key_parameter_name = :payment_key
9
+
10
+ hash_builder = Barzahlen::Api::Online::HashBuilder.new(parameters_order, key_parameter_name)
11
+ hash = hash_builder.build_hash 'foobarfoobar', :foo1 => 'foo1', :foo2 => 'bar2', :foo3 => 'bar3'
12
+
13
+ hash.should == '539a7a8cf60febe6865ecb64369e8df819940249cbd6cdbe1a3ff72d3ca7087b1fdcd5c9396f2a0da6bced901364bfc5a2a4430b8dd405b96a4705c533eedeb0'
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'net/http'
5
+
6
+ describe Barzahlen::Api::Online::Http do
7
+ it 'should return HTTPResponse' do
8
+ http = Barzahlen::Api::Online::Http.new
9
+ response = http.request URI('http://www.barzahlen.de/'), {}
10
+
11
+ expect(response).to be_a Net::HTTPResponse
12
+ end
13
+ end
@@ -0,0 +1,240 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Barzahlen::Api::Online::NotificationHandler do
6
+ context 'validate_request TRANSACTION_PAID' do
7
+ it 'should return correct request on transaction-paid notification' do
8
+ request_parameters = {
9
+ :state => Barzahlen::Api::Online::NotificationHandler::TRANSACTION_PAID,
10
+ :transaction_id => '123',
11
+ :shop_id => '456',
12
+ :customer_email => 'foo@example.com',
13
+ :amount => '13.37',
14
+ :currency => 'EUR',
15
+ :order_id => '123',
16
+ :custom_var_0 => 'custom_var_0',
17
+ :custom_var_1 => 'custom_var_1',
18
+ :custom_var_2 => 'custom_var_2',
19
+ :hash => 'some hash'
20
+ }
21
+
22
+ notification_handler = Barzahlen::Api::Online::NotificationHandler.new get_api
23
+ request = notification_handler.validate_request(request_parameters)
24
+ request.should == {
25
+ :state => Barzahlen::Api::Online::NotificationHandler::TRANSACTION_PAID,
26
+ :transaction_id => '123',
27
+ :shop_id => '456',
28
+ :customer_email => 'foo@example.com',
29
+ :amount => '13.37',
30
+ :currency => 'EUR',
31
+ :order_id => '123',
32
+ :custom_var_0 => 'custom_var_0',
33
+ :custom_var_1 => 'custom_var_1',
34
+ :custom_var_2 => 'custom_var_2',
35
+ :hash => 'some hash'
36
+ }
37
+ end
38
+
39
+ it 'should raise a runtime error on wrong hash on transaction-paid notification' do
40
+ request_parameters = {
41
+ :state => Barzahlen::Api::Online::NotificationHandler::TRANSACTION_PAID,
42
+ :transaction_id => '123',
43
+ :shop_id => '456',
44
+ :customer_email => 'foo@example.com',
45
+ :amount => '13.37',
46
+ :currency => 'EUR',
47
+ :order_id => '123',
48
+ :custom_var_0 => 'custom_var_0',
49
+ :custom_var_1 => 'custom_var_1',
50
+ :custom_var_2 => 'custom_var_2',
51
+ :hash => '1111'
52
+ }
53
+
54
+ notification_handler = Barzahlen::Api::Online::NotificationHandler.new get_api
55
+ expect { notification_handler.validate_request(request_parameters) }.to raise_error
56
+ end
57
+ end
58
+
59
+ context 'validate_request TRANSACTION_EXPIRED' do
60
+ it 'should return correct request on transaction-expired notification' do
61
+ request_parameters = {
62
+ :state => Barzahlen::Api::Online::NotificationHandler::TRANSACTION_EXPIRED,
63
+ :transaction_id => '123',
64
+ :shop_id => '456',
65
+ :customer_email => 'foo@example.com',
66
+ :amount => '13.37',
67
+ :currency => 'EUR',
68
+ :order_id => '123',
69
+ :custom_var_0 => 'custom_var_0',
70
+ :custom_var_1 => 'custom_var_1',
71
+ :custom_var_2 => 'custom_var_2',
72
+ :hash => 'some hash'
73
+ }
74
+
75
+ notification_handler = Barzahlen::Api::Online::NotificationHandler.new get_api
76
+ request = notification_handler.validate_request(request_parameters)
77
+ request.should == {
78
+ :state => Barzahlen::Api::Online::NotificationHandler::TRANSACTION_EXPIRED,
79
+ :transaction_id => '123',
80
+ :shop_id => '456',
81
+ :customer_email => 'foo@example.com',
82
+ :amount => '13.37',
83
+ :currency => 'EUR',
84
+ :order_id => '123',
85
+ :custom_var_0 => 'custom_var_0',
86
+ :custom_var_1 => 'custom_var_1',
87
+ :custom_var_2 => 'custom_var_2',
88
+ :hash => 'some hash'
89
+ }
90
+ end
91
+
92
+ it 'should raise a runtime error on wrong hash on transaction-expired notification' do
93
+ request_parameters = {
94
+ :state => Barzahlen::Api::Online::NotificationHandler::TRANSACTION_EXPIRED,
95
+ :transaction_id => '123',
96
+ :shop_id => '456',
97
+ :customer_email => 'foo@example.com',
98
+ :amount => '13.37',
99
+ :currency => 'EUR',
100
+ :order_id => '123',
101
+ :custom_var_0 => 'custom_var_0',
102
+ :custom_var_1 => 'custom_var_1',
103
+ :custom_var_2 => 'custom_var_2',
104
+ :hash => '2222'
105
+ }
106
+
107
+ notification_handler = Barzahlen::Api::Online::NotificationHandler.new get_api
108
+ expect { notification_handler.validate_request(request_parameters) }.to raise_error
109
+ end
110
+ end
111
+
112
+ context 'validate_request REFUND_COMPLETED' do
113
+ it 'should return correct request on refund-completed notification' do
114
+ request_parameters = {
115
+ :state => Barzahlen::Api::Online::NotificationHandler::REFUND_COMPLETED,
116
+ :refund_transaction_id => '123',
117
+ :origin_transaction_id => '444',
118
+ :shop_id => '456',
119
+ :customer_email => 'foo@example.com',
120
+ :amount => '13.37',
121
+ :currency => 'EUR',
122
+ :origin_order_id => '123',
123
+ :custom_var_0 => 'custom_var_0',
124
+ :custom_var_1 => 'custom_var_1',
125
+ :custom_var_2 => 'custom_var_2',
126
+ :hash => 'some hash'
127
+ }
128
+
129
+ notification_handler = Barzahlen::Api::Online::NotificationHandler.new get_api
130
+ request = notification_handler.validate_request(request_parameters)
131
+ request.should == {
132
+ :state => Barzahlen::Api::Online::NotificationHandler::REFUND_COMPLETED,
133
+ :refund_transaction_id => '123',
134
+ :origin_transaction_id => '444',
135
+ :shop_id => '456',
136
+ :customer_email => 'foo@example.com',
137
+ :amount => '13.37',
138
+ :currency => 'EUR',
139
+ :origin_order_id => '123',
140
+ :custom_var_0 => 'custom_var_0',
141
+ :custom_var_1 => 'custom_var_1',
142
+ :custom_var_2 => 'custom_var_2',
143
+ :hash => 'some hash'
144
+ }
145
+ end
146
+
147
+ it 'should raise a runtime error on wrong hash on refund-complete notification' do
148
+ request_parameters = {
149
+ :state => Barzahlen::Api::Online::NotificationHandler::REFUND_COMPLETED,
150
+ :refund_transaction_id => '123',
151
+ :origin_transaction_id => '111',
152
+ :shop_id => '456',
153
+ :customer_email => 'foo@example.com',
154
+ :amount => '13.37',
155
+ :currency => 'EUR',
156
+ :origin_order_id => '123',
157
+ :custom_var_0 => 'custom_var_0',
158
+ :custom_var_1 => 'custom_var_1',
159
+ :custom_var_2 => 'custom_var_2',
160
+ :hash => '333'
161
+ }
162
+
163
+ notification_handler = Barzahlen::Api::Online::NotificationHandler.new get_api
164
+ expect { notification_handler.validate_request(request_parameters) }.to raise_error
165
+ end
166
+ end
167
+
168
+ context 'validate_request REFUND_EXPIRED' do
169
+ it 'should return correct request on refund-expired notification' do
170
+ request_parameters = {
171
+ :state => Barzahlen::Api::Online::NotificationHandler::REFUND_EXPIRED,
172
+ :refund_transaction_id => '123',
173
+ :origin_transaction_id => '444',
174
+ :shop_id => '456',
175
+ :customer_email => 'foo@example.com',
176
+ :amount => '13.37',
177
+ :currency => 'EUR',
178
+ :origin_order_id => '123',
179
+ :custom_var_0 => 'custom_var_0',
180
+ :custom_var_1 => 'custom_var_1',
181
+ :custom_var_2 => 'custom_var_2',
182
+ :hash => 'some hash'
183
+ }
184
+
185
+ notification_handler = Barzahlen::Api::Online::NotificationHandler.new get_api
186
+ request = notification_handler.validate_request(request_parameters)
187
+ request.should == {
188
+ :state => Barzahlen::Api::Online::NotificationHandler::REFUND_EXPIRED,
189
+ :refund_transaction_id => '123',
190
+ :origin_transaction_id => '444',
191
+ :shop_id => '456',
192
+ :customer_email => 'foo@example.com',
193
+ :amount => '13.37',
194
+ :currency => 'EUR',
195
+ :origin_order_id => '123',
196
+ :custom_var_0 => 'custom_var_0',
197
+ :custom_var_1 => 'custom_var_1',
198
+ :custom_var_2 => 'custom_var_2',
199
+ :hash => 'some hash'
200
+ }
201
+ end
202
+
203
+ it 'should raise a runtime error on wrong hash on refund-complete notification' do
204
+ request_parameters = {
205
+ :state => Barzahlen::Api::Online::NotificationHandler::REFUND_EXPIRED,
206
+ :refund_transaction_id => '123',
207
+ :origin_transaction_id => '123',
208
+ :shop_id => '456',
209
+ :customer_email => 'foo@example.com',
210
+ :amount => '13.37',
211
+ :currency => 'EUR',
212
+ :origin_order_id => '123',
213
+ :custom_var_0 => 'custom_var_0',
214
+ :custom_var_1 => 'custom_var_1',
215
+ :custom_var_2 => 'custom_var_2',
216
+ :hash => '444'
217
+ }
218
+
219
+ notification_handler = Barzahlen::Api::Online::NotificationHandler.new get_api
220
+ expect { notification_handler.validate_request(request_parameters) }.to raise_error
221
+ end
222
+ end
223
+
224
+ it 'should raise a runtime error on wrong state' do
225
+ request_parameters = {
226
+ :state => 'foobar',
227
+ :hash => 'hash'
228
+ }
229
+
230
+ notification_handler = Barzahlen::Api::Online::NotificationHandler.new get_api
231
+ expect { notification_handler.validate_request(request_parameters) }.to raise_error
232
+ end
233
+
234
+ private
235
+ def get_api
236
+ api = double 'Barzahlen::Api::Online::Api'
237
+ allow(api).to receive(:build_hash).and_return('some hash')
238
+ api
239
+ end
240
+ end
@@ -0,0 +1,99 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Barzahlen::Api::Online::ResponseParser do
6
+ it 'should return correct hash when passing transaction-create-xml' do
7
+ xml = '<response>
8
+ <transaction-id>227840174</transaction-id>
9
+ <payment-slip-link>https://cdn.barzahlen.de/slip/227840174/c91dc292bdb8f0ba1a83c738119ef13e652a43b8a8f261cf93d3bfbf233d7da2/Zahlschein_Barzahlen_227840174.pdf</payment-slip-link>
10
+ <expiration-notice>Der Zahlschein ist 2 Wochen gültig.</expiration-notice>
11
+ <infotext-1>Text mit einem &lt;a href="http://www.barzahlen.de" target="_blank"&gt;Link&lt;/a&gt;</infotext-1>
12
+ <infotext-2>Text mit einem &lt;a href="http://www.barzahlen.de" target="_blank"&gt;Link&lt;/a&gt;</infotext-2>
13
+ <result>0</result>
14
+ <hash>c5422fbcbaba04d65598cd847f2f91b1a18c6b0dc5eab927302affe235e6c37976307e23eef645b43b13c7d3cfbbbca9349247449a49b8aebcdd9b0a2554a893</hash>
15
+ </response>'
16
+
17
+ result = Barzahlen::Api::Online::ResponseParser.parse xml
18
+
19
+ result.should == {
20
+ :transaction_id => '227840174',
21
+ :payment_slip_link => 'https://cdn.barzahlen.de/slip/227840174/c91dc292bdb8f0ba1a83c738119ef13e652a43b8a8f261cf93d3bfbf233d7da2/Zahlschein_Barzahlen_227840174.pdf',
22
+ :expiration_notice => 'Der Zahlschein ist 2 Wochen gültig.',
23
+ :infotext_1 => 'Text mit einem <a href="http://www.barzahlen.de" target="_blank">Link</a>',
24
+ :infotext_2 => 'Text mit einem <a href="http://www.barzahlen.de" target="_blank">Link</a>',
25
+ :result => '0',
26
+ :hash => 'c5422fbcbaba04d65598cd847f2f91b1a18c6b0dc5eab927302affe235e6c37976307e23eef645b43b13c7d3cfbbbca9349247449a49b8aebcdd9b0a2554a893'
27
+ }
28
+ end
29
+
30
+ it 'should return correct hash when passing transaction-update-xml' do
31
+ xml = '<?xml version="1.0" encoding="UTF-8"?>
32
+ <response>
33
+ <transaction-id>227840174</transaction-id>
34
+ <result>0</result>
35
+ <hash>0714be1522e16fe67f397767c98cf37e37fd9c2a5391f49f8b01cb66642150751c77a0cce1ef7268e7bdeee792ed63eab53ef9b860f721c9d9d47ffc871ee3f9</hash>
36
+ </response>'
37
+
38
+ result = Barzahlen::Api::Online::ResponseParser.parse xml
39
+
40
+ result.should == {
41
+ :transaction_id => '227840174',
42
+ :result => '0',
43
+ :hash => '0714be1522e16fe67f397767c98cf37e37fd9c2a5391f49f8b01cb66642150751c77a0cce1ef7268e7bdeee792ed63eab53ef9b860f721c9d9d47ffc871ee3f9'
44
+ }
45
+ end
46
+
47
+ it 'should return correct hash when passing transaction-resend-email-xml' do
48
+ xml = '<?xml version="1.0" encoding="UTF-8"?>
49
+ <response>
50
+ <transaction-id>227840174</transaction-id>
51
+ <result>0</result>
52
+ <hash>0714be1522e16fe67f397767c98cf37e37fd9c2a5391f49f8b01cb66642150751c77a0cce1ef7268e7bdeee792ed63eab53ef9b860f721c9d9d47ffc871ee3f9</hash>
53
+ </response>'
54
+
55
+ result = Barzahlen::Api::Online::ResponseParser.parse xml
56
+
57
+ result.should == {
58
+ :transaction_id => '227840174',
59
+ :result => '0',
60
+ :hash => '0714be1522e16fe67f397767c98cf37e37fd9c2a5391f49f8b01cb66642150751c77a0cce1ef7268e7bdeee792ed63eab53ef9b860f721c9d9d47ffc871ee3f9'
61
+ }
62
+ end
63
+
64
+ it 'should return correct hash when passing transaction-cancel-xml' do
65
+ xml = '<?xml version="1.0" encoding="UTF-8"?>
66
+ <response>
67
+ <transaction-id>227840174</transaction-id>
68
+ <result>0</result>
69
+ <hash>0714be1522e16fe67f397767c98cf37e37fd9c2a5391f49f8b01cb66642150751c77a0cce1ef7268e7bdeee792ed63eab53ef9b860f721c9d9d47ffc871ee3f9</hash>
70
+ </response>'
71
+
72
+ result = Barzahlen::Api::Online::ResponseParser.parse xml
73
+
74
+ result.should == {
75
+ :transaction_id => '227840174',
76
+ :result => '0',
77
+ :hash => '0714be1522e16fe67f397767c98cf37e37fd9c2a5391f49f8b01cb66642150751c77a0cce1ef7268e7bdeee792ed63eab53ef9b860f721c9d9d47ffc871ee3f9'
78
+ }
79
+ end
80
+
81
+ it 'should return correct hash when passing transaction-refund-xml' do
82
+ xml = '<?xml version="1.0" encoding="UTF-8"?>
83
+ <response>
84
+ <origin-transaction-id>22780174</origin-transaction-id>
85
+ <refund-transaction-id>22791842</refund-transaction-id>
86
+ <result>0</result>
87
+ <hash>0714be1522e16fe67f397767c98cf37e37fd9c2a5391f49f8b01cb66642150751c77a0cce1ef7268e7bdeee792ed63eab53ef9b860f721c9d9d47ffc871ee3f9</hash>
88
+ </response>'
89
+
90
+ result = Barzahlen::Api::Online::ResponseParser.parse xml
91
+
92
+ result.should == {
93
+ :origin_transaction_id => '22780174',
94
+ :refund_transaction_id => '22791842',
95
+ :result => '0',
96
+ :hash => '0714be1522e16fe67f397767c98cf37e37fd9c2a5391f49f8b01cb66642150751c77a0cce1ef7268e7bdeee792ed63eab53ef9b860f721c9d9d47ffc871ee3f9'
97
+ }
98
+ end
99
+ end
@@ -0,0 +1,108 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'net/http'
5
+
6
+ describe Barzahlen::Api::Online::Transaction do
7
+ context 'create' do
8
+ it 'should send correct request to api' do
9
+ api = create_api
10
+ api.should_receive(:request)
11
+ .with('v1/transactions/create', :payment_key,
12
+ [:shop_id, :customer_email, :amount, :currency, :language, :order_id, :customer_street_nr,
13
+ :customer_zipcode, :customer_city, :customer_country, :custom_var_0, :custom_var_1, :custom_var_2,
14
+ :payment_key],
15
+ :customer_email => 'barzahlen@example.com',
16
+ :amount => '13.37',
17
+ :currency => 'EUR',
18
+ :order_id => '123',
19
+ :customer_street_nr => 'Wallstr. 14a',
20
+ :customer_zipcode => '10179',
21
+ :customer_city => 'Berlin',
22
+ :customer_country => 'DE',
23
+ :customer_custom_var_0 => 'customer_custom_var_0',
24
+ :customer_custom_var_1 => 'customer_custom_var_1',
25
+ :customer_custom_var_2 => 'customer_custom_var_2',)
26
+
27
+ transaction = Barzahlen::Api::Online::Transaction.new api
28
+ transaction.create(:customer_email => 'barzahlen@example.com',
29
+ :amount => '13.37',
30
+ :currency => 'EUR',
31
+ :order_id => '123',
32
+ :customer_street_nr => 'Wallstr. 14a',
33
+ :customer_zipcode => '10179',
34
+ :customer_city => 'Berlin',
35
+ :customer_country => 'DE',
36
+ :customer_custom_var_0 => 'customer_custom_var_0',
37
+ :customer_custom_var_1 => 'customer_custom_var_1',
38
+ :customer_custom_var_2 => 'customer_custom_var_2',)
39
+ end
40
+ end
41
+
42
+ context 'update_order_id' do
43
+ it 'should send correct request to api' do
44
+ api = create_api
45
+ api.should_receive(:request)
46
+ .with('v1/transactions/update', :payment_key,
47
+ [:shop_id, :transaction_id, :order_id, :payment_key],
48
+ :transaction_id => '123',
49
+ :order_id => '456')
50
+
51
+ transaction = Barzahlen::Api::Online::Transaction.new api
52
+ transaction.update_order_id '123', '456'
53
+ end
54
+ end
55
+
56
+ context 'resend_email' do
57
+ it 'should send correct request to api' do
58
+ api = create_api
59
+ api.should_receive(:request)
60
+ .with('v1/transactions/resend_email', :payment_key,
61
+ [:shop_id, :transaction_id, :language, :payment_key],
62
+ :transaction_id => '123',
63
+ :language => 'de')
64
+
65
+ transaction = Barzahlen::Api::Online::Transaction.new api
66
+ transaction.resend_email '123', 'de'
67
+ end
68
+ end
69
+
70
+ context 'cancel' do
71
+ it 'should send correct request to api' do
72
+ api = create_api
73
+ api.should_receive(:request)
74
+ .with('v1/transactions/cancel', :payment_key,
75
+ [:shop_id, :transaction_id, :language, :payment_key],
76
+ :transaction_id => '123',
77
+ :language => 'de')
78
+
79
+ transaction = Barzahlen::Api::Online::Transaction.new(api)
80
+ transaction.cancel '123', 'de'
81
+ end
82
+ end
83
+
84
+ context 'refund' do
85
+ it 'should send correct request to api' do
86
+ api = create_api
87
+ api.should_receive(:request)
88
+ .with('v1/transactions/refund', :payment_key,
89
+ [:shop_id, :transaction_id, :amount, :currency, :language, :payment_key],
90
+ :transaction_id => '123',
91
+ :amount => '12.23',
92
+ :currency => 'EUR',
93
+ :language => 'de')
94
+
95
+ transaction = Barzahlen::Api::Online::Transaction.new api
96
+ transaction.refund '123', '12.23', 'EUR', 'de'
97
+ end
98
+ end
99
+
100
+ private
101
+ def create_api
102
+ Barzahlen::Api::Online::Api.new(double('Net::HTTP'),
103
+ :shop_id => 12345,
104
+ :payment_key => 'asdfasdf',
105
+ :notification_key => 'foobarfoobar',
106
+ :language => 'de',)
107
+ end
108
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Barzahlen::Api::Online do
6
+ before(:each) do
7
+ Barzahlen::Api::Online.config = nil
8
+ Barzahlen::Api::Online.api = nil
9
+ end
10
+
11
+ context 'new_transaction_api' do
12
+ it 'should raise an error, if no config and api is specified' do
13
+ expect { Barzahlen::Api::Online.new_transaction_api }.to raise_error
14
+ end
15
+
16
+ it 'should return Transcation object' do
17
+ Barzahlen::Api::Online.config = {}
18
+ transaction_api = Barzahlen::Api::Online.new_transaction_api
19
+ expect(transaction_api).to be_a Barzahlen::Api::Online::Transaction
20
+ end
21
+ end
22
+
23
+ context 'new_notification_handler' do
24
+ it 'should raise an error, if no config and api is specified' do
25
+ expect { Barzahlen::Api::Online.new_notification_handler }.to raise_error
26
+ end
27
+
28
+ it 'should return NotificationHandler object' do
29
+ Barzahlen::Api::Online.config = {}
30
+ notification_handler = Barzahlen::Api::Online.new_notification_handler
31
+ expect(notification_handler).to be_a Barzahlen::Api::Online::NotificationHandler
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,8 @@
1
+ # coding: utf-8
2
+
3
+ require 'barzahlen/api/online'
4
+ require 'barzahlen/api/online/api'
5
+ require 'barzahlen/api/online/transaction'
6
+ require 'barzahlen/api/online/hash_builder'
7
+ require 'barzahlen/api/online/response_parser'
8
+ require 'barzahlen/api/online/notification_handler'