gocardless_pro 1.0.3 → 1.0.4

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -0
  3. data/README.md +71 -28
  4. data/gocardless_pro.gemspec +1 -1
  5. data/lib/gocardless_pro/api_service.rb +4 -2
  6. data/lib/gocardless_pro/client.rb +2 -1
  7. data/lib/gocardless_pro/error.rb +12 -1
  8. data/lib/gocardless_pro/resources/mandate.rb +3 -0
  9. data/lib/gocardless_pro/resources/payout.rb +3 -0
  10. data/lib/gocardless_pro/resources/redirect_flow.rb +15 -14
  11. data/lib/gocardless_pro/services/bank_details_lookups_service.rb +10 -0
  12. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +5 -2
  13. data/lib/gocardless_pro/services/creditors_service.rb +5 -2
  14. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +7 -3
  15. data/lib/gocardless_pro/services/customers_service.rb +5 -2
  16. data/lib/gocardless_pro/services/events_service.rb +2 -1
  17. data/lib/gocardless_pro/services/mandate_pdfs_service.rb +2 -1
  18. data/lib/gocardless_pro/services/mandates_service.rb +10 -5
  19. data/lib/gocardless_pro/services/payments_service.rb +11 -6
  20. data/lib/gocardless_pro/services/payouts_service.rb +2 -1
  21. data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -3
  22. data/lib/gocardless_pro/services/refunds_service.rb +5 -2
  23. data/lib/gocardless_pro/services/subscriptions_service.rb +7 -3
  24. data/lib/gocardless_pro/version.rb +1 -1
  25. data/spec/api_response_spec.rb +4 -4
  26. data/spec/api_service_spec.rb +41 -43
  27. data/spec/client_spec.rb +2 -2
  28. data/spec/error_spec.rb +27 -18
  29. data/spec/resources/bank_details_lookup_spec.rb +19 -34
  30. data/spec/resources/creditor_bank_account_spec.rb +54 -99
  31. data/spec/resources/creditor_spec.rb +66 -115
  32. data/spec/resources/customer_bank_account_spec.rb +54 -99
  33. data/spec/resources/customer_spec.rb +71 -138
  34. data/spec/resources/event_spec.rb +74 -107
  35. data/spec/resources/mandate_pdf_spec.rb +15 -26
  36. data/spec/resources/mandate_spec.rb +54 -87
  37. data/spec/resources/payment_spec.rb +70 -119
  38. data/spec/resources/payout_spec.rb +50 -79
  39. data/spec/resources/redirect_flow_spec.rb +58 -95
  40. data/spec/resources/refund_spec.rb +42 -75
  41. data/spec/resources/subscription_spec.rb +82 -155
  42. data/spec/response_spec.rb +45 -46
  43. data/spec/services/bank_details_lookups_service_spec.rb +55 -60
  44. data/spec/services/creditor_bank_accounts_service_spec.rb +303 -347
  45. data/spec/services/creditors_service_spec.rb +290 -333
  46. data/spec/services/customer_bank_accounts_service_spec.rb +332 -380
  47. data/spec/services/customers_service_spec.rb +347 -400
  48. data/spec/services/events_service_spec.rb +154 -184
  49. data/spec/services/mandate_pdfs_service_spec.rb +52 -57
  50. data/spec/services/mandates_service_spec.rb +374 -410
  51. data/spec/services/payments_service_spec.rb +404 -461
  52. data/spec/services/payouts_service_spec.rb +161 -184
  53. data/spec/services/redirect_flows_service_spec.rb +188 -205
  54. data/spec/services/refunds_service_spec.rb +245 -280
  55. data/spec/services/subscriptions_service_spec.rb +423 -485
  56. data/spec/spec_helper.rb +46 -48
  57. metadata +22 -20
@@ -3,341 +3,306 @@ require 'spec_helper'
3
3
  describe GoCardlessPro::Services::RefundsService do
4
4
  let(:client) do
5
5
  GoCardlessPro::Client.new(
6
- access_token: "SECRET_TOKEN"
6
+ access_token: 'SECRET_TOKEN'
7
7
  )
8
8
  end
9
9
 
10
-
11
-
12
-
13
-
14
-
15
-
16
- describe "#create" do
10
+ describe '#create' do
17
11
  subject(:post_create_response) { client.refunds.create(params: new_resource) }
