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,1288 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GoCardlessPro::Services::BillingRequestsService 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 '#list' do
|
13
|
-
describe 'with no filters' do
|
14
|
-
subject(:get_list_response) { client.billing_requests.list }
|
15
|
-
|
16
|
-
let(:body) do
|
17
|
-
{
|
18
|
-
'billing_requests' => [{
|
19
|
-
|
20
|
-
'actions' => 'actions-input',
|
21
|
-
'created_at' => 'created_at-input',
|
22
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
23
|
-
'id' => 'id-input',
|
24
|
-
'links' => 'links-input',
|
25
|
-
'mandate_request' => 'mandate_request-input',
|
26
|
-
'metadata' => 'metadata-input',
|
27
|
-
'payment_request' => 'payment_request-input',
|
28
|
-
'resources' => 'resources-input',
|
29
|
-
'status' => 'status-input',
|
30
|
-
}],
|
31
|
-
meta: {
|
32
|
-
cursors: {
|
33
|
-
before: nil,
|
34
|
-
after: 'ABC123',
|
35
|
-
},
|
36
|
-
},
|
37
|
-
}.to_json
|
38
|
-
end
|
39
|
-
|
40
|
-
before do
|
41
|
-
stub_request(:get, %r{.*api.gocardless.com/billing_requests}).to_return(
|
42
|
-
body: body,
|
43
|
-
headers: response_headers
|
44
|
-
)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'wraps each item in the resource class' do
|
48
|
-
expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::BillingRequest)
|
49
|
-
|
50
|
-
expect(get_list_response.records.first.actions).to eq('actions-input')
|
51
|
-
|
52
|
-
expect(get_list_response.records.first.created_at).to eq('created_at-input')
|
53
|
-
|
54
|
-
expect(get_list_response.records.first.fallback_enabled).to eq('fallback_enabled-input')
|
55
|
-
|
56
|
-
expect(get_list_response.records.first.id).to eq('id-input')
|
57
|
-
|
58
|
-
expect(get_list_response.records.first.mandate_request).to eq('mandate_request-input')
|
59
|
-
|
60
|
-
expect(get_list_response.records.first.metadata).to eq('metadata-input')
|
61
|
-
|
62
|
-
expect(get_list_response.records.first.payment_request).to eq('payment_request-input')
|
63
|
-
|
64
|
-
expect(get_list_response.records.first.resources).to eq('resources-input')
|
65
|
-
|
66
|
-
expect(get_list_response.records.first.status).to eq('status-input')
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'exposes the cursors for before and after' do
|
70
|
-
expect(get_list_response.before).to eq(nil)
|
71
|
-
expect(get_list_response.after).to eq('ABC123')
|
72
|
-
end
|
73
|
-
|
74
|
-
specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
|
75
|
-
|
76
|
-
describe 'retry behaviour' do
|
77
|
-
before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
|
78
|
-
|
79
|
-
it 'retries timeouts' do
|
80
|
-
stub = stub_request(:get, %r{.*api.gocardless.com/billing_requests}).
|
81
|
-
to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
|
82
|
-
|
83
|
-
get_list_response
|
84
|
-
expect(stub).to have_been_requested.twice
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'retries 5XX errors' do
|
88
|
-
stub = stub_request(:get, %r{.*api.gocardless.com/billing_requests}).
|
89
|
-
to_return(status: 502,
|
90
|
-
headers: { 'Content-Type' => 'text/html' },
|
91
|
-
body: '<html><body>Response from Cloudflare</body></html>').
|
92
|
-
then.to_return(status: 200, headers: response_headers, body: body)
|
93
|
-
|
94
|
-
get_list_response
|
95
|
-
expect(stub).to have_been_requested.twice
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe '#all' do
|
102
|
-
let!(:first_response_stub) do
|
103
|
-
stub_request(:get, %r{.*api.gocardless.com/billing_requests$}).to_return(
|
104
|
-
body: {
|
105
|
-
'billing_requests' => [{
|
106
|
-
|
107
|
-
'actions' => 'actions-input',
|
108
|
-
'created_at' => 'created_at-input',
|
109
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
110
|
-
'id' => 'id-input',
|
111
|
-
'links' => 'links-input',
|
112
|
-
'mandate_request' => 'mandate_request-input',
|
113
|
-
'metadata' => 'metadata-input',
|
114
|
-
'payment_request' => 'payment_request-input',
|
115
|
-
'resources' => 'resources-input',
|
116
|
-
'status' => 'status-input',
|
117
|
-
}],
|
118
|
-
meta: {
|
119
|
-
cursors: { after: 'AB345' },
|
120
|
-
limit: 1,
|
121
|
-
},
|
122
|
-
}.to_json,
|
123
|
-
headers: response_headers
|
124
|
-
)
|
125
|
-
end
|
126
|
-
|
127
|
-
let!(:second_response_stub) do
|
128
|
-
stub_request(:get, %r{.*api.gocardless.com/billing_requests\?after=AB345}).to_return(
|
129
|
-
body: {
|
130
|
-
'billing_requests' => [{
|
131
|
-
|
132
|
-
'actions' => 'actions-input',
|
133
|
-
'created_at' => 'created_at-input',
|
134
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
135
|
-
'id' => 'id-input',
|
136
|
-
'links' => 'links-input',
|
137
|
-
'mandate_request' => 'mandate_request-input',
|
138
|
-
'metadata' => 'metadata-input',
|
139
|
-
'payment_request' => 'payment_request-input',
|
140
|
-
'resources' => 'resources-input',
|
141
|
-
'status' => 'status-input',
|
142
|
-
}],
|
143
|
-
meta: {
|
144
|
-
limit: 2,
|
145
|
-
cursors: {},
|
146
|
-
},
|
147
|
-
}.to_json,
|
148
|
-
headers: response_headers
|
149
|
-
)
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'automatically makes the extra requests' do
|
153
|
-
expect(client.billing_requests.all.to_a.length).to eq(2)
|
154
|
-
expect(first_response_stub).to have_been_requested
|
155
|
-
expect(second_response_stub).to have_been_requested
|
156
|
-
end
|
157
|
-
|
158
|
-
describe 'retry behaviour' do
|
159
|
-
before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
|
160
|
-
|
161
|
-
it 'retries timeouts' do
|
162
|
-
first_response_stub = stub_request(:get, %r{.*api.gocardless.com/billing_requests$}).to_return(
|
163
|
-
body: {
|
164
|
-
'billing_requests' => [{
|
165
|
-
|
166
|
-
'actions' => 'actions-input',
|
167
|
-
'created_at' => 'created_at-input',
|
168
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
169
|
-
'id' => 'id-input',
|
170
|
-
'links' => 'links-input',
|
171
|
-
'mandate_request' => 'mandate_request-input',
|
172
|
-
'metadata' => 'metadata-input',
|
173
|
-
'payment_request' => 'payment_request-input',
|
174
|
-
'resources' => 'resources-input',
|
175
|
-
'status' => 'status-input',
|
176
|
-
}],
|
177
|
-
meta: {
|
178
|
-
cursors: { after: 'AB345' },
|
179
|
-
limit: 1,
|
180
|
-
},
|
181
|
-
}.to_json,
|
182
|
-
headers: response_headers
|
183
|
-
)
|
184
|
-
|
185
|
-
second_response_stub = stub_request(:get, %r{.*api.gocardless.com/billing_requests\?after=AB345}).
|
186
|
-
to_timeout.then.
|
187
|
-
to_return(
|
188
|
-
body: {
|
189
|
-
'billing_requests' => [{
|
190
|
-
|
191
|
-
'actions' => 'actions-input',
|
192
|
-
'created_at' => 'created_at-input',
|
193
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
194
|
-
'id' => 'id-input',
|
195
|
-
'links' => 'links-input',
|
196
|
-
'mandate_request' => 'mandate_request-input',
|
197
|
-
'metadata' => 'metadata-input',
|
198
|
-
'payment_request' => 'payment_request-input',
|
199
|
-
'resources' => 'resources-input',
|
200
|
-
'status' => 'status-input',
|
201
|
-
}],
|
202
|
-
meta: {
|
203
|
-
limit: 2,
|
204
|
-
cursors: {},
|
205
|
-
},
|
206
|
-
}.to_json,
|
207
|
-
headers: response_headers
|
208
|
-
)
|
209
|
-
|
210
|
-
client.billing_requests.all.to_a
|
211
|
-
|
212
|
-
expect(first_response_stub).to have_been_requested
|
213
|
-
expect(second_response_stub).to have_been_requested.twice
|
214
|
-
end
|
215
|
-
|
216
|
-
it 'retries 5XX errors' do
|
217
|
-
first_response_stub = stub_request(:get, %r{.*api.gocardless.com/billing_requests$}).to_return(
|
218
|
-
body: {
|
219
|
-
'billing_requests' => [{
|
220
|
-
|
221
|
-
'actions' => 'actions-input',
|
222
|
-
'created_at' => 'created_at-input',
|
223
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
224
|
-
'id' => 'id-input',
|
225
|
-
'links' => 'links-input',
|
226
|
-
'mandate_request' => 'mandate_request-input',
|
227
|
-
'metadata' => 'metadata-input',
|
228
|
-
'payment_request' => 'payment_request-input',
|
229
|
-
'resources' => 'resources-input',
|
230
|
-
'status' => 'status-input',
|
231
|
-
}],
|
232
|
-
meta: {
|
233
|
-
cursors: { after: 'AB345' },
|
234
|
-
limit: 1,
|
235
|
-
},
|
236
|
-
}.to_json,
|
237
|
-
headers: response_headers
|
238
|
-
)
|
239
|
-
|
240
|
-
second_response_stub = stub_request(:get, %r{.*api.gocardless.com/billing_requests\?after=AB345}).
|
241
|
-
to_return(
|
242
|
-
status: 502,
|
243
|
-
body: '<html><body>Response from Cloudflare</body></html>',
|
244
|
-
headers: { 'Content-Type' => 'text/html' }
|
245
|
-
).then.to_return(
|
246
|
-
body: {
|
247
|
-
'billing_requests' => [{
|
248
|
-
|
249
|
-
'actions' => 'actions-input',
|
250
|
-
'created_at' => 'created_at-input',
|
251
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
252
|
-
'id' => 'id-input',
|
253
|
-
'links' => 'links-input',
|
254
|
-
'mandate_request' => 'mandate_request-input',
|
255
|
-
'metadata' => 'metadata-input',
|
256
|
-
'payment_request' => 'payment_request-input',
|
257
|
-
'resources' => 'resources-input',
|
258
|
-
'status' => 'status-input',
|
259
|
-
}],
|
260
|
-
meta: {
|
261
|
-
limit: 2,
|
262
|
-
cursors: {},
|
263
|
-
},
|
264
|
-
}.to_json,
|
265
|
-
headers: response_headers
|
266
|
-
)
|
267
|
-
|
268
|
-
client.billing_requests.all.to_a
|
269
|
-
|
270
|
-
expect(first_response_stub).to have_been_requested
|
271
|
-
expect(second_response_stub).to have_been_requested.twice
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
describe '#create' do
|
277
|
-
subject(:post_create_response) { client.billing_requests.create(params: new_resource) }
|
278
|
-
context 'with a valid request' do
|
279
|
-
let(:new_resource) do
|
280
|
-
{
|
281
|
-
|
282
|
-
'actions' => 'actions-input',
|
283
|
-
'created_at' => 'created_at-input',
|
284
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
285
|
-
'id' => 'id-input',
|
286
|
-
'links' => 'links-input',
|
287
|
-
'mandate_request' => 'mandate_request-input',
|
288
|
-
'metadata' => 'metadata-input',
|
289
|
-
'payment_request' => 'payment_request-input',
|
290
|
-
'resources' => 'resources-input',
|
291
|
-
'status' => 'status-input',
|
292
|
-
}
|
293
|
-
end
|
294
|
-
|
295
|
-
before do
|
296
|
-
stub_request(:post, %r{.*api.gocardless.com/billing_requests}).
|
297
|
-
with(
|
298
|
-
body: {
|
299
|
-
'billing_requests' => {
|
300
|
-
|
301
|
-
'actions' => 'actions-input',
|
302
|
-
'created_at' => 'created_at-input',
|
303
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
304
|
-
'id' => 'id-input',
|
305
|
-
'links' => 'links-input',
|
306
|
-
'mandate_request' => 'mandate_request-input',
|
307
|
-
'metadata' => 'metadata-input',
|
308
|
-
'payment_request' => 'payment_request-input',
|
309
|
-
'resources' => 'resources-input',
|
310
|
-
'status' => 'status-input',
|
311
|
-
},
|
312
|
-
}
|
313
|
-
).
|
314
|
-
to_return(
|
315
|
-
body: {
|
316
|
-
'billing_requests' =>
|
317
|
-
|
318
|
-
{
|
319
|
-
|
320
|
-
'actions' => 'actions-input',
|
321
|
-
'created_at' => 'created_at-input',
|
322
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
323
|
-
'id' => 'id-input',
|
324
|
-
'links' => 'links-input',
|
325
|
-
'mandate_request' => 'mandate_request-input',
|
326
|
-
'metadata' => 'metadata-input',
|
327
|
-
'payment_request' => 'payment_request-input',
|
328
|
-
'resources' => 'resources-input',
|
329
|
-
'status' => 'status-input',
|
330
|
-
},
|
331
|
-
|
332
|
-
}.to_json,
|
333
|
-
headers: response_headers
|
334
|
-
)
|
335
|
-
end
|
336
|
-
|
337
|
-
it 'creates and returns the resource' do
|
338
|
-
expect(post_create_response).to be_a(GoCardlessPro::Resources::BillingRequest)
|
339
|
-
end
|
340
|
-
|
341
|
-
describe 'retry behaviour' do
|
342
|
-
before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
|
343
|
-
|
344
|
-
it 'retries timeouts' do
|
345
|
-
stub = stub_request(:post, %r{.*api.gocardless.com/billing_requests}).
|
346
|
-
to_timeout.then.to_return(status: 200, headers: response_headers)
|
347
|
-
|
348
|
-
post_create_response
|
349
|
-
expect(stub).to have_been_requested.twice
|
350
|
-
end
|
351
|
-
|
352
|
-
it 'retries 5XX errors' do
|
353
|
-
stub = stub_request(:post, %r{.*api.gocardless.com/billing_requests}).
|
354
|
-
to_return(status: 502,
|
355
|
-
headers: { 'Content-Type' => 'text/html' },
|
356
|
-
body: '<html><body>Response from Cloudflare</body></html>').
|
357
|
-
then.to_return(status: 200, headers: response_headers)
|
358
|
-
|
359
|
-
post_create_response
|
360
|
-
expect(stub).to have_been_requested.twice
|
361
|
-
end
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
context 'with a request that returns a validation error' do
|
366
|
-
let(:new_resource) { {} }
|
367
|
-
|
368
|
-
before do
|
369
|
-
stub_request(:post, %r{.*api.gocardless.com/billing_requests}).to_return(
|
370
|
-
body: {
|
371
|
-
error: {
|
372
|
-
type: 'validation_failed',
|
373
|
-
code: 422,
|
374
|
-
errors: [
|
375
|
-
{ message: 'test error message', field: 'test_field' },
|
376
|
-
],
|
377
|
-
},
|
378
|
-
}.to_json,
|
379
|
-
headers: response_headers,
|
380
|
-
status: 422
|
381
|
-
)
|
382
|
-
end
|
383
|
-
|
384
|
-
it 'throws the correct error' do
|
385
|
-
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
context 'with a request that returns an idempotent creation conflict error' do
|
390
|
-
let(:id) { 'ID123' }
|
391
|
-
|
392
|
-
let(:new_resource) do
|
393
|
-
{
|
394
|
-
|
395
|
-
'actions' => 'actions-input',
|
396
|
-
'created_at' => 'created_at-input',
|
397
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
398
|
-
'id' => 'id-input',
|
399
|
-
'links' => 'links-input',
|
400
|
-
'mandate_request' => 'mandate_request-input',
|
401
|
-
'metadata' => 'metadata-input',
|
402
|
-
'payment_request' => 'payment_request-input',
|
403
|
-
'resources' => 'resources-input',
|
404
|
-
'status' => 'status-input',
|
405
|
-
}
|
406
|
-
end
|
407
|
-
|
408
|
-
let!(:post_stub) do
|
409
|
-
stub_request(:post, %r{.*api.gocardless.com/billing_requests}).to_return(
|
410
|
-
body: {
|
411
|
-
error: {
|
412
|
-
type: 'invalid_state',
|
413
|
-
code: 409,
|
414
|
-
errors: [
|
415
|
-
{
|
416
|
-
message: 'A resource has already been created with this idempotency key',
|
417
|
-
reason: 'idempotent_creation_conflict',
|
418
|
-
links: {
|
419
|
-
conflicting_resource_id: id,
|
420
|
-
},
|
421
|
-
},
|
422
|
-
],
|
423
|
-
},
|
424
|
-
}.to_json,
|
425
|
-
headers: response_headers,
|
426
|
-
status: 409
|
427
|
-
)
|
428
|
-
end
|
429
|
-
|
430
|
-
let!(:get_stub) do
|
431
|
-
stub_url = "/billing_requests/#{id}"
|
432
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
433
|
-
to_return(
|
434
|
-
body: {
|
435
|
-
'billing_requests' => {
|
436
|
-
|
437
|
-
'actions' => 'actions-input',
|
438
|
-
'created_at' => 'created_at-input',
|
439
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
440
|
-
'id' => 'id-input',
|
441
|
-
'links' => 'links-input',
|
442
|
-
'mandate_request' => 'mandate_request-input',
|
443
|
-
'metadata' => 'metadata-input',
|
444
|
-
'payment_request' => 'payment_request-input',
|
445
|
-
'resources' => 'resources-input',
|
446
|
-
'status' => 'status-input',
|
447
|
-
},
|
448
|
-
}.to_json,
|
449
|
-
headers: response_headers
|
450
|
-
)
|
451
|
-
end
|
452
|
-
|
453
|
-
context 'with default behaviour' do
|
454
|
-
it 'fetches the already-created resource' do
|
455
|
-
post_create_response
|
456
|
-
expect(post_stub).to have_been_requested
|
457
|
-
expect(get_stub).to have_been_requested
|
458
|
-
end
|
459
|
-
end
|
460
|
-
|
461
|
-
context 'with on_idempotency_conflict: :raise' do
|
462
|
-
let(:client) do
|
463
|
-
GoCardlessPro::Client.new(
|
464
|
-
access_token: 'SECRET_TOKEN',
|
465
|
-
on_idempotency_conflict: :raise
|
466
|
-
)
|
467
|
-
end
|
468
|
-
|
469
|
-
it 'raises an IdempotencyConflict error' do
|
470
|
-
expect { post_create_response }.
|
471
|
-
to raise_error(GoCardlessPro::IdempotencyConflict)
|
472
|
-
end
|
473
|
-
end
|
474
|
-
end
|
475
|
-
end
|
476
|
-
|
477
|
-
describe '#get' do
|
478
|
-
let(:id) { 'ID123' }
|
479
|
-
|
480
|
-
subject(:get_response) { client.billing_requests.get(id) }
|
481
|
-
|
482
|
-
context 'passing in a custom header' do
|
483
|
-
let!(:stub) do
|
484
|
-
stub_url = '/billing_requests/:identity'.gsub(':identity', id)
|
485
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
486
|
-
with(headers: { 'Foo' => 'Bar' }).
|
487
|
-
to_return(
|
488
|
-
body: {
|
489
|
-
'billing_requests' => {
|
490
|
-
|
491
|
-
'actions' => 'actions-input',
|
492
|
-
'created_at' => 'created_at-input',
|
493
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
494
|
-
'id' => 'id-input',
|
495
|
-
'links' => 'links-input',
|
496
|
-
'mandate_request' => 'mandate_request-input',
|
497
|
-
'metadata' => 'metadata-input',
|
498
|
-
'payment_request' => 'payment_request-input',
|
499
|
-
'resources' => 'resources-input',
|
500
|
-
'status' => 'status-input',
|
501
|
-
},
|
502
|
-
}.to_json,
|
503
|
-
headers: response_headers
|
504
|
-
)
|
505
|
-
end
|
506
|
-
|
507
|
-
subject(:get_response) do
|
508
|
-
client.billing_requests.get(id, headers: {
|
509
|
-
'Foo' => 'Bar',
|
510
|
-
})
|
511
|
-
end
|
512
|
-
|
513
|
-
it 'includes the header' do
|
514
|
-
get_response
|
515
|
-
expect(stub).to have_been_requested
|
516
|
-
end
|
517
|
-
end
|
518
|
-
|
519
|
-
context 'when there is a billing_request to return' do
|
520
|
-
before do
|
521
|
-
stub_url = '/billing_requests/:identity'.gsub(':identity', id)
|
522
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
523
|
-
body: {
|
524
|
-
'billing_requests' => {
|
525
|
-
|
526
|
-
'actions' => 'actions-input',
|
527
|
-
'created_at' => 'created_at-input',
|
528
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
529
|
-
'id' => 'id-input',
|
530
|
-
'links' => 'links-input',
|
531
|
-
'mandate_request' => 'mandate_request-input',
|
532
|
-
'metadata' => 'metadata-input',
|
533
|
-
'payment_request' => 'payment_request-input',
|
534
|
-
'resources' => 'resources-input',
|
535
|
-
'status' => 'status-input',
|
536
|
-
},
|
537
|
-
}.to_json,
|
538
|
-
headers: response_headers
|
539
|
-
)
|
540
|
-
end
|
541
|
-
|
542
|
-
it 'wraps the response in a resource' do
|
543
|
-
expect(get_response).to be_a(GoCardlessPro::Resources::BillingRequest)
|
544
|
-
end
|
545
|
-
end
|
546
|
-
|
547
|
-
context 'when nothing is returned' do
|
548
|
-
before do
|
549
|
-
stub_url = '/billing_requests/:identity'.gsub(':identity', id)
|
550
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
551
|
-
body: '',
|
552
|
-
headers: response_headers
|
553
|
-
)
|
554
|
-
end
|
555
|
-
|
556
|
-
it 'returns nil' do
|
557
|
-
expect(get_response).to be_nil
|
558
|
-
end
|
559
|
-
end
|
560
|
-
|
561
|
-
context "when an ID is specified which can't be included in a valid URI" do
|
562
|
-
let(:id) { '`' }
|
563
|
-
|
564
|
-
it "doesn't raise an error" do
|
565
|
-
expect { get_response }.to_not raise_error(/bad URI/)
|
566
|
-
end
|
567
|
-
end
|
568
|
-
|
569
|
-
describe 'retry behaviour' do
|
570
|
-
before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
|
571
|
-
|
572
|
-
it 'retries timeouts' do
|
573
|
-
stub_url = '/billing_requests/:identity'.gsub(':identity', id)
|
574
|
-
|
575
|
-
stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
576
|
-
to_timeout.then.to_return(status: 200, headers: response_headers)
|
577
|
-
|
578
|
-
get_response
|
579
|
-
expect(stub).to have_been_requested.twice
|
580
|
-
end
|
581
|
-
|
582
|
-
it 'retries 5XX errors, other than 500s' do
|
583
|
-
stub_url = '/billing_requests/:identity'.gsub(':identity', id)
|
584
|
-
|
585
|
-
stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
586
|
-
to_return(status: 502,
|
587
|
-
headers: { 'Content-Type' => 'text/html' },
|
588
|
-
body: '<html><body>Response from Cloudflare</body></html>').
|
589
|
-
then.to_return(status: 200, headers: response_headers)
|
590
|
-
|
591
|
-
get_response
|
592
|
-
expect(stub).to have_been_requested.twice
|
593
|
-
end
|
594
|
-
|
595
|
-
it 'retries 500 errors returned by the API' do
|
596
|
-
stub_url = '/billing_requests/:identity'.gsub(':identity', id)
|
597
|
-
|
598
|
-
gocardless_error = {
|
599
|
-
'error' => {
|
600
|
-
'message' => 'Internal server error',
|
601
|
-
'documentation_url' => 'https://developer.gocardless.com/#gocardless',
|
602
|
-
'errors' => [{
|
603
|
-
'message' => 'Internal server error',
|
604
|
-
'reason' => 'internal_server_error',
|
605
|
-
}],
|
606
|
-
'type' => 'gocardless',
|
607
|
-
'code' => 500,
|
608
|
-
'request_id' => 'dummy_request_id',
|
609
|
-
'id' => 'dummy_exception_id',
|
610
|
-
},
|
611
|
-
}
|
612
|
-
|
613
|
-
stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
614
|
-
to_return(status: 500,
|
615
|
-
headers: response_headers,
|
616
|
-
body: gocardless_error.to_json).
|
617
|
-
then.to_return(status: 200, headers: response_headers)
|
618
|
-
|
619
|
-
get_response
|
620
|
-
expect(stub).to have_been_requested.twice
|
621
|
-
end
|
622
|
-
end
|
623
|
-
end
|
624
|
-
|
625
|
-
describe '#collect_customer_details' do
|
626
|
-
subject(:post_response) { client.billing_requests.collect_customer_details(resource_id) }
|
627
|
-
|
628
|
-
let(:resource_id) { 'ABC123' }
|
629
|
-
|
630
|
-
let!(:stub) do
|
631
|
-
# /billing_requests/%v/actions/collect_customer_details
|
632
|
-
stub_url = '/billing_requests/:identity/actions/collect_customer_details'.gsub(':identity', resource_id)
|
633
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
634
|
-
|
635
|
-
body: {
|
636
|
-
'billing_requests' => {
|
637
|
-
|
638
|
-
'actions' => 'actions-input',
|
639
|
-
'created_at' => 'created_at-input',
|
640
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
641
|
-
'id' => 'id-input',
|
642
|
-
'links' => 'links-input',
|
643
|
-
'mandate_request' => 'mandate_request-input',
|
644
|
-
'metadata' => 'metadata-input',
|
645
|
-
'payment_request' => 'payment_request-input',
|
646
|
-
'resources' => 'resources-input',
|
647
|
-
'status' => 'status-input',
|
648
|
-
},
|
649
|
-
}.to_json,
|
650
|
-
|
651
|
-
headers: response_headers
|
652
|
-
)
|
653
|
-
end
|
654
|
-
|
655
|
-
it 'wraps the response and calls the right endpoint' do
|
656
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
|
657
|
-
|
658
|
-
expect(stub).to have_been_requested
|
659
|
-
end
|
660
|
-
|
661
|
-
describe 'retry behaviour' do
|
662
|
-
it "doesn't retry errors" do
|
663
|
-
stub_url = '/billing_requests/:identity/actions/collect_customer_details'.gsub(':identity', resource_id)
|
664
|
-
stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
665
|
-
to_timeout
|
666
|
-
|
667
|
-
expect { post_response }.to raise_error(Faraday::ConnectionFailed)
|
668
|
-
expect(stub).to have_been_requested
|
669
|
-
end
|
670
|
-
end
|
671
|
-
|
672
|
-
context 'when the request needs a body and custom header' do
|
673
|
-
let(:body) { { foo: 'bar' } }
|
674
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
675
|
-
subject(:post_response) { client.billing_requests.collect_customer_details(resource_id, body, headers) }
|
676
|
-
|
677
|
-
let(:resource_id) { 'ABC123' }
|
678
|
-
|
679
|
-
let!(:stub) do
|
680
|
-
# /billing_requests/%v/actions/collect_customer_details
|
681
|
-
stub_url = '/billing_requests/:identity/actions/collect_customer_details'.gsub(':identity', resource_id)
|
682
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
683
|
-
with(
|
684
|
-
body: { foo: 'bar' },
|
685
|
-
headers: { 'Foo' => 'Bar' }
|
686
|
-
).to_return(
|
687
|
-
body: {
|
688
|
-
'billing_requests' => {
|
689
|
-
|
690
|
-
'actions' => 'actions-input',
|
691
|
-
'created_at' => 'created_at-input',
|
692
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
693
|
-
'id' => 'id-input',
|
694
|
-
'links' => 'links-input',
|
695
|
-
'mandate_request' => 'mandate_request-input',
|
696
|
-
'metadata' => 'metadata-input',
|
697
|
-
'payment_request' => 'payment_request-input',
|
698
|
-
'resources' => 'resources-input',
|
699
|
-
'status' => 'status-input',
|
700
|
-
},
|
701
|
-
}.to_json,
|
702
|
-
headers: response_headers
|
703
|
-
)
|
704
|
-
end
|
705
|
-
end
|
706
|
-
end
|
707
|
-
|
708
|
-
describe '#collect_bank_account' do
|
709
|
-
subject(:post_response) { client.billing_requests.collect_bank_account(resource_id) }
|
710
|
-
|
711
|
-
let(:resource_id) { 'ABC123' }
|
712
|
-
|
713
|
-
let!(:stub) do
|
714
|
-
# /billing_requests/%v/actions/collect_bank_account
|
715
|
-
stub_url = '/billing_requests/:identity/actions/collect_bank_account'.gsub(':identity', resource_id)
|
716
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
717
|
-
|
718
|
-
body: {
|
719
|
-
'billing_requests' => {
|
720
|
-
|
721
|
-
'actions' => 'actions-input',
|
722
|
-
'created_at' => 'created_at-input',
|
723
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
724
|
-
'id' => 'id-input',
|
725
|
-
'links' => 'links-input',
|
726
|
-
'mandate_request' => 'mandate_request-input',
|
727
|
-
'metadata' => 'metadata-input',
|
728
|
-
'payment_request' => 'payment_request-input',
|
729
|
-
'resources' => 'resources-input',
|
730
|
-
'status' => 'status-input',
|
731
|
-
},
|
732
|
-
}.to_json,
|
733
|
-
|
734
|
-
headers: response_headers
|
735
|
-
)
|
736
|
-
end
|
737
|
-
|
738
|
-
it 'wraps the response and calls the right endpoint' do
|
739
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
|
740
|
-
|
741
|
-
expect(stub).to have_been_requested
|
742
|
-
end
|
743
|
-
|
744
|
-
describe 'retry behaviour' do
|
745
|
-
it "doesn't retry errors" do
|
746
|
-
stub_url = '/billing_requests/:identity/actions/collect_bank_account'.gsub(':identity', resource_id)
|
747
|
-
stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
748
|
-
to_timeout
|
749
|
-
|
750
|
-
expect { post_response }.to raise_error(Faraday::ConnectionFailed)
|
751
|
-
expect(stub).to have_been_requested
|
752
|
-
end
|
753
|
-
end
|
754
|
-
|
755
|
-
context 'when the request needs a body and custom header' do
|
756
|
-
let(:body) { { foo: 'bar' } }
|
757
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
758
|
-
subject(:post_response) { client.billing_requests.collect_bank_account(resource_id, body, headers) }
|
759
|
-
|
760
|
-
let(:resource_id) { 'ABC123' }
|
761
|
-
|
762
|
-
let!(:stub) do
|
763
|
-
# /billing_requests/%v/actions/collect_bank_account
|
764
|
-
stub_url = '/billing_requests/:identity/actions/collect_bank_account'.gsub(':identity', resource_id)
|
765
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
766
|
-
with(
|
767
|
-
body: { foo: 'bar' },
|
768
|
-
headers: { 'Foo' => 'Bar' }
|
769
|
-
).to_return(
|
770
|
-
body: {
|
771
|
-
'billing_requests' => {
|
772
|
-
|
773
|
-
'actions' => 'actions-input',
|
774
|
-
'created_at' => 'created_at-input',
|
775
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
776
|
-
'id' => 'id-input',
|
777
|
-
'links' => 'links-input',
|
778
|
-
'mandate_request' => 'mandate_request-input',
|
779
|
-
'metadata' => 'metadata-input',
|
780
|
-
'payment_request' => 'payment_request-input',
|
781
|
-
'resources' => 'resources-input',
|
782
|
-
'status' => 'status-input',
|
783
|
-
},
|
784
|
-
}.to_json,
|
785
|
-
headers: response_headers
|
786
|
-
)
|
787
|
-
end
|
788
|
-
end
|
789
|
-
end
|
790
|
-
|
791
|
-
describe '#fulfil' do
|
792
|
-
subject(:post_response) { client.billing_requests.fulfil(resource_id) }
|
793
|
-
|
794
|
-
let(:resource_id) { 'ABC123' }
|
795
|
-
|
796
|
-
let!(:stub) do
|
797
|
-
# /billing_requests/%v/actions/fulfil
|
798
|
-
stub_url = '/billing_requests/:identity/actions/fulfil'.gsub(':identity', resource_id)
|
799
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
800
|
-
|
801
|
-
body: {
|
802
|
-
'billing_requests' => {
|
803
|
-
|
804
|
-
'actions' => 'actions-input',
|
805
|
-
'created_at' => 'created_at-input',
|
806
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
807
|
-
'id' => 'id-input',
|
808
|
-
'links' => 'links-input',
|
809
|
-
'mandate_request' => 'mandate_request-input',
|
810
|
-
'metadata' => 'metadata-input',
|
811
|
-
'payment_request' => 'payment_request-input',
|
812
|
-
'resources' => 'resources-input',
|
813
|
-
'status' => 'status-input',
|
814
|
-
},
|
815
|
-
}.to_json,
|
816
|
-
|
817
|
-
headers: response_headers
|
818
|
-
)
|
819
|
-
end
|
820
|
-
|
821
|
-
it 'wraps the response and calls the right endpoint' do
|
822
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
|
823
|
-
|
824
|
-
expect(stub).to have_been_requested
|
825
|
-
end
|
826
|
-
|
827
|
-
describe 'retry behaviour' do
|
828
|
-
it "doesn't retry errors" do
|
829
|
-
stub_url = '/billing_requests/:identity/actions/fulfil'.gsub(':identity', resource_id)
|
830
|
-
stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
831
|
-
to_timeout
|
832
|
-
|
833
|
-
expect { post_response }.to raise_error(Faraday::ConnectionFailed)
|
834
|
-
expect(stub).to have_been_requested
|
835
|
-
end
|
836
|
-
end
|
837
|
-
|
838
|
-
context 'when the request needs a body and custom header' do
|
839
|
-
let(:body) { { foo: 'bar' } }
|
840
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
841
|
-
subject(:post_response) { client.billing_requests.fulfil(resource_id, body, headers) }
|
842
|
-
|
843
|
-
let(:resource_id) { 'ABC123' }
|
844
|
-
|
845
|
-
let!(:stub) do
|
846
|
-
# /billing_requests/%v/actions/fulfil
|
847
|
-
stub_url = '/billing_requests/:identity/actions/fulfil'.gsub(':identity', resource_id)
|
848
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
849
|
-
with(
|
850
|
-
body: { foo: 'bar' },
|
851
|
-
headers: { 'Foo' => 'Bar' }
|
852
|
-
).to_return(
|
853
|
-
body: {
|
854
|
-
'billing_requests' => {
|
855
|
-
|
856
|
-
'actions' => 'actions-input',
|
857
|
-
'created_at' => 'created_at-input',
|
858
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
859
|
-
'id' => 'id-input',
|
860
|
-
'links' => 'links-input',
|
861
|
-
'mandate_request' => 'mandate_request-input',
|
862
|
-
'metadata' => 'metadata-input',
|
863
|
-
'payment_request' => 'payment_request-input',
|
864
|
-
'resources' => 'resources-input',
|
865
|
-
'status' => 'status-input',
|
866
|
-
},
|
867
|
-
}.to_json,
|
868
|
-
headers: response_headers
|
869
|
-
)
|
870
|
-
end
|
871
|
-
end
|
872
|
-
end
|
873
|
-
|
874
|
-
describe '#choose_currency' do
|
875
|
-
subject(:post_response) { client.billing_requests.choose_currency(resource_id) }
|
876
|
-
|
877
|
-
let(:resource_id) { 'ABC123' }
|
878
|
-
|
879
|
-
let!(:stub) do
|
880
|
-
# /billing_requests/%v/actions/choose_currency
|
881
|
-
stub_url = '/billing_requests/:identity/actions/choose_currency'.gsub(':identity', resource_id)
|
882
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
883
|
-
|
884
|
-
body: {
|
885
|
-
'billing_requests' => {
|
886
|
-
|
887
|
-
'actions' => 'actions-input',
|
888
|
-
'created_at' => 'created_at-input',
|
889
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
890
|
-
'id' => 'id-input',
|
891
|
-
'links' => 'links-input',
|
892
|
-
'mandate_request' => 'mandate_request-input',
|
893
|
-
'metadata' => 'metadata-input',
|
894
|
-
'payment_request' => 'payment_request-input',
|
895
|
-
'resources' => 'resources-input',
|
896
|
-
'status' => 'status-input',
|
897
|
-
},
|
898
|
-
}.to_json,
|
899
|
-
|
900
|
-
headers: response_headers
|
901
|
-
)
|
902
|
-
end
|
903
|
-
|
904
|
-
it 'wraps the response and calls the right endpoint' do
|
905
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
|
906
|
-
|
907
|
-
expect(stub).to have_been_requested
|
908
|
-
end
|
909
|
-
|
910
|
-
describe 'retry behaviour' do
|
911
|
-
it "doesn't retry errors" do
|
912
|
-
stub_url = '/billing_requests/:identity/actions/choose_currency'.gsub(':identity', resource_id)
|
913
|
-
stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
914
|
-
to_timeout
|
915
|
-
|
916
|
-
expect { post_response }.to raise_error(Faraday::ConnectionFailed)
|
917
|
-
expect(stub).to have_been_requested
|
918
|
-
end
|
919
|
-
end
|
920
|
-
|
921
|
-
context 'when the request needs a body and custom header' do
|
922
|
-
let(:body) { { foo: 'bar' } }
|
923
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
924
|
-
subject(:post_response) { client.billing_requests.choose_currency(resource_id, body, headers) }
|
925
|
-
|
926
|
-
let(:resource_id) { 'ABC123' }
|
927
|
-
|
928
|
-
let!(:stub) do
|
929
|
-
# /billing_requests/%v/actions/choose_currency
|
930
|
-
stub_url = '/billing_requests/:identity/actions/choose_currency'.gsub(':identity', resource_id)
|
931
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
932
|
-
with(
|
933
|
-
body: { foo: 'bar' },
|
934
|
-
headers: { 'Foo' => 'Bar' }
|
935
|
-
).to_return(
|
936
|
-
body: {
|
937
|
-
'billing_requests' => {
|
938
|
-
|
939
|
-
'actions' => 'actions-input',
|
940
|
-
'created_at' => 'created_at-input',
|
941
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
942
|
-
'id' => 'id-input',
|
943
|
-
'links' => 'links-input',
|
944
|
-
'mandate_request' => 'mandate_request-input',
|
945
|
-
'metadata' => 'metadata-input',
|
946
|
-
'payment_request' => 'payment_request-input',
|
947
|
-
'resources' => 'resources-input',
|
948
|
-
'status' => 'status-input',
|
949
|
-
},
|
950
|
-
}.to_json,
|
951
|
-
headers: response_headers
|
952
|
-
)
|
953
|
-
end
|
954
|
-
end
|
955
|
-
end
|
956
|
-
|
957
|
-
describe '#confirm_payer_details' do
|
958
|
-
subject(:post_response) { client.billing_requests.confirm_payer_details(resource_id) }
|
959
|
-
|
960
|
-
let(:resource_id) { 'ABC123' }
|
961
|
-
|
962
|
-
let!(:stub) do
|
963
|
-
# /billing_requests/%v/actions/confirm_payer_details
|
964
|
-
stub_url = '/billing_requests/:identity/actions/confirm_payer_details'.gsub(':identity', resource_id)
|
965
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
966
|
-
|
967
|
-
body: {
|
968
|
-
'billing_requests' => {
|
969
|
-
|
970
|
-
'actions' => 'actions-input',
|
971
|
-
'created_at' => 'created_at-input',
|
972
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
973
|
-
'id' => 'id-input',
|
974
|
-
'links' => 'links-input',
|
975
|
-
'mandate_request' => 'mandate_request-input',
|
976
|
-
'metadata' => 'metadata-input',
|
977
|
-
'payment_request' => 'payment_request-input',
|
978
|
-
'resources' => 'resources-input',
|
979
|
-
'status' => 'status-input',
|
980
|
-
},
|
981
|
-
}.to_json,
|
982
|
-
|
983
|
-
headers: response_headers
|
984
|
-
)
|
985
|
-
end
|
986
|
-
|
987
|
-
it 'wraps the response and calls the right endpoint' do
|
988
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
|
989
|
-
|
990
|
-
expect(stub).to have_been_requested
|
991
|
-
end
|
992
|
-
|
993
|
-
describe 'retry behaviour' do
|
994
|
-
it "doesn't retry errors" do
|
995
|
-
stub_url = '/billing_requests/:identity/actions/confirm_payer_details'.gsub(':identity', resource_id)
|
996
|
-
stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
997
|
-
to_timeout
|
998
|
-
|
999
|
-
expect { post_response }.to raise_error(Faraday::ConnectionFailed)
|
1000
|
-
expect(stub).to have_been_requested
|
1001
|
-
end
|
1002
|
-
end
|
1003
|
-
|
1004
|
-
context 'when the request needs a body and custom header' do
|
1005
|
-
let(:body) { { foo: 'bar' } }
|
1006
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
1007
|
-
subject(:post_response) { client.billing_requests.confirm_payer_details(resource_id, body, headers) }
|
1008
|
-
|
1009
|
-
let(:resource_id) { 'ABC123' }
|
1010
|
-
|
1011
|
-
let!(:stub) do
|
1012
|
-
# /billing_requests/%v/actions/confirm_payer_details
|
1013
|
-
stub_url = '/billing_requests/:identity/actions/confirm_payer_details'.gsub(':identity', resource_id)
|
1014
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
1015
|
-
with(
|
1016
|
-
body: { foo: 'bar' },
|
1017
|
-
headers: { 'Foo' => 'Bar' }
|
1018
|
-
).to_return(
|
1019
|
-
body: {
|
1020
|
-
'billing_requests' => {
|
1021
|
-
|
1022
|
-
'actions' => 'actions-input',
|
1023
|
-
'created_at' => 'created_at-input',
|
1024
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
1025
|
-
'id' => 'id-input',
|
1026
|
-
'links' => 'links-input',
|
1027
|
-
'mandate_request' => 'mandate_request-input',
|
1028
|
-
'metadata' => 'metadata-input',
|
1029
|
-
'payment_request' => 'payment_request-input',
|
1030
|
-
'resources' => 'resources-input',
|
1031
|
-
'status' => 'status-input',
|
1032
|
-
},
|
1033
|
-
}.to_json,
|
1034
|
-
headers: response_headers
|
1035
|
-
)
|
1036
|
-
end
|
1037
|
-
end
|
1038
|
-
end
|
1039
|
-
|
1040
|
-
describe '#cancel' do
|
1041
|
-
subject(:post_response) { client.billing_requests.cancel(resource_id) }
|
1042
|
-
|
1043
|
-
let(:resource_id) { 'ABC123' }
|
1044
|
-
|
1045
|
-
let!(:stub) do
|
1046
|
-
# /billing_requests/%v/actions/cancel
|
1047
|
-
stub_url = '/billing_requests/:identity/actions/cancel'.gsub(':identity', resource_id)
|
1048
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
1049
|
-
|
1050
|
-
body: {
|
1051
|
-
'billing_requests' => {
|
1052
|
-
|
1053
|
-
'actions' => 'actions-input',
|
1054
|
-
'created_at' => 'created_at-input',
|
1055
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
1056
|
-
'id' => 'id-input',
|
1057
|
-
'links' => 'links-input',
|
1058
|
-
'mandate_request' => 'mandate_request-input',
|
1059
|
-
'metadata' => 'metadata-input',
|
1060
|
-
'payment_request' => 'payment_request-input',
|
1061
|
-
'resources' => 'resources-input',
|
1062
|
-
'status' => 'status-input',
|
1063
|
-
},
|
1064
|
-
}.to_json,
|
1065
|
-
|
1066
|
-
headers: response_headers
|
1067
|
-
)
|
1068
|
-
end
|
1069
|
-
|
1070
|
-
it 'wraps the response and calls the right endpoint' do
|
1071
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
|
1072
|
-
|
1073
|
-
expect(stub).to have_been_requested
|
1074
|
-
end
|
1075
|
-
|
1076
|
-
describe 'retry behaviour' do
|
1077
|
-
it "doesn't retry errors" do
|
1078
|
-
stub_url = '/billing_requests/:identity/actions/cancel'.gsub(':identity', resource_id)
|
1079
|
-
stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
1080
|
-
to_timeout
|
1081
|
-
|
1082
|
-
expect { post_response }.to raise_error(Faraday::ConnectionFailed)
|
1083
|
-
expect(stub).to have_been_requested
|
1084
|
-
end
|
1085
|
-
end
|
1086
|
-
|
1087
|
-
context 'when the request needs a body and custom header' do
|
1088
|
-
let(:body) { { foo: 'bar' } }
|
1089
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
1090
|
-
subject(:post_response) { client.billing_requests.cancel(resource_id, body, headers) }
|
1091
|
-
|
1092
|
-
let(:resource_id) { 'ABC123' }
|
1093
|
-
|
1094
|
-
let!(:stub) do
|
1095
|
-
# /billing_requests/%v/actions/cancel
|
1096
|
-
stub_url = '/billing_requests/:identity/actions/cancel'.gsub(':identity', resource_id)
|
1097
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
1098
|
-
with(
|
1099
|
-
body: { foo: 'bar' },
|
1100
|
-
headers: { 'Foo' => 'Bar' }
|
1101
|
-
).to_return(
|
1102
|
-
body: {
|
1103
|
-
'billing_requests' => {
|
1104
|
-
|
1105
|
-
'actions' => 'actions-input',
|
1106
|
-
'created_at' => 'created_at-input',
|
1107
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
1108
|
-
'id' => 'id-input',
|
1109
|
-
'links' => 'links-input',
|
1110
|
-
'mandate_request' => 'mandate_request-input',
|
1111
|
-
'metadata' => 'metadata-input',
|
1112
|
-
'payment_request' => 'payment_request-input',
|
1113
|
-
'resources' => 'resources-input',
|
1114
|
-
'status' => 'status-input',
|
1115
|
-
},
|
1116
|
-
}.to_json,
|
1117
|
-
headers: response_headers
|
1118
|
-
)
|
1119
|
-
end
|
1120
|
-
end
|
1121
|
-
end
|
1122
|
-
|
1123
|
-
describe '#notify' do
|
1124
|
-
subject(:post_response) { client.billing_requests.notify(resource_id) }
|
1125
|
-
|
1126
|
-
let(:resource_id) { 'ABC123' }
|
1127
|
-
|
1128
|
-
let!(:stub) do
|
1129
|
-
# /billing_requests/%v/actions/notify
|
1130
|
-
stub_url = '/billing_requests/:identity/actions/notify'.gsub(':identity', resource_id)
|
1131
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
1132
|
-
|
1133
|
-
body: {
|
1134
|
-
'billing_requests' => {
|
1135
|
-
|
1136
|
-
'actions' => 'actions-input',
|
1137
|
-
'created_at' => 'created_at-input',
|
1138
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
1139
|
-
'id' => 'id-input',
|
1140
|
-
'links' => 'links-input',
|
1141
|
-
'mandate_request' => 'mandate_request-input',
|
1142
|
-
'metadata' => 'metadata-input',
|
1143
|
-
'payment_request' => 'payment_request-input',
|
1144
|
-
'resources' => 'resources-input',
|
1145
|
-
'status' => 'status-input',
|
1146
|
-
},
|
1147
|
-
}.to_json,
|
1148
|
-
|
1149
|
-
headers: response_headers
|
1150
|
-
)
|
1151
|
-
end
|
1152
|
-
|
1153
|
-
it 'wraps the response and calls the right endpoint' do
|
1154
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
|
1155
|
-
|
1156
|
-
expect(stub).to have_been_requested
|
1157
|
-
end
|
1158
|
-
|
1159
|
-
describe 'retry behaviour' do
|
1160
|
-
it "doesn't retry errors" do
|
1161
|
-
stub_url = '/billing_requests/:identity/actions/notify'.gsub(':identity', resource_id)
|
1162
|
-
stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
1163
|
-
to_timeout
|
1164
|
-
|
1165
|
-
expect { post_response }.to raise_error(Faraday::ConnectionFailed)
|
1166
|
-
expect(stub).to have_been_requested
|
1167
|
-
end
|
1168
|
-
end
|
1169
|
-
|
1170
|
-
context 'when the request needs a body and custom header' do
|
1171
|
-
let(:body) { { foo: 'bar' } }
|
1172
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
1173
|
-
subject(:post_response) { client.billing_requests.notify(resource_id, body, headers) }
|
1174
|
-
|
1175
|
-
let(:resource_id) { 'ABC123' }
|
1176
|
-
|
1177
|
-
let!(:stub) do
|
1178
|
-
# /billing_requests/%v/actions/notify
|
1179
|
-
stub_url = '/billing_requests/:identity/actions/notify'.gsub(':identity', resource_id)
|
1180
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
1181
|
-
with(
|
1182
|
-
body: { foo: 'bar' },
|
1183
|
-
headers: { 'Foo' => 'Bar' }
|
1184
|
-
).to_return(
|
1185
|
-
body: {
|
1186
|
-
'billing_requests' => {
|
1187
|
-
|
1188
|
-
'actions' => 'actions-input',
|
1189
|
-
'created_at' => 'created_at-input',
|
1190
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
1191
|
-
'id' => 'id-input',
|
1192
|
-
'links' => 'links-input',
|
1193
|
-
'mandate_request' => 'mandate_request-input',
|
1194
|
-
'metadata' => 'metadata-input',
|
1195
|
-
'payment_request' => 'payment_request-input',
|
1196
|
-
'resources' => 'resources-input',
|
1197
|
-
'status' => 'status-input',
|
1198
|
-
},
|
1199
|
-
}.to_json,
|
1200
|
-
headers: response_headers
|
1201
|
-
)
|
1202
|
-
end
|
1203
|
-
end
|
1204
|
-
end
|
1205
|
-
|
1206
|
-
describe '#fallback' do
|
1207
|
-
subject(:post_response) { client.billing_requests.fallback(resource_id) }
|
1208
|
-
|
1209
|
-
let(:resource_id) { 'ABC123' }
|
1210
|
-
|
1211
|
-
let!(:stub) do
|
1212
|
-
# /billing_requests/%v/actions/fallback
|
1213
|
-
stub_url = '/billing_requests/:identity/actions/fallback'.gsub(':identity', resource_id)
|
1214
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
1215
|
-
|
1216
|
-
body: {
|
1217
|
-
'billing_requests' => {
|
1218
|
-
|
1219
|
-
'actions' => 'actions-input',
|
1220
|
-
'created_at' => 'created_at-input',
|
1221
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
1222
|
-
'id' => 'id-input',
|
1223
|
-
'links' => 'links-input',
|
1224
|
-
'mandate_request' => 'mandate_request-input',
|
1225
|
-
'metadata' => 'metadata-input',
|
1226
|
-
'payment_request' => 'payment_request-input',
|
1227
|
-
'resources' => 'resources-input',
|
1228
|
-
'status' => 'status-input',
|
1229
|
-
},
|
1230
|
-
}.to_json,
|
1231
|
-
|
1232
|
-
headers: response_headers
|
1233
|
-
)
|
1234
|
-
end
|
1235
|
-
|
1236
|
-
it 'wraps the response and calls the right endpoint' do
|
1237
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
|
1238
|
-
|
1239
|
-
expect(stub).to have_been_requested
|
1240
|
-
end
|
1241
|
-
|
1242
|
-
describe 'retry behaviour' do
|
1243
|
-
it "doesn't retry errors" do
|
1244
|
-
stub_url = '/billing_requests/:identity/actions/fallback'.gsub(':identity', resource_id)
|
1245
|
-
stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
1246
|
-
to_timeout
|
1247
|
-
|
1248
|
-
expect { post_response }.to raise_error(Faraday::ConnectionFailed)
|
1249
|
-
expect(stub).to have_been_requested
|
1250
|
-
end
|
1251
|
-
end
|
1252
|
-
|
1253
|
-
context 'when the request needs a body and custom header' do
|
1254
|
-
let(:body) { { foo: 'bar' } }
|
1255
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
1256
|
-
subject(:post_response) { client.billing_requests.fallback(resource_id, body, headers) }
|
1257
|
-
|
1258
|
-
let(:resource_id) { 'ABC123' }
|
1259
|
-
|
1260
|
-
let!(:stub) do
|
1261
|
-
# /billing_requests/%v/actions/fallback
|
1262
|
-
stub_url = '/billing_requests/:identity/actions/fallback'.gsub(':identity', resource_id)
|
1263
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
1264
|
-
with(
|
1265
|
-
body: { foo: 'bar' },
|
1266
|
-
headers: { 'Foo' => 'Bar' }
|
1267
|
-
).to_return(
|
1268
|
-
body: {
|
1269
|
-
'billing_requests' => {
|
1270
|
-
|
1271
|
-
'actions' => 'actions-input',
|
1272
|
-
'created_at' => 'created_at-input',
|
1273
|
-
'fallback_enabled' => 'fallback_enabled-input',
|
1274
|
-
'id' => 'id-input',
|
1275
|
-
'links' => 'links-input',
|
1276
|
-
'mandate_request' => 'mandate_request-input',
|
1277
|
-
'metadata' => 'metadata-input',
|
1278
|
-
'payment_request' => 'payment_request-input',
|
1279
|
-
'resources' => 'resources-input',
|
1280
|
-
'status' => 'status-input',
|
1281
|
-
},
|
1282
|
-
}.to_json,
|
1283
|
-
headers: response_headers
|
1284
|
-
)
|
1285
|
-
end
|
1286
|
-
end
|
1287
|
-
end
|
1288
|
-
end
|