paysio 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +9 -0
- data/CONTRIBUTORS +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +42 -0
- data/History.txt +4 -0
- data/LICENSE +21 -0
- data/README.rdoc +12 -0
- data/Rakefile +12 -0
- data/VERSION +1 -0
- data/bin/paysio +7 -0
- data/gemfiles/default-with-activesupport.gemfile +3 -0
- data/gemfiles/json.gemfile +4 -0
- data/gemfiles/yajl.gemfile +4 -0
- data/lib/data/ca-certificates.crt +3918 -0
- data/lib/paysio/account.rb +4 -0
- data/lib/paysio/api_operations/create.rb +16 -0
- data/lib/paysio/api_operations/delete.rb +11 -0
- data/lib/paysio/api_operations/list.rb +16 -0
- data/lib/paysio/api_operations/update.rb +15 -0
- data/lib/paysio/api_resource.rb +33 -0
- data/lib/paysio/charge.rb +39 -0
- data/lib/paysio/coupon.rb +7 -0
- data/lib/paysio/customer.rb +51 -0
- data/lib/paysio/errors/api_connection_error.rb +4 -0
- data/lib/paysio/errors/api_error.rb +4 -0
- data/lib/paysio/errors/authentication_error.rb +4 -0
- data/lib/paysio/errors/card_error.rb +11 -0
- data/lib/paysio/errors/invalid_request_error.rb +10 -0
- data/lib/paysio/errors/paysio_error.rb +20 -0
- data/lib/paysio/event.rb +5 -0
- data/lib/paysio/json.rb +21 -0
- data/lib/paysio/list_object.rb +14 -0
- data/lib/paysio/paysio_object.rb +159 -0
- data/lib/paysio/singleton_api_resource.rb +20 -0
- data/lib/paysio/util.rb +100 -0
- data/lib/paysio/version.rb +3 -0
- data/lib/paysio.rb +252 -0
- data/paysio.gemspec +28 -0
- data/test/test_helper.rb +162 -0
- data/test/test_paysio.rb +479 -0
- data/test/test_paysio_with_active_support.rb +2 -0
- metadata +193 -0
data/test/test_paysio.rb
ADDED
@@ -0,0 +1,479 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path('../test_helper', __FILE__)
|
3
|
+
require 'test/unit'
|
4
|
+
require 'shoulda'
|
5
|
+
require 'mocha'
|
6
|
+
require 'pp'
|
7
|
+
require 'rest-client'
|
8
|
+
require 'cgi'
|
9
|
+
require 'uri'
|
10
|
+
|
11
|
+
class TestPaysioRuby < Test::Unit::TestCase
|
12
|
+
include Mocha
|
13
|
+
|
14
|
+
context "Util" do
|
15
|
+
should "symbolize_names should convert names to symbols" do
|
16
|
+
start = {
|
17
|
+
'foo' => 'bar',
|
18
|
+
'array' => [{ 'foo' => 'bar' }],
|
19
|
+
'nested' => {
|
20
|
+
1 => 2,
|
21
|
+
:symbol => 9,
|
22
|
+
'string' => nil
|
23
|
+
}
|
24
|
+
}
|
25
|
+
finish = {
|
26
|
+
:foo => 'bar',
|
27
|
+
:array => [{ :foo => 'bar' }],
|
28
|
+
:nested => {
|
29
|
+
1 => 2,
|
30
|
+
:symbol => 9,
|
31
|
+
:string => nil
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
symbolized = Paysio::Util.symbolize_names(start)
|
36
|
+
assert_equal(finish, symbolized)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "API Bindings" do
|
41
|
+
setup do
|
42
|
+
@mock = mock
|
43
|
+
Paysio.mock_rest_client = @mock
|
44
|
+
end
|
45
|
+
|
46
|
+
teardown do
|
47
|
+
Paysio.mock_rest_client = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
should "creating a new APIResource should not fetch over the network" do
|
51
|
+
@mock.expects(:get).never
|
52
|
+
c = Paysio::Customer.new("someid")
|
53
|
+
end
|
54
|
+
|
55
|
+
should "creating a new APIResource from a hash should not fetch over the network" do
|
56
|
+
@mock.expects(:get).never
|
57
|
+
c = Paysio::Customer.construct_from({
|
58
|
+
:id => "somecustomer",
|
59
|
+
:card => {:id => "somecard", :object => "card"},
|
60
|
+
:object => "customer"
|
61
|
+
})
|
62
|
+
end
|
63
|
+
|
64
|
+
should "setting an attribute should not cause a network request" do
|
65
|
+
@mock.expects(:get).never
|
66
|
+
@mock.expects(:post).never
|
67
|
+
c = Paysio::Customer.new("test_customer");
|
68
|
+
c.card = {:id => "somecard", :object => "card"}
|
69
|
+
end
|
70
|
+
|
71
|
+
should "accessing id should not issue a fetch" do
|
72
|
+
@mock.expects(:get).never
|
73
|
+
c = Paysio::Customer.new("test_customer");
|
74
|
+
c.id
|
75
|
+
end
|
76
|
+
|
77
|
+
should "not specifying api credentials should raise an exception" do
|
78
|
+
Paysio.api_key = nil
|
79
|
+
assert_raises Paysio::AuthenticationError do
|
80
|
+
Paysio::Customer.new("test_customer").refresh
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
should "specifying invalid api credentials should raise an exception" do
|
85
|
+
Paysio.api_key = "invalid"
|
86
|
+
response = test_response(test_invalid_api_key_error, 401)
|
87
|
+
assert_raises Paysio::AuthenticationError do
|
88
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
|
89
|
+
Paysio::Customer.retrieve("failing_customer")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
should "AuthenticationErrors should have an http status, http body, and JSON body" do
|
94
|
+
Paysio.api_key = "invalid"
|
95
|
+
response = test_response(test_invalid_api_key_error, 401)
|
96
|
+
begin
|
97
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
|
98
|
+
Paysio::Customer.retrieve("failing_customer")
|
99
|
+
rescue Paysio::AuthenticationError => e
|
100
|
+
assert_equal(401, e.http_status)
|
101
|
+
assert_equal(true, !!e.http_body)
|
102
|
+
assert_equal(true, !!e.json_body[:error][:message])
|
103
|
+
assert_equal(test_invalid_api_key_error['error']['message'], e.json_body[:error][:message])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "with valid credentials" do
|
108
|
+
setup do
|
109
|
+
Paysio.api_key="foo"
|
110
|
+
end
|
111
|
+
|
112
|
+
teardown do
|
113
|
+
Paysio.api_key=nil
|
114
|
+
end
|
115
|
+
|
116
|
+
should "urlencode values in GET params" do
|
117
|
+
response = test_response(test_charge_array)
|
118
|
+
@mock.expects(:get).with("#{Paysio.api_base}/v1/charges?customer=test%20customer", nil, nil).returns(response)
|
119
|
+
charges = Paysio::Charge.all(:customer => 'test customer').data
|
120
|
+
assert charges.kind_of? Array
|
121
|
+
end
|
122
|
+
|
123
|
+
should "a 400 should give an InvalidRequestError with http status, body, and JSON body" do
|
124
|
+
response = test_response(test_missing_id_error, 400)
|
125
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
126
|
+
begin
|
127
|
+
Paysio::Customer.retrieve("foo")
|
128
|
+
rescue Paysio::InvalidRequestError => e
|
129
|
+
assert_equal(400, e.http_status)
|
130
|
+
assert_equal(true, !!e.http_body)
|
131
|
+
assert_equal(true, e.json_body.kind_of?(Hash))
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
should "a 401 should give an AuthenticationError with http status, body, and JSON body" do
|
136
|
+
response = test_response(test_missing_id_error, 401)
|
137
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
138
|
+
begin
|
139
|
+
Paysio::Customer.retrieve("foo")
|
140
|
+
rescue Paysio::AuthenticationError => e
|
141
|
+
assert_equal(401, e.http_status)
|
142
|
+
assert_equal(true, !!e.http_body)
|
143
|
+
assert_equal(true, e.json_body.kind_of?(Hash))
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
should "a 402 should give a CardError with http status, body, and JSON body" do
|
148
|
+
response = test_response(test_missing_id_error, 402)
|
149
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
150
|
+
begin
|
151
|
+
Paysio::Customer.retrieve("foo")
|
152
|
+
rescue Paysio::CardError => e
|
153
|
+
assert_equal(402, e.http_status)
|
154
|
+
assert_equal(true, !!e.http_body)
|
155
|
+
assert_equal(true, e.json_body.kind_of?(Hash))
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
should "a 404 should give an InvalidRequestError with http status, body, and JSON body" do
|
160
|
+
response = test_response(test_missing_id_error, 404)
|
161
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
162
|
+
begin
|
163
|
+
Paysio::Customer.retrieve("foo")
|
164
|
+
rescue Paysio::InvalidRequestError => e
|
165
|
+
assert_equal(404, e.http_status)
|
166
|
+
assert_equal(true, !!e.http_body)
|
167
|
+
assert_equal(true, e.json_body.kind_of?(Hash))
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
should "setting a nil value for a param should exclude that param from the request" do
|
172
|
+
@mock.expects(:get).with do |url, api_key, params|
|
173
|
+
uri = URI(url)
|
174
|
+
query = CGI.parse(uri.query)
|
175
|
+
(url =~ %r{^#{Paysio.api_base}/v1/charges?} &&
|
176
|
+
query.keys.sort == ['offset', 'sad'])
|
177
|
+
end.returns(test_response({ :count => 1, :data => [test_charge] }))
|
178
|
+
c = Paysio::Charge.all(:count => nil, :offset => 5, :sad => false)
|
179
|
+
|
180
|
+
@mock.expects(:post).with do |url, api_key, params|
|
181
|
+
url == "#{Paysio.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == { 'amount' => ['50'], 'currency' => ['usd'] }
|
182
|
+
end.returns(test_response({ :count => 1, :data => [test_charge] }))
|
183
|
+
c = Paysio::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
|
184
|
+
end
|
185
|
+
|
186
|
+
should "requesting with a unicode ID should result in a request" do
|
187
|
+
response = test_response(test_missing_id_error, 404)
|
188
|
+
@mock.expects(:get).once.with("#{Paysio.api_base}/v1/customers/%E2%98%83", nil, nil).raises(RestClient::ExceptionWithResponse.new(response, 404))
|
189
|
+
c = Paysio::Customer.new("☃")
|
190
|
+
assert_raises(Paysio::InvalidRequestError) { c.refresh }
|
191
|
+
end
|
192
|
+
|
193
|
+
should "requesting with no ID should result in an InvalidRequestError with no request" do
|
194
|
+
c = Paysio::Customer.new
|
195
|
+
assert_raises(Paysio::InvalidRequestError) { c.refresh }
|
196
|
+
end
|
197
|
+
|
198
|
+
should "making a GET request with parameters should have a query string and no body" do
|
199
|
+
params = { :limit => 1 }
|
200
|
+
@mock.expects(:get).once.with("#{Paysio.api_base}/v1/charges?limit=1", nil, nil).returns(test_response([test_charge]))
|
201
|
+
c = Paysio::Charge.all(params)
|
202
|
+
end
|
203
|
+
|
204
|
+
should "making a POST request with parameters should have a body and no query string" do
|
205
|
+
params = { :amount => 100, :currency => 'usd', :card => 'sc_token' }
|
206
|
+
@mock.expects(:post).once.with do |url, get, post|
|
207
|
+
get.nil? && CGI.parse(post) == {'amount' => ['100'], 'currency' => ['usd'], 'card' => ['sc_token']}
|
208
|
+
end.returns(test_response(test_charge))
|
209
|
+
c = Paysio::Charge.create(params)
|
210
|
+
end
|
211
|
+
|
212
|
+
should "loading an object should issue a GET request" do
|
213
|
+
@mock.expects(:get).once.returns(test_response(test_customer))
|
214
|
+
c = Paysio::Customer.new("test_customer")
|
215
|
+
c.refresh
|
216
|
+
end
|
217
|
+
|
218
|
+
should "using array accessors should be the same as the method interface" do
|
219
|
+
@mock.expects(:get).once.returns(test_response(test_customer))
|
220
|
+
c = Paysio::Customer.new("test_customer")
|
221
|
+
c.refresh
|
222
|
+
assert_equal c.created, c[:created]
|
223
|
+
assert_equal c.created, c['created']
|
224
|
+
c['created'] = 12345
|
225
|
+
assert_equal c.created, 12345
|
226
|
+
end
|
227
|
+
|
228
|
+
should "accessing a property other than id or parent on an unfetched object should fetch it" do
|
229
|
+
@mock.expects(:get).once.returns(test_response(test_customer))
|
230
|
+
c = Paysio::Customer.new("test_customer")
|
231
|
+
c.charges
|
232
|
+
end
|
233
|
+
|
234
|
+
should "updating an object should issue a POST request with only the changed properties" do
|
235
|
+
@mock.expects(:post).with do |url, api_key, params|
|
236
|
+
url == "#{Paysio.api_base}/v1/customers/c_test_customer" && api_key.nil? && CGI.parse(params) == {'mnemonic' => ['another_mn']}
|
237
|
+
end.once.returns(test_response(test_customer))
|
238
|
+
c = Paysio::Customer.construct_from(test_customer)
|
239
|
+
c.mnemonic = "another_mn"
|
240
|
+
c.save
|
241
|
+
end
|
242
|
+
|
243
|
+
should "updating should merge in returned properties" do
|
244
|
+
@mock.expects(:post).once.returns(test_response(test_customer))
|
245
|
+
c = Paysio::Customer.new("c_test_customer")
|
246
|
+
c.mnemonic = "another_mn"
|
247
|
+
c.save
|
248
|
+
assert_equal false, c.livemode
|
249
|
+
end
|
250
|
+
|
251
|
+
should "deleting should send no props and result in an object that has no props other deleted" do
|
252
|
+
@mock.expects(:get).never
|
253
|
+
@mock.expects(:post).never
|
254
|
+
@mock.expects(:delete).with("#{Paysio.api_base}/v1/customers/c_test_customer", nil, nil).once.returns(test_response({ "id" => "test_customer", "deleted" => true }))
|
255
|
+
|
256
|
+
c = Paysio::Customer.construct_from(test_customer)
|
257
|
+
c.delete
|
258
|
+
assert_equal true, c.deleted
|
259
|
+
|
260
|
+
assert_raises NoMethodError do
|
261
|
+
c.livemode
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
should "loading an object with properties that have specific types should instantiate those classes" do
|
266
|
+
@mock.expects(:get).once.returns(test_response(test_charge))
|
267
|
+
c = Paysio::Charge.retrieve("test_charge")
|
268
|
+
assert c.card.kind_of?(Paysio::PaysioObject) && c.card.object == 'card'
|
269
|
+
end
|
270
|
+
|
271
|
+
should "loading all of an APIResource should return an array of recursively instantiated objects" do
|
272
|
+
@mock.expects(:get).once.returns(test_response(test_charge_array))
|
273
|
+
c = Paysio::Charge.all.data
|
274
|
+
assert c.kind_of? Array
|
275
|
+
assert c[0].kind_of? Paysio::Charge
|
276
|
+
assert c[0].card.kind_of?(Paysio::PaysioObject) && c[0].card.object == 'card'
|
277
|
+
end
|
278
|
+
|
279
|
+
context "account tests" do
|
280
|
+
should "account should be retrievable" do
|
281
|
+
resp = {:email => "test+bindings@stripe.com", :charge_enabled => false, :details_submitted => false}
|
282
|
+
@mock.expects(:get).once.returns(test_response(resp))
|
283
|
+
a = Paysio::Account.retrieve
|
284
|
+
assert_equal "test+bindings@stripe.com", a.email
|
285
|
+
assert !a.charge_enabled
|
286
|
+
assert !a.details_submitted
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
context "list tests" do
|
291
|
+
should "be able to retrieve full lists given a listobject" do
|
292
|
+
@mock.expects(:get).twice.returns(test_response(test_charge_array))
|
293
|
+
c = Paysio::Charge.all
|
294
|
+
assert c.kind_of?(Paysio::ListObject)
|
295
|
+
assert_equal('/v1/charges', c.url)
|
296
|
+
all = c.all
|
297
|
+
assert all.kind_of?(Paysio::ListObject)
|
298
|
+
assert_equal('/v1/charges', all.url)
|
299
|
+
assert all.data.kind_of?(Array)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
context "charge tests" do
|
304
|
+
|
305
|
+
should "charges should be listable" do
|
306
|
+
@mock.expects(:get).once.returns(test_response(test_charge_array))
|
307
|
+
c = Paysio::Charge.all
|
308
|
+
assert c.data.kind_of? Array
|
309
|
+
c.each do |charge|
|
310
|
+
assert charge.kind_of?(Paysio::Charge)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
should "charges should be refundable" do
|
315
|
+
@mock.expects(:get).never
|
316
|
+
@mock.expects(:post).once.returns(test_response({:id => "ch_test_charge", :refunded => true}))
|
317
|
+
c = Paysio::Charge.new("test_charge")
|
318
|
+
c.refund
|
319
|
+
assert c.refunded
|
320
|
+
end
|
321
|
+
|
322
|
+
should "charges should not be deletable" do
|
323
|
+
assert_raises NoMethodError do
|
324
|
+
@mock.expects(:get).once.returns(test_response(test_charge))
|
325
|
+
c = Paysio::Charge.retrieve("test_charge")
|
326
|
+
c.delete
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
should "charges should be updateable" do
|
331
|
+
@mock.expects(:get).once.returns(test_response(test_charge))
|
332
|
+
@mock.expects(:post).once.returns(test_response(test_charge))
|
333
|
+
c = Paysio::Charge.new("test_charge")
|
334
|
+
c.refresh
|
335
|
+
c.mnemonic = "New charge description"
|
336
|
+
c.save
|
337
|
+
end
|
338
|
+
|
339
|
+
should "charges should have Card objects associated with their Card property" do
|
340
|
+
@mock.expects(:get).once.returns(test_response(test_charge))
|
341
|
+
c = Paysio::Charge.retrieve("test_charge")
|
342
|
+
assert c.card.kind_of?(Paysio::PaysioObject) && c.card.object == 'card'
|
343
|
+
end
|
344
|
+
|
345
|
+
should "execute should return a new, fully executed charge when passed correct parameters" do
|
346
|
+
@mock.expects(:post).with do |url, api_key, params|
|
347
|
+
url == "#{Paysio.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == {
|
348
|
+
'currency' => ['usd'], 'amount' => ['100'],
|
349
|
+
'card[exp_year]' => ['2012'],
|
350
|
+
'card[number]' => ['4242424242424242'],
|
351
|
+
'card[exp_month]' => ['11']
|
352
|
+
}
|
353
|
+
end.once.returns(test_response(test_charge))
|
354
|
+
|
355
|
+
c = Paysio::Charge.create({
|
356
|
+
:amount => 100,
|
357
|
+
:card => {
|
358
|
+
:number => "4242424242424242",
|
359
|
+
:exp_month => 11,
|
360
|
+
:exp_year => 2012,
|
361
|
+
},
|
362
|
+
:currency => "usd"
|
363
|
+
})
|
364
|
+
assert c.paid
|
365
|
+
end
|
366
|
+
|
367
|
+
end
|
368
|
+
|
369
|
+
context "customer tests" do
|
370
|
+
|
371
|
+
should "customers should be listable" do
|
372
|
+
@mock.expects(:get).once.returns(test_response(test_customer_array))
|
373
|
+
c = Paysio::Customer.all.data
|
374
|
+
assert c.kind_of? Array
|
375
|
+
assert c[0].kind_of? Paysio::Customer
|
376
|
+
end
|
377
|
+
|
378
|
+
should "customers should be deletable" do
|
379
|
+
@mock.expects(:delete).once.returns(test_response(test_customer({:deleted => true})))
|
380
|
+
c = Paysio::Customer.new("test_customer")
|
381
|
+
c.delete
|
382
|
+
assert c.deleted
|
383
|
+
end
|
384
|
+
|
385
|
+
should "customers should be updateable" do
|
386
|
+
@mock.expects(:get).once.returns(test_response(test_customer({:mnemonic => "foo"})))
|
387
|
+
@mock.expects(:post).once.returns(test_response(test_customer({:mnemonic => "bar"})))
|
388
|
+
c = Paysio::Customer.new("test_customer").refresh
|
389
|
+
assert_equal c.mnemonic, "foo"
|
390
|
+
c.mnemonic = "bar"
|
391
|
+
c.save
|
392
|
+
assert_equal c.mnemonic, "bar"
|
393
|
+
end
|
394
|
+
|
395
|
+
should "customers should have Card objects associated with their active_ard property" do
|
396
|
+
@mock.expects(:get).once.returns(test_response(test_customer))
|
397
|
+
c = Paysio::Customer.retrieve("test_customer")
|
398
|
+
assert c.active_card.kind_of?(Paysio::PaysioObject) && c.active_card.object == 'card'
|
399
|
+
end
|
400
|
+
|
401
|
+
should "create should return a new customer" do
|
402
|
+
@mock.expects(:post).once.returns(test_response(test_customer))
|
403
|
+
c = Paysio::Customer.create
|
404
|
+
assert_equal "c_test_customer", c.id
|
405
|
+
end
|
406
|
+
|
407
|
+
should "be able to delete a customer's discount" do
|
408
|
+
@mock.expects(:get).once.returns(test_response(test_customer))
|
409
|
+
c = Paysio::Customer.retrieve("test_customer")
|
410
|
+
|
411
|
+
@mock.expects(:delete).once.with("#{Paysio.api_base}/v1/customers/c_test_customer/discount", nil, nil).returns(test_response(test_delete_discount_response))
|
412
|
+
s = c.delete_discount
|
413
|
+
assert_equal nil, c.discount
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
context "coupon tests" do
|
418
|
+
should "create should return a new coupon" do
|
419
|
+
@mock.expects(:post).once.returns(test_response(test_coupon))
|
420
|
+
c = Paysio::Coupon.create
|
421
|
+
assert_equal "co_test_coupon", c.id
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
context "error checking" do
|
426
|
+
|
427
|
+
should "404s should raise an InvalidRequestError" do
|
428
|
+
response = test_response(test_missing_id_error, 404)
|
429
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
430
|
+
|
431
|
+
begin
|
432
|
+
Paysio::Customer.new("test_customer").refresh
|
433
|
+
assert false #shouldn't get here either
|
434
|
+
rescue Paysio::InvalidRequestError => e # we don't use assert_raises because we want to examine e
|
435
|
+
assert e.kind_of? Paysio::InvalidRequestError
|
436
|
+
assert_equal "id", e.param
|
437
|
+
assert_equal "Missing id", e.message
|
438
|
+
return
|
439
|
+
end
|
440
|
+
|
441
|
+
assert false #shouldn't get here
|
442
|
+
end
|
443
|
+
|
444
|
+
should "5XXs should raise an APIError" do
|
445
|
+
response = test_response(test_api_error, 500)
|
446
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 500))
|
447
|
+
|
448
|
+
begin
|
449
|
+
Paysio::Customer.new("test_customer").refresh
|
450
|
+
assert false #shouldn't get here either
|
451
|
+
rescue Paysio::APIError => e # we don't use assert_raises because we want to examine e
|
452
|
+
assert e.kind_of? Paysio::APIError
|
453
|
+
return
|
454
|
+
end
|
455
|
+
|
456
|
+
assert false #shouldn't get here
|
457
|
+
end
|
458
|
+
|
459
|
+
should "402s should raise a CardError" do
|
460
|
+
response = test_response(test_invalid_exp_year_error, 402)
|
461
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 402))
|
462
|
+
|
463
|
+
begin
|
464
|
+
Paysio::Customer.new("test_customer").refresh
|
465
|
+
assert false #shouldn't get here either
|
466
|
+
rescue Paysio::CardError => e # we don't use assert_raises because we want to examine e
|
467
|
+
assert e.kind_of? Paysio::CardError
|
468
|
+
assert_equal "invalid_expiry_year", e.code
|
469
|
+
assert_equal "exp_year", e.param
|
470
|
+
assert_equal "Your card's expiration year is invalid", e.message
|
471
|
+
return
|
472
|
+
end
|
473
|
+
|
474
|
+
assert false #shouldn't get here
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|
478
|
+
end
|
479
|
+
end
|
metadata
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paysio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Iskander Haziev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.4'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.4'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: multi_json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.4
|
38
|
+
- - <
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.0.4
|
49
|
+
- - <
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '2'
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: mocha
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: shoulda
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: test-unit
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: rake
|
102
|
+
requirement: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
type: :development
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
description: See https://paysio.com for details.
|
117
|
+
email:
|
118
|
+
- gvalmon@gmail.com
|
119
|
+
executables:
|
120
|
+
- paysio
|
121
|
+
extensions: []
|
122
|
+
extra_rdoc_files: []
|
123
|
+
files:
|
124
|
+
- .gitignore
|
125
|
+
- .travis.yml
|
126
|
+
- CONTRIBUTORS
|
127
|
+
- Gemfile
|
128
|
+
- Gemfile.lock
|
129
|
+
- History.txt
|
130
|
+
- LICENSE
|
131
|
+
- README.rdoc
|
132
|
+
- Rakefile
|
133
|
+
- VERSION
|
134
|
+
- bin/paysio
|
135
|
+
- gemfiles/default-with-activesupport.gemfile
|
136
|
+
- gemfiles/json.gemfile
|
137
|
+
- gemfiles/yajl.gemfile
|
138
|
+
- lib/data/ca-certificates.crt
|
139
|
+
- lib/paysio.rb
|
140
|
+
- lib/paysio/account.rb
|
141
|
+
- lib/paysio/api_operations/create.rb
|
142
|
+
- lib/paysio/api_operations/delete.rb
|
143
|
+
- lib/paysio/api_operations/list.rb
|
144
|
+
- lib/paysio/api_operations/update.rb
|
145
|
+
- lib/paysio/api_resource.rb
|
146
|
+
- lib/paysio/charge.rb
|
147
|
+
- lib/paysio/coupon.rb
|
148
|
+
- lib/paysio/customer.rb
|
149
|
+
- lib/paysio/errors/api_connection_error.rb
|
150
|
+
- lib/paysio/errors/api_error.rb
|
151
|
+
- lib/paysio/errors/authentication_error.rb
|
152
|
+
- lib/paysio/errors/card_error.rb
|
153
|
+
- lib/paysio/errors/invalid_request_error.rb
|
154
|
+
- lib/paysio/errors/paysio_error.rb
|
155
|
+
- lib/paysio/event.rb
|
156
|
+
- lib/paysio/json.rb
|
157
|
+
- lib/paysio/list_object.rb
|
158
|
+
- lib/paysio/paysio_object.rb
|
159
|
+
- lib/paysio/singleton_api_resource.rb
|
160
|
+
- lib/paysio/util.rb
|
161
|
+
- lib/paysio/version.rb
|
162
|
+
- paysio.gemspec
|
163
|
+
- test/test_helper.rb
|
164
|
+
- test/test_paysio.rb
|
165
|
+
- test/test_paysio_with_active_support.rb
|
166
|
+
homepage: https://paysio.com
|
167
|
+
licenses: []
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
none: false
|
174
|
+
requirements:
|
175
|
+
- - ! '>='
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
none: false
|
180
|
+
requirements:
|
181
|
+
- - ! '>='
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
requirements: []
|
185
|
+
rubyforge_project:
|
186
|
+
rubygems_version: 1.8.25
|
187
|
+
signing_key:
|
188
|
+
specification_version: 3
|
189
|
+
summary: Ruby bindings for the Pays.io API
|
190
|
+
test_files:
|
191
|
+
- test/test_helper.rb
|
192
|
+
- test/test_paysio.rb
|
193
|
+
- test/test_paysio_with_active_support.rb
|