gocardless 1.8.0 → 1.9.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.
- checksums.yaml +7 -0
- data/.travis.yml +2 -2
- data/CHANGELOG.md +7 -0
- data/README.md +1 -2
- data/gocardless.gemspec +3 -3
- data/lib/gocardless.rb +1 -0
- data/lib/gocardless/bill.rb +15 -1
- data/lib/gocardless/client.rb +2 -1
- data/lib/gocardless/payout.rb +11 -0
- data/lib/gocardless/utils.rb +1 -1
- data/lib/gocardless/version.rb +1 -1
- data/spec/bill_spec.rb +23 -11
- data/spec/client_spec.rb +45 -45
- data/spec/gocardless_spec.rb +2 -2
- data/spec/pre_authorization_spec.rb +9 -9
- data/spec/resource_spec.rb +14 -14
- data/spec/spec_helper.rb +2 -7
- data/spec/subscription_spec.rb +9 -9
- data/spec/utils_spec.rb +1 -1
- metadata +30 -59
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed8ff8ba2e1109b3ec370bd8c52e2d1f2dc0ae70
|
4
|
+
data.tar.gz: 4321b58cabecafefbf4a5257ae6ee6e218d49364
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8594375ca0b9ea638fedf5d2fc4ef137b81b791e2248307277eb4459e941b1606abd49f53e86a4829acd2fd3f09d72ca5a3fd5dbaadda148784d65df24d6a0e
|
7
|
+
data.tar.gz: c92b6f3708f2595533dcc368f904fbd83593f8eabf7059b8b9955cfe5bb964792335e584fd129da8b150773f1c0e9a317e70948a374974682ec12c69d23bd214
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -11,5 +11,4 @@ you want to support multiple merchant accounts, see the
|
|
11
11
|
The full API reference is available at on
|
12
12
|
[rubydoc.info](http://rubydoc.info/github/gocardless/gocardless-ruby/master/frames).
|
13
13
|
|
14
|
-
[](http://travis-ci.org/gocardless/gocardless-ruby)
|
15
|
-
|
14
|
+
[](http://travis-ci.org/gocardless/gocardless-ruby) [](http://badge.fury.io/rb/gocardless)
|
data/gocardless.gemspec
CHANGED
@@ -4,9 +4,8 @@ Gem::Specification.new do |gem|
|
|
4
4
|
gem.add_runtime_dependency 'oauth2', '~> 0.7'
|
5
5
|
gem.add_runtime_dependency 'multi_json', '~> 1.0'
|
6
6
|
|
7
|
-
gem.add_development_dependency 'rspec', '~> 2.
|
8
|
-
gem.add_development_dependency '
|
9
|
-
gem.add_development_dependency 'yard', '~> 0.7.3'
|
7
|
+
gem.add_development_dependency 'rspec', '~> 2.13'
|
8
|
+
gem.add_development_dependency 'yard', '~> 0.7'
|
10
9
|
gem.add_development_dependency 'activesupport', '~> 3.1'
|
11
10
|
gem.add_development_dependency 'rake', '~> 10.0'
|
12
11
|
|
@@ -20,4 +19,5 @@ Gem::Specification.new do |gem|
|
|
20
19
|
gem.summary = %q{Ruby wrapper for the GoCardless API}
|
21
20
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
21
|
gem.version = GoCardless::VERSION.dup
|
22
|
+
gem.licenses = ['MIT']
|
23
23
|
end
|
data/lib/gocardless.rb
CHANGED
data/lib/gocardless/bill.rb
CHANGED
@@ -17,7 +17,7 @@ module GoCardless
|
|
17
17
|
# @return [String] the ID of the bill's source (eg subscription, pre_authorization)
|
18
18
|
attr_accessor :source_id
|
19
19
|
|
20
|
-
reference_accessor :merchant_id, :user_id, :payment_id
|
20
|
+
reference_accessor :merchant_id, :user_id, :payment_id, :payout_id
|
21
21
|
date_accessor :created_at, :paid_at
|
22
22
|
|
23
23
|
def source
|
@@ -40,6 +40,20 @@ module GoCardless
|
|
40
40
|
client.api_post(path)
|
41
41
|
end
|
42
42
|
|
43
|
+
def cancel!
|
44
|
+
path = self.class.endpoint.gsub(':id', id.to_s) + '/cancel'
|
45
|
+
client.api_put(path)
|
46
|
+
end
|
47
|
+
|
48
|
+
# The ability to refund a payment is disabled by default.
|
49
|
+
#
|
50
|
+
# Please contact help@gocardless.com if you require access to
|
51
|
+
# the refunds API endpoint.
|
52
|
+
def refund!
|
53
|
+
path = self.class.endpoint.gsub(':id', id.to_s) + '/refund'
|
54
|
+
client.api_post(path)
|
55
|
+
end
|
56
|
+
|
43
57
|
def save
|
44
58
|
save_data({
|
45
59
|
:bill => {
|
data/lib/gocardless/client.rb
CHANGED
@@ -195,7 +195,8 @@ module GoCardless
|
|
195
195
|
# Create a new bill under a given pre-authorization
|
196
196
|
# @see PreAuthorization#create_bill
|
197
197
|
#
|
198
|
-
# @param [Hash] attrs must include +:
|
198
|
+
# @param [Hash] attrs must include +:source_id+ (the id of the
|
199
|
+
# pre_authorization you want to bill from) and +:amount+
|
199
200
|
# @return [Bill] the created bill object
|
200
201
|
def create_bill(attrs)
|
201
202
|
Bill.new_with_client(self, attrs).save
|
data/lib/gocardless/utils.rb
CHANGED
@@ -90,7 +90,7 @@ module GoCardless
|
|
90
90
|
# @return [String] the resulting signature
|
91
91
|
def sign_params(params, key)
|
92
92
|
msg = Utils.normalize_params(params)
|
93
|
-
digest = OpenSSL::Digest
|
93
|
+
digest = OpenSSL::Digest.new('sha256')
|
94
94
|
OpenSSL::HMAC.hexdigest(digest, key, msg)
|
95
95
|
end
|
96
96
|
|
data/lib/gocardless/version.rb
CHANGED
data/spec/bill_spec.rb
CHANGED
@@ -28,56 +28,68 @@ describe GoCardless::Bill do
|
|
28
28
|
|
29
29
|
it "should be able to be retried" do
|
30
30
|
b = GoCardless::Bill.new(:id => 123)
|
31
|
-
@client.
|
31
|
+
@client.should_receive(:api_post).with('/bills/123/retry')
|
32
32
|
b.retry!
|
33
33
|
end
|
34
34
|
|
35
|
+
it "should be able to be cancelled" do
|
36
|
+
b = GoCardless::Bill.new(:id => 123)
|
37
|
+
@client.should_receive(:api_put).with('/bills/123/cancel')
|
38
|
+
b.cancel!
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to be refunded" do
|
42
|
+
b = GoCardless::Bill.new(:id => 123)
|
43
|
+
@client.should_receive(:api_post).with('/bills/123/refund')
|
44
|
+
b.refund!
|
45
|
+
end
|
46
|
+
|
35
47
|
describe "pending query method" do
|
36
|
-
it "
|
48
|
+
it "and_return true when the subscription status is pending" do
|
37
49
|
GoCardless::Bill.new(:status => 'pending').pending?.should be_true
|
38
50
|
end
|
39
51
|
|
40
|
-
it "
|
52
|
+
it "and_return false otherwise" do
|
41
53
|
GoCardless::Bill.new.pending?.should be_false
|
42
54
|
end
|
43
55
|
end
|
44
56
|
|
45
57
|
describe "paid query method" do
|
46
|
-
it "
|
58
|
+
it "and_return true when the subscription status is paid" do
|
47
59
|
GoCardless::Bill.new(:status => 'paid').paid?.should be_true
|
48
60
|
end
|
49
61
|
|
50
|
-
it "
|
62
|
+
it "and_return false otherwise" do
|
51
63
|
GoCardless::Bill.new.paid?.should be_false
|
52
64
|
end
|
53
65
|
end
|
54
66
|
|
55
67
|
describe "failed query method" do
|
56
|
-
it "
|
68
|
+
it "and_return true when the subscription status is failed" do
|
57
69
|
GoCardless::Bill.new(:status => 'failed').failed?.should be_true
|
58
70
|
end
|
59
71
|
|
60
|
-
it "
|
72
|
+
it "and_return false otherwise" do
|
61
73
|
GoCardless::Bill.new.failed?.should be_false
|
62
74
|
end
|
63
75
|
end
|
64
76
|
|
65
77
|
describe "withdrawn query method" do
|
66
|
-
it "
|
78
|
+
it "and_return true when the subscription status is withdrawn" do
|
67
79
|
GoCardless::Bill.new(:status => 'withdrawn').withdrawn?.should be_true
|
68
80
|
end
|
69
81
|
|
70
|
-
it "
|
82
|
+
it "and_return false otherwise" do
|
71
83
|
GoCardless::Bill.new.withdrawn?.should be_false
|
72
84
|
end
|
73
85
|
end
|
74
86
|
|
75
87
|
describe "refunded query method" do
|
76
|
-
it "
|
88
|
+
it "and_return true when the subscription status is refunded" do
|
77
89
|
GoCardless::Bill.new(:status => 'refunded').refunded?.should be_true
|
78
90
|
end
|
79
91
|
|
80
|
-
it "
|
92
|
+
it "and_return false otherwise" do
|
81
93
|
GoCardless::Bill.new.refunded?.should be_false
|
82
94
|
end
|
83
95
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -8,17 +8,17 @@ describe GoCardless::Client do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe ".base_url" do
|
11
|
-
it "
|
11
|
+
it "and_return the correct url for the production environment" do
|
12
12
|
GoCardless.environment = :production
|
13
13
|
GoCardless::Client.base_url.should == 'https://gocardless.com'
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
16
|
+
it "and_return the correct url for the sandbox environment" do
|
17
17
|
GoCardless.environment = :sandbox
|
18
18
|
GoCardless::Client.base_url.should == 'https://sandbox.gocardless.com'
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
21
|
+
it "and_return the correct url when it's set manually" do
|
22
22
|
GoCardless::Client.base_url = 'https://abc.gocardless.com'
|
23
23
|
GoCardless::Client.base_url.should == 'https://abc.gocardless.com'
|
24
24
|
end
|
@@ -38,8 +38,8 @@ describe GoCardless::Client do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "does not raise an error if the credentials are provided as environment variables" do
|
41
|
-
ENV.
|
42
|
-
ENV.
|
41
|
+
ENV.should_receive(:[]).with('GOCARDLESS_APP_ID').and_return(@app_id)
|
42
|
+
ENV.should_receive(:[]).with('GOCARDLESS_APP_SECRET').and_return(@app_secret)
|
43
43
|
|
44
44
|
GoCardless::Client.new
|
45
45
|
end
|
@@ -104,14 +104,14 @@ describe GoCardless::Client do
|
|
104
104
|
stub(:params => {'scope' => 'manage_merchant:x'}, :token => 'abc')
|
105
105
|
end
|
106
106
|
|
107
|
-
before { oauth_client.auth_code.
|
107
|
+
before { oauth_client.auth_code.stub(:get_token).and_return(fake_token) }
|
108
108
|
|
109
109
|
it "calls correct method with correct args" do
|
110
110
|
auth_code = 'fakecode'
|
111
111
|
|
112
|
-
oauth_client.auth_code.
|
113
|
-
auth_code,
|
114
|
-
).
|
112
|
+
oauth_client.auth_code.should_receive(:get_token).with(
|
113
|
+
auth_code, hash_including(:redirect_uri => @redirect_uri)
|
114
|
+
).and_return(fake_token)
|
115
115
|
|
116
116
|
@client.fetch_access_token(auth_code, {:redirect_uri => @redirect_uri})
|
117
117
|
end
|
@@ -140,13 +140,13 @@ describe GoCardless::Client do
|
|
140
140
|
@client.access_token.should == 'TOKEN123 a:1 b:2'
|
141
141
|
end
|
142
142
|
|
143
|
-
it "
|
143
|
+
it "and_return nil when there's no token" do
|
144
144
|
@client.access_token.should be_nil
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
describe "#access_token=" do
|
149
|
-
before { @client.
|
149
|
+
before { @client.stub(:warn) }
|
150
150
|
|
151
151
|
it "deserializes access token correctly" do
|
152
152
|
@client.access_token = 'TOKEN123 a:1 b:2'
|
@@ -161,12 +161,12 @@ describe GoCardless::Client do
|
|
161
161
|
end
|
162
162
|
|
163
163
|
it "issues a deprecation warning when the scope is present" do
|
164
|
-
@client.
|
164
|
+
@client.should_receive(:warn)
|
165
165
|
@client.access_token = 'TOKEN123 manage_merchant:xyz'
|
166
166
|
end
|
167
167
|
|
168
168
|
it "doesn't issue a deprecation warning when the scope is missing" do
|
169
|
-
@client.
|
169
|
+
@client.should_receive(:warn).never
|
170
170
|
@client.access_token = 'TOKEN123'
|
171
171
|
end
|
172
172
|
|
@@ -183,8 +183,8 @@ describe GoCardless::Client do
|
|
183
183
|
@client.access_token = 'TOKEN123'
|
184
184
|
token = @client.instance_variable_get(:@access_token)
|
185
185
|
r = mock
|
186
|
-
r.
|
187
|
-
token.
|
186
|
+
r.stub(:parsed)
|
187
|
+
token.should_receive(:get).with { |p,o| p =~ %r|/api/v1/test| }.and_return(r)
|
188
188
|
@client.api_get('/test')
|
189
189
|
end
|
190
190
|
|
@@ -198,8 +198,8 @@ describe GoCardless::Client do
|
|
198
198
|
@client.access_token = 'TOKEN123'
|
199
199
|
token = @client.instance_variable_get(:@access_token)
|
200
200
|
r = mock
|
201
|
-
r.
|
202
|
-
token.
|
201
|
+
r.stub(:parsed)
|
202
|
+
token.should_receive(:post).with { |p,opts| opts[:body] == '{"a":1}' }.and_return(r)
|
203
203
|
@client.api_post('/test', {:a => 1})
|
204
204
|
end
|
205
205
|
|
@@ -213,8 +213,8 @@ describe GoCardless::Client do
|
|
213
213
|
@client.access_token = 'TOKEN123'
|
214
214
|
token = @client.instance_variable_get(:@access_token)
|
215
215
|
r = mock
|
216
|
-
r.
|
217
|
-
token.
|
216
|
+
r.stub(:parsed)
|
217
|
+
token.should_receive(:delete).with { |p,opts| opts[:body] == '{"a":1}' }.and_return(r)
|
218
218
|
@client.api_delete('/test', {:a => 1})
|
219
219
|
end
|
220
220
|
|
@@ -228,13 +228,13 @@ describe GoCardless::Client do
|
|
228
228
|
@client.access_token = 'TOKEN'
|
229
229
|
@client.merchant_id = '123'
|
230
230
|
response = mock
|
231
|
-
response.
|
231
|
+
response.should_receive(:parsed)
|
232
232
|
|
233
233
|
token = @client.instance_variable_get(:@access_token)
|
234
234
|
merchant_url = '/api/v1/merchants/123'
|
235
|
-
token.
|
235
|
+
token.should_receive(:get).with { |p,o| p == merchant_url }.and_return response
|
236
236
|
|
237
|
-
GoCardless::Merchant.
|
237
|
+
GoCardless::Merchant.stub(:new_with_client)
|
238
238
|
|
239
239
|
@client.merchant
|
240
240
|
end
|
@@ -243,10 +243,10 @@ describe GoCardless::Client do
|
|
243
243
|
@client.access_token = 'TOKEN'
|
244
244
|
@client.merchant_id = '123'
|
245
245
|
response = mock
|
246
|
-
response.
|
246
|
+
response.should_receive(:parsed).and_return({:name => 'test', :id => 123})
|
247
247
|
|
248
248
|
token = @client.instance_variable_get(:@access_token)
|
249
|
-
token.
|
249
|
+
token.should_receive(:get).and_return response
|
250
250
|
|
251
251
|
merchant = @client.merchant
|
252
252
|
merchant.should be_an_instance_of GoCardless::Merchant
|
@@ -257,7 +257,7 @@ describe GoCardless::Client do
|
|
257
257
|
|
258
258
|
%w{subscription pre_authorization user bill payment}.each do |resource|
|
259
259
|
describe "##{resource}" do
|
260
|
-
it "
|
260
|
+
it "and_return the correct #{GoCardless::Utils.camelize(resource)} object" do
|
261
261
|
@client.access_token = 'TOKEN'
|
262
262
|
@client.merchant_id = '123'
|
263
263
|
stub_get(@client, {:id => 123})
|
@@ -299,7 +299,7 @@ describe GoCardless::Client do
|
|
299
299
|
end
|
300
300
|
|
301
301
|
it "doesn't confirm the resource when the signature is invalid" do
|
302
|
-
@client.
|
302
|
+
@client.should_receive(:request).never
|
303
303
|
@client.confirm_resource({:signature => 'xxx'}.merge(@params)) rescue nil
|
304
304
|
end
|
305
305
|
|
@@ -311,14 +311,14 @@ describe GoCardless::Client do
|
|
311
311
|
|
312
312
|
it "confirms the resource when the signature is valid" do
|
313
313
|
# Once for confirm, once to fetch result
|
314
|
-
@client.
|
314
|
+
@client.should_receive(:request).twice.and_return(stub(:parsed => {}))
|
315
315
|
@client.confirm_resource(@client.send(:sign_params, @params))
|
316
316
|
end
|
317
317
|
|
318
|
-
it "
|
319
|
-
@client.
|
318
|
+
it "and_return the correct object when the signature is valid" do
|
319
|
+
@client.stub(:request).and_return(stub(:parsed => {}))
|
320
320
|
subscription = GoCardless::Subscription.new_with_client @client
|
321
|
-
GoCardless::Subscription.
|
321
|
+
GoCardless::Subscription.should_receive(:find_with_client).and_return subscription
|
322
322
|
|
323
323
|
# confirm_resource should use the Subcription class because
|
324
324
|
# the :response_type is set to subscription
|
@@ -327,9 +327,9 @@ describe GoCardless::Client do
|
|
327
327
|
end
|
328
328
|
|
329
329
|
it "includes valid http basic credentials" do
|
330
|
-
GoCardless::Subscription.
|
330
|
+
GoCardless::Subscription.stub(:find_with_client)
|
331
331
|
auth = 'Basic YWJjOnh5eg=='
|
332
|
-
@client.
|
332
|
+
@client.should_receive(:request).once.with do |type, path, opts|
|
333
333
|
opts.should include :headers
|
334
334
|
opts[:headers].should include 'Authorization'
|
335
335
|
opts[:headers]['Authorization'].should == auth
|
@@ -338,8 +338,8 @@ describe GoCardless::Client do
|
|
338
338
|
end
|
339
339
|
|
340
340
|
it "works with string params" do
|
341
|
-
@client.
|
342
|
-
GoCardless::Subscription.
|
341
|
+
@client.stub(:request)
|
342
|
+
GoCardless::Subscription.stub(:find_with_client)
|
343
343
|
params = Hash[@params.dup.map { |k,v| [k.to_s, v] }]
|
344
344
|
params.keys.each { |p| p.should be_a String }
|
345
345
|
# No ArgumentErrors should be raised
|
@@ -377,20 +377,20 @@ describe GoCardless::Client do
|
|
377
377
|
end
|
378
378
|
|
379
379
|
it "rejects other params not required for the signature" do
|
380
|
-
@client.
|
380
|
+
@client.should_receive(:signature_valid?) do |hash|
|
381
381
|
!hash.keys.include?(:foo) && !hash.keys.include?('foo')
|
382
|
-
end
|
382
|
+
end.and_return(true)
|
383
383
|
|
384
384
|
params = @client.send(:sign_params, @params).merge('foo' => 'bar')
|
385
385
|
@client.response_params_valid?(params)
|
386
386
|
end
|
387
387
|
|
388
|
-
it "
|
388
|
+
it "and_return false when the signature is invalid" do
|
389
389
|
params = {:signature => 'xxx'}.merge(@params)
|
390
390
|
@client.response_params_valid?(params).should be_false
|
391
391
|
end
|
392
392
|
|
393
|
-
it "
|
393
|
+
it "and_return true when the signature is valid" do
|
394
394
|
params = @client.send(:sign_params, @params)
|
395
395
|
@client.response_params_valid?(params).should be_true
|
396
396
|
end
|
@@ -468,7 +468,7 @@ describe GoCardless::Client do
|
|
468
468
|
it "should include a timestamp" do
|
469
469
|
# Time.now returning Pacific time
|
470
470
|
time = Time.parse('Sat Jan 01 2011 00:00:00 -0800')
|
471
|
-
Time.
|
471
|
+
Time.should_receive(:now).and_return time
|
472
472
|
params = get_params(@client.send(:new_limit_url, :subscription, :x => 1))
|
473
473
|
# Check that timezone is ISO formatted UTC
|
474
474
|
params['timestamp'].should == "2011-01-01T08:00:00Z"
|
@@ -476,7 +476,7 @@ describe GoCardless::Client do
|
|
476
476
|
end
|
477
477
|
|
478
478
|
describe "#merchant_id" do
|
479
|
-
it "
|
479
|
+
it "and_return the merchant id when an access token is set" do
|
480
480
|
@client.merchant_id = '123'
|
481
481
|
@client.send(:merchant_id).should == '123'
|
482
482
|
end
|
@@ -489,12 +489,12 @@ describe GoCardless::Client do
|
|
489
489
|
end
|
490
490
|
|
491
491
|
describe "#webhook_valid?" do
|
492
|
-
it "
|
492
|
+
it "and_return false when the webhook signature is invalid" do
|
493
493
|
@client.webhook_valid?({:some => 'stuff', :signature => 'invalid'}).
|
494
494
|
should be_false
|
495
495
|
end
|
496
496
|
|
497
|
-
it "
|
497
|
+
it "and_return true when the webhook signature is valid" do
|
498
498
|
valid_signature = '175e814f0f64e5e86d41fb8fe06a857cedda715a96d3dc3d885e6d97dbeb7e49'
|
499
499
|
@client.webhook_valid?({:some => 'stuff', :signature => valid_signature}).
|
500
500
|
should be_true
|
@@ -502,13 +502,13 @@ describe GoCardless::Client do
|
|
502
502
|
end
|
503
503
|
|
504
504
|
describe "base_url" do
|
505
|
-
it "
|
505
|
+
it "and_return a custom base URL when one has been set" do
|
506
506
|
@client.base_url = 'http://test.com/'
|
507
507
|
@client.base_url.should == 'http://test.com/'
|
508
508
|
end
|
509
509
|
|
510
|
-
it "
|
511
|
-
GoCardless::Client.
|
510
|
+
it "and_return the default value when base_url is not set for the instance" do
|
511
|
+
GoCardless::Client.stub(:base_url => 'http://gc.com/')
|
512
512
|
@client.base_url.should == 'http://gc.com/'
|
513
513
|
end
|
514
514
|
end
|
data/spec/gocardless_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe GoCardless do
|
|
10
10
|
|
11
11
|
describe ".account_details=" do
|
12
12
|
it "creates a Client instance" do
|
13
|
-
GoCardless::Client.
|
13
|
+
GoCardless::Client.should_receive :new
|
14
14
|
subject.account_details = @details
|
15
15
|
end
|
16
16
|
|
@@ -26,7 +26,7 @@ describe GoCardless do
|
|
26
26
|
%w(new_subscription_url new_pre_authorization_url new_bill_url confirm_resource webhook_valid?).each do |name|
|
27
27
|
it "#{name} delegates to @client" do
|
28
28
|
subject.account_details = @details
|
29
|
-
subject.instance_variable_get(:@client).
|
29
|
+
subject.instance_variable_get(:@client).should_receive(name.to_sym)
|
30
30
|
subject.send(name)
|
31
31
|
end
|
32
32
|
|
@@ -11,46 +11,46 @@ describe GoCardless::PreAuthorization do
|
|
11
11
|
|
12
12
|
it "should be cancellable" do
|
13
13
|
s = GoCardless::PreAuthorization.new_with_client(@client, :id => '009988')
|
14
|
-
@client.
|
14
|
+
@client.should_receive(:api_put).with('/pre_authorizations/009988/cancel')
|
15
15
|
s.cancel!
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "inactive query method" do
|
19
|
-
it "
|
19
|
+
it "and_return true when the subscription status is inactive" do
|
20
20
|
GoCardless::PreAuthorization.new(:status => 'inactive').inactive?.should be_true
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
23
|
+
it "and_return false otherwise" do
|
24
24
|
GoCardless::PreAuthorization.new.inactive?.should be_false
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "active query method" do
|
29
|
-
it "
|
29
|
+
it "and_return true when the subscription status is active" do
|
30
30
|
GoCardless::PreAuthorization.new(:status => 'active').active?.should be_true
|
31
31
|
end
|
32
32
|
|
33
|
-
it "
|
33
|
+
it "and_return false otherwise" do
|
34
34
|
GoCardless::PreAuthorization.new.active?.should be_false
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "cancelled query method" do
|
39
|
-
it "
|
39
|
+
it "and_return true when the subscription status is cancelled" do
|
40
40
|
GoCardless::PreAuthorization.new(:status => 'cancelled').cancelled?.should be_true
|
41
41
|
end
|
42
42
|
|
43
|
-
it "
|
43
|
+
it "and_return false otherwise" do
|
44
44
|
GoCardless::PreAuthorization.new.cancelled?.should be_false
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "expired query method" do
|
49
|
-
it "
|
49
|
+
it "and_return true when the subscription status is expired" do
|
50
50
|
GoCardless::PreAuthorization.new(:status => 'expired').expired?.should be_true
|
51
51
|
end
|
52
52
|
|
53
|
-
it "
|
53
|
+
it "and_return false otherwise" do
|
54
54
|
GoCardless::PreAuthorization.new.expired?.should be_false
|
55
55
|
end
|
56
56
|
end
|
data/spec/resource_spec.rb
CHANGED
@@ -64,7 +64,7 @@ describe GoCardless::Resource do
|
|
64
64
|
self.endpoint = '/test/:id'
|
65
65
|
end
|
66
66
|
mock_client = mock
|
67
|
-
mock_client.
|
67
|
+
mock_client.should_receive(:api_get).and_return({:id => 123})
|
68
68
|
resource = test_resource.find_with_client(mock_client, 123)
|
69
69
|
resource.should be_a test_resource
|
70
70
|
resource.id.should == 123
|
@@ -76,8 +76,8 @@ describe GoCardless::Resource do
|
|
76
76
|
test_resource = Class.new(GoCardless::Resource) do
|
77
77
|
self.endpoint = '/test/:id'
|
78
78
|
end
|
79
|
-
GoCardless.
|
80
|
-
test_resource.
|
79
|
+
GoCardless.stub(:client => mock)
|
80
|
+
test_resource.should_receive(:find_with_client).with(GoCardless.client, 1)
|
81
81
|
test_resource.find(1)
|
82
82
|
unset_ivar GoCardless, :client
|
83
83
|
end
|
@@ -214,28 +214,28 @@ describe GoCardless::Resource do
|
|
214
214
|
client = mock
|
215
215
|
data = {:x => 1, :y => 2}
|
216
216
|
resource = @test_resource.new_with_client(client, data)
|
217
|
-
client.
|
217
|
+
client.should_receive(:api_post).with(anything, data)
|
218
218
|
resource.save
|
219
219
|
end
|
220
220
|
|
221
221
|
it "sends the correct path" do
|
222
222
|
client = mock
|
223
223
|
resource = @test_resource.new_with_client(client)
|
224
|
-
client.
|
224
|
+
client.should_receive(:api_post).with('/test', anything)
|
225
225
|
resource.save
|
226
226
|
end
|
227
227
|
|
228
228
|
it "POSTs when not persisted" do
|
229
229
|
client = mock
|
230
230
|
resource = @test_resource.new_with_client(client)
|
231
|
-
client.
|
231
|
+
client.should_receive(:api_post)
|
232
232
|
resource.save
|
233
233
|
end
|
234
234
|
|
235
235
|
it "PUTs when already persisted" do
|
236
236
|
client = mock
|
237
237
|
resource = @test_resource.new_with_client(client, :id => 1)
|
238
|
-
client.
|
238
|
+
client.should_receive(:api_put)
|
239
239
|
resource.save
|
240
240
|
end
|
241
241
|
end
|
@@ -246,7 +246,7 @@ describe GoCardless::Resource do
|
|
246
246
|
creatable
|
247
247
|
end
|
248
248
|
|
249
|
-
client =
|
249
|
+
client = double('client', :api_post => nil)
|
250
250
|
test_resource.new_with_client(client).save
|
251
251
|
end
|
252
252
|
|
@@ -256,7 +256,7 @@ describe GoCardless::Resource do
|
|
256
256
|
updatable
|
257
257
|
end
|
258
258
|
|
259
|
-
client =
|
259
|
+
client = double('client', :api_put => nil)
|
260
260
|
test_resource.new_with_client(client, :id => 1).save
|
261
261
|
end
|
262
262
|
|
@@ -357,14 +357,14 @@ describe GoCardless::Resource do
|
|
357
357
|
|
358
358
|
it "use the correct uri path" do
|
359
359
|
client = mock()
|
360
|
-
client.
|
360
|
+
client.should_receive(:api_get).with('/api/bills/', anything).and_return([])
|
361
361
|
r = @test_resource.new_with_client(client, @attrs)
|
362
362
|
r.bills
|
363
363
|
end
|
364
364
|
|
365
365
|
it "strips the api prefix from the path" do
|
366
366
|
client = mock()
|
367
|
-
client.
|
367
|
+
client.should_receive(:api_get).with('/bills/', anything).and_return([])
|
368
368
|
uris = {'bills' => 'https://test.com/api/v123/bills/'}
|
369
369
|
r = @test_resource.new_with_client(client, 'sub_resource_uris' => uris)
|
370
370
|
r.bills
|
@@ -372,7 +372,7 @@ describe GoCardless::Resource do
|
|
372
372
|
|
373
373
|
it "use the correct query string params" do
|
374
374
|
client = mock()
|
375
|
-
client.
|
375
|
+
client.should_receive(:api_get).with(anything, 'merchant_id' => '1').and_return([])
|
376
376
|
r = @test_resource.new_with_client(client, @attrs)
|
377
377
|
r.bills
|
378
378
|
end
|
@@ -380,7 +380,7 @@ describe GoCardless::Resource do
|
|
380
380
|
it "adds provided params to existing query string params" do
|
381
381
|
client = mock()
|
382
382
|
params = { 'merchant_id' => '1', :amount => '10.00' }
|
383
|
-
client.
|
383
|
+
client.should_receive(:api_get).with(anything, params).and_return([])
|
384
384
|
r = @test_resource.new_with_client(client, @attrs)
|
385
385
|
r.bills(:amount => '10.00')
|
386
386
|
end
|
@@ -388,7 +388,7 @@ describe GoCardless::Resource do
|
|
388
388
|
it "adds provided params when there are no existing query string params" do
|
389
389
|
client = mock()
|
390
390
|
params = { :source_id => 'xxx' }
|
391
|
-
client.
|
391
|
+
client.should_receive(:api_get).with(anything, params).and_return([])
|
392
392
|
r = @test_resource.new_with_client(client, {
|
393
393
|
'sub_resource_uris' => {
|
394
394
|
'bills' => 'https://test.com/merchants/1/bills'
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
|
-
require 'mocha'
|
2
1
|
require 'active_support/hash_with_indifferent_access'
|
3
2
|
require 'gocardless'
|
4
3
|
|
5
|
-
RSpec.configure do |config|
|
6
|
-
config.mock_with :mocha
|
7
|
-
end
|
8
|
-
|
9
4
|
def stub_get(client, data)
|
10
5
|
response = mock
|
11
|
-
response.
|
6
|
+
response.stub(:parsed).and_return(data)
|
12
7
|
|
13
8
|
token = client.instance_variable_get(:@access_token)
|
14
|
-
token.
|
9
|
+
token.stub(:get).and_return response
|
15
10
|
end
|
16
11
|
|
17
12
|
def unset_ivar(obj, var)
|
data/spec/subscription_spec.rb
CHANGED
@@ -11,46 +11,46 @@ describe GoCardless::Subscription do
|
|
11
11
|
|
12
12
|
it "should be cancellable" do
|
13
13
|
s = GoCardless::Subscription.new_with_client(@client, :id => '009988')
|
14
|
-
@client.
|
14
|
+
@client.should_receive(:api_put).with('/subscriptions/009988/cancel')
|
15
15
|
s.cancel!
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "inactive query method" do
|
19
|
-
it "
|
19
|
+
it "and_return true when the subscription status is inactive" do
|
20
20
|
GoCardless::Subscription.new(:status => 'inactive').inactive?.should be_true
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
23
|
+
it "and_return false otherwise" do
|
24
24
|
GoCardless::Subscription.new.inactive?.should be_false
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "active query method" do
|
29
|
-
it "
|
29
|
+
it "and_return true when the subscription status is active" do
|
30
30
|
GoCardless::Subscription.new(:status => 'active').active?.should be_true
|
31
31
|
end
|
32
32
|
|
33
|
-
it "
|
33
|
+
it "and_return false otherwise" do
|
34
34
|
GoCardless::Subscription.new.active?.should be_false
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "cancelled query method" do
|
39
|
-
it "
|
39
|
+
it "and_return true when the subscription status is cancelled" do
|
40
40
|
GoCardless::Subscription.new(:status => 'cancelled').cancelled?.should be_true
|
41
41
|
end
|
42
42
|
|
43
|
-
it "
|
43
|
+
it "and_return false otherwise" do
|
44
44
|
GoCardless::Subscription.new.cancelled?.should be_false
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "expired query method" do
|
49
|
-
it "
|
49
|
+
it "and_return true when the subscription status is expired" do
|
50
50
|
GoCardless::Subscription.new(:status => 'expired').expired?.should be_true
|
51
51
|
end
|
52
52
|
|
53
|
-
it "
|
53
|
+
it "and_return false otherwise" do
|
54
54
|
GoCardless::Subscription.new.expired?.should be_false
|
55
55
|
end
|
56
56
|
end
|
data/spec/utils_spec.rb
CHANGED
@@ -108,7 +108,7 @@ describe GoCardless::Utils do
|
|
108
108
|
describe ".flatten_params" do
|
109
109
|
subject { GoCardless::Utils.method(:flatten_params) }
|
110
110
|
|
111
|
-
it "
|
111
|
+
it "and_return an empty array when provided with an empty hash" do
|
112
112
|
subject[{}].should == []
|
113
113
|
end
|
114
114
|
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gocardless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.8.0
|
4
|
+
version: 1.9.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Harry Marr
|
@@ -10,120 +9,92 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
|
-
|
15
|
+
name: oauth2
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - ~>
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0.7'
|
21
|
-
none: false
|
22
|
-
name: oauth2
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
|
-
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
24
|
requirements:
|
27
25
|
- - ~>
|
28
26
|
- !ruby/object:Gem::Version
|
29
27
|
version: '0.7'
|
30
|
-
none: false
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
|
-
|
29
|
+
name: multi_json
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
33
31
|
requirements:
|
34
32
|
- - ~>
|
35
33
|
- !ruby/object:Gem::Version
|
36
34
|
version: '1.0'
|
37
|
-
none: false
|
38
|
-
name: multi_json
|
39
35
|
type: :runtime
|
40
36
|
prerelease: false
|
41
|
-
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
38
|
requirements:
|
43
39
|
- - ~>
|
44
40
|
- !ruby/object:Gem::Version
|
45
41
|
version: '1.0'
|
46
|
-
none: false
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
|
-
version_requirements: !ruby/object:Gem::Requirement
|
49
|
-
requirements:
|
50
|
-
- - ~>
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '2.6'
|
53
|
-
none: false
|
54
43
|
name: rspec
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
44
|
requirement: !ruby/object:Gem::Requirement
|
58
45
|
requirements:
|
59
46
|
- - ~>
|
60
47
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2.
|
62
|
-
none: false
|
63
|
-
- !ruby/object:Gem::Dependency
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ~>
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.9.12
|
69
|
-
none: false
|
70
|
-
name: mocha
|
48
|
+
version: '2.13'
|
71
49
|
type: :development
|
72
50
|
prerelease: false
|
73
|
-
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
52
|
requirements:
|
75
53
|
- - ~>
|
76
54
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
78
|
-
none: false
|
55
|
+
version: '2.13'
|
79
56
|
- !ruby/object:Gem::Dependency
|
80
|
-
|
57
|
+
name: yard
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
81
59
|
requirements:
|
82
60
|
- - ~>
|
83
61
|
- !ruby/object:Gem::Version
|
84
|
-
version: 0.7
|
85
|
-
none: false
|
86
|
-
name: yard
|
62
|
+
version: '0.7'
|
87
63
|
type: :development
|
88
64
|
prerelease: false
|
89
|
-
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
66
|
requirements:
|
91
67
|
- - ~>
|
92
68
|
- !ruby/object:Gem::Version
|
93
|
-
version: 0.7
|
94
|
-
none: false
|
69
|
+
version: '0.7'
|
95
70
|
- !ruby/object:Gem::Dependency
|
96
|
-
|
71
|
+
name: activesupport
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
97
73
|
requirements:
|
98
74
|
- - ~>
|
99
75
|
- !ruby/object:Gem::Version
|
100
76
|
version: '3.1'
|
101
|
-
none: false
|
102
|
-
name: activesupport
|
103
77
|
type: :development
|
104
78
|
prerelease: false
|
105
|
-
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
80
|
requirements:
|
107
81
|
- - ~>
|
108
82
|
- !ruby/object:Gem::Version
|
109
83
|
version: '3.1'
|
110
|
-
none: false
|
111
84
|
- !ruby/object:Gem::Dependency
|
112
|
-
|
85
|
+
name: rake
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
113
87
|
requirements:
|
114
88
|
- - ~>
|
115
89
|
- !ruby/object:Gem::Version
|
116
90
|
version: '10.0'
|
117
|
-
none: false
|
118
|
-
name: rake
|
119
91
|
type: :development
|
120
92
|
prerelease: false
|
121
|
-
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
94
|
requirements:
|
123
95
|
- - ~>
|
124
96
|
- !ruby/object:Gem::Version
|
125
97
|
version: '10.0'
|
126
|
-
none: false
|
127
98
|
description: A Ruby wrapper for the GoCardless API
|
128
99
|
email:
|
129
100
|
- developers@gocardless.com
|
@@ -147,6 +118,7 @@ files:
|
|
147
118
|
- lib/gocardless/errors.rb
|
148
119
|
- lib/gocardless/merchant.rb
|
149
120
|
- lib/gocardless/payment.rb
|
121
|
+
- lib/gocardless/payout.rb
|
150
122
|
- lib/gocardless/pre_authorization.rb
|
151
123
|
- lib/gocardless/resource.rb
|
152
124
|
- lib/gocardless/subscription.rb
|
@@ -163,28 +135,28 @@ files:
|
|
163
135
|
- spec/user_spec.rb
|
164
136
|
- spec/utils_spec.rb
|
165
137
|
homepage: https://github.com/gocardless/gocardless-ruby
|
166
|
-
licenses:
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata: {}
|
167
141
|
post_install_message:
|
168
142
|
rdoc_options: []
|
169
143
|
require_paths:
|
170
144
|
- lib
|
171
145
|
required_ruby_version: !ruby/object:Gem::Requirement
|
172
146
|
requirements:
|
173
|
-
- -
|
147
|
+
- - '>='
|
174
148
|
- !ruby/object:Gem::Version
|
175
149
|
version: '0'
|
176
|
-
none: false
|
177
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
151
|
requirements:
|
179
|
-
- -
|
152
|
+
- - '>='
|
180
153
|
- !ruby/object:Gem::Version
|
181
154
|
version: '0'
|
182
|
-
none: false
|
183
155
|
requirements: []
|
184
156
|
rubyforge_project:
|
185
|
-
rubygems_version:
|
157
|
+
rubygems_version: 2.2.2
|
186
158
|
signing_key:
|
187
|
-
specification_version:
|
159
|
+
specification_version: 4
|
188
160
|
summary: Ruby wrapper for the GoCardless API
|
189
161
|
test_files:
|
190
162
|
- spec/bill_spec.rb
|
@@ -196,4 +168,3 @@ test_files:
|
|
196
168
|
- spec/subscription_spec.rb
|
197
169
|
- spec/user_spec.rb
|
198
170
|
- spec/utils_spec.rb
|
199
|
-
has_rdoc:
|