gocardless_pro 0.3.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.
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,97 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Resources::RedirectFlow do
4
+ describe "initialising" do
5
+ let(:data) do
6
+ {
7
+
8
+
9
+ "created_at" => "created_at-input",
10
+
11
+
12
+
13
+ "description" => "description-input",
14
+
15
+
16
+
17
+ "id" => "id-input",
18
+
19
+
20
+
21
+ "links" => {
22
+
23
+ "creditor" => "creditor-input",
24
+
25
+ "mandate" => "mandate-input",
26
+
27
+ },
28
+
29
+
30
+
31
+ "redirect_url" => "redirect_url-input",
32
+
33
+
34
+
35
+ "scheme" => "scheme-input",
36
+
37
+
38
+
39
+ "session_token" => "session_token-input",
40
+
41
+
42
+
43
+ "success_redirect_url" => "success_redirect_url-input",
44
+
45
+
46
+ }
47
+ end
48
+
49
+ it "can be initialized from an uneveloped response" do
50
+ resource = described_class.new(data)
51
+
52
+
53
+ expect(resource.created_at).to eq("created_at-input")
54
+
55
+
56
+
57
+ expect(resource.description).to eq("description-input")
58
+
59
+
60
+
61
+ expect(resource.id).to eq("id-input")
62
+
63
+
64
+
65
+
66
+ expect(resource.links.creditor).to eq("creditor-input")
67
+
68
+ expect(resource.links.mandate).to eq("mandate-input")
69
+
70
+
71
+
72
+
73
+ expect(resource.redirect_url).to eq("redirect_url-input")
74
+
75
+
76
+
77
+ expect(resource.scheme).to eq("scheme-input")
78
+
79
+
80
+
81
+ expect(resource.session_token).to eq("session_token-input")
82
+
83
+
84
+
85
+ expect(resource.success_redirect_url).to eq("success_redirect_url-input")
86
+
87
+
88
+ end
89
+
90
+ describe "#to_h" do
91
+ it "returns a hash representing the resource" do
92
+ expect(described_class.new(data).to_h).to eq(data)
93
+ end
94
+ end
95
+ end
96
+ end
97
+
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Resources::Refund do
4
+ describe "initialising" do
5
+ let(:data) do
6
+ {
7
+
8
+
9
+ "amount" => "amount-input",
10
+
11
+
12
+
13
+ "created_at" => "created_at-input",
14
+
15
+
16
+
17
+ "currency" => "currency-input",
18
+
19
+
20
+
21
+ "id" => "id-input",
22
+
23
+
24
+
25
+ "links" => {
26
+
27
+ "payment" => "payment-input",
28
+
29
+ },
30
+
31
+
32
+
33
+ "metadata" => "metadata-input",
34
+
35
+
36
+ }
37
+ end
38
+
39
+ it "can be initialized from an uneveloped response" do
40
+ resource = described_class.new(data)
41
+
42
+
43
+ expect(resource.amount).to eq("amount-input")
44
+
45
+
46
+
47
+ expect(resource.created_at).to eq("created_at-input")
48
+
49
+
50
+
51
+ expect(resource.currency).to eq("currency-input")
52
+
53
+
54
+
55
+ expect(resource.id).to eq("id-input")
56
+
57
+
58
+
59
+
60
+ expect(resource.links.payment).to eq("payment-input")
61
+
62
+
63
+
64
+
65
+ expect(resource.metadata).to eq("metadata-input")
66
+
67
+
68
+ end
69
+
70
+ describe "#to_h" do
71
+ it "returns a hash representing the resource" do
72
+ expect(described_class.new(data).to_h).to eq(data)
73
+ end
74
+ end
75
+ end
76
+ end
77
+
@@ -0,0 +1,165 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Resources::Subscription do
4
+ describe "initialising" do
5
+ let(:data) do
6
+ {
7
+
8
+
9
+ "amount" => "amount-input",
10
+
11
+
12
+
13
+ "count" => "count-input",
14
+
15
+
16
+
17
+ "created_at" => "created_at-input",
18
+
19
+
20
+
21
+ "currency" => "currency-input",
22
+
23
+
24
+
25
+ "day_of_month" => "day_of_month-input",
26
+
27
+
28
+
29
+ "end_at" => "end_at-input",
30
+
31
+
32
+
33
+ "id" => "id-input",
34
+
35
+
36
+
37
+ "interval" => "interval-input",
38
+
39
+
40
+
41
+ "interval_unit" => "interval_unit-input",
42
+
43
+
44
+
45
+ "links" => {
46
+
47
+ "mandate" => "mandate-input",
48
+
49
+ },
50
+
51
+
52
+
53
+ "metadata" => "metadata-input",
54
+
55
+
56
+
57
+ "month" => "month-input",
58
+
59
+
60
+
61
+ "name" => "name-input",
62
+
63
+
64
+
65
+ "payment_reference" => "payment_reference-input",
66
+
67
+
68
+
69
+ "start_at" => "start_at-input",
70
+
71
+
72
+
73
+ "status" => "status-input",
74
+
75
+
76
+
77
+ "upcoming_payments" => "upcoming_payments-input",
78
+
79
+
80
+ }
81
+ end
82
+
83
+ it "can be initialized from an uneveloped response" do
84
+ resource = described_class.new(data)
85
+
86
+
87
+ expect(resource.amount).to eq("amount-input")
88
+
89
+
90
+
91
+ expect(resource.count).to eq("count-input")
92
+
93
+
94
+
95
+ expect(resource.created_at).to eq("created_at-input")
96
+
97
+
98
+
99
+ expect(resource.currency).to eq("currency-input")
100
+
101
+
102
+
103
+ expect(resource.day_of_month).to eq("day_of_month-input")
104
+
105
+
106
+
107
+ expect(resource.end_at).to eq("end_at-input")
108
+
109
+
110
+
111
+ expect(resource.id).to eq("id-input")
112
+
113
+
114
+
115
+ expect(resource.interval).to eq("interval-input")
116
+
117
+
118
+
119
+ expect(resource.interval_unit).to eq("interval_unit-input")
120
+
121
+
122
+
123
+
124
+ expect(resource.links.mandate).to eq("mandate-input")
125
+
126
+
127
+
128
+
129
+ expect(resource.metadata).to eq("metadata-input")
130
+
131
+
132
+
133
+ expect(resource.month).to eq("month-input")
134
+
135
+
136
+
137
+ expect(resource.name).to eq("name-input")
138
+
139
+
140
+
141
+ expect(resource.payment_reference).to eq("payment_reference-input")
142
+
143
+
144
+
145
+ expect(resource.start_at).to eq("start_at-input")
146
+
147
+
148
+
149
+ expect(resource.status).to eq("status-input")
150
+
151
+
152
+
153
+ expect(resource.upcoming_payments).to eq("upcoming_payments-input")
154
+
155
+
156
+ end
157
+
158
+ describe "#to_h" do
159
+ it "returns a hash representing the resource" do
160
+ expect(described_class.new(data).to_h).to eq(data)
161
+ end
162
+ end
163
+ end
164
+ end
165
+
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Response do
4
+
5
+ subject(:response) { described_class.new(raw_response) }
6
+ let(:default_headers) do
7
+ { 'Content-Type' => 'application/json' }
8
+ end
9
+
10
+ context "when the response is not an error" do
11
+ let(:raw_response) do
12
+ double("response",
13
+ headers: default_headers,
14
+ status: 200,
15
+ body: { customers: [] }.to_json
16
+ )
17
+ end
18
+
19
+ it "returns the body parsed into a hash" do
20
+ expect(response.body).to eq("customers" => [])
21
+ end
22
+ end
23
+
24
+ context "when the response is empty" do
25
+ let(:raw_response) do
26
+ double("response", headers: default_headers, status: 204, body: '')
27
+ end
28
+
29
+ it "returns nil" do
30
+ expect(response.body).to be_nil
31
+ end
32
+ end
33
+
34
+ context "when the resonse is a validation error" do
35
+ let(:raw_response) do
36
+ double("response",
37
+ headers: default_headers,
38
+ status: 400,
39
+ body: { error: { type: 'validation_failed' } }.to_json
40
+ )
41
+ end
42
+
43
+ it "raises a ValidationError" do
44
+ expect { response.body }.to raise_error(GoCardlessPro::ValidationError)
45
+ end
46
+ end
47
+
48
+ context "when the resonse is a gocardless error" do
49
+ let(:raw_response) do
50
+ double("response",
51
+ headers: default_headers,
52
+ status: 400,
53
+ body: { error: { type: 'gocardless' } }.to_json
54
+ )
55
+ end
56
+
57
+ it "raises a ValidationError" do
58
+ expect { response.body }.to raise_error(GoCardlessPro::GoCardlessError)
59
+ end
60
+ end
61
+
62
+ context "when the resonse is an invalid api usage error" do
63
+ let(:raw_response) do
64
+ double("response",
65
+ headers: default_headers,
66
+ status: 400,
67
+ body: { error: { type: 'invalid_api_usage' } }.to_json
68
+ )
69
+ end
70
+
71
+ it "raises a ValidationError" do
72
+ expect { response.body }.to raise_error(GoCardlessPro::InvalidApiUsageError)
73
+ end
74
+ end
75
+
76
+ context "when the resonse is an invalid invalid state error" do
77
+ let(:raw_response) do
78
+ double("response",
79
+ headers: default_headers,
80
+ status: 400,
81
+ body: { error: { type: 'invalid_state' } }.to_json
82
+ )
83
+ end
84
+
85
+ it "raises a ValidationError" do
86
+ expect { response.body }.to raise_error(GoCardlessPro::InvalidStateError)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,413 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Services::CreditorBankAccountsService 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.creditor_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\/creditor_bank_accounts/).
36
+ with(
37
+ body: {
38
+ creditor_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
+ creditor_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::CreditorBankAccount)
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\/creditor_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.creditor_bank_accounts.list }
110
+
111
+ before do
112
+ stub_request(:get, /.*api.gocardless.com\/creditor_bank_accounts/).to_return(
113
+ body: {
114
+ creditor_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::CreditorBankAccount)
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\/creditor_bank_accounts$/).to_return(
192
+ body: {
193
+ creditor_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\/creditor_bank_accounts\?after=AB345/).to_return(
217
+ body: {
218
+ creditor_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.creditor_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.creditor_bank_accounts.get(id) }
256
+
257
+ context "passing in a custom header" do
258
+ let!(:stub) do
259
+ stub_request(:get, /.*api.gocardless.com\/creditor_bank_accounts\/ID123/)
260
+ .with(headers: { 'Foo' => 'Bar' })
261
+ .to_return(
262
+ body: {
263
+ creditor_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.creditor_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 creditor_bank_account to return" do
294
+ before do
295
+ stub_request(:get, /.*api.gocardless.com\/creditor_bank_accounts\/ID123/).to_return(
296
+ body: {
297
+ creditor_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::CreditorBankAccount)
317
+ end
318
+ end
319
+
320
+ context "when nothing is returned" do
321
+ before do
322
+ stub_request(:get, /.*api.gocardless.com\/creditor_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 "#disable" do
340
+
341
+
342
+ subject(:post_response) { client.creditor_bank_accounts.disable(resource_id) }
343
+
344
+ let(:resource_id) { "ABC123" }
345
+
346
+ let!(:stub) do
347
+ # /creditor_bank_accounts/%v/actions/disable
348
+ stub_url = "/creditor_bank_accounts/:identity/actions/disable".gsub(':identity', resource_id)
349
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
350
+ body: {
351
+ creditor_bank_accounts: {
352
+
353
+ "account_holder_name" => "account_holder_name-input",
354
+ "account_number_ending" => "account_number_ending-input",
355
+ "bank_name" => "bank_name-input",
356
+ "country_code" => "country_code-input",
357
+ "created_at" => "created_at-input",
358
+ "currency" => "currency-input",
359
+ "enabled" => "enabled-input",
360
+ "id" => "id-input",
361
+ "links" => "links-input",
362
+ "metadata" => "metadata-input",
363
+ }
364
+ }.to_json,
365
+ headers: {'Content-Type' => 'application/json'},
366
+ )
367
+ end
368
+
369
+ it "wraps the response and calls the right endpoint" do
370
+ expect(post_response).to be_a(GoCardlessPro::Resources::CreditorBankAccount)
371
+
372
+ expect(stub).to have_been_requested
373
+ end
374
+
375
+ context "when the request needs a body and custom header" do
376
+
377
+ let(:body) { { foo: 'bar' } }
378
+ let(:headers) { { 'Foo' => 'Bar' } }
379
+ subject(:post_response) { client.creditor_bank_accounts.disable(resource_id, body, headers) }
380
+
381
+ let(:resource_id) { "ABC123" }
382
+
383
+ let!(:stub) do
384
+ # /creditor_bank_accounts/%v/actions/disable
385
+ stub_url = "/creditor_bank_accounts/:identity/actions/disable".gsub(':identity', resource_id)
386
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
387
+ with(
388
+ body: { foo: 'bar' },
389
+ headers: { 'Foo' => 'Bar' }
390
+ ).to_return(
391
+ body: {
392
+ creditor_bank_accounts: {
393
+
394
+ "account_holder_name" => "account_holder_name-input",
395
+ "account_number_ending" => "account_number_ending-input",
396
+ "bank_name" => "bank_name-input",
397
+ "country_code" => "country_code-input",
398
+ "created_at" => "created_at-input",
399
+ "currency" => "currency-input",
400
+ "enabled" => "enabled-input",
401
+ "id" => "id-input",
402
+ "links" => "links-input",
403
+ "metadata" => "metadata-input",
404
+ }
405
+ }.to_json,
406
+ headers: {'Content-Type' => 'application/json'},
407
+ )
408
+ end
409
+ end
410
+ end
411
+
412
+
413
+ end