gocardless 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/lib/gocardless/bill.rb +2 -1
- data/lib/gocardless/client.rb +31 -10
- data/lib/gocardless/merchant.rb +9 -6
- data/lib/gocardless/pre_authorization.rb +4 -1
- data/lib/gocardless/subscription.rb +7 -2
- data/lib/gocardless/version.rb +1 -1
- data/spec/client_spec.rb +49 -25
- metadata +5 -5
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 1.2.0 - June 19, 2012
|
2
|
+
|
3
|
+
- Add some extra attributes to resources (e.g. status, merchant's balance, etc)
|
4
|
+
- Add a response_params_valid? method to check that resource response data is
|
5
|
+
valid (including signature)
|
6
|
+
|
1
7
|
## 1.1.1 - June 07, 2012
|
2
8
|
|
3
9
|
- Fix handling of cancel_uri
|
data/lib/gocardless/bill.rb
CHANGED
data/lib/gocardless/client.rb
CHANGED
@@ -220,16 +220,7 @@ module GoCardless
|
|
220
220
|
# @param [Hash] params the response parameters returned by the API server
|
221
221
|
# @return [Resource] the confirmed resource object
|
222
222
|
def confirm_resource(params)
|
223
|
-
|
224
|
-
# always a String)
|
225
|
-
params = Utils.symbolize_keys(Hash[params])
|
226
|
-
# Only pull out the relevant parameters, other won't be included in the
|
227
|
-
# signature so will cause false negatives
|
228
|
-
keys = [:resource_id, :resource_type, :resource_uri, :state, :signature]
|
229
|
-
params = Hash[params.select { |k,v| keys.include? k }]
|
230
|
-
(keys - [:state]).each do |key|
|
231
|
-
raise ArgumentError, "Parameters missing #{key}" if !params.key?(key)
|
232
|
-
end
|
223
|
+
params = prepare_params(params)
|
233
224
|
|
234
225
|
if signature_valid?(params)
|
235
226
|
data = {
|
@@ -254,6 +245,17 @@ module GoCardless
|
|
254
245
|
end
|
255
246
|
|
256
247
|
|
248
|
+
# Check that resource response data includes a valid signature.
|
249
|
+
#
|
250
|
+
# @param [Hash] params the response parameters returned by the API server
|
251
|
+
# @return [Boolean] true when valid, false otherwise
|
252
|
+
def response_params_valid?(params)
|
253
|
+
params = prepare_params(params)
|
254
|
+
|
255
|
+
signature_valid?(params)
|
256
|
+
end
|
257
|
+
|
258
|
+
|
257
259
|
# Validates the payload contents of a webhook request.
|
258
260
|
#
|
259
261
|
# @param [Hash] params the contents of payload of the webhook
|
@@ -310,6 +312,25 @@ module GoCardless
|
|
310
312
|
params
|
311
313
|
end
|
312
314
|
|
315
|
+
# Prepare a Hash of parameters for signing. Presence of required
|
316
|
+
# parameters is checked and the others are discarded.
|
317
|
+
#
|
318
|
+
# @param [Hash] params the parameters to be prepared for signing
|
319
|
+
# @return [Hash] the prepared parameters
|
320
|
+
def prepare_params(params)
|
321
|
+
# Create a new hash in case is a HashWithIndifferentAccess (keys are
|
322
|
+
# always a String)
|
323
|
+
params = Utils.symbolize_keys(Hash[params])
|
324
|
+
# Only pull out the relevant parameters, other won't be included in the
|
325
|
+
# signature so will cause false negatives
|
326
|
+
keys = [:resource_id, :resource_type, :resource_uri, :state, :signature]
|
327
|
+
params = Hash[params.select { |k,v| keys.include? k }]
|
328
|
+
(keys - [:state]).each do |key|
|
329
|
+
raise ArgumentError, "Parameters missing #{key}" if !params.key?(key)
|
330
|
+
end
|
331
|
+
params
|
332
|
+
end
|
333
|
+
|
313
334
|
# Check if a hash's :signature is valid
|
314
335
|
#
|
315
336
|
# @param [Hash] params the parameters to check
|
data/lib/gocardless/merchant.rb
CHANGED
@@ -2,12 +2,15 @@ module GoCardless
|
|
2
2
|
class Merchant < Resource
|
3
3
|
self.endpoint = '/merchants/:id'
|
4
4
|
|
5
|
-
attr_accessor :name
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
attr_accessor :name,
|
6
|
+
:description,
|
7
|
+
:email,
|
8
|
+
:first_name,
|
9
|
+
:last_name,
|
10
|
+
:balance,
|
11
|
+
:pending_balance,
|
12
|
+
:next_payout_amount
|
13
|
+
date_accessor :created_at, :next_payout_date
|
11
14
|
|
12
15
|
def subscriptions(params = {})
|
13
16
|
path = "/merchants/#{self.id}/subscriptions"
|
@@ -9,11 +9,16 @@ module GoCardless
|
|
9
9
|
:interval_unit,
|
10
10
|
:name,
|
11
11
|
:description,
|
12
|
-
:plan_id
|
12
|
+
:plan_id,
|
13
|
+
:status,
|
14
|
+
:setup_fee,
|
15
|
+
:trial_length,
|
16
|
+
:trial_unit,
|
17
|
+
:next_interval_start
|
13
18
|
|
14
19
|
reference_accessor :merchant_id, :user_id
|
15
20
|
|
16
|
-
date_accessor :expires_at, :created_at
|
21
|
+
date_accessor :start_at, :expires_at, :created_at
|
17
22
|
|
18
23
|
|
19
24
|
def cancel!
|
data/lib/gocardless/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -259,31 +259,6 @@ describe GoCardless::Client do
|
|
259
259
|
}
|
260
260
|
end
|
261
261
|
|
262
|
-
[:resource_id, :resource_uri, :resource_type].each do |param|
|
263
|
-
it "fails when :#{param} is missing" do
|
264
|
-
p = @params.tap { |d| d.delete(param) }
|
265
|
-
expect { @client.confirm_resource p }.to raise_exception ArgumentError
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
it "does not fail when keys are strings in a HashWithIndiferentAccess" do
|
270
|
-
params = {'resource_id' => 1,
|
271
|
-
'resource_uri' => 'a',
|
272
|
-
'resource_type' => 'subscription',
|
273
|
-
'signature' => 'foo'}
|
274
|
-
params_indifferent_access = HashWithIndifferentAccess.new(params)
|
275
|
-
expect { @client.confirm_resource params_indifferent_access }.to_not raise_exception ArgumentError
|
276
|
-
end
|
277
|
-
|
278
|
-
it "rejects other params not required for the signature" do
|
279
|
-
@client.stubs(:request).returns(stub(:parsed => {}))
|
280
|
-
@client.expects(:signature_valid?).returns(true).with(hash) do |hash|
|
281
|
-
!hash.keys.include?(:foo) && !hash.keys.include?('foo')
|
282
|
-
end
|
283
|
-
|
284
|
-
@client.confirm_resource(@client.send(:sign_params, @params).merge('foo' => 'bar'))
|
285
|
-
end
|
286
|
-
|
287
262
|
it "doesn't confirm the resource when the signature is invalid" do
|
288
263
|
@client.expects(:request).never
|
289
264
|
@client.confirm_resource({:signature => 'xxx'}.merge(@params)) rescue nil
|
@@ -333,6 +308,55 @@ describe GoCardless::Client do
|
|
333
308
|
end
|
334
309
|
end
|
335
310
|
|
311
|
+
describe "#response_params_valid?" do
|
312
|
+
before :each do
|
313
|
+
@params = {
|
314
|
+
:resource_id => '1',
|
315
|
+
:resource_uri => 'a',
|
316
|
+
:resource_type => 'subscription',
|
317
|
+
}
|
318
|
+
end
|
319
|
+
|
320
|
+
[:resource_id, :resource_uri, :resource_type].each do |param|
|
321
|
+
it "fails when :#{param} is missing" do
|
322
|
+
params = @params.tap { |d| d.delete(param) }
|
323
|
+
expect do
|
324
|
+
@client.response_params_valid? params
|
325
|
+
end.to raise_exception ArgumentError
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
it "does not fail when keys are strings in a HashWithIndiferentAccess" do
|
330
|
+
params = {'resource_id' => 1,
|
331
|
+
'resource_uri' => 'a',
|
332
|
+
'resource_type' => 'subscription',
|
333
|
+
'signature' => 'foo'}
|
334
|
+
params_indifferent_access = HashWithIndifferentAccess.new(params)
|
335
|
+
expect do
|
336
|
+
@client.response_params_valid? params_indifferent_access
|
337
|
+
end.to_not raise_exception ArgumentError
|
338
|
+
end
|
339
|
+
|
340
|
+
it "rejects other params not required for the signature" do
|
341
|
+
@client.expects(:signature_valid?).returns(true).with(hash) do |hash|
|
342
|
+
!hash.keys.include?(:foo) && !hash.keys.include?('foo')
|
343
|
+
end
|
344
|
+
|
345
|
+
params = @client.send(:sign_params, @params).merge('foo' => 'bar')
|
346
|
+
@client.response_params_valid?(params)
|
347
|
+
end
|
348
|
+
|
349
|
+
it "returns false when the signature is invalid" do
|
350
|
+
params = {:signature => 'xxx'}.merge(@params)
|
351
|
+
@client.response_params_valid?(params).should be_false
|
352
|
+
end
|
353
|
+
|
354
|
+
it "returns true when the signature is valid" do
|
355
|
+
params = @client.send(:sign_params, @params)
|
356
|
+
@client.response_params_valid?(params).should be_true
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
336
360
|
it "#generate_nonce should generate a random string" do
|
337
361
|
@client.send(:generate_nonce).should_not == @client.send(:generate_nonce)
|
338
362
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gocardless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 242951009964279202
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Harry Marr
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-06-
|
19
|
+
date: 2012-06-19 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: oauth2
|