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