gocardless_pro 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +146 -0
  6. data/circle.yml +3 -0
  7. data/demo.rb +9 -0
  8. data/gocardless_pro.gemspec +26 -0
  9. data/lib/gocardless_pro.rb +73 -0
  10. data/lib/gocardless_pro/api_service.rb +58 -0
  11. data/lib/gocardless_pro/client.rb +135 -0
  12. data/lib/gocardless_pro/error.rb +42 -0
  13. data/lib/gocardless_pro/error/gocardless_error.rb +5 -0
  14. data/lib/gocardless_pro/error/invalid_api_usage_error.rb +5 -0
  15. data/lib/gocardless_pro/error/invalid_state_error.rb +5 -0
  16. data/lib/gocardless_pro/error/validation_error.rb +5 -0
  17. data/lib/gocardless_pro/list_response.rb +29 -0
  18. data/lib/gocardless_pro/paginator.rb +43 -0
  19. data/lib/gocardless_pro/request.rb +69 -0
  20. data/lib/gocardless_pro/resources/creditor.rb +84 -0
  21. data/lib/gocardless_pro/resources/creditor_bank_account.rb +78 -0
  22. data/lib/gocardless_pro/resources/customer.rb +75 -0
  23. data/lib/gocardless_pro/resources/customer_bank_account.rb +80 -0
  24. data/lib/gocardless_pro/resources/event.rb +75 -0
  25. data/lib/gocardless_pro/resources/helper.rb +29 -0
  26. data/lib/gocardless_pro/resources/mandate.rb +70 -0
  27. data/lib/gocardless_pro/resources/payment.rb +87 -0
  28. data/lib/gocardless_pro/resources/payout.rb +66 -0
  29. data/lib/gocardless_pro/resources/redirect_flow.rb +106 -0
  30. data/lib/gocardless_pro/resources/refund.rb +71 -0
  31. data/lib/gocardless_pro/resources/subscription.rb +155 -0
  32. data/lib/gocardless_pro/response.rb +77 -0
  33. data/lib/gocardless_pro/services/base_service.rb +28 -0
  34. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +119 -0
  35. data/lib/gocardless_pro/services/creditors_service.rb +113 -0
  36. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +154 -0
  37. data/lib/gocardless_pro/services/customers_service.rb +113 -0
  38. data/lib/gocardless_pro/services/events_service.rb +80 -0
  39. data/lib/gocardless_pro/services/helpers_service.rb +99 -0
  40. data/lib/gocardless_pro/services/mandates_service.rb +173 -0
  41. data/lib/gocardless_pro/services/payments_service.rb +168 -0
  42. data/lib/gocardless_pro/services/payouts_service.rb +82 -0
  43. data/lib/gocardless_pro/services/redirect_flows_service.rb +98 -0
  44. data/lib/gocardless_pro/services/refunds_service.rb +132 -0
  45. data/lib/gocardless_pro/services/subscriptions_service.rb +134 -0
  46. data/lib/gocardless_pro/version.rb +8 -0
  47. data/spec/api_service_spec.rb +73 -0
  48. data/spec/client_spec.rb +19 -0
  49. data/spec/error_spec.rb +44 -0
  50. data/spec/resources/creditor_bank_account_spec.rb +109 -0
  51. data/spec/resources/creditor_spec.rb +125 -0
  52. data/spec/resources/customer_bank_account_spec.rb +109 -0
  53. data/spec/resources/customer_spec.rb +135 -0
  54. data/spec/resources/event_spec.rb +113 -0
  55. data/spec/resources/helper_spec.rb +23 -0
  56. data/spec/resources/mandate_spec.rb +97 -0
  57. data/spec/resources/payment_spec.rb +129 -0
  58. data/spec/resources/payout_spec.rb +89 -0
  59. data/spec/resources/redirect_flow_spec.rb +97 -0
  60. data/spec/resources/refund_spec.rb +77 -0
  61. data/spec/resources/subscription_spec.rb +165 -0
  62. data/spec/response_spec.rb +89 -0
  63. data/spec/services/creditor_bank_accounts_service_spec.rb +413 -0
  64. data/spec/services/creditors_service_spec.rb +388 -0
  65. data/spec/services/customer_bank_accounts_service_spec.rb +452 -0
  66. data/spec/services/customers_service_spec.rb +429 -0
  67. data/spec/services/events_service_spec.rb +217 -0
  68. data/spec/services/helpers_service_spec.rb +122 -0
  69. data/spec/services/mandates_service_spec.rb +495 -0
  70. data/spec/services/payments_service_spec.rb +546 -0
  71. data/spec/services/payouts_service_spec.rb +217 -0
  72. data/spec/services/redirect_flows_service_spec.rb +254 -0
  73. data/spec/services/refunds_service_spec.rb +323 -0
  74. data/spec/services/subscriptions_service_spec.rb +557 -0
  75. data/spec/spec_helper.rb +91 -0
  76. metadata +224 -0
