zaypay 1.0.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/lib/zaypay.rb +5 -0
- data/lib/zaypay/error.rb +10 -0
- data/lib/zaypay/price_setting.rb +138 -0
- data/lib/zaypay/util.rb +28 -0
- data/lib/zaypay/version.rb +3 -0
- data/test/create_payment.xml +33 -0
- data/test/error_with_dynamic_amounts.xml +4 -0
- data/test/locale_for_ip.xml +4 -0
- data/test/mark_payload_provided.xml +28 -0
- data/test/multi_countries_ps.xml +280 -0
- data/test/multiple_payment_methods.xml +28 -0
- data/test/price_setting_test.rb +498 -0
- data/test/show_payment.xml +28 -0
- data/test/single_country_ps.xml +116 -0
- data/test/single_payment_method.xml +18 -0
- data/test/test_helper.rb +20 -0
- data/test/util_test.rb +48 -0
- data/test/verification_code.xml +28 -0
- metadata +223 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<response status="success">
|
3
|
+
<locale-info>
|
4
|
+
<current-locale>nl-NL</current-locale>
|
5
|
+
</locale-info>
|
6
|
+
<payment-methods>
|
7
|
+
<payment-method>
|
8
|
+
<charged-amount type="decimal">1.000000000</charged-amount>
|
9
|
+
<eur-charged-amount type="decimal">1.0</eur-charged-amount>
|
10
|
+
<payout type="decimal">0.700000000000000000</payout>
|
11
|
+
<name>phone</name>
|
12
|
+
<payment-method-id type="integer">1</payment-method-id>
|
13
|
+
<very-short-instructions>betaal per telefoon</very-short-instructions>
|
14
|
+
<formatted-amount>€ 1,00</formatted-amount>
|
15
|
+
<very-short-instructions-with-amount>betaal € 1,00 per telefoon</very-short-instructions-with-amount>
|
16
|
+
</payment-method>
|
17
|
+
<payment-method>
|
18
|
+
<charged-amount type="decimal">1.100000000</charged-amount>
|
19
|
+
<eur-charged-amount type="decimal">1.1</eur-charged-amount>
|
20
|
+
<payout type="decimal">0.540000000000000000</payout>
|
21
|
+
<name>sms</name>
|
22
|
+
<payment-method-id type="integer">2</payment-method-id>
|
23
|
+
<very-short-instructions>betaal per sms</very-short-instructions>
|
24
|
+
<formatted-amount>€ 1,10</formatted-amount>
|
25
|
+
<very-short-instructions-with-amount>betaal € 1,10 per sms</very-short-instructions-with-amount>
|
26
|
+
</payment-method>
|
27
|
+
</payment-methods>
|
28
|
+
</response>
|
@@ -0,0 +1,498 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'zaypay'
|
3
|
+
|
4
|
+
class PriceSettingTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "Zaypay::PriceSetting" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@price_setting_id = 111111
|
10
|
+
@payalogue_id = 222222
|
11
|
+
@payment_id = 999999999
|
12
|
+
@api_key = '999a99999999aa9aaa99aa9a99a99a9a'
|
13
|
+
@ps = Zaypay::PriceSetting.new(@price_setting_id, @api_key)
|
14
|
+
@optional_amount = 10
|
15
|
+
|
16
|
+
@base_uri = 'https://secure.zaypay.com'
|
17
|
+
@headers = {'Accept' => 'application/xml' }
|
18
|
+
@ip = '12.34.456.89'
|
19
|
+
end
|
20
|
+
|
21
|
+
context "#initialize" do
|
22
|
+
context "with no-args" do
|
23
|
+
should "lookup for zaypay.yml within Rails config directory and use the default" do
|
24
|
+
YAML.expects(:load_file).with('anywhere/config/zaypay.yml').returns({ @price_setting_id => @api_key, "default"=>@price_setting_id})
|
25
|
+
ps = Zaypay::PriceSetting.new
|
26
|
+
assert_equal @price_setting_id, ps.price_setting_id
|
27
|
+
assert_equal @api_key, ps.key
|
28
|
+
end
|
29
|
+
should "raise Error if yml is blank" do
|
30
|
+
error = assert_raise Zaypay::Error do
|
31
|
+
YAML.expects(:load_file).with('anywhere/config/zaypay.yml').returns({})
|
32
|
+
Zaypay::PriceSetting.new
|
33
|
+
end
|
34
|
+
assert_equal :config_error, error.type
|
35
|
+
assert_match "You did not provide a price_setting id or/and an API-key", error.message
|
36
|
+
end
|
37
|
+
|
38
|
+
should "raise Error if the yml file is not present" do
|
39
|
+
assert_raise Errno::ENOENT do
|
40
|
+
Zaypay::PriceSetting.new
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with price_setting_id and key" do
|
46
|
+
should "not lookup for zaypay.yml within Rails config directory" do
|
47
|
+
YAML.expects(:load_file).never
|
48
|
+
ps = Zaypay::PriceSetting.new(@price_setting_id, @api_key)
|
49
|
+
assert_equal @price_setting_id, ps.price_setting_id
|
50
|
+
assert_equal @api_key, ps.key
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "only price_setting_id is provided" do
|
55
|
+
context "with a valid yml file" do
|
56
|
+
should "return a PriceSetting with price_setting_id and key" do
|
57
|
+
YAML.expects(:load_file).with('anywhere/config/zaypay.yml').returns({@price_setting_id => @api_key})
|
58
|
+
ps = Zaypay::PriceSetting.new(@price_setting_id)
|
59
|
+
assert_equal @price_setting_id, ps.price_setting_id
|
60
|
+
assert_equal @api_key, ps.key
|
61
|
+
end
|
62
|
+
end
|
63
|
+
context "without a valid yml file" do
|
64
|
+
should "raise RuntimeError" do
|
65
|
+
error = assert_raise Zaypay::Error do
|
66
|
+
YAML.expects(:load_file).with('anywhere/config/zaypay.yml').returns({})
|
67
|
+
ps = Zaypay::PriceSetting.new(@price_setting_id)
|
68
|
+
end
|
69
|
+
assert_equal :config_error, error.type
|
70
|
+
assert_match "You did not provide a price_setting id or/and an API-key", error.message
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "#locale_for_ip" do
|
77
|
+
setup do
|
78
|
+
FakeWeb.register_uri(:get,"#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip?key=#{@api_key}", :body => 'test/locale_for_ip.xml', :content_type => "text/xml")
|
79
|
+
@response = HTTParty.get("#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip", {:query => {:key => @api_key}, :headers => @headers })
|
80
|
+
end
|
81
|
+
should "call class method get with the correct url" do
|
82
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip", {:query => {:key => @api_key}, :headers => @headers }).returns @response
|
83
|
+
@ps.locale_for_ip(@ip)
|
84
|
+
end
|
85
|
+
should "return a country-language hash" do
|
86
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip", {:query => {:key => @api_key}, :headers => @headers }).returns @response
|
87
|
+
locale = @ps.locale_for_ip(@ip)
|
88
|
+
assert locale.has_key?(:country)
|
89
|
+
assert locale.has_key?(:language)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "#locale_string_for_ip" do
|
94
|
+
setup do
|
95
|
+
FakeWeb.register_uri(:get,"#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip?key=#{@api_key}", :body => 'test/locale_for_ip.xml', :content_type => "text/xml")
|
96
|
+
@response = HTTParty.get("#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip", {:query => {:key => @api_key}, :headers => @headers })
|
97
|
+
end
|
98
|
+
|
99
|
+
should "call class method get with the correct url" do
|
100
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip", {:query => {:key => @api_key}, :headers => @headers }).returns @response
|
101
|
+
@ps.locale_string_for_ip(@ip)
|
102
|
+
end
|
103
|
+
should "return a string with the correct locale" do
|
104
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip", {:query => {:key => @api_key}, :headers => @headers }).returns @response
|
105
|
+
assert_equal 'nl-NL', @ps.locale_string_for_ip(@ip)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "#list_locales" do
|
110
|
+
setup do
|
111
|
+
FakeWeb.register_uri(:get, "#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales?key=#{@api_key}", :body => 'test/multi_countries_ps.xml', :content_type => "text/xml")
|
112
|
+
@response = HTTParty.get("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales", {:query => {:key => @api_key}, :headers => @headers })
|
113
|
+
end
|
114
|
+
|
115
|
+
context "with optional amount" do
|
116
|
+
should "call class method GET with the correct url" do
|
117
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}/#{@optional_amount}/pay/#{@ps.price_setting_id}/list_locales",
|
118
|
+
{:query => {:key => @api_key}, :headers => @headers }).returns @response
|
119
|
+
@ps.list_locales(:amount => @optional_amount)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "without optional amount" do
|
124
|
+
should "call class method GET with the correct url" do
|
125
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales", {:query => {:key => @api_key}, :headers => @headers }).returns @response
|
126
|
+
@ps.list_locales
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
should "return a hash containing a langauages hash and a countries hash" do
|
131
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales", {:query => {:key => @api_key}, :headers => @headers }).returns @response
|
132
|
+
locales = @ps.list_locales
|
133
|
+
assert locales.has_key?(:countries)
|
134
|
+
assert locales.has_key?(:languages)
|
135
|
+
end
|
136
|
+
|
137
|
+
should "always wrap up countries in an array" do
|
138
|
+
FakeWeb.register_uri(:get, "#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales?key=#{@api_key}", :body => 'test/single_country_ps.xml', :content_type => "text/xml")
|
139
|
+
@single_country_response = HTTParty.get("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales", {:query => {:key => @api_key}, :headers => @headers })
|
140
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales",
|
141
|
+
{:query => {:key => @api_key}, :headers => @headers }).returns @single_country_response
|
142
|
+
|
143
|
+
assert @ps.list_locales[:countries].is_a?(Array)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "#list_countries" do
|
148
|
+
context "with multiple countries" do
|
149
|
+
setup do
|
150
|
+
FakeWeb.register_uri(:get,"#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales?key=#{@api_key}", :body => 'test/multi_countries_ps.xml', :content_type => "text/xml")
|
151
|
+
@response = HTTParty.get("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales", {:query => {:key => @api_key}, :headers => @headers })
|
152
|
+
end
|
153
|
+
context "with optional amount" do
|
154
|
+
should "call class method get with the correct url" do
|
155
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}/#{@optional_amount}/pay/#{@price_setting_id}/list_locales",
|
156
|
+
{:query => {:key => @api_key}, :headers => @headers } ).returns @response
|
157
|
+
@ps.list_countries(:amount => @optional_amount)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
context "without optional amount" do
|
161
|
+
should "call class method get with the correct url" do
|
162
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}//pay/#{@price_setting_id}/list_locales",
|
163
|
+
{:query => {:key => @api_key}, :headers => @headers } ).returns @response
|
164
|
+
@ps.list_countries
|
165
|
+
end
|
166
|
+
end
|
167
|
+
should "returns an array identical to #list_locales[:countries]" do
|
168
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}//pay/#{@price_setting_id}/list_locales",
|
169
|
+
{:query => {:key => @api_key}, :headers => @headers } ).twice.returns @response
|
170
|
+
results = @ps.list_countries
|
171
|
+
assert results.kind_of?(Array)
|
172
|
+
assert_equal results, @ps.list_locales[:countries]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "with one country" do
|
177
|
+
should "always return an array even for single-country price_settings" do
|
178
|
+
FakeWeb.register_uri(:get,"#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales?key=#{@api_key}", :body => 'test/single_country_ps.xml', :content_type => "text/xml")
|
179
|
+
@single_country_response = HTTParty.get("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales", {:query => {:key => @api_key}, :headers => @headers })
|
180
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}//pay/#{@price_setting_id}/list_locales",
|
181
|
+
{:query => {:key => @api_key}, :headers => @headers } ).returns @single_country_response
|
182
|
+
assert @ps.list_countries.is_a?(Array)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context "#list_languages" do
|
188
|
+
setup do
|
189
|
+
FakeWeb.register_uri(:get,"#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales?key=#{@api_key}", :body => 'test/multi_countries_ps.xml', :content_type => "text/xml")
|
190
|
+
@response = HTTParty.get("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales", {:query => {:key => @api_key}, :headers => @headers })
|
191
|
+
end
|
192
|
+
context "with optional amount" do
|
193
|
+
should "call class method get with the correct url" do
|
194
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}/#{@optional_amount}/pay/#{@price_setting_id}/list_locales",
|
195
|
+
{:query => {:key => @api_key}, :headers => @headers }).returns @response
|
196
|
+
@ps.list_languages(:amount => @optional_amount)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
context "without optional amount" do
|
200
|
+
should "call class method get with the correct url" do
|
201
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}//pay/#{@price_setting_id}/list_locales",
|
202
|
+
{:query => {:key => @api_key}, :headers => @headers }).returns @response
|
203
|
+
@ps.list_languages
|
204
|
+
end
|
205
|
+
end
|
206
|
+
should "returns array identical to #list_locales[:languages]" do
|
207
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}//pay/#{@price_setting_id}/list_locales",
|
208
|
+
{:query => {:key => @api_key}, :headers => @headers }).twice.returns(@response)
|
209
|
+
results = @ps.list_languages
|
210
|
+
assert_equal true, results.kind_of?(Array)
|
211
|
+
assert_equal results, @ps.list_locales[:languages]
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context "#list_payment_methods" do
|
216
|
+
|
217
|
+
setup do
|
218
|
+
FakeWeb.register_uri(:get, "#{@base_uri}//nl-NL/pay/#{@price_setting_id}/payments/new", :body => 'test/multiple_payment_methods.xml', :content_type => "text/xml" )
|
219
|
+
@multi_methods_response = HTTParty.get("#{@base_uri}//nl-NL/pay/#{@price_setting_id}/payments/new", {:headers => @headers })
|
220
|
+
FakeWeb.register_uri(:get, "#{@base_uri}//nl-BE/pay/#{@price_setting_id}/payments/new", :body => 'test/single_payment_method.xml', :content_type => "text/xml" )
|
221
|
+
@single_method_response = HTTParty.get("#{@base_uri}//nl-BE/pay/#{@price_setting_id}/payments/new", {:headers => @headers })
|
222
|
+
end
|
223
|
+
|
224
|
+
context "the locale is set" do
|
225
|
+
setup do
|
226
|
+
@ps.locale = 'nl-NL'
|
227
|
+
end
|
228
|
+
|
229
|
+
def mock_payment_methods(optional_amount=nil)
|
230
|
+
response = @ps.locale == 'nl-NL' ? @multi_methods_response : @single_method_response
|
231
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}/#{optional_amount}/#{@ps.locale}/pay/#{@price_setting_id}/payments/new",
|
232
|
+
{:query => {:key => @api_key}, :headers => @headers }).returns response
|
233
|
+
end
|
234
|
+
|
235
|
+
should "not need any args" do
|
236
|
+
mock_payment_methods
|
237
|
+
@ps.list_payment_methods
|
238
|
+
end
|
239
|
+
|
240
|
+
should "return an array when multiple payment methods are available" do
|
241
|
+
mock_payment_methods
|
242
|
+
nl_payment_methods = @ps.list_payment_methods
|
243
|
+
assert_equal 2, nl_payment_methods.size
|
244
|
+
assert nl_payment_methods.is_a?(Array)
|
245
|
+
end
|
246
|
+
|
247
|
+
should "return an array when only one payment method is available" do
|
248
|
+
@ps.locale = 'nl-BE'
|
249
|
+
mock_payment_methods
|
250
|
+
be_payment_methods = @ps.list_payment_methods
|
251
|
+
assert_equal 1, be_payment_methods.size
|
252
|
+
assert be_payment_methods.is_a?(Array)
|
253
|
+
end
|
254
|
+
|
255
|
+
context "and an optional amount" do
|
256
|
+
should "call class method GET with the correct url" do
|
257
|
+
mock_payment_methods(@optional_amount)
|
258
|
+
payment_methods = @ps.list_payment_methods(:amount => @optional_amount)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
context "the locale is not set" do
|
264
|
+
should "throw an error" do
|
265
|
+
error = assert_raise Zaypay::Error do
|
266
|
+
@ps.list_payment_methods
|
267
|
+
end
|
268
|
+
assert_equal :locale_not_set, error.type
|
269
|
+
assert_equal "locale was not set for your price setting", error.message
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
context "#create_payment" do
|
276
|
+
setup do
|
277
|
+
FakeWeb.register_uri(:post,"#{@base_uri}//nl-NL/pay/#{@price_setting_id}/payments?key=#{@api_key}", :body => 'test/create_payment.xml', :content_type => "text/xml")
|
278
|
+
@response = HTTParty.post("#{@base_uri}//nl-NL/pay/#{@price_setting_id}/payments", {:query => {:key => @api_key}, :headers => @headers })
|
279
|
+
end
|
280
|
+
|
281
|
+
should "call class method POST with correct URL" do
|
282
|
+
Zaypay::PriceSetting.expects(:post).with("#{@base_uri}//nl-NL/pay/#{@price_setting_id}/payments",
|
283
|
+
{:query => {:key => @api_key, :payment_method_id => 2}, :headers => @headers }).returns @response
|
284
|
+
@ps.locale = "nl-NL"
|
285
|
+
@ps.payment_method_id = 2
|
286
|
+
@ps.create_payment
|
287
|
+
end
|
288
|
+
|
289
|
+
should "return a hash with a :payment and :instructions keys" do
|
290
|
+
Zaypay::PriceSetting.expects(:post).with("#{@base_uri}//nl-NL/pay/#{@price_setting_id}/payments",
|
291
|
+
{:query => {:key => @api_key, :payment_method_id => 2}, :headers => @headers }).returns @response
|
292
|
+
@ps.locale = "nl-NL"
|
293
|
+
@ps.payment_method_id = 2
|
294
|
+
payment = @ps.create_payment
|
295
|
+
assert payment.has_key?(:payment)
|
296
|
+
assert payment.has_key?(:instructions)
|
297
|
+
end
|
298
|
+
|
299
|
+
should "raise an error when no locale has been set" do
|
300
|
+
error = assert_raise Zaypay::Error do
|
301
|
+
@ps.payment_method_id = 2
|
302
|
+
@ps.create_payment
|
303
|
+
end
|
304
|
+
assert_equal :locale_not_set, error.type
|
305
|
+
assert_equal "locale was not set for your price setting", error.message
|
306
|
+
end
|
307
|
+
|
308
|
+
should "raise an error when no payment_method_id has been set" do
|
309
|
+
error = assert_raise Zaypay::Error do
|
310
|
+
@ps.locale = 'nl-NL'
|
311
|
+
@ps.create_payment
|
312
|
+
end
|
313
|
+
assert_equal :payment_method_id_not_set, error.type
|
314
|
+
assert_equal "payment_method_id was not set for your price setting", error.message
|
315
|
+
end
|
316
|
+
|
317
|
+
context "with an options hash" do
|
318
|
+
context "containing custom_variables" do
|
319
|
+
should "call class method POST with the correct url" do
|
320
|
+
Zaypay::PriceSetting.expects(:post).with("#{@base_uri}//nl-NL/pay/#{@price_setting_id}/payments", {:query => {:key => @api_key,
|
321
|
+
:payment_method_id => 2,
|
322
|
+
:product_id => 23,
|
323
|
+
:purchase_id => 45 },
|
324
|
+
:headers => @headers }).returns @response
|
325
|
+
@ps.locale = "nl-NL"
|
326
|
+
@ps.payment_method_id = 2
|
327
|
+
@ps.create_payment(:product_id => 23, :purchase_id => 45)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
context "including a payalogue_id key" do
|
332
|
+
should "call class method POST with the correct url" do
|
333
|
+
Zaypay::PriceSetting.expects(:post).with("#{@base_uri}//nl-NL/pay/#{@price_setting_id}/payments", {:query => {:key => @api_key,
|
334
|
+
:payment_method_id => 2,
|
335
|
+
:payalogue_id => @payalogue_id },
|
336
|
+
:headers => @headers }).returns @response
|
337
|
+
@ps.locale = "nl-NL"
|
338
|
+
@ps.payment_method_id = 2
|
339
|
+
@ps.create_payment(:payalogue_id => @payalogue_id )
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
context "including an optional amount" do
|
344
|
+
should "call class method POST with the correct url" do
|
345
|
+
Zaypay::PriceSetting.expects(:post).with("#{@base_uri}/#{@optional_amount}/nl-NL/pay/#{@price_setting_id}/payments", {:query => {:key => @api_key,
|
346
|
+
:payment_method_id => 2 },
|
347
|
+
:headers => @headers }).returns @response
|
348
|
+
@ps.locale = "nl-NL"
|
349
|
+
@ps.payment_method_id = 2
|
350
|
+
@ps.create_payment(:amount => @optional_amount )
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
context "with custom_variables and payalogue_id" do
|
355
|
+
should "call class method POST with the correct url" do
|
356
|
+
Zaypay::PriceSetting.expects(:post).with("#{@base_uri}//nl-NL/pay/#{@price_setting_id}/payments", {:query => {:key => @api_key,
|
357
|
+
:product_id => 23,
|
358
|
+
:purchase_id => 45,
|
359
|
+
:payalogue_id => @payalogue_id,
|
360
|
+
:payment_method_id => 2 },
|
361
|
+
:headers => @headers }).returns @response
|
362
|
+
@ps.locale = "nl-NL"
|
363
|
+
@ps.payment_method_id = 2
|
364
|
+
@ps.create_payment(:product_id => 23, :purchase_id => 45, :payalogue_id => @payalogue_id )
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
context "with custom_variable, payalogue_id and optional_amount" do
|
369
|
+
should "call class method POST with the correct url" do
|
370
|
+
Zaypay::PriceSetting.expects(:post).with("#{@base_uri}/#{@optional_amount}/nl-NL/pay/#{@price_setting_id}/payments", {:query => {:key => @api_key,
|
371
|
+
:product_id => 23,
|
372
|
+
:purchase_id => 45,
|
373
|
+
:payalogue_id => @payalogue_id,
|
374
|
+
:payment_method_id => 2 },
|
375
|
+
:headers => @headers }).returns @response
|
376
|
+
@ps.locale = 'nl-NL'
|
377
|
+
@ps.payment_method_id = 2
|
378
|
+
@ps.create_payment( :product_id => 23, :purchase_id => 45, :payalogue_id => @payalogue_id, :amount => @optional_amount)
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
context "#show_payment" do
|
385
|
+
setup do
|
386
|
+
FakeWeb.register_uri(:get,"#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}?key=#{@api_key}", :body => 'test/show_payment.xml', :content_type => "text/xml")
|
387
|
+
@response = HTTParty.get("#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}", {:query => {:key => @api_key}, :headers => @headers })
|
388
|
+
end
|
389
|
+
should "call class method GET and returns a hash with a key named :payment" do
|
390
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}", {:query => {:key => @api_key}, :headers => @headers } ).returns @response
|
391
|
+
payment = @ps.show_payment(@payment_id)
|
392
|
+
assert payment.has_key?(:payment)
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
context "#verification_code" do
|
397
|
+
setup do
|
398
|
+
FakeWeb.register_uri(:post,"#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}/verification_code?key=#{@api_key}&verification_code=1234",
|
399
|
+
:body => 'test/verification_code.xml', :content_type => "text/xml")
|
400
|
+
@response = HTTParty.post("#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}/verification_code",
|
401
|
+
{:query => {:key => @api_key, :verification_code => 1234}, :headers => @headers })
|
402
|
+
end
|
403
|
+
should "call class method POST and returns a hash with a key named :payment" do
|
404
|
+
Zaypay::PriceSetting.expects(:post).with("#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}/verification_code",
|
405
|
+
{:query => {:key => @api_key, :verification_code => 1234}, :headers => @headers } ).returns @response
|
406
|
+
payment = @ps.verification_code(@payment_id, 1234)
|
407
|
+
assert payment.has_key?(:payment)
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
context "#mark_payload_provided" do
|
412
|
+
setup do
|
413
|
+
FakeWeb.register_uri(:post, "#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}/mark_payload_provided?key=#{@api_key}",
|
414
|
+
:body => 'test/mark_payload_provided.xml', :content_type => "text/xml")
|
415
|
+
@response = HTTParty.post("#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}/mark_payload_provided",
|
416
|
+
{:query => {:key => @api_key}, :headers => @headers })
|
417
|
+
end
|
418
|
+
should "call class method POST and returns a payment with a key name :payload_provided" do
|
419
|
+
Zaypay::PriceSetting.expects(:post).with("#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}/mark_payload_provided",
|
420
|
+
{ :query => {:key => @api_key}, :headers => @headers }).returns @response
|
421
|
+
payment = @ps.mark_payload_provided(@payment_id)
|
422
|
+
assert payment[:payment].has_key?(:payload_provided)
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
context "#ip_country_within_configured_countries" do
|
427
|
+
setup do
|
428
|
+
FakeWeb.register_uri(:get,"#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip?key=#{@api_key}", :body => 'test/locale_for_ip.xml', :content_type => "text/xml")
|
429
|
+
@ip_response = HTTParty.get("#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip", {:query => {:key => @api_key}, :headers => @headers })
|
430
|
+
end
|
431
|
+
context "when ip_country is NOT configured" do
|
432
|
+
setup do
|
433
|
+
# IP country is the Netherlands but we have a price_setting configured for Belgium only
|
434
|
+
FakeWeb.register_uri(:get, "#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales?key=#{@api_key}", :body => 'test/single_country_ps.xml', :content_type => "text/xml")
|
435
|
+
@single_country_response = HTTParty.get("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales", {:query => {:key => @api_key}, :headers => @headers })
|
436
|
+
end
|
437
|
+
|
438
|
+
should "return nil" do
|
439
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip",
|
440
|
+
{:query => {:key => @api_key}, :headers => @headers }).returns @ip_response
|
441
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales",
|
442
|
+
{:query => {:key => @api_key}, :headers => @headers }).returns @single_country_response
|
443
|
+
assert_nil @ps.ip_country_is_configured?(@ip)
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
context "ip_country is within configured countries" do
|
448
|
+
context "when ip_country IS configured" do
|
449
|
+
setup do
|
450
|
+
FakeWeb.register_uri(:get, "#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales?key=#{@api_key}", :body => 'test/multi_countries_ps.xml', :content_type => "text/xml")
|
451
|
+
@multi_country_response = HTTParty.get("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales", {:query => {:key => @api_key}, :headers => @headers })
|
452
|
+
end
|
453
|
+
should "return a country-hash " do
|
454
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}/#{@ip}/pay/#{@ps.price_setting_id}/locale_for_ip",
|
455
|
+
{:query => {:key => @api_key}, :headers => @headers }).returns @ip_response
|
456
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}//pay/#{@ps.price_setting_id}/list_locales",
|
457
|
+
{:query => {:key => @api_key}, :headers => @headers }).returns @multi_country_response
|
458
|
+
assert_equal({:country => {:name => 'Netherlands', :code => 'NL'}, :locale => {:country => 'NL', :language => 'nl'}} , @ps.ip_country_is_configured?(@ip))
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
context "protected method #check" do
|
465
|
+
setup do
|
466
|
+
FakeWeb.register_uri(:get,"#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}?key=#{@api_key}",
|
467
|
+
[{:body => 'foobar', :status => ["404", "Not Found"]},
|
468
|
+
{:body => 'test/error_with_dynamic_amounts.xml', :content_type => "text/xml"}])
|
469
|
+
|
470
|
+
@response_with_404 = HTTParty.get("#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}", {:query => {:key => @api_key}, :headers => @headers })
|
471
|
+
@response_with_error_status= HTTParty.get("#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}", {:query => {:key => @api_key}, :headers => @headers })
|
472
|
+
end
|
473
|
+
context "response code is not 200" do
|
474
|
+
should "raise Zaypay::Error of type :http_error" do
|
475
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}",
|
476
|
+
{:query => {:key => @api_key}, :headers => @headers } ).returns @response_with_404
|
477
|
+
error = assert_raise Zaypay::Error do
|
478
|
+
@ps.show_payment(@payment_id)
|
479
|
+
end
|
480
|
+
assert_equal :http_error, error.type
|
481
|
+
assert_equal "HTTP-request to zaypay yielded status 404..\n\nzaypay said:\nfoobar", error.message
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
context "reponse code is 200 but status of the xml-response is error" do
|
486
|
+
should "raise Zaypay::Error of type :http_error" do
|
487
|
+
Zaypay::PriceSetting.expects(:get).with("#{@base_uri}///pay/#{@price_setting_id}/payments/#{@payment_id}",
|
488
|
+
{:query => {:key => @api_key}, :headers => @headers } ).returns @response_with_error_status
|
489
|
+
error = assert_raise Zaypay::Error do
|
490
|
+
@ps.show_payment(@payment_id)
|
491
|
+
end
|
492
|
+
assert_equal :http_error, error.type
|
493
|
+
assert_equal "HTTP-request to yielded an error:\n#{@response_with_error_status[:response][:error]}", error.message
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|