gocardless_pro 1.0.3 → 1.0.4

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