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