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