18
- context "with a valid request" do
19
- let(:new_resource) do
20
- {
21
-
22
- "amount" => "amount-input",
23
- "created_at" => "created_at-input",
24
- "currency" => "currency-input",
25
- "id" => "id-input",
26
- "links" => "links-input",
27
- "metadata" => "metadata-input",
28
- "reference" => "reference-input",
29
- }
30
- end
12
+ context 'with a valid request' do
13
+ let(:new_resource) do
14
+ {
15
+
16
+ 'amount' => 'amount-input',
17
+ 'created_at' => 'created_at-input',
18
+ 'currency' => 'currency-input',
19
+ 'id' => 'id-input',
20
+ 'links' => 'links-input',
21
+ 'metadata' => 'metadata-input',
22
+ 'reference' => 'reference-input'
23
+ }
24
+ end
31
25
 
32
- before do
33
- stub_request(:post, %r(.*api.gocardless.com/refunds)).
34
- with(
26
+ before do
27
+ stub_request(:post, %r{.*api.gocardless.com/refunds})
28
+ .with(
35
29
  body: {
36
- "refunds" => {
37
-
38
- "amount" => "amount-input",
39
- "created_at" => "created_at-input",
40
- "currency" => "currency-input",
41
- "id" => "id-input",
42
- "links" => "links-input",
43
- "metadata" => "metadata-input",
44
- "reference" => "reference-input",
45
- }
30
+ 'refunds' => {
31
+
32
+ 'amount' => 'amount-input',
33
+ 'created_at' => 'created_at-input',
34
+ 'currency' => 'currency-input',
35
+ 'id' => 'id-input',
36
+ 'links' => 'links-input',
37
+ 'metadata' => 'metadata-input',
38
+ 'reference' => 'reference-input'
39
+ }
46
40
  }
47
- ).
48
- to_return(
49
- body: {
50
- "refunds" => {
51
-
52
- "amount" => "amount-input",
53
- "created_at" => "created_at-input",
54
- "currency" => "currency-input",
55
- "id" => "id-input",
56
- "links" => "links-input",
57
- "metadata" => "metadata-input",
58
- "reference" => "reference-input",
59
- }
60
- }.to_json,
61
- :headers => {'Content-Type' => 'application/json'}
62
41
  )
63
- end
42
+ .to_return(
43
+ body: {
44
+ 'refunds' =>
64
45
 
65
- it "creates and returns the resource" do
66
- expect(post_create_response).to be_a(GoCardlessPro::Resources::Refund)
67
- end
68
- end
46
+ {
69
47
 
70
- context "with a request that returns a validation error" do
71
- let(:new_resource) { {} }
48
+ 'amount' => 'amount-input',
49
+ 'created_at' => 'created_at-input',
50
+ 'currency' => 'currency-input',
51
+ 'id' => 'id-input',
52
+ 'links' => 'links-input',
53
+ 'metadata' => 'metadata-input',
54
+ 'reference' => 'reference-input'
55
+ }
72
56
 
73
- before do
74
- stub_request(:post, %r(.*api.gocardless.com/refunds)).to_return(
75
- body: {
76
- error: {
77
- type: 'validation_failed',
78
- code: 422,
79
- errors: [
80
- { message: 'test error message', field: 'test_field' }
81
- ]
82
- }
83
57
  }.to_json,
84
- headers: {'Content-Type' => 'application/json'},
85
- status: 422
58
+ headers: { 'Content-Type' => 'application/json' }
86
59
  )
87
- end
88
-
89
- it "throws the correct error" do
90
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
91
- end
92
60
  end
93
- end
94
-
95
-
96
-
97
-
98
-
99
- describe "#list" do
100
- describe "with no filters" do
101
- subject(:get_list_response) { client.refunds.list }
102
61
 
103
- before do
104
- stub_request(:get, %r(.*api.gocardless.com/refunds)).to_return(
105
- body: {
106
- "refunds" => [{
107
-
108
- "amount" => "amount-input",
109
- "created_at" => "created_at-input",
110
- "currency" => "currency-input",
111
- "id" => "id-input",
112
- "links" => "links-input",
113
- "metadata" => "metadata-input",
114
- "reference" => "reference-input",
115
- }],
116
- meta: {
117
- cursors: {
118
- before: nil,
119
- after: "ABC123"
120
- }
121
- }
122
- }.to_json,
123
- :headers => {'Content-Type' => 'application/json'}
124
- )
125
- end
126
-
127
- it "wraps each item in the resource class" do
128
- expect(get_list_response.records.map { |x| x.class }.uniq.first).to eq(GoCardlessPro::Resources::Refund)
129
-
130
-
131
-
132
- expect(get_list_response.records.first.amount).to eq("amount-input")
133
-
134
-
135
-
136
- expect(get_list_response.records.first.created_at).to eq("created_at-input")
137
-
138
-
139
-
140
- expect(get_list_response.records.first.currency).to eq("currency-input")
141
-
142
-
143
-
144
- expect(get_list_response.records.first.id).to eq("id-input")
145
-
146
-
147
-
148
-
149
-
150
- expect(get_list_response.records.first.metadata).to eq("metadata-input")
151
-
152
-
153
-
154
- expect(get_list_response.records.first.reference).to eq("reference-input")
155
-
156
-
157
- end
158
-
159
- it "exposes the cursors for before and after" do
160
- expect(get_list_response.before).to eq(nil)
161
- expect(get_list_response.after).to eq("ABC123")
162
- end
163
-
164
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
62
+ it 'creates and returns the resource' do
63
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::Refund)
165
64
  end
166
65
  end
167
66
 
168
- describe "#all" do
169
- let!(:first_response_stub) do
170
- stub_request(:get, %r(.*api.gocardless.com/refunds$)).to_return(
67
+ context 'with a request that returns a validation error' do
68
+ let(:new_resource) { {} }
69
+
70
+ before do
71
+ stub_request(:post, %r{.*api.gocardless.com/refunds}).to_return(
171
72
  body: {
172
- "refunds" => [{
173
-
174
- "amount" => "amount-input",
175
- "created_at" => "created_at-input",
176
- "currency" => "currency-input",
177
- "id" => "id-input",
178
- "links" => "links-input",
179
- "metadata" => "metadata-input",
180
- "reference" => "reference-input",
181
- }],
182
- meta: {
183
- cursors: { after: 'AB345' },
184
- limit: 1
73
+ error: {
74
+ type: 'validation_failed',
75
+ code: 422,
76
+ errors: [
77
+ { message: 'test error message', field: 'test_field' }
78
+ ]
185
79
  }
186
80
  }.to_json,
187
- :headers => {'Content-Type' => 'application/json'}
81
+ headers: { 'Content-Type' => 'application/json' },
82
+ status: 422
188
83
  )
189
84
  end
190
85
 
191
- let!(:second_response_stub) do
192
- stub_request(:get, %r(.*api.gocardless.com/refunds\?after=AB345)).to_return(
86
+ it 'throws the correct error' do
87
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
88
+ end
89
+ end
90
+ end
91
+
92
+ describe '#list' do
93
+ describe 'with no filters' do
94
+ subject(:get_list_response) { client.refunds.list }
95
+
96
+ before do
97
+ stub_request(:get, %r{.*api.gocardless.com/refunds}).to_return(
193
98
  body: {
194
- "refunds" => [{
195
-
196
- "amount" => "amount-input",
197
- "created_at" => "created_at-input",
198
- "currency" => "currency-input",
199
- "id" => "id-input",
200
- "links" => "links-input",
201
- "metadata" => "metadata-input",
202
- "reference" => "reference-input",
99
+ 'refunds' => [{
100
+
101
+ 'amount' => 'amount-input',
102
+ 'created_at' => 'created_at-input',
103
+ 'currency' => 'currency-input',
104
+ 'id' => 'id-input',
105
+ 'links' => 'links-input',
106
+ 'metadata' => 'metadata-input',
107
+ 'reference' => 'reference-input'
203
108
  }],
204
109
  meta: {
205
- limit: 2,
206
- cursors: {}
110
+ cursors: {
111
+ before: nil,
112
+ after: 'ABC123'
113
+ }
207
114
  }
208
115
  }.to_json,
209
- :headers => {'Content-Type' => 'application/json'}
116
+ headers: { 'Content-Type' => 'application/json' }
210
117
  )
211
118
  end
212
119
 
213
- it "automatically makes the extra requests" do
214
- expect(client.refunds.all.to_a.length).to eq(2)
215
- expect(first_response_stub).to have_been_requested
216
- expect(second_response_stub).to have_been_requested
120
+ it 'wraps each item in the resource class' do
121
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Refund)
122
+
123
+ expect(get_list_response.records.first.amount).to eq('amount-input')
124
+
125
+ expect(get_list_response.records.first.created_at).to eq('created_at-input')
126
+
127
+ expect(get_list_response.records.first.currency).to eq('currency-input')
128
+
129
+ expect(get_list_response.records.first.id).to eq('id-input')
130
+
131
+ expect(get_list_response.records.first.metadata).to eq('metadata-input')
132
+
133
+ expect(get_list_response.records.first.reference).to eq('reference-input')
134
+ end
135
+
136
+ it 'exposes the cursors for before and after' do
137
+ expect(get_list_response.before).to eq(nil)
138
+ expect(get_list_response.after).to eq('ABC123')
217
139
  end
140
+
141
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
142
+ end
143
+ end
144
+
145
+ describe '#all' do
146
+ let!(:first_response_stub) do
147
+ stub_request(:get, %r{.*api.gocardless.com/refunds$}).to_return(
148
+ body: {
149
+ 'refunds' => [{
150
+
151
+ 'amount' => 'amount-input',
152
+ 'created_at' => 'created_at-input',
153
+ 'currency' => 'currency-input',
154
+ 'id' => 'id-input',
155
+ 'links' => 'links-input',
156
+ 'metadata' => 'metadata-input',
157
+ 'reference' => 'reference-input'
158
+ }],
159
+ meta: {
160
+ cursors: { after: 'AB345' },
161
+ limit: 1
162
+ }
163
+ }.to_json,
164
+ headers: { 'Content-Type' => 'application/json' }
165
+ )
166
+ end
167
+
168
+ let!(:second_response_stub) do
169
+ stub_request(:get, %r{.*api.gocardless.com/refunds\?after=AB345}).to_return(
170
+ body: {
171
+ 'refunds' => [{
172
+
173
+ 'amount' => 'amount-input',
174
+ 'created_at' => 'created_at-input',
175
+ 'currency' => 'currency-input',
176
+ 'id' => 'id-input',
177
+ 'links' => 'links-input',
178
+ 'metadata' => 'metadata-input',
179
+ 'reference' => 'reference-input'
180
+ }],
181
+ meta: {
182
+ limit: 2,
183
+ cursors: {}
184
+ }
185
+ }.to_json,
186
+ headers: { 'Content-Type' => 'application/json' }
187
+ )
218
188
  end
219
189
 
220
-
221
-
222
-
190
+ it 'automatically makes the extra requests' do
191
+ expect(client.refunds.all.to_a.length).to eq(2)
192
+ expect(first_response_stub).to have_been_requested
193
+ expect(second_response_stub).to have_been_requested
194
+ end
195
+ end
223
196
 
224
-
225
- describe "#get" do
226
- let(:id) { "ID123" }
197
+ describe '#get' do
198
+ let(:id) { 'ID123' }
227
199
 
228
- subject(:get_response) { client.refunds.get(id) }
200
+ subject(:get_response) { client.refunds.get(id) }
229
201
 
230
- context "passing in a custom header" do
231
- let!(:stub) do
232
- stub_url = "/refunds/:identity".gsub(':identity', id)
233
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).
234
- with(headers: { 'Foo' => 'Bar' }).
235
- to_return(
202
+ context 'passing in a custom header' do
203
+ let!(:stub) do
204
+ stub_url = '/refunds/:identity'.gsub(':identity', id)
205
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/)
206
+ .with(headers: { 'Foo' => 'Bar' })
207
+ .to_return(
236
208
  body: {
237
- "refunds" => {
238
-
239
- "amount" => "amount-input",
240
- "created_at" => "created_at-input",
241
- "currency" => "currency-input",
242
- "id" => "id-input",
243
- "links" => "links-input",
244
- "metadata" => "metadata-input",
245
- "reference" => "reference-input",
209
+ 'refunds' => {
210
+
211
+ 'amount' => 'amount-input',
212
+ 'created_at' => 'created_at-input',
213
+ 'currency' => 'currency-input',
214
+ 'id' => 'id-input',
215
+ 'links' => 'links-input',
216
+ 'metadata' => 'metadata-input',
217
+ 'reference' => 'reference-input'
246
218
  }
247
219
  }.to_json,
248
- :headers => {'Content-Type' => 'application/json'}
220
+ headers: { 'Content-Type' => 'application/json' }
249
221
  )
250
- end
251
-
252
- subject(:get_response) do
253
- client.refunds.get(id, headers: {
254
- 'Foo' => 'Bar'
255
- })
256
- end
257
-
258
- it "includes the header" do
259
- get_response
260
- expect(stub).to have_been_requested
261
- end
262
222
  end
263
223
 
264
- context "when there is a refund to return" do
265
- before do
266
- stub_url = "/refunds/:identity".gsub(':identity', id)
267
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
268
- body: {
269
- "refunds" => {
270
-
271
- "amount" => "amount-input",
272
- "created_at" => "created_at-input",
273
- "currency" => "currency-input",
274
- "id" => "id-input",
275
- "links" => "links-input",
276
- "metadata" => "metadata-input",
277
- "reference" => "reference-input",
278
- }
279
- }.to_json,
280
- :headers => {'Content-Type' => 'application/json'}
281
- )
282
- end
224
+ subject(:get_response) do
225
+ client.refunds.get(id, headers: {
226
+ 'Foo' => 'Bar'
227
+ })
228
+ end
283
229
 
284
- it "wraps the response in a resource" do
285
- expect(get_response).to be_a(GoCardlessPro::Resources::Refund)
286
- end
230
+ it 'includes the header' do
231
+ get_response
232
+ expect(stub).to have_been_requested
287
233
  end
234
+ end
288
235
 
289
- context "when nothing is returned" do
290
- before do
291
- stub_url = "/refunds/:identity".gsub(':identity', id)
292
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
293
- body: "",
294
- headers: { 'Content-Type' => 'application/json' }
295
- )
296
- end
236
+ context 'when there is a refund to return' do
237
+ before do
238
+ stub_url = '/refunds/:identity'.gsub(':identity', id)
239
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
240
+ body: {
241
+ 'refunds' => {
242
+
243
+ 'amount' => 'amount-input',
244
+ 'created_at' => 'created_at-input',
245
+ 'currency' => 'currency-input',
246
+ 'id' => 'id-input',
247
+ 'links' => 'links-input',
248
+ 'metadata' => 'metadata-input',
249
+ 'reference' => 'reference-input'
250
+ }
251
+ }.to_json,
252
+ headers: { 'Content-Type' => 'application/json' }
253
+ )
254
+ end
297
255
 
298
- it "returns nil" do
299
- expect(get_response).to be_nil
300
- end
256
+ it 'wraps the response in a resource' do
257
+ expect(get_response).to be_a(GoCardlessPro::Resources::Refund)
301
258
  end
302
259
  end
303
260
 
304
-
305
-
306
-
261
+ context 'when nothing is returned' do
262
+ before do
263
+ stub_url = '/refunds/:identity'.gsub(':identity', id)
264
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
265
+ body: '',
266
+ headers: { 'Content-Type' => 'application/json' }
267
+ )
268
+ end
307
269
 
308
-
309
- describe "#update" do
310
- subject(:put_update_response) { client.refunds.update(id, params: update_params) }
311
- let(:id) { "ABC123" }
270
+ it 'returns nil' do
271
+ expect(get_response).to be_nil
272
+ end
273
+ end
274
+ end
312
275
 
313
- context "with a valid request" do
314
- let(:update_params) { { "hello" => "world" } }
276
+ describe '#update' do
277
+ subject(:put_update_response) { client.refunds.update(id, params: update_params) }
278
+ let(:id) { 'ABC123' }
315
279
 
316
- let!(:stub) do
317
- stub_url = "/refunds/:identity".gsub(':identity', id)
318
- stub_request(:put, %r(.*api.gocardless.com#{stub_url})).to_return(
319
- body: {
320
- "refunds" => {
321
-
322
- "amount" => "amount-input",
323
- "created_at" => "created_at-input",
324
- "currency" => "currency-input",
325
- "id" => "id-input",
326
- "links" => "links-input",
327
- "metadata" => "metadata-input",
328
- "reference" => "reference-input",
329
- }
330
- }.to_json,
331
- :headers => {'Content-Type' => 'application/json'}
332
- )
333
- end
280
+ context 'with a valid request' do
281
+ let(:update_params) { { 'hello' => 'world' } }
334
282
 
335
- it "updates and returns the resource" do
336
- expect(put_update_response).to be_a(GoCardlessPro::Resources::Refund)
337
- expect(stub).to have_been_requested
338
- end
283
+ let!(:stub) do
284
+ stub_url = '/refunds/:identity'.gsub(':identity', id)
285
+ stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
286
+ body: {
287
+ 'refunds' => {
288
+
289
+ 'amount' => 'amount-input',
290
+ 'created_at' => 'created_at-input',
291
+ 'currency' => 'currency-input',
292
+ 'id' => 'id-input',
293
+ 'links' => 'links-input',
294
+ 'metadata' => 'metadata-input',
295
+ 'reference' => 'reference-input'
296
+ }
297
+ }.to_json,
298
+ headers: { 'Content-Type' => 'application/json' }
299
+ )
300
+ end
301
+
302
+ it 'updates and returns the resource' do
303
+ expect(put_update_response).to be_a(GoCardlessPro::Resources::Refund)
304
+ expect(stub).to have_been_requested
339
305
  end
340
306
  end
341
-
342
-
307
+ end
343
308
  end