gocardless_pro 2.41.0 → 2.41.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gocardless_pro/api_service.rb +4 -5
- data/lib/gocardless_pro/client.rb +3 -3
- data/lib/gocardless_pro/error/invalid_state_error.rb +1 -0
- data/lib/gocardless_pro/error.rb +1 -0
- data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +7 -9
- data/lib/gocardless_pro/request.rb +5 -7
- data/lib/gocardless_pro/resources/bank_authorisation.rb +0 -2
- data/lib/gocardless_pro/resources/bank_details_lookup.rb +0 -2
- data/lib/gocardless_pro/resources/billing_request.rb +0 -2
- data/lib/gocardless_pro/resources/billing_request_flow.rb +0 -2
- data/lib/gocardless_pro/resources/billing_request_template.rb +0 -2
- data/lib/gocardless_pro/resources/block.rb +0 -2
- data/lib/gocardless_pro/resources/creditor.rb +0 -2
- data/lib/gocardless_pro/resources/creditor_bank_account.rb +0 -2
- data/lib/gocardless_pro/resources/currency_exchange_rate.rb +0 -2
- data/lib/gocardless_pro/resources/customer.rb +0 -2
- data/lib/gocardless_pro/resources/customer_bank_account.rb +0 -2
- data/lib/gocardless_pro/resources/customer_notification.rb +0 -2
- data/lib/gocardless_pro/resources/event.rb +0 -2
- data/lib/gocardless_pro/resources/instalment_schedule.rb +0 -2
- data/lib/gocardless_pro/resources/institution.rb +0 -2
- data/lib/gocardless_pro/resources/mandate.rb +0 -2
- data/lib/gocardless_pro/resources/mandate_import.rb +0 -2
- data/lib/gocardless_pro/resources/mandate_import_entry.rb +0 -2
- data/lib/gocardless_pro/resources/mandate_pdf.rb +0 -2
- data/lib/gocardless_pro/resources/payer_authorisation.rb +0 -2
- data/lib/gocardless_pro/resources/payment.rb +0 -2
- data/lib/gocardless_pro/resources/payout.rb +0 -2
- data/lib/gocardless_pro/resources/payout_item.rb +0 -2
- data/lib/gocardless_pro/resources/redirect_flow.rb +0 -2
- data/lib/gocardless_pro/resources/refund.rb +0 -2
- data/lib/gocardless_pro/resources/scenario_simulator.rb +0 -2
- data/lib/gocardless_pro/resources/scheme_identifier.rb +0 -2
- data/lib/gocardless_pro/resources/subscription.rb +0 -2
- data/lib/gocardless_pro/resources/tax_rate.rb +0 -2
- data/lib/gocardless_pro/resources/verification_detail.rb +0 -2
- data/lib/gocardless_pro/resources/webhook.rb +0 -2
- data/lib/gocardless_pro/services/bank_authorisations_service.rb +3 -1
- data/lib/gocardless_pro/services/billing_request_flows_service.rb +3 -1
- data/lib/gocardless_pro/services/billing_request_templates_service.rb +6 -2
- data/lib/gocardless_pro/services/billing_requests_service.rb +27 -9
- data/lib/gocardless_pro/services/blocks_service.rb +9 -3
- data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +6 -2
- data/lib/gocardless_pro/services/creditors_service.rb +9 -3
- data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +9 -3
- data/lib/gocardless_pro/services/customer_notifications_service.rb +3 -1
- data/lib/gocardless_pro/services/customers_service.rb +9 -3
- data/lib/gocardless_pro/services/events_service.rb +3 -1
- data/lib/gocardless_pro/services/instalment_schedules_service.rb +9 -3
- data/lib/gocardless_pro/services/mandate_imports_service.rb +9 -3
- data/lib/gocardless_pro/services/mandates_service.rb +12 -4
- data/lib/gocardless_pro/services/payer_authorisations_service.rb +12 -4
- data/lib/gocardless_pro/services/payments_service.rb +12 -4
- data/lib/gocardless_pro/services/payouts_service.rb +6 -2
- data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -2
- data/lib/gocardless_pro/services/refunds_service.rb +6 -2
- data/lib/gocardless_pro/services/scenario_simulators_service.rb +3 -1
- data/lib/gocardless_pro/services/scheme_identifiers_service.rb +3 -1
- data/lib/gocardless_pro/services/subscriptions_service.rb +15 -5
- data/lib/gocardless_pro/services/tax_rates_service.rb +3 -1
- data/lib/gocardless_pro/services/webhooks_service.rb +6 -2
- data/lib/gocardless_pro/version.rb +1 -2
- data/lib/gocardless_pro/webhook.rb +5 -4
- data/lib/gocardless_pro.rb +2 -4
- metadata +5 -195
- data/.github/workflows/tests.yml +0 -40
- data/.gitignore +0 -1
- data/.rspec +0 -2
- data/.rubocop.yml +0 -5
- data/.travis.yml +0 -10
- data/LICENSE.txt +0 -22
- data/demo.rb +0 -9
- data/gocardless_pro.gemspec +0 -39
- data/spec/api_response_spec.rb +0 -28
- data/spec/api_service_spec.rb +0 -188
- data/spec/client_spec.rb +0 -19
- data/spec/error_spec.rb +0 -53
- data/spec/middlewares/raise_gocardless_errors_spec.rb +0 -127
- data/spec/resources/bank_authorisation_spec.rb +0 -259
- data/spec/resources/bank_details_lookup_spec.rb +0 -121
- data/spec/resources/billing_request_flow_spec.rb +0 -257
- data/spec/resources/billing_request_spec.rb +0 -962
- data/spec/resources/billing_request_template_spec.rb +0 -515
- data/spec/resources/block_spec.rb +0 -577
- data/spec/resources/creditor_bank_account_spec.rb +0 -472
- data/spec/resources/creditor_spec.rb +0 -659
- data/spec/resources/currency_exchange_rate_spec.rb +0 -103
- data/spec/resources/customer_bank_account_spec.rb +0 -509
- data/spec/resources/customer_notification_spec.rb +0 -75
- data/spec/resources/customer_spec.rb +0 -616
- data/spec/resources/event_spec.rb +0 -210
- data/spec/resources/instalment_schedule_spec.rb +0 -636
- data/spec/resources/institution_spec.rb +0 -113
- data/spec/resources/mandate_import_entry_spec.rb +0 -206
- data/spec/resources/mandate_import_spec.rb +0 -344
- data/spec/resources/mandate_pdf_spec.rb +0 -117
- data/spec/resources/mandate_spec.rb +0 -600
- data/spec/resources/payer_authorisation_spec.rb +0 -422
- data/spec/resources/payment_spec.rb +0 -617
- data/spec/resources/payout_item_spec.rb +0 -101
- data/spec/resources/payout_spec.rb +0 -284
- data/spec/resources/redirect_flow_spec.rb +0 -347
- data/spec/resources/refund_spec.rb +0 -409
- data/spec/resources/scenario_simulator_spec.rb +0 -65
- data/spec/resources/scheme_identifier_spec.rb +0 -484
- data/spec/resources/subscription_spec.rb +0 -828
- data/spec/resources/tax_rate_spec.rb +0 -198
- data/spec/resources/verification_detail_spec.rb +0 -145
- data/spec/resources/webhook_spec.rb +0 -325
- data/spec/response_spec.rb +0 -34
- data/spec/services/bank_authorisations_service_spec.rb +0 -353
- data/spec/services/bank_details_lookups_service_spec.rb +0 -144
- data/spec/services/billing_request_flows_service_spec.rb +0 -291
- data/spec/services/billing_request_templates_service_spec.rb +0 -806
- data/spec/services/billing_requests_service_spec.rb +0 -1288
- data/spec/services/blocks_service_spec.rb +0 -840
- data/spec/services/creditor_bank_accounts_service_spec.rb +0 -725
- data/spec/services/creditors_service_spec.rb +0 -977
- data/spec/services/currency_exchange_rates_service_spec.rb +0 -223
- data/spec/services/customer_bank_accounts_service_spec.rb +0 -787
- data/spec/services/customer_notifications_service_spec.rb +0 -86
- data/spec/services/customers_service_spec.rb +0 -922
- data/spec/services/events_service_spec.rb +0 -401
- data/spec/services/instalment_schedules_service_spec.rb +0 -945
- data/spec/services/institutions_service_spec.rb +0 -241
- data/spec/services/mandate_import_entries_service_spec.rb +0 -345
- data/spec/services/mandate_imports_service_spec.rb +0 -460
- data/spec/services/mandate_pdfs_service_spec.rb +0 -140
- data/spec/services/mandates_service_spec.rb +0 -893
- data/spec/services/payer_authorisations_service_spec.rb +0 -563
- data/spec/services/payments_service_spec.rb +0 -914
- data/spec/services/payout_items_service_spec.rb +0 -221
- data/spec/services/payouts_service_spec.rb +0 -520
- data/spec/services/redirect_flows_service_spec.rb +0 -452
- data/spec/services/refunds_service_spec.rb +0 -668
- data/spec/services/scenario_simulators_service_spec.rb +0 -76
- data/spec/services/scheme_identifiers_service_spec.rb +0 -754
- data/spec/services/subscriptions_service_spec.rb +0 -1164
- data/spec/services/tax_rates_service_spec.rb +0 -381
- data/spec/services/verification_details_service_spec.rb +0 -168
- data/spec/services/webhooks_service_spec.rb +0 -547
- data/spec/spec_helper.rb +0 -90
- data/spec/webhook_spec.rb +0 -122
@@ -1,600 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GoCardlessPro::Resources::Mandate do
|
4
|
-
let(:client) do
|
5
|
-
GoCardlessPro::Client.new(
|
6
|
-
access_token: 'SECRET_TOKEN'
|
7
|
-
)
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:response_headers) { { 'Content-Type' => 'application/json' } }
|
11
|
-
|
12
|
-
describe '#create' do
|
13
|
-
subject(:post_create_response) { client.mandates.create(params: new_resource) }
|
14
|
-
context 'with a valid request' do
|
15
|
-
let(:new_resource) do
|
16
|
-
{
|
17
|
-
|
18
|
-
'authorisation_source' => 'authorisation_source-input',
|
19
|
-
'consent_parameters' => 'consent_parameters-input',
|
20
|
-
'created_at' => 'created_at-input',
|
21
|
-
'id' => 'id-input',
|
22
|
-
'links' => 'links-input',
|
23
|
-
'metadata' => 'metadata-input',
|
24
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
25
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
26
|
-
'reference' => 'reference-input',
|
27
|
-
'scheme' => 'scheme-input',
|
28
|
-
'status' => 'status-input',
|
29
|
-
'verified_at' => 'verified_at-input',
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
before do
|
34
|
-
stub_request(:post, %r{.*api.gocardless.com/mandates}).
|
35
|
-
with(
|
36
|
-
body: {
|
37
|
-
'mandates' => {
|
38
|
-
|
39
|
-
'authorisation_source' => 'authorisation_source-input',
|
40
|
-
'consent_parameters' => 'consent_parameters-input',
|
41
|
-
'created_at' => 'created_at-input',
|
42
|
-
'id' => 'id-input',
|
43
|
-
'links' => 'links-input',
|
44
|
-
'metadata' => 'metadata-input',
|
45
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
46
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
47
|
-
'reference' => 'reference-input',
|
48
|
-
'scheme' => 'scheme-input',
|
49
|
-
'status' => 'status-input',
|
50
|
-
'verified_at' => 'verified_at-input',
|
51
|
-
},
|
52
|
-
}
|
53
|
-
).
|
54
|
-
to_return(
|
55
|
-
body: {
|
56
|
-
'mandates' =>
|
57
|
-
|
58
|
-
{
|
59
|
-
|
60
|
-
'authorisation_source' => 'authorisation_source-input',
|
61
|
-
'consent_parameters' => 'consent_parameters-input',
|
62
|
-
'created_at' => 'created_at-input',
|
63
|
-
'id' => 'id-input',
|
64
|
-
'links' => 'links-input',
|
65
|
-
'metadata' => 'metadata-input',
|
66
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
67
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
68
|
-
'reference' => 'reference-input',
|
69
|
-
'scheme' => 'scheme-input',
|
70
|
-
'status' => 'status-input',
|
71
|
-
'verified_at' => 'verified_at-input',
|
72
|
-
},
|
73
|
-
|
74
|
-
}.to_json,
|
75
|
-
headers: response_headers
|
76
|
-
)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'creates and returns the resource' do
|
80
|
-
expect(post_create_response).to be_a(GoCardlessPro::Resources::Mandate)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'with a request that returns a validation error' do
|
85
|
-
let(:new_resource) { {} }
|
86
|
-
|
87
|
-
before do
|
88
|
-
stub_request(:post, %r{.*api.gocardless.com/mandates}).to_return(
|
89
|
-
body: {
|
90
|
-
error: {
|
91
|
-
type: 'validation_failed',
|
92
|
-
code: 422,
|
93
|
-
errors: [
|
94
|
-
{ message: 'test error message', field: 'test_field' },
|
95
|
-
],
|
96
|
-
},
|
97
|
-
}.to_json,
|
98
|
-
headers: response_headers,
|
99
|
-
status: 422
|
100
|
-
)
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'throws the correct error' do
|
104
|
-
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'with a request that returns an idempotent creation conflict error' do
|
109
|
-
let(:id) { 'ID123' }
|
110
|
-
|
111
|
-
let(:new_resource) do
|
112
|
-
{
|
113
|
-
|
114
|
-
'authorisation_source' => 'authorisation_source-input',
|
115
|
-
'consent_parameters' => 'consent_parameters-input',
|
116
|
-
'created_at' => 'created_at-input',
|
117
|
-
'id' => 'id-input',
|
118
|
-
'links' => 'links-input',
|
119
|
-
'metadata' => 'metadata-input',
|
120
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
121
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
122
|
-
'reference' => 'reference-input',
|
123
|
-
'scheme' => 'scheme-input',
|
124
|
-
'status' => 'status-input',
|
125
|
-
'verified_at' => 'verified_at-input',
|
126
|
-
}
|
127
|
-
end
|
128
|
-
|
129
|
-
let!(:post_stub) do
|
130
|
-
stub_request(:post, %r{.*api.gocardless.com/mandates}).to_return(
|
131
|
-
body: {
|
132
|
-
error: {
|
133
|
-
type: 'invalid_state',
|
134
|
-
code: 409,
|
135
|
-
errors: [
|
136
|
-
{
|
137
|
-
message: 'A resource has already been created with this idempotency key',
|
138
|
-
reason: 'idempotent_creation_conflict',
|
139
|
-
links: {
|
140
|
-
conflicting_resource_id: id,
|
141
|
-
},
|
142
|
-
},
|
143
|
-
],
|
144
|
-
},
|
145
|
-
}.to_json,
|
146
|
-
headers: response_headers,
|
147
|
-
status: 409
|
148
|
-
)
|
149
|
-
end
|
150
|
-
|
151
|
-
let!(:get_stub) do
|
152
|
-
stub_url = "/mandates/#{id}"
|
153
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
154
|
-
to_return(
|
155
|
-
body: {
|
156
|
-
'mandates' => {
|
157
|
-
|
158
|
-
'authorisation_source' => 'authorisation_source-input',
|
159
|
-
'consent_parameters' => 'consent_parameters-input',
|
160
|
-
'created_at' => 'created_at-input',
|
161
|
-
'id' => 'id-input',
|
162
|
-
'links' => 'links-input',
|
163
|
-
'metadata' => 'metadata-input',
|
164
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
165
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
166
|
-
'reference' => 'reference-input',
|
167
|
-
'scheme' => 'scheme-input',
|
168
|
-
'status' => 'status-input',
|
169
|
-
'verified_at' => 'verified_at-input',
|
170
|
-
},
|
171
|
-
}.to_json,
|
172
|
-
headers: response_headers
|
173
|
-
)
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'fetches the already-created resource' do
|
177
|
-
post_create_response
|
178
|
-
expect(post_stub).to have_been_requested
|
179
|
-
expect(get_stub).to have_been_requested
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe '#list' do
|
185
|
-
describe 'with no filters' do
|
186
|
-
subject(:get_list_response) { client.mandates.list }
|
187
|
-
|
188
|
-
before do
|
189
|
-
stub_request(:get, %r{.*api.gocardless.com/mandates}).to_return(
|
190
|
-
body: {
|
191
|
-
'mandates' => [{
|
192
|
-
|
193
|
-
'authorisation_source' => 'authorisation_source-input',
|
194
|
-
'consent_parameters' => 'consent_parameters-input',
|
195
|
-
'created_at' => 'created_at-input',
|
196
|
-
'id' => 'id-input',
|
197
|
-
'links' => 'links-input',
|
198
|
-
'metadata' => 'metadata-input',
|
199
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
200
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
201
|
-
'reference' => 'reference-input',
|
202
|
-
'scheme' => 'scheme-input',
|
203
|
-
'status' => 'status-input',
|
204
|
-
'verified_at' => 'verified_at-input',
|
205
|
-
}],
|
206
|
-
meta: {
|
207
|
-
cursors: {
|
208
|
-
before: nil,
|
209
|
-
after: 'ABC123',
|
210
|
-
},
|
211
|
-
},
|
212
|
-
}.to_json,
|
213
|
-
headers: response_headers
|
214
|
-
)
|
215
|
-
end
|
216
|
-
|
217
|
-
it 'wraps each item in the resource class' do
|
218
|
-
expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Mandate)
|
219
|
-
|
220
|
-
expect(get_list_response.records.first.authorisation_source).to eq('authorisation_source-input')
|
221
|
-
|
222
|
-
expect(get_list_response.records.first.consent_parameters).to eq('consent_parameters-input')
|
223
|
-
|
224
|
-
expect(get_list_response.records.first.created_at).to eq('created_at-input')
|
225
|
-
|
226
|
-
expect(get_list_response.records.first.id).to eq('id-input')
|
227
|
-
|
228
|
-
expect(get_list_response.records.first.metadata).to eq('metadata-input')
|
229
|
-
|
230
|
-
expect(get_list_response.records.first.next_possible_charge_date).to eq('next_possible_charge_date-input')
|
231
|
-
|
232
|
-
expect(get_list_response.records.first.payments_require_approval).to eq('payments_require_approval-input')
|
233
|
-
|
234
|
-
expect(get_list_response.records.first.reference).to eq('reference-input')
|
235
|
-
|
236
|
-
expect(get_list_response.records.first.scheme).to eq('scheme-input')
|
237
|
-
|
238
|
-
expect(get_list_response.records.first.status).to eq('status-input')
|
239
|
-
|
240
|
-
expect(get_list_response.records.first.verified_at).to eq('verified_at-input')
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'exposes the cursors for before and after' do
|
244
|
-
expect(get_list_response.before).to eq(nil)
|
245
|
-
expect(get_list_response.after).to eq('ABC123')
|
246
|
-
end
|
247
|
-
|
248
|
-
specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
describe '#all' do
|
253
|
-
let!(:first_response_stub) do
|
254
|
-
stub_request(:get, %r{.*api.gocardless.com/mandates$}).to_return(
|
255
|
-
body: {
|
256
|
-
'mandates' => [{
|
257
|
-
|
258
|
-
'authorisation_source' => 'authorisation_source-input',
|
259
|
-
'consent_parameters' => 'consent_parameters-input',
|
260
|
-
'created_at' => 'created_at-input',
|
261
|
-
'id' => 'id-input',
|
262
|
-
'links' => 'links-input',
|
263
|
-
'metadata' => 'metadata-input',
|
264
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
265
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
266
|
-
'reference' => 'reference-input',
|
267
|
-
'scheme' => 'scheme-input',
|
268
|
-
'status' => 'status-input',
|
269
|
-
'verified_at' => 'verified_at-input',
|
270
|
-
}],
|
271
|
-
meta: {
|
272
|
-
cursors: { after: 'AB345' },
|
273
|
-
limit: 1,
|
274
|
-
},
|
275
|
-
}.to_json,
|
276
|
-
headers: response_headers
|
277
|
-
)
|
278
|
-
end
|
279
|
-
|
280
|
-
let!(:second_response_stub) do
|
281
|
-
stub_request(:get, %r{.*api.gocardless.com/mandates\?after=AB345}).to_return(
|
282
|
-
body: {
|
283
|
-
'mandates' => [{
|
284
|
-
|
285
|
-
'authorisation_source' => 'authorisation_source-input',
|
286
|
-
'consent_parameters' => 'consent_parameters-input',
|
287
|
-
'created_at' => 'created_at-input',
|
288
|
-
'id' => 'id-input',
|
289
|
-
'links' => 'links-input',
|
290
|
-
'metadata' => 'metadata-input',
|
291
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
292
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
293
|
-
'reference' => 'reference-input',
|
294
|
-
'scheme' => 'scheme-input',
|
295
|
-
'status' => 'status-input',
|
296
|
-
'verified_at' => 'verified_at-input',
|
297
|
-
}],
|
298
|
-
meta: {
|
299
|
-
limit: 2,
|
300
|
-
cursors: {},
|
301
|
-
},
|
302
|
-
}.to_json,
|
303
|
-
headers: response_headers
|
304
|
-
)
|
305
|
-
end
|
306
|
-
|
307
|
-
it 'automatically makes the extra requests' do
|
308
|
-
expect(client.mandates.all.to_a.length).to eq(2)
|
309
|
-
expect(first_response_stub).to have_been_requested
|
310
|
-
expect(second_response_stub).to have_been_requested
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
describe '#get' do
|
315
|
-
let(:id) { 'ID123' }
|
316
|
-
|
317
|
-
subject(:get_response) { client.mandates.get(id) }
|
318
|
-
|
319
|
-
context 'passing in a custom header' do
|
320
|
-
let!(:stub) do
|
321
|
-
stub_url = '/mandates/:identity'.gsub(':identity', id)
|
322
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
323
|
-
with(headers: { 'Foo' => 'Bar' }).
|
324
|
-
to_return(
|
325
|
-
body: {
|
326
|
-
'mandates' => {
|
327
|
-
|
328
|
-
'authorisation_source' => 'authorisation_source-input',
|
329
|
-
'consent_parameters' => 'consent_parameters-input',
|
330
|
-
'created_at' => 'created_at-input',
|
331
|
-
'id' => 'id-input',
|
332
|
-
'links' => 'links-input',
|
333
|
-
'metadata' => 'metadata-input',
|
334
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
335
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
336
|
-
'reference' => 'reference-input',
|
337
|
-
'scheme' => 'scheme-input',
|
338
|
-
'status' => 'status-input',
|
339
|
-
'verified_at' => 'verified_at-input',
|
340
|
-
},
|
341
|
-
}.to_json,
|
342
|
-
headers: response_headers
|
343
|
-
)
|
344
|
-
end
|
345
|
-
|
346
|
-
subject(:get_response) do
|
347
|
-
client.mandates.get(id, headers: {
|
348
|
-
'Foo' => 'Bar',
|
349
|
-
})
|
350
|
-
end
|
351
|
-
|
352
|
-
it 'includes the header' do
|
353
|
-
get_response
|
354
|
-
expect(stub).to have_been_requested
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
context 'when there is a mandate to return' do
|
359
|
-
before do
|
360
|
-
stub_url = '/mandates/:identity'.gsub(':identity', id)
|
361
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
362
|
-
body: {
|
363
|
-
'mandates' => {
|
364
|
-
|
365
|
-
'authorisation_source' => 'authorisation_source-input',
|
366
|
-
'consent_parameters' => 'consent_parameters-input',
|
367
|
-
'created_at' => 'created_at-input',
|
368
|
-
'id' => 'id-input',
|
369
|
-
'links' => 'links-input',
|
370
|
-
'metadata' => 'metadata-input',
|
371
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
372
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
373
|
-
'reference' => 'reference-input',
|
374
|
-
'scheme' => 'scheme-input',
|
375
|
-
'status' => 'status-input',
|
376
|
-
'verified_at' => 'verified_at-input',
|
377
|
-
},
|
378
|
-
}.to_json,
|
379
|
-
headers: response_headers
|
380
|
-
)
|
381
|
-
end
|
382
|
-
|
383
|
-
it 'wraps the response in a resource' do
|
384
|
-
expect(get_response).to be_a(GoCardlessPro::Resources::Mandate)
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
context 'when nothing is returned' do
|
389
|
-
before do
|
390
|
-
stub_url = '/mandates/:identity'.gsub(':identity', id)
|
391
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
392
|
-
body: '',
|
393
|
-
headers: response_headers
|
394
|
-
)
|
395
|
-
end
|
396
|
-
|
397
|
-
it 'returns nil' do
|
398
|
-
expect(get_response).to be_nil
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
context "when an ID is specified which can't be included in a valid URI" do
|
403
|
-
let(:id) { '`' }
|
404
|
-
|
405
|
-
it "doesn't raise an error" do
|
406
|
-
expect { get_response }.to_not raise_error(/bad URI/)
|
407
|
-
end
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
describe '#update' do
|
412
|
-
subject(:put_update_response) { client.mandates.update(id, params: update_params) }
|
413
|
-
let(:id) { 'ABC123' }
|
414
|
-
|
415
|
-
context 'with a valid request' do
|
416
|
-
let(:update_params) { { 'hello' => 'world' } }
|
417
|
-
|
418
|
-
let!(:stub) do
|
419
|
-
stub_url = '/mandates/:identity'.gsub(':identity', id)
|
420
|
-
stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
|
421
|
-
body: {
|
422
|
-
'mandates' => {
|
423
|
-
|
424
|
-
'authorisation_source' => 'authorisation_source-input',
|
425
|
-
'consent_parameters' => 'consent_parameters-input',
|
426
|
-
'created_at' => 'created_at-input',
|
427
|
-
'id' => 'id-input',
|
428
|
-
'links' => 'links-input',
|
429
|
-
'metadata' => 'metadata-input',
|
430
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
431
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
432
|
-
'reference' => 'reference-input',
|
433
|
-
'scheme' => 'scheme-input',
|
434
|
-
'status' => 'status-input',
|
435
|
-
'verified_at' => 'verified_at-input',
|
436
|
-
},
|
437
|
-
}.to_json,
|
438
|
-
headers: response_headers
|
439
|
-
)
|
440
|
-
end
|
441
|
-
|
442
|
-
it 'updates and returns the resource' do
|
443
|
-
expect(put_update_response).to be_a(GoCardlessPro::Resources::Mandate)
|
444
|
-
expect(stub).to have_been_requested
|
445
|
-
end
|
446
|
-
end
|
447
|
-
end
|
448
|
-
|
449
|
-
describe '#cancel' do
|
450
|
-
subject(:post_response) { client.mandates.cancel(resource_id) }
|
451
|
-
|
452
|
-
let(:resource_id) { 'ABC123' }
|
453
|
-
|
454
|
-
let!(:stub) do
|
455
|
-
# /mandates/%v/actions/cancel
|
456
|
-
stub_url = '/mandates/:identity/actions/cancel'.gsub(':identity', resource_id)
|
457
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
458
|
-
|
459
|
-
body: {
|
460
|
-
'mandates' => {
|
461
|
-
|
462
|
-
'authorisation_source' => 'authorisation_source-input',
|
463
|
-
'consent_parameters' => 'consent_parameters-input',
|
464
|
-
'created_at' => 'created_at-input',
|
465
|
-
'id' => 'id-input',
|
466
|
-
'links' => 'links-input',
|
467
|
-
'metadata' => 'metadata-input',
|
468
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
469
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
470
|
-
'reference' => 'reference-input',
|
471
|
-
'scheme' => 'scheme-input',
|
472
|
-
'status' => 'status-input',
|
473
|
-
'verified_at' => 'verified_at-input',
|
474
|
-
},
|
475
|
-
}.to_json,
|
476
|
-
|
477
|
-
headers: response_headers
|
478
|
-
)
|
479
|
-
end
|
480
|
-
|
481
|
-
it 'wraps the response and calls the right endpoint' do
|
482
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::Mandate)
|
483
|
-
|
484
|
-
expect(stub).to have_been_requested
|
485
|
-
end
|
486
|
-
|
487
|
-
context 'when the request needs a body and custom header' do
|
488
|
-
let(:body) { { foo: 'bar' } }
|
489
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
490
|
-
subject(:post_response) { client.mandates.cancel(resource_id, body, headers) }
|
491
|
-
|
492
|
-
let(:resource_id) { 'ABC123' }
|
493
|
-
|
494
|
-
let!(:stub) do
|
495
|
-
# /mandates/%v/actions/cancel
|
496
|
-
stub_url = '/mandates/:identity/actions/cancel'.gsub(':identity', resource_id)
|
497
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
498
|
-
with(
|
499
|
-
body: { foo: 'bar' },
|
500
|
-
headers: { 'Foo' => 'Bar' }
|
501
|
-
).to_return(
|
502
|
-
body: {
|
503
|
-
'mandates' => {
|
504
|
-
|
505
|
-
'authorisation_source' => 'authorisation_source-input',
|
506
|
-
'consent_parameters' => 'consent_parameters-input',
|
507
|
-
'created_at' => 'created_at-input',
|
508
|
-
'id' => 'id-input',
|
509
|
-
'links' => 'links-input',
|
510
|
-
'metadata' => 'metadata-input',
|
511
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
512
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
513
|
-
'reference' => 'reference-input',
|
514
|
-
'scheme' => 'scheme-input',
|
515
|
-
'status' => 'status-input',
|
516
|
-
'verified_at' => 'verified_at-input',
|
517
|
-
},
|
518
|
-
}.to_json,
|
519
|
-
headers: response_headers
|
520
|
-
)
|
521
|
-
end
|
522
|
-
end
|
523
|
-
end
|
524
|
-
|
525
|
-
describe '#reinstate' do
|
526
|
-
subject(:post_response) { client.mandates.reinstate(resource_id) }
|
527
|
-
|
528
|
-
let(:resource_id) { 'ABC123' }
|
529
|
-
|
530
|
-
let!(:stub) do
|
531
|
-
# /mandates/%v/actions/reinstate
|
532
|
-
stub_url = '/mandates/:identity/actions/reinstate'.gsub(':identity', resource_id)
|
533
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
534
|
-
|
535
|
-
body: {
|
536
|
-
'mandates' => {
|
537
|
-
|
538
|
-
'authorisation_source' => 'authorisation_source-input',
|
539
|
-
'consent_parameters' => 'consent_parameters-input',
|
540
|
-
'created_at' => 'created_at-input',
|
541
|
-
'id' => 'id-input',
|
542
|
-
'links' => 'links-input',
|
543
|
-
'metadata' => 'metadata-input',
|
544
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
545
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
546
|
-
'reference' => 'reference-input',
|
547
|
-
'scheme' => 'scheme-input',
|
548
|
-
'status' => 'status-input',
|
549
|
-
'verified_at' => 'verified_at-input',
|
550
|
-
},
|
551
|
-
}.to_json,
|
552
|
-
|
553
|
-
headers: response_headers
|
554
|
-
)
|
555
|
-
end
|
556
|
-
|
557
|
-
it 'wraps the response and calls the right endpoint' do
|
558
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::Mandate)
|
559
|
-
|
560
|
-
expect(stub).to have_been_requested
|
561
|
-
end
|
562
|
-
|
563
|
-
context 'when the request needs a body and custom header' do
|
564
|
-
let(:body) { { foo: 'bar' } }
|
565
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
566
|
-
subject(:post_response) { client.mandates.reinstate(resource_id, body, headers) }
|
567
|
-
|
568
|
-
let(:resource_id) { 'ABC123' }
|
569
|
-
|
570
|
-
let!(:stub) do
|
571
|
-
# /mandates/%v/actions/reinstate
|
572
|
-
stub_url = '/mandates/:identity/actions/reinstate'.gsub(':identity', resource_id)
|
573
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
574
|
-
with(
|
575
|
-
body: { foo: 'bar' },
|
576
|
-
headers: { 'Foo' => 'Bar' }
|
577
|
-
).to_return(
|
578
|
-
body: {
|
579
|
-
'mandates' => {
|
580
|
-
|
581
|
-
'authorisation_source' => 'authorisation_source-input',
|
582
|
-
'consent_parameters' => 'consent_parameters-input',
|
583
|
-
'created_at' => 'created_at-input',
|
584
|
-
'id' => 'id-input',
|
585
|
-
'links' => 'links-input',
|
586
|
-
'metadata' => 'metadata-input',
|
587
|
-
'next_possible_charge_date' => 'next_possible_charge_date-input',
|
588
|
-
'payments_require_approval' => 'payments_require_approval-input',
|
589
|
-
'reference' => 'reference-input',
|
590
|
-
'scheme' => 'scheme-input',
|
591
|
-
'status' => 'status-input',
|
592
|
-
'verified_at' => 'verified_at-input',
|
593
|
-
},
|
594
|
-
}.to_json,
|
595
|
-
headers: response_headers
|
596
|
-
)
|
597
|
-
end
|
598
|
-
end
|
599
|
-
end
|
600
|
-
end
|