@@ -0,0 +1,388 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Services::CreditorsService do
4
+ let(:client) do
5
+ GoCardlessPro::Client.new(
6
+ access_token: "SECRET_TOKEN"
7
+ )
8
+ end
9
+
10
+
11
+
12
+
13
+
14
+
15
+ describe "#create" do
16
+ subject(:post_create_response) { client.creditors.create(params: new_resource) }
17
+ context "with a valid request" do
18
+ let(:new_resource) do
19
+ {
20
+
21
+ "address_line1" => "address_line1-input",
22
+ "address_line2" => "address_line2-input",
23
+ "address_line3" => "address_line3-input",
24
+ "city" => "city-input",
25
+ "country_code" => "country_code-input",
26
+ "created_at" => "created_at-input",
27
+ "id" => "id-input",
28
+ "links" => "links-input",
29
+ "name" => "name-input",
30
+ "postal_code" => "postal_code-input",
31
+ "region" => "region-input",
32
+ }
33
+ end
34
+
35
+ before do
36
+ stub_request(:post, /.*api.gocardless.com\/creditors/).
37
+ with(
38
+ body: {
39
+ creditors: {
40
+
41
+ "address_line1" => "address_line1-input",
42
+ "address_line2" => "address_line2-input",
43
+ "address_line3" => "address_line3-input",
44
+ "city" => "city-input",
45
+ "country_code" => "country_code-input",
46
+ "created_at" => "created_at-input",
47
+ "id" => "id-input",
48
+ "links" => "links-input",
49
+ "name" => "name-input",
50
+ "postal_code" => "postal_code-input",
51
+ "region" => "region-input",
52
+ }
53
+ }
54
+ ).
55
+ to_return(
56
+ body: {
57
+ creditors: {
58
+
59
+ "address_line1" => "address_line1-input",
60
+ "address_line2" => "address_line2-input",
61
+ "address_line3" => "address_line3-input",
62
+ "city" => "city-input",
63
+ "country_code" => "country_code-input",
64
+ "created_at" => "created_at-input",
65
+ "id" => "id-input",
66
+ "links" => "links-input",
67
+ "name" => "name-input",
68
+ "postal_code" => "postal_code-input",
69
+ "region" => "region-input",
70
+ }
71
+ }.to_json,
72
+ :headers => {'Content-Type' => 'application/json'}
73
+ )
74
+ end
75
+
76
+ it "creates and returns the resource" do
77
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::Creditor)
78
+ end
79
+ end
80
+
81
+ context "with a request that returns a validation error" do
82
+ let(:new_resource) { {} }
83
+
84
+ before do
85
+ stub_request(:post, /.*api.gocardless.com\/creditors/).to_return(
86
+ body: {
87
+ error: {
88
+ type: 'validation_failed',
89
+ code: 422,
90
+ errors: [
91
+ { message: 'test error message', field: 'test_field' }
92
+ ]
93
+ }
94
+ }.to_json,
95
+ headers: {'Content-Type' => 'application/json'},
96
+ status: 422
97
+ )
98
+ end
99
+
100
+ it "throws the correct error" do
101
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
102
+ end
103
+ end
104
+ end
105
+
106
+
107
+
108
+
109
+
110
+ describe "#list" do
111
+ describe "with no filters" do
112
+ subject(:get_list_response) { client.creditors.list }
113
+
114
+ before do
115
+ stub_request(:get, /.*api.gocardless.com\/creditors/).to_return(
116
+ body: {
117
+ creditors: [{
118
+
119
+ "address_line1" => "address_line1-input",
120
+ "address_line2" => "address_line2-input",
121
+ "address_line3" => "address_line3-input",
122
+ "city" => "city-input",
123
+ "country_code" => "country_code-input",
124
+ "created_at" => "created_at-input",
125
+ "id" => "id-input",
126
+ "links" => "links-input",
127
+ "name" => "name-input",
128
+ "postal_code" => "postal_code-input",
129
+ "region" => "region-input",
130
+ }],
131
+ meta: {
132
+ cursors: {
133
+ before: nil,
134
+ after: "ABC123"
135
+ }
136
+ }
137
+ }.to_json,
138
+ :headers => {'Content-Type' => 'application/json'}
139
+ )
140
+ end
141
+
142
+ it "wraps each item in the resource class" do
143
+ expect(get_list_response.records.map { |x| x.class }.uniq.first).to eq(GoCardlessPro::Resources::Creditor)
144
+
145
+
146
+
147
+ expect(get_list_response.records.first.address_line1).to eq("address_line1-input")
148
+
149
+
150
+
151
+ expect(get_list_response.records.first.address_line2).to eq("address_line2-input")
152
+
153
+
154
+
155
+ expect(get_list_response.records.first.address_line3).to eq("address_line3-input")
156
+
157
+
158
+
159
+ expect(get_list_response.records.first.city).to eq("city-input")
160
+
161
+
162
+
163
+ expect(get_list_response.records.first.country_code).to eq("country_code-input")
164
+
165
+
166
+
167
+ expect(get_list_response.records.first.created_at).to eq("created_at-input")
168
+
169
+
170
+
171
+ expect(get_list_response.records.first.id).to eq("id-input")
172
+
173
+
174
+
175
+
176
+
177
+ expect(get_list_response.records.first.name).to eq("name-input")
178
+
179
+
180
+
181
+ expect(get_list_response.records.first.postal_code).to eq("postal_code-input")
182
+
183
+
184
+
185
+ expect(get_list_response.records.first.region).to eq("region-input")
186
+
187
+
188
+ end
189
+
190
+ it "exposes the cursors for before and after" do
191
+ expect(get_list_response.before).to eq(nil)
192
+ expect(get_list_response.after).to eq("ABC123")
193
+ end
194
+ end
195
+ end
196
+
197
+ describe "#all" do
198
+ let!(:first_response_stub) do
199
+ stub_request(:get, /.*api.gocardless.com\/creditors$/).to_return(
200
+ body: {
201
+ creditors: [{
202
+
203
+ "address_line1" => "address_line1-input",
204
+ "address_line2" => "address_line2-input",
205
+ "address_line3" => "address_line3-input",
206
+ "city" => "city-input",
207
+ "country_code" => "country_code-input",
208
+ "created_at" => "created_at-input",
209
+ "id" => "id-input",
210
+ "links" => "links-input",
211
+ "name" => "name-input",
212
+ "postal_code" => "postal_code-input",
213
+ "region" => "region-input",
214
+ }],
215
+ meta: {
216
+ cursors: { after: 'AB345' },
217
+ limit: 1
218
+ }
219
+ }.to_json,
220
+ :headers => {'Content-Type' => 'application/json'}
221
+ )
222
+ end
223
+
224
+ let!(:second_response_stub) do
225
+ stub_request(:get, /.*api.gocardless.com\/creditors\?after=AB345/).to_return(
226
+ body: {
227
+ creditors: [{
228
+
229
+ "address_line1" => "address_line1-input",
230
+ "address_line2" => "address_line2-input",
231
+ "address_line3" => "address_line3-input",
232
+ "city" => "city-input",
233
+ "country_code" => "country_code-input",
234
+ "created_at" => "created_at-input",
235
+ "id" => "id-input",
236
+ "links" => "links-input",
237
+ "name" => "name-input",
238
+ "postal_code" => "postal_code-input",
239
+ "region" => "region-input",
240
+ }],
241
+ meta: {
242
+ limit: 2,
243
+ cursors: {}
244
+ }
245
+ }.to_json,
246
+ :headers => {'Content-Type' => 'application/json'}
247
+ )
248
+ end
249
+
250
+ it "automatically makes the extra requests" do
251
+ expect(client.creditors.all.to_a.length).to eq(2)
252
+ expect(first_response_stub).to have_been_requested
253
+ expect(second_response_stub).to have_been_requested
254
+ end
255
+ end
256
+
257
+
258
+
259
+
260
+
261
+
262
+ describe "#get" do
263
+ let(:id) { "ID123" }
264
+
265
+ subject(:get_response) { client.creditors.get(id) }
266
+
267
+ context "passing in a custom header" do
268
+ let!(:stub) do
269
+ stub_request(:get, /.*api.gocardless.com\/creditors\/ID123/)
270
+ .with(headers: { 'Foo' => 'Bar' })
271
+ .to_return(
272
+ body: {
273
+ creditors: {
274
+
275
+ "address_line1" => "address_line1-input",
276
+ "address_line2" => "address_line2-input",
277
+ "address_line3" => "address_line3-input",
278
+ "city" => "city-input",
279
+ "country_code" => "country_code-input",
280
+ "created_at" => "created_at-input",
281
+ "id" => "id-input",
282
+ "links" => "links-input",
283
+ "name" => "name-input",
284
+ "postal_code" => "postal_code-input",
285
+ "region" => "region-input",
286
+ }
287
+ }.to_json,
288
+ :headers => {'Content-Type' => 'application/json'}
289
+ )
290
+ end
291
+
292
+ subject(:get_response) do
293
+ client.creditors.get(id, headers: {
294
+ 'Foo' => 'Bar'
295
+ })
296
+ end
297
+
298
+ it "includes the header" do
299
+ get_response
300
+ expect(stub).to have_been_requested
301
+ end
302
+ end
303
+
304
+ context "when there is a creditor to return" do
305
+ before do
306
+ stub_request(:get, /.*api.gocardless.com\/creditors\/ID123/).to_return(
307
+ body: {
308
+ creditors: {
309
+
310
+ "address_line1" => "address_line1-input",
311
+ "address_line2" => "address_line2-input",
312
+ "address_line3" => "address_line3-input",
313
+ "city" => "city-input",
314
+ "country_code" => "country_code-input",
315
+ "created_at" => "created_at-input",
316
+ "id" => "id-input",
317
+ "links" => "links-input",
318
+ "name" => "name-input",
319
+ "postal_code" => "postal_code-input",
320
+ "region" => "region-input",
321
+ }
322
+ }.to_json,
323
+ :headers => {'Content-Type' => 'application/json'}
324
+ )
325
+ end
326
+
327
+ it "wraps the response in a resource" do
328
+ expect(get_response).to be_a(GoCardlessPro::Resources::Creditor)
329
+ end
330
+ end
331
+
332
+ context "when nothing is returned" do
333
+ before do
334
+ stub_request(:get, /.*api.gocardless.com\/creditors\/ID123/).to_return(
335
+ body: "",
336
+ headers: { 'Content-Type' => 'application/json' }
337
+ )
338
+ end
339
+
340
+ it "returns nil" do
341
+ expect(get_response).to be_nil
342
+ end
343
+ end
344
+ end
345
+
346
+
347
+
348
+
349
+
350
+
351
+ describe "#update" do
352
+ subject(:put_update_response) { client.creditors.update(id, params: update_params) }
353
+ let(:id) { "ABC123" }
354
+
355
+ context "with a valid request" do
356
+ let(:update_params) { { "hello" => "world" } }
357
+
358
+ let!(:stub) do
359
+ stub_request(:put, /.*api.gocardless.com\/creditors\/ABC123/).to_return(
360
+ body: {
361
+ creditors: {
362
+
363
+ "address_line1" => "address_line1-input",
364
+ "address_line2" => "address_line2-input",
365
+ "address_line3" => "address_line3-input",
366
+ "city" => "city-input",
367
+ "country_code" => "country_code-input",
368
+ "created_at" => "created_at-input",
369
+ "id" => "id-input",
370
+ "links" => "links-input",
371
+ "name" => "name-input",
372
+ "postal_code" => "postal_code-input",
373
+ "region" => "region-input",
374
+ }
375
+ }.to_json,
376
+ :headers => {'Content-Type' => 'application/json'}
377
+ )
378
+ end
379
+
380
+ it "updates and returns the resource" do
381
+ expect(put_update_response).to be_a(GoCardlessPro::Resources::Creditor)
382
+ expect(stub).to have_been_requested
383
+ end
384
+ end
385
+ end
386
+
387
+
388
+ end
@@ -0,0 +1,452 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Services::CustomerBankAccountsService do
4
+ let(:client) do
5
+ GoCardlessPro::Client.new(
6
+ access_token: "SECRET_TOKEN"
7
+ )
8
+ end
9
+
10
+
11
+
12
+
13
+
14
+
15
+ describe "#create" do
16
+ subject(:post_create_response) { client.customer_bank_accounts.create(params: new_resource) }
17
+ context "with a valid request" do
18
+ let(:new_resource) do
19
+ {
20
+
21
+ "account_holder_name" => "account_holder_name-input",
22
+ "account_number_ending" => "account_number_ending-input",
23
+ "bank_name" => "bank_name-input",
24
+ "country_code" => "country_code-input",
25
+ "created_at" => "created_at-input",
26
+ "currency" => "currency-input",
27
+ "enabled" => "enabled-input",
28
+ "id" => "id-input",
29
+ "links" => "links-input",
30
+ "metadata" => "metadata-input",
31
+ }
32
+ end
33
+
34
+ before do
35
+ stub_request(:post, /.*api.gocardless.com\/customer_bank_accounts/).
36
+ with(
37
+ body: {
38
+ customer_bank_accounts: {
39
+
40
+ "account_holder_name" => "account_holder_name-input",
41
+ "account_number_ending" => "account_number_ending-input",
42
+ "bank_name" => "bank_name-input",
43
+ "country_code" => "country_code-input",
44
+ "created_at" => "created_at-input",
45
+ "currency" => "currency-input",
46
+ "enabled" => "enabled-input",
47
+ "id" => "id-input",
48
+ "links" => "links-input",
49
+ "metadata" => "metadata-input",
50
+ }
51
+ }
52
+ ).
53
+ to_return(
54
+ body: {
55
+ customer_bank_accounts: {
56
+
57
+ "account_holder_name" => "account_holder_name-input",
58
+ "account_number_ending" => "account_number_ending-input",
59
+ "bank_name" => "bank_name-input",
60
+ "country_code" => "country_code-input",
61
+ "created_at" => "created_at-input",
62
+ "currency" => "currency-input",
63
+ "enabled" => "enabled-input",
64
+ "id" => "id-input",
65
+ "links" => "links-input",
66
+ "metadata" => "metadata-input",
67
+ }
68
+ }.to_json,
69
+ :headers => {'Content-Type' => 'application/json'}
70
+ )
71
+ end
72
+
73
+ it "creates and returns the resource" do
74
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
75
+ end
76
+ end
77
+
78
+ context "with a request that returns a validation error" do
79
+ let(:new_resource) { {} }
80
+
81
+ before do
82
+ stub_request(:post, /.*api.gocardless.com\/customer_bank_accounts/).to_return(
83
+ body: {
84
+ error: {
85
+ type: 'validation_failed',
86
+ code: 422,
87
+ errors: [
88
+ { message: 'test error message', field: 'test_field' }
89
+ ]
90
+ }
91
+ }.to_json,
92
+ headers: {'Content-Type' => 'application/json'},
93
+ status: 422
94
+ )
95
+ end
96
+
97
+ it "throws the correct error" do
98
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
99
+ end
100
+ end
101
+ end
102
+
103
+
104
+
105
+
106
+
107
+ describe "#list" do
108
+ describe "with no filters" do
109
+ subject(:get_list_response) { client.customer_bank_accounts.list }
110
+
111
+ before do
112
+ stub_request(:get, /.*api.gocardless.com\/customer_bank_accounts/).to_return(
113
+ body: {
114
+ customer_bank_accounts: [{
115
+
116
+ "account_holder_name" => "account_holder_name-input",
117
+ "account_number_ending" => "account_number_ending-input",
118
+ "bank_name" => "bank_name-input",
119
+ "country_code" => "country_code-input",
120
+ "created_at" => "created_at-input",
121
+ "currency" => "currency-input",
122
+ "enabled" => "enabled-input",
123
+ "id" => "id-input",
124
+ "links" => "links-input",
125
+ "metadata" => "metadata-input",
126
+ }],
127
+ meta: {
128
+ cursors: {
129
+ before: nil,
130
+ after: "ABC123"
131
+ }
132
+ }
133
+ }.to_json,
134
+ :headers => {'Content-Type' => 'application/json'}
135
+ )
136
+ end
137
+
138
+ it "wraps each item in the resource class" do
139
+ expect(get_list_response.records.map { |x| x.class }.uniq.first).to eq(GoCardlessPro::Resources::CustomerBankAccount)
140
+
141
+
142
+
143
+ expect(get_list_response.records.first.account_holder_name).to eq("account_holder_name-input")
144
+
145
+
146
+
147
+ expect(get_list_response.records.first.account_number_ending).to eq("account_number_ending-input")
148
+
149
+
150
+
151
+ expect(get_list_response.records.first.bank_name).to eq("bank_name-input")
152
+
153
+
154
+
155
+ expect(get_list_response.records.first.country_code).to eq("country_code-input")
156
+
157
+
158
+
159
+ expect(get_list_response.records.first.created_at).to eq("created_at-input")
160
+
161
+
162
+
163
+ expect(get_list_response.records.first.currency).to eq("currency-input")
164
+
165
+
166
+
167
+ expect(get_list_response.records.first.enabled).to eq("enabled-input")
168
+
169
+
170
+
171
+ expect(get_list_response.records.first.id).to eq("id-input")
172
+
173
+
174
+
175
+
176
+
177
+ expect(get_list_response.records.first.metadata).to eq("metadata-input")
178
+
179
+
180
+ end
181
+
182
+ it "exposes the cursors for before and after" do
183
+ expect(get_list_response.before).to eq(nil)
184
+ expect(get_list_response.after).to eq("ABC123")
185
+ end
186
+ end
187
+ end
188
+
189
+ describe "#all" do
190
+ let!(:first_response_stub) do
191
+ stub_request(:get, /.*api.gocardless.com\/customer_bank_accounts$/).to_return(
192
+ body: {
193
+ customer_bank_accounts: [{
194
+
195
+ "account_holder_name" => "account_holder_name-input",
196
+ "account_number_ending" => "account_number_ending-input",
197
+ "bank_name" => "bank_name-input",
198
+ "country_code" => "country_code-input",
199
+ "created_at" => "created_at-input",
200
+ "currency" => "currency-input",
201
+ "enabled" => "enabled-input",
202
+ "id" => "id-input",
203
+ "links" => "links-input",
204
+ "metadata" => "metadata-input",
205
+ }],
206
+ meta: {
207
+ cursors: { after: 'AB345' },
208
+ limit: 1
209
+ }
210
+ }.to_json,
211
+ :headers => {'Content-Type' => 'application/json'}
212
+ )
213
+ end
214
+
215
+ let!(:second_response_stub) do
216
+ stub_request(:get, /.*api.gocardless.com\/customer_bank_accounts\?after=AB345/).to_return(
217
+ body: {
218
+ customer_bank_accounts: [{
219
+
220
+ "account_holder_name" => "account_holder_name-input",
221
+ "account_number_ending" => "account_number_ending-input",
222
+ "bank_name" => "bank_name-input",
223
+ "country_code" => "country_code-input",
224
+ "created_at" => "created_at-input",
225
+ "currency" => "currency-input",
226
+ "enabled" => "enabled-input",
227
+ "id" => "id-input",
228
+ "links" => "links-input",
229
+ "metadata" => "metadata-input",
230
+ }],
231
+ meta: {
232
+ limit: 2,
233
+ cursors: {}
234
+ }
235
+ }.to_json,
236
+ :headers => {'Content-Type' => 'application/json'}
237
+ )
238
+ end
239
+
240
+ it "automatically makes the extra requests" do
241
+ expect(client.customer_bank_accounts.all.to_a.length).to eq(2)
242
+ expect(first_response_stub).to have_been_requested
243
+ expect(second_response_stub).to have_been_requested
244
+ end
245
+ end
246
+
247
+
248
+
249
+
250
+
251
+
252
+ describe "#get" do
253
+ let(:id) { "ID123" }
254
+
255
+ subject(:get_response) { client.customer_bank_accounts.get(id) }
256
+
257
+ context "passing in a custom header" do
258
+ let!(:stub) do
259
+ stub_request(:get, /.*api.gocardless.com\/customer_bank_accounts\/ID123/)
260
+ .with(headers: { 'Foo' => 'Bar' })
261
+ .to_return(
262
+ body: {
263
+ customer_bank_accounts: {
264
+
265
+ "account_holder_name" => "account_holder_name-input",
266
+ "account_number_ending" => "account_number_ending-input",
267
+ "bank_name" => "bank_name-input",
268
+ "country_code" => "country_code-input",
269
+ "created_at" => "created_at-input",
270
+ "currency" => "currency-input",
271
+ "enabled" => "enabled-input",
272
+ "id" => "id-input",
273
+ "links" => "links-input",
274
+ "metadata" => "metadata-input",
275
+ }
276
+ }.to_json,
277
+ :headers => {'Content-Type' => 'application/json'}
278
+ )
279
+ end
280
+
281
+ subject(:get_response) do
282
+ client.customer_bank_accounts.get(id, headers: {
283
+ 'Foo' => 'Bar'
284
+ })
285
+ end
286
+
287
+ it "includes the header" do
288
+ get_response
289
+ expect(stub).to have_been_requested
290
+ end
291
+ end
292
+
293
+ context "when there is a customer_bank_account to return" do
294
+ before do
295
+ stub_request(:get, /.*api.gocardless.com\/customer_bank_accounts\/ID123/).to_return(
296
+ body: {
297
+ customer_bank_accounts: {
298
+
299
+ "account_holder_name" => "account_holder_name-input",
300
+ "account_number_ending" => "account_number_ending-input",
301
+ "bank_name" => "bank_name-input",
302
+ "country_code" => "country_code-input",
303
+ "created_at" => "created_at-input",
304
+ "currency" => "currency-input",
305
+ "enabled" => "enabled-input",
306
+ "id" => "id-input",
307
+ "links" => "links-input",
308
+ "metadata" => "metadata-input",
309
+ }
310
+ }.to_json,
311
+ :headers => {'Content-Type' => 'application/json'}
312
+ )
313
+ end
314
+
315
+ it "wraps the response in a resource" do
316
+ expect(get_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
317
+ end
318
+ end
319
+
320
+ context "when nothing is returned" do
321
+ before do
322
+ stub_request(:get, /.*api.gocardless.com\/customer_bank_accounts\/ID123/).to_return(
323
+ body: "",
324
+ headers: { 'Content-Type' => 'application/json' }
325
+ )
326
+ end
327
+
328
+ it "returns nil" do
329
+ expect(get_response).to be_nil
330
+ end
331
+ end
332
+ end
333
+
334
+
335
+
336
+
337
+
338
+
339
+ describe "#update" do
340
+ subject(:put_update_response) { client.customer_bank_accounts.update(id, params: update_params) }
341
+ let(:id) { "ABC123" }
342
+
343
+ context "with a valid request" do
344
+ let(:update_params) { { "hello" => "world" } }
345
+
346
+ let!(:stub) do
347
+ stub_request(:put, /.*api.gocardless.com\/customer_bank_accounts\/ABC123/).to_return(
348
+ body: {
349
+ customer_bank_accounts: {
350
+
351
+ "account_holder_name" => "account_holder_name-input",
352
+ "account_number_ending" => "account_number_ending-input",
353
+ "bank_name" => "bank_name-input",
354
+ "country_code" => "country_code-input",
355
+ "created_at" => "created_at-input",
356
+ "currency" => "currency-input",
357
+ "enabled" => "enabled-input",
358
+ "id" => "id-input",
359
+ "links" => "links-input",
360
+ "metadata" => "metadata-input",
361
+ }
362
+ }.to_json,
363
+ :headers => {'Content-Type' => 'application/json'}
364
+ )
365
+ end
366
+
367
+ it "updates and returns the resource" do
368
+ expect(put_update_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
369
+ expect(stub).to have_been_requested
370
+ end
371
+ end
372
+ end
373
+
374
+
375
+
376
+
377
+
378
+ describe "#disable" do
379
+
380
+
381
+ subject(:post_response) { client.customer_bank_accounts.disable(resource_id) }
382
+
383
+ let(:resource_id) { "ABC123" }
384
+
385
+ let!(:stub) do
386
+ # /customer_bank_accounts/%v/actions/disable
387
+ stub_url = "/customer_bank_accounts/:identity/actions/disable".gsub(':identity', resource_id)
388
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
389
+ body: {
390
+ customer_bank_accounts: {
391
+
392
+ "account_holder_name" => "account_holder_name-input",
393
+ "account_number_ending" => "account_number_ending-input",
394
+ "bank_name" => "bank_name-input",
395
+ "country_code" => "country_code-input",
396
+ "created_at" => "created_at-input",
397
+ "currency" => "currency-input",
398
+ "enabled" => "enabled-input",
399
+ "id" => "id-input",
400
+ "links" => "links-input",
401
+ "metadata" => "metadata-input",
402
+ }
403
+ }.to_json,
404
+ headers: {'Content-Type' => 'application/json'},
405
+ )
406
+ end
407
+
408
+ it "wraps the response and calls the right endpoint" do
409
+ expect(post_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
410
+
411
+ expect(stub).to have_been_requested
412
+ end
413
+
414
+ context "when the request needs a body and custom header" do
415
+
416
+ let(:body) { { foo: 'bar' } }
417
+ let(:headers) { { 'Foo' => 'Bar' } }
418
+ subject(:post_response) { client.customer_bank_accounts.disable(resource_id, body, headers) }
419
+
420
+ let(:resource_id) { "ABC123" }
421
+
422
+ let!(:stub) do
423
+ # /customer_bank_accounts/%v/actions/disable
424
+ stub_url = "/customer_bank_accounts/:identity/actions/disable".gsub(':identity', resource_id)
425
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
426
+ with(
427
+ body: { foo: 'bar' },
428
+ headers: { 'Foo' => 'Bar' }
429
+ ).to_return(
430
+ body: {
431
+ customer_bank_accounts: {
432
+
433
+ "account_holder_name" => "account_holder_name-input",
434
+ "account_number_ending" => "account_number_ending-input",
435
+ "bank_name" => "bank_name-input",
436
+ "country_code" => "country_code-input",
437
+ "created_at" => "created_at-input",
438
+ "currency" => "currency-input",
439
+ "enabled" => "enabled-input",
440
+ "id" => "id-input",
441
+ "links" => "links-input",
442
+ "metadata" => "metadata-input",
443
+ }
444
+ }.to_json,
445
+ headers: {'Content-Type' => 'application/json'},
446
+ )
447
+ end
448
+ end
449
+ end
450
+
451
+
452
+ end