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,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:
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
34
|
-
|
35
|
-
with(
|
28
|
+
before do
|
29
|
+
stub_request(:post, %r{.*api.gocardless.com/mandates})
|
30
|
+
.with(
|
36
31
|
body: {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
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
|
-
|
177
|
-
let
|
178
|
-
|
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
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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
|
-
:
|
87
|
+
headers: { 'Content-Type' => 'application/json' },
|
88
|
+
status: 422
|
197
89
|
)
|
198
90
|
end
|
199
91
|
|
200
|
-
|
201
|
-
|
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
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
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
|
-
|
216
|
-
|
118
|
+
cursors: {
|
119
|
+
before: nil,
|
120
|
+
after: 'ABC123'
|
121
|
+
}
|
217
122
|
}
|
218
123
|
}.to_json,
|
219
|
-
:
|
124
|
+
headers: { 'Content-Type' => 'application/json' }
|
220
125
|
)
|
221
126
|
end
|
222
127
|
|
223
|
-
it
|
224
|
-
expect(
|
225
|
-
|
226
|
-
expect(
|
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
|
-
|
236
|
-
|
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
|
-
|
213
|
+
describe '#get' do
|
214
|
+
let(:id) { 'ID123' }
|
239
215
|
|
240
|
-
|
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
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
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
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
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
|
-
:
|
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
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
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
|
-
|
311
|
-
|
312
|
-
|
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
|
-
|
322
|
-
|
323
|
-
|
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
|
-
|
326
|
-
|
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
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
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
|
-
|
349
|
-
|
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
|
-
|
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
|
-
|
368
|
-
|
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
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
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
|
388
|
-
expect(
|
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
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
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
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
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
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
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
|
-
|
461
|
-
|
426
|
+
it 'wraps the response and calls the right endpoint' do
|
427
|
+
expect(post_response).to be_a(GoCardlessPro::Resources::Mandate)
|
462
428
|
|
463
|
-
|
464
|
-
|
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
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
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
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
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
|