gocardless_pro 2.18.1 → 2.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gocardless_pro/client.rb +1 -1
- data/lib/gocardless_pro/resources/payout.rb +2 -0
- data/lib/gocardless_pro/services/payouts_service.rb +21 -0
- data/lib/gocardless_pro/services/subscriptions_service.rb +21 -6
- data/lib/gocardless_pro/version.rb +1 -1
- data/spec/resources/payout_spec.rb +45 -0
- data/spec/services/payouts_service_spec.rb +74 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7e71f4726525b3ce899c9f4ce10cb6f957805c654f1025a5aad542c6181aa60
|
4
|
+
data.tar.gz: 9501e18394e43ab7d541712fd3130f2184d6f4caede7916abf01c24add413160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8015fa41e3a0b6c5bd62810ff5f00438d880313d3a0051f756af8ba4d3c6eccd3f71c7b56452fcf9981a52a265feb692caf2deca77cf8705b094e24bb1e3a25
|
7
|
+
data.tar.gz: 972c8baa19abfbe69390010d4350788b04263c4af0665f19f35161f6b899cc32c3d5a073b36bb0596a010f9c8f34442dac56fe643e27588edfbd800ddbd6414e
|
@@ -148,7 +148,7 @@ module GoCardlessPro
|
|
148
148
|
'User-Agent' => user_agent.to_s,
|
149
149
|
'Content-Type' => 'application/json',
|
150
150
|
'GoCardless-Client-Library' => 'gocardless-pro-ruby',
|
151
|
-
'GoCardless-Client-Version' => '2.
|
151
|
+
'GoCardless-Client-Version' => '2.19.0',
|
152
152
|
},
|
153
153
|
}
|
154
154
|
end
|
@@ -26,6 +26,7 @@ module GoCardlessPro
|
|
26
26
|
attr_reader :deducted_fees
|
27
27
|
attr_reader :fx
|
28
28
|
attr_reader :id
|
29
|
+
attr_reader :metadata
|
29
30
|
attr_reader :payout_type
|
30
31
|
attr_reader :reference
|
31
32
|
attr_reader :status
|
@@ -43,6 +44,7 @@ module GoCardlessPro
|
|
43
44
|
@fx = object['fx']
|
44
45
|
@id = object['id']
|
45
46
|
@links = object['links']
|
47
|
+
@metadata = object['metadata']
|
46
48
|
@payout_type = object['payout_type']
|
47
49
|
@reference = object['reference']
|
48
50
|
@status = object['status']
|
@@ -59,6 +59,27 @@ module GoCardlessPro
|
|
59
59
|
Resources::Payout.new(unenvelope_body(response.body), response)
|
60
60
|
end
|
61
61
|
|
62
|
+
# Updates a payout object. This accepts only the metadata parameter.
|
63
|
+
# Example URL: /payouts/:identity
|
64
|
+
#
|
65
|
+
# @param identity # Unique identifier, beginning with "PO".
|
66
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
67
|
+
def update(identity, options = {})
|
68
|
+
path = sub_url('/payouts/:identity', 'identity' => identity)
|
69
|
+
|
70
|
+
params = options.delete(:params) || {}
|
71
|
+
options[:params] = {}
|
72
|
+
options[:params][envelope_key] = params
|
73
|
+
|
74
|
+
options[:retry_failures] = true
|
75
|
+
|
76
|
+
response = make_request(:put, path, options)
|
77
|
+
|
78
|
+
return if response.body.nil?
|
79
|
+
|
80
|
+
Resources::Payout.new(unenvelope_body(response.body), response)
|
81
|
+
end
|
82
|
+
|
62
83
|
private
|
63
84
|
|
64
85
|
# Unenvelope the response of the body using the service's `envelope_key`
|
@@ -141,9 +141,22 @@ module GoCardlessPro
|
|
141
141
|
# Pause a subscription object.
|
142
142
|
# No payments will be created until it is resumed.
|
143
143
|
#
|
144
|
-
# This can only be used
|
145
|
-
#
|
146
|
-
#
|
144
|
+
# This can only be used when a subscription collecting a fixed number of
|
145
|
+
# payments (created using `count`)
|
146
|
+
# or when they continue forever (created without `count` or `end_date`)
|
147
|
+
#
|
148
|
+
# When `pause_cycles` is omitted the subscription is paused until the [resume
|
149
|
+
# endpoint](#subscriptions-resume-a-subscription) is called.
|
150
|
+
# If the subscription is collecting a fixed number of payments, `end_date` will
|
151
|
+
# be set to `nil`.
|
152
|
+
# When paused indefinitely, `upcoming_payments` will be empty.
|
153
|
+
#
|
154
|
+
# When `pause_cycles` is provided the subscription will be paused for the number
|
155
|
+
# of cycles requested.
|
156
|
+
# If the subscription is collecting a fixed number of payments, `end_date` will
|
157
|
+
# be set to a new value.
|
158
|
+
# When paused for a number of cycles, `upcoming_payments` will still contain the
|
159
|
+
# upcoming charge dates.
|
147
160
|
#
|
148
161
|
# This fails with:
|
149
162
|
#
|
@@ -158,6 +171,9 @@ module GoCardlessPro
|
|
158
171
|
#
|
159
172
|
# - `subscription_already_ended` if the subscription has taken all payments.
|
160
173
|
#
|
174
|
+
# - `pause_cycles_must_be_greater_than_or_equal_to` if the provided value for
|
175
|
+
# `pause_cycles` cannot be satisfied.
|
176
|
+
#
|
161
177
|
# Example URL: /subscriptions/:identity/actions/pause
|
162
178
|
#
|
163
179
|
# @param identity # Unique identifier, beginning with "SB".
|
@@ -199,6 +215,8 @@ module GoCardlessPro
|
|
199
215
|
# Resume a subscription object.
|
200
216
|
# Payments will start to be created again based on the subscriptions recurrence
|
201
217
|
# rules.
|
218
|
+
# The `charge_date` on the next payment will be the same as the subscriptions
|
219
|
+
# `earliest_charge_date_after_resume`
|
202
220
|
#
|
203
221
|
# This fails with:
|
204
222
|
#
|
@@ -211,9 +229,6 @@ module GoCardlessPro
|
|
211
229
|
#
|
212
230
|
# - `subscription_not_paused` if the subscription is not paused.
|
213
231
|
#
|
214
|
-
# - `subscription_already_scheduled_to_resume` if a subscription already has a
|
215
|
-
# scheduled resume date.
|
216
|
-
#
|
217
232
|
# Example URL: /subscriptions/:identity/actions/resume
|
218
233
|
#
|
219
234
|
# @param identity # Unique identifier, beginning with "SB".
|
@@ -26,6 +26,7 @@ describe GoCardlessPro::Resources::Payout do
|
|
26
26
|
'fx' => 'fx-input',
|
27
27
|
'id' => 'id-input',
|
28
28
|
'links' => 'links-input',
|
29
|
+
'metadata' => 'metadata-input',
|
29
30
|
'payout_type' => 'payout_type-input',
|
30
31
|
'reference' => 'reference-input',
|
31
32
|
'status' => 'status-input',
|
@@ -58,6 +59,8 @@ describe GoCardlessPro::Resources::Payout do
|
|
58
59
|
|
59
60
|
expect(get_list_response.records.first.id).to eq('id-input')
|
60
61
|
|
62
|
+
expect(get_list_response.records.first.metadata).to eq('metadata-input')
|
63
|
+
|
61
64
|
expect(get_list_response.records.first.payout_type).to eq('payout_type-input')
|
62
65
|
|
63
66
|
expect(get_list_response.records.first.reference).to eq('reference-input')
|
@@ -88,6 +91,7 @@ describe GoCardlessPro::Resources::Payout do
|
|
88
91
|
'fx' => 'fx-input',
|
89
92
|
'id' => 'id-input',
|
90
93
|
'links' => 'links-input',
|
94
|
+
'metadata' => 'metadata-input',
|
91
95
|
'payout_type' => 'payout_type-input',
|
92
96
|
'reference' => 'reference-input',
|
93
97
|
'status' => 'status-input',
|
@@ -114,6 +118,7 @@ describe GoCardlessPro::Resources::Payout do
|
|
114
118
|
'fx' => 'fx-input',
|
115
119
|
'id' => 'id-input',
|
116
120
|
'links' => 'links-input',
|
121
|
+
'metadata' => 'metadata-input',
|
117
122
|
'payout_type' => 'payout_type-input',
|
118
123
|
'reference' => 'reference-input',
|
119
124
|
'status' => 'status-input',
|
@@ -156,6 +161,7 @@ describe GoCardlessPro::Resources::Payout do
|
|
156
161
|
'fx' => 'fx-input',
|
157
162
|
'id' => 'id-input',
|
158
163
|
'links' => 'links-input',
|
164
|
+
'metadata' => 'metadata-input',
|
159
165
|
'payout_type' => 'payout_type-input',
|
160
166
|
'reference' => 'reference-input',
|
161
167
|
'status' => 'status-input',
|
@@ -192,6 +198,7 @@ describe GoCardlessPro::Resources::Payout do
|
|
192
198
|
'fx' => 'fx-input',
|
193
199
|
'id' => 'id-input',
|
194
200
|
'links' => 'links-input',
|
201
|
+
'metadata' => 'metadata-input',
|
195
202
|
'payout_type' => 'payout_type-input',
|
196
203
|
'reference' => 'reference-input',
|
197
204
|
'status' => 'status-input',
|
@@ -228,4 +235,42 @@ describe GoCardlessPro::Resources::Payout do
|
|
228
235
|
end
|
229
236
|
end
|
230
237
|
end
|
238
|
+
|
239
|
+
describe '#update' do
|
240
|
+
subject(:put_update_response) { client.payouts.update(id, params: update_params) }
|
241
|
+
let(:id) { 'ABC123' }
|
242
|
+
|
243
|
+
context 'with a valid request' do
|
244
|
+
let(:update_params) { { 'hello' => 'world' } }
|
245
|
+
|
246
|
+
let!(:stub) do
|
247
|
+
stub_url = '/payouts/:identity'.gsub(':identity', id)
|
248
|
+
stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
|
249
|
+
body: {
|
250
|
+
'payouts' => {
|
251
|
+
|
252
|
+
'amount' => 'amount-input',
|
253
|
+
'arrival_date' => 'arrival_date-input',
|
254
|
+
'created_at' => 'created_at-input',
|
255
|
+
'currency' => 'currency-input',
|
256
|
+
'deducted_fees' => 'deducted_fees-input',
|
257
|
+
'fx' => 'fx-input',
|
258
|
+
'id' => 'id-input',
|
259
|
+
'links' => 'links-input',
|
260
|
+
'metadata' => 'metadata-input',
|
261
|
+
'payout_type' => 'payout_type-input',
|
262
|
+
'reference' => 'reference-input',
|
263
|
+
'status' => 'status-input',
|
264
|
+
},
|
265
|
+
}.to_json,
|
266
|
+
headers: response_headers
|
267
|
+
)
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'updates and returns the resource' do
|
271
|
+
expect(put_update_response).to be_a(GoCardlessPro::Resources::Payout)
|
272
|
+
expect(stub).to have_been_requested
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
231
276
|
end
|
@@ -25,6 +25,7 @@ describe GoCardlessPro::Services::PayoutsService do
|
|
25
25
|
'fx' => 'fx-input',
|
26
26
|
'id' => 'id-input',
|
27
27
|
'links' => 'links-input',
|
28
|
+
'metadata' => 'metadata-input',
|
28
29
|
'payout_type' => 'payout_type-input',
|
29
30
|
'reference' => 'reference-input',
|
30
31
|
'status' => 'status-input',
|
@@ -62,6 +63,8 @@ describe GoCardlessPro::Services::PayoutsService do
|
|
62
63
|
|
63
64
|
expect(get_list_response.records.first.id).to eq('id-input')
|
64
65
|
|
66
|
+
expect(get_list_response.records.first.metadata).to eq('metadata-input')
|
67
|
+
|
65
68
|
expect(get_list_response.records.first.payout_type).to eq('payout_type-input')
|
66
69
|
|
67
70
|
expect(get_list_response.records.first.reference).to eq('reference-input')
|
@@ -115,6 +118,7 @@ describe GoCardlessPro::Services::PayoutsService do
|
|
115
118
|
'fx' => 'fx-input',
|
116
119
|
'id' => 'id-input',
|
117
120
|
'links' => 'links-input',
|
121
|
+
'metadata' => 'metadata-input',
|
118
122
|
'payout_type' => 'payout_type-input',
|
119
123
|
'reference' => 'reference-input',
|
120
124
|
'status' => 'status-input',
|
@@ -141,6 +145,7 @@ describe GoCardlessPro::Services::PayoutsService do
|
|
141
145
|
'fx' => 'fx-input',
|
142
146
|
'id' => 'id-input',
|
143
147
|
'links' => 'links-input',
|
148
|
+
'metadata' => 'metadata-input',
|
144
149
|
'payout_type' => 'payout_type-input',
|
145
150
|
'reference' => 'reference-input',
|
146
151
|
'status' => 'status-input',
|
@@ -176,6 +181,7 @@ describe GoCardlessPro::Services::PayoutsService do
|
|
176
181
|
'fx' => 'fx-input',
|
177
182
|
'id' => 'id-input',
|
178
183
|
'links' => 'links-input',
|
184
|
+
'metadata' => 'metadata-input',
|
179
185
|
'payout_type' => 'payout_type-input',
|
180
186
|
'reference' => 'reference-input',
|
181
187
|
'status' => 'status-input',
|
@@ -202,6 +208,7 @@ describe GoCardlessPro::Services::PayoutsService do
|
|
202
208
|
'fx' => 'fx-input',
|
203
209
|
'id' => 'id-input',
|
204
210
|
'links' => 'links-input',
|
211
|
+
'metadata' => 'metadata-input',
|
205
212
|
'payout_type' => 'payout_type-input',
|
206
213
|
'reference' => 'reference-input',
|
207
214
|
'status' => 'status-input',
|
@@ -233,6 +240,7 @@ describe GoCardlessPro::Services::PayoutsService do
|
|
233
240
|
'fx' => 'fx-input',
|
234
241
|
'id' => 'id-input',
|
235
242
|
'links' => 'links-input',
|
243
|
+
'metadata' => 'metadata-input',
|
236
244
|
'payout_type' => 'payout_type-input',
|
237
245
|
'reference' => 'reference-input',
|
238
246
|
'status' => 'status-input',
|
@@ -262,6 +270,7 @@ describe GoCardlessPro::Services::PayoutsService do
|
|
262
270
|
'fx' => 'fx-input',
|
263
271
|
'id' => 'id-input',
|
264
272
|
'links' => 'links-input',
|
273
|
+
'metadata' => 'metadata-input',
|
265
274
|
'payout_type' => 'payout_type-input',
|
266
275
|
'reference' => 'reference-input',
|
267
276
|
'status' => 'status-input',
|
@@ -304,6 +313,7 @@ describe GoCardlessPro::Services::PayoutsService do
|
|
304
313
|
'fx' => 'fx-input',
|
305
314
|
'id' => 'id-input',
|
306
315
|
'links' => 'links-input',
|
316
|
+
'metadata' => 'metadata-input',
|
307
317
|
'payout_type' => 'payout_type-input',
|
308
318
|
'reference' => 'reference-input',
|
309
319
|
'status' => 'status-input',
|
@@ -340,6 +350,7 @@ describe GoCardlessPro::Services::PayoutsService do
|
|
340
350
|
'fx' => 'fx-input',
|
341
351
|
'id' => 'id-input',
|
342
352
|
'links' => 'links-input',
|
353
|
+
'metadata' => 'metadata-input',
|
343
354
|
'payout_type' => 'payout_type-input',
|
344
355
|
'reference' => 'reference-input',
|
345
356
|
'status' => 'status-input',
|
@@ -431,4 +442,67 @@ describe GoCardlessPro::Services::PayoutsService do
|
|
431
442
|
end
|
432
443
|
end
|
433
444
|
end
|
445
|
+
|
446
|
+
describe '#update' do
|
447
|
+
subject(:put_update_response) { client.payouts.update(id, params: update_params) }
|
448
|
+
let(:id) { 'ABC123' }
|
449
|
+
|
450
|
+
context 'with a valid request' do
|
451
|
+
let(:update_params) { { 'hello' => 'world' } }
|
452
|
+
|
453
|
+
let!(:stub) do
|
454
|
+
stub_url = '/payouts/:identity'.gsub(':identity', id)
|
455
|
+
stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
|
456
|
+
body: {
|
457
|
+
'payouts' => {
|
458
|
+
|
459
|
+
'amount' => 'amount-input',
|
460
|
+
'arrival_date' => 'arrival_date-input',
|
461
|
+
'created_at' => 'created_at-input',
|
462
|
+
'currency' => 'currency-input',
|
463
|
+
'deducted_fees' => 'deducted_fees-input',
|
464
|
+
'fx' => 'fx-input',
|
465
|
+
'id' => 'id-input',
|
466
|
+
'links' => 'links-input',
|
467
|
+
'metadata' => 'metadata-input',
|
468
|
+
'payout_type' => 'payout_type-input',
|
469
|
+
'reference' => 'reference-input',
|
470
|
+
'status' => 'status-input',
|
471
|
+
},
|
472
|
+
}.to_json,
|
473
|
+
headers: response_headers
|
474
|
+
)
|
475
|
+
end
|
476
|
+
|
477
|
+
it 'updates and returns the resource' do
|
478
|
+
expect(put_update_response).to be_a(GoCardlessPro::Resources::Payout)
|
479
|
+
expect(stub).to have_been_requested
|
480
|
+
end
|
481
|
+
|
482
|
+
describe 'retry behaviour' do
|
483
|
+
before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
|
484
|
+
|
485
|
+
it 'retries timeouts' do
|
486
|
+
stub_url = '/payouts/:identity'.gsub(':identity', id)
|
487
|
+
stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
|
488
|
+
to_timeout.then.to_return(status: 200, headers: response_headers)
|
489
|
+
|
490
|
+
put_update_response
|
491
|
+
expect(stub).to have_been_requested.twice
|
492
|
+
end
|
493
|
+
|
494
|
+
it 'retries 5XX errors' do
|
495
|
+
stub_url = '/payouts/:identity'.gsub(':identity', id)
|
496
|
+
stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
|
497
|
+
to_return(status: 502,
|
498
|
+
headers: { 'Content-Type' => 'text/html' },
|
499
|
+
body: '<html><body>Response from Cloudflare</body></html>').
|
500
|
+
then.to_return(status: 200, headers: response_headers)
|
501
|
+
|
502
|
+
put_update_response
|
503
|
+
expect(stub).to have_been_requested.twice
|
504
|
+
end
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end
|
434
508
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gocardless_pro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GoCardless
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -266,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
266
|
- !ruby/object:Gem::Version
|
267
267
|
version: '0'
|
268
268
|
requirements: []
|
269
|
-
rubygems_version: 3.0.
|
269
|
+
rubygems_version: 3.0.6
|
270
270
|
signing_key:
|
271
271
|
specification_version: 4
|
272
272
|
summary: A gem for calling the GoCardless Pro API
|