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,914 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GoCardlessPro::Services::PaymentsService 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.payments.create(params: new_resource) }
|
14
|
-
context 'with a valid request' do
|
15
|
-
let(:new_resource) do
|
16
|
-
{
|
17
|
-
|
18
|
-
'amount' => 'amount-input',
|
19
|
-
'amount_refunded' => 'amount_refunded-input',
|
20
|
-
'charge_date' => 'charge_date-input',
|
21
|
-
'created_at' => 'created_at-input',
|
22
|
-
'currency' => 'currency-input',
|
23
|
-
'description' => 'description-input',
|
24
|
-
'fx' => 'fx-input',
|
25
|
-
'id' => 'id-input',
|
26
|
-
'links' => 'links-input',
|
27
|
-
'metadata' => 'metadata-input',
|
28
|
-
'reference' => 'reference-input',
|
29
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
30
|
-
'status' => 'status-input',
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
before do
|
35
|
-
stub_request(:post, %r{.*api.gocardless.com/payments}).
|
36
|
-
with(
|
37
|
-
body: {
|
38
|
-
'payments' => {
|
39
|
-
|
40
|
-
'amount' => 'amount-input',
|
41
|
-
'amount_refunded' => 'amount_refunded-input',
|
42
|
-
'charge_date' => 'charge_date-input',
|
43
|
-
'created_at' => 'created_at-input',
|
44
|
-
'currency' => 'currency-input',
|
45
|
-
'description' => 'description-input',
|
46
|
-
'fx' => 'fx-input',
|
47
|
-
'id' => 'id-input',
|
48
|
-
'links' => 'links-input',
|
49
|
-
'metadata' => 'metadata-input',
|
50
|
-
'reference' => 'reference-input',
|
51
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
52
|
-
'status' => 'status-input',
|
53
|
-
},
|
54
|
-
}
|
55
|
-
).
|
56
|
-
to_return(
|
57
|
-
body: {
|
58
|
-
'payments' =>
|
59
|
-
|
60
|
-
{
|
61
|
-
|
62
|
-
'amount' => 'amount-input',
|
63
|
-
'amount_refunded' => 'amount_refunded-input',
|
64
|
-
'charge_date' => 'charge_date-input',
|
65
|
-
'created_at' => 'created_at-input',
|
66
|
-
'currency' => 'currency-input',
|
67
|
-
'description' => 'description-input',
|
68
|
-
'fx' => 'fx-input',
|
69
|
-
'id' => 'id-input',
|
70
|
-
'links' => 'links-input',
|
71
|
-
'metadata' => 'metadata-input',
|
72
|
-
'reference' => 'reference-input',
|
73
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
74
|
-
'status' => 'status-input',
|
75
|
-
},
|
76
|
-
|
77
|
-
}.to_json,
|
78
|
-
headers: response_headers
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'creates and returns the resource' do
|
83
|
-
expect(post_create_response).to be_a(GoCardlessPro::Resources::Payment)
|
84
|
-
end
|
85
|
-
|
86
|
-
describe 'retry behaviour' do
|
87
|
-
before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
|
88
|
-
|
89
|
-
it 'retries timeouts' do
|
90
|
-
stub = stub_request(:post, %r{.*api.gocardless.com/payments}).
|
91
|
-
to_timeout.then.to_return(status: 200, headers: response_headers)
|
92
|
-
|
93
|
-
post_create_response
|
94
|
-
expect(stub).to have_been_requested.twice
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'retries 5XX errors' do
|
98
|
-
stub = stub_request(:post, %r{.*api.gocardless.com/payments}).
|
99
|
-
to_return(status: 502,
|
100
|
-
headers: { 'Content-Type' => 'text/html' },
|
101
|
-
body: '<html><body>Response from Cloudflare</body></html>').
|
102
|
-
then.to_return(status: 200, headers: response_headers)
|
103
|
-
|
104
|
-
post_create_response
|
105
|
-
expect(stub).to have_been_requested.twice
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context 'with a request that returns a validation error' do
|
111
|
-
let(:new_resource) { {} }
|
112
|
-
|
113
|
-
before do
|
114
|
-
stub_request(:post, %r{.*api.gocardless.com/payments}).to_return(
|
115
|
-
body: {
|
116
|
-
error: {
|
117
|
-
type: 'validation_failed',
|
118
|
-
code: 422,
|
119
|
-
errors: [
|
120
|
-
{ message: 'test error message', field: 'test_field' },
|
121
|
-
],
|
122
|
-
},
|
123
|
-
}.to_json,
|
124
|
-
headers: response_headers,
|
125
|
-
status: 422
|
126
|
-
)
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'throws the correct error' do
|
130
|
-
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'with a request that returns an idempotent creation conflict error' do
|
135
|
-
let(:id) { 'ID123' }
|
136
|
-
|
137
|
-
let(:new_resource) do
|
138
|
-
{
|
139
|
-
|
140
|
-
'amount' => 'amount-input',
|
141
|
-
'amount_refunded' => 'amount_refunded-input',
|
142
|
-
'charge_date' => 'charge_date-input',
|
143
|
-
'created_at' => 'created_at-input',
|
144
|
-
'currency' => 'currency-input',
|
145
|
-
'description' => 'description-input',
|
146
|
-
'fx' => 'fx-input',
|
147
|
-
'id' => 'id-input',
|
148
|
-
'links' => 'links-input',
|
149
|
-
'metadata' => 'metadata-input',
|
150
|
-
'reference' => 'reference-input',
|
151
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
152
|
-
'status' => 'status-input',
|
153
|
-
}
|
154
|
-
end
|
155
|
-
|
156
|
-
let!(:post_stub) do
|
157
|
-
stub_request(:post, %r{.*api.gocardless.com/payments}).to_return(
|
158
|
-
body: {
|
159
|
-
error: {
|
160
|
-
type: 'invalid_state',
|
161
|
-
code: 409,
|
162
|
-
errors: [
|
163
|
-
{
|
164
|
-
message: 'A resource has already been created with this idempotency key',
|
165
|
-
reason: 'idempotent_creation_conflict',
|
166
|
-
links: {
|
167
|
-
conflicting_resource_id: id,
|
168
|
-
},
|
169
|
-
},
|
170
|
-
],
|
171
|
-
},
|
172
|
-
}.to_json,
|
173
|
-
headers: response_headers,
|
174
|
-
status: 409
|
175
|
-
)
|
176
|
-
end
|
177
|
-
|
178
|
-
let!(:get_stub) do
|
179
|
-
stub_url = "/payments/#{id}"
|
180
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
181
|
-
to_return(
|
182
|
-
body: {
|
183
|
-
'payments' => {
|
184
|
-
|
185
|
-
'amount' => 'amount-input',
|
186
|
-
'amount_refunded' => 'amount_refunded-input',
|
187
|
-
'charge_date' => 'charge_date-input',
|
188
|
-
'created_at' => 'created_at-input',
|
189
|
-
'currency' => 'currency-input',
|
190
|
-
'description' => 'description-input',
|
191
|
-
'fx' => 'fx-input',
|
192
|
-
'id' => 'id-input',
|
193
|
-
'links' => 'links-input',
|
194
|
-
'metadata' => 'metadata-input',
|
195
|
-
'reference' => 'reference-input',
|
196
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
197
|
-
'status' => 'status-input',
|
198
|
-
},
|
199
|
-
}.to_json,
|
200
|
-
headers: response_headers
|
201
|
-
)
|
202
|
-
end
|
203
|
-
|
204
|
-
context 'with default behaviour' do
|
205
|
-
it 'fetches the already-created resource' do
|
206
|
-
post_create_response
|
207
|
-
expect(post_stub).to have_been_requested
|
208
|
-
expect(get_stub).to have_been_requested
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
context 'with on_idempotency_conflict: :raise' do
|
213
|
-
let(:client) do
|
214
|
-
GoCardlessPro::Client.new(
|
215
|
-
access_token: 'SECRET_TOKEN',
|
216
|
-
on_idempotency_conflict: :raise
|
217
|
-
)
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'raises an IdempotencyConflict error' do
|
221
|
-
expect { post_create_response }.
|
222
|
-
to raise_error(GoCardlessPro::IdempotencyConflict)
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
describe '#list' do
|
229
|
-
describe 'with no filters' do
|
230
|
-
subject(:get_list_response) { client.payments.list }
|
231
|
-
|
232
|
-
let(:body) do
|
233
|
-
{
|
234
|
-
'payments' => [{
|
235
|
-
|
236
|
-
'amount' => 'amount-input',
|
237
|
-
'amount_refunded' => 'amount_refunded-input',
|
238
|
-
'charge_date' => 'charge_date-input',
|
239
|
-
'created_at' => 'created_at-input',
|
240
|
-
'currency' => 'currency-input',
|
241
|
-
'description' => 'description-input',
|
242
|
-
'fx' => 'fx-input',
|
243
|
-
'id' => 'id-input',
|
244
|
-
'links' => 'links-input',
|
245
|
-
'metadata' => 'metadata-input',
|
246
|
-
'reference' => 'reference-input',
|
247
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
248
|
-
'status' => 'status-input',
|
249
|
-
}],
|
250
|
-
meta: {
|
251
|
-
cursors: {
|
252
|
-
before: nil,
|
253
|
-
after: 'ABC123',
|
254
|
-
},
|
255
|
-
},
|
256
|
-
}.to_json
|
257
|
-
end
|
258
|
-
|
259
|
-
before do
|
260
|
-
stub_request(:get, %r{.*api.gocardless.com/payments}).to_return(
|
261
|
-
body: body,
|
262
|
-
headers: response_headers
|
263
|
-
)
|
264
|
-
end
|
265
|
-
|
266
|
-
it 'wraps each item in the resource class' do
|
267
|
-
expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Payment)
|
268
|
-
|
269
|
-
expect(get_list_response.records.first.amount).to eq('amount-input')
|
270
|
-
|
271
|
-
expect(get_list_response.records.first.amount_refunded).to eq('amount_refunded-input')
|
272
|
-
|
273
|
-
expect(get_list_response.records.first.charge_date).to eq('charge_date-input')
|
274
|
-
|
275
|
-
expect(get_list_response.records.first.created_at).to eq('created_at-input')
|
276
|
-
|
277
|
-
expect(get_list_response.records.first.currency).to eq('currency-input')
|
278
|
-
|
279
|
-
expect(get_list_response.records.first.description).to eq('description-input')
|
280
|
-
|
281
|
-
expect(get_list_response.records.first.fx).to eq('fx-input')
|
282
|
-
|
283
|
-
expect(get_list_response.records.first.id).to eq('id-input')
|
284
|
-
|
285
|
-
expect(get_list_response.records.first.metadata).to eq('metadata-input')
|
286
|
-
|
287
|
-
expect(get_list_response.records.first.reference).to eq('reference-input')
|
288
|
-
|
289
|
-
expect(get_list_response.records.first.retry_if_possible).to eq('retry_if_possible-input')
|
290
|
-
|
291
|
-
expect(get_list_response.records.first.status).to eq('status-input')
|
292
|
-
end
|
293
|
-
|
294
|
-
it 'exposes the cursors for before and after' do
|
295
|
-
expect(get_list_response.before).to eq(nil)
|
296
|
-
expect(get_list_response.after).to eq('ABC123')
|
297
|
-
end
|
298
|
-
|
299
|
-
specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
|
300
|
-
|
301
|
-
describe 'retry behaviour' do
|
302
|
-
before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
|
303
|
-
|
304
|
-
it 'retries timeouts' do
|
305
|
-
stub = stub_request(:get, %r{.*api.gocardless.com/payments}).
|
306
|
-
to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
|
307
|
-
|
308
|
-
get_list_response
|
309
|
-
expect(stub).to have_been_requested.twice
|
310
|
-
end
|
311
|
-
|
312
|
-
it 'retries 5XX errors' do
|
313
|
-
stub = stub_request(:get, %r{.*api.gocardless.com/payments}).
|
314
|
-
to_return(status: 502,
|
315
|
-
headers: { 'Content-Type' => 'text/html' },
|
316
|
-
body: '<html><body>Response from Cloudflare</body></html>').
|
317
|
-
then.to_return(status: 200, headers: response_headers, body: body)
|
318
|
-
|
319
|
-
get_list_response
|
320
|
-
expect(stub).to have_been_requested.twice
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
describe '#all' do
|
327
|
-
let!(:first_response_stub) do
|
328
|
-
stub_request(:get, %r{.*api.gocardless.com/payments$}).to_return(
|
329
|
-
body: {
|
330
|
-
'payments' => [{
|
331
|
-
|
332
|
-
'amount' => 'amount-input',
|
333
|
-
'amount_refunded' => 'amount_refunded-input',
|
334
|
-
'charge_date' => 'charge_date-input',
|
335
|
-
'created_at' => 'created_at-input',
|
336
|
-
'currency' => 'currency-input',
|
337
|
-
'description' => 'description-input',
|
338
|
-
'fx' => 'fx-input',
|
339
|
-
'id' => 'id-input',
|
340
|
-
'links' => 'links-input',
|
341
|
-
'metadata' => 'metadata-input',
|
342
|
-
'reference' => 'reference-input',
|
343
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
344
|
-
'status' => 'status-input',
|
345
|
-
}],
|
346
|
-
meta: {
|
347
|
-
cursors: { after: 'AB345' },
|
348
|
-
limit: 1,
|
349
|
-
},
|
350
|
-
}.to_json,
|
351
|
-
headers: response_headers
|
352
|
-
)
|
353
|
-
end
|
354
|
-
|
355
|
-
let!(:second_response_stub) do
|
356
|
-
stub_request(:get, %r{.*api.gocardless.com/payments\?after=AB345}).to_return(
|
357
|
-
body: {
|
358
|
-
'payments' => [{
|
359
|
-
|
360
|
-
'amount' => 'amount-input',
|
361
|
-
'amount_refunded' => 'amount_refunded-input',
|
362
|
-
'charge_date' => 'charge_date-input',
|
363
|
-
'created_at' => 'created_at-input',
|
364
|
-
'currency' => 'currency-input',
|
365
|
-
'description' => 'description-input',
|
366
|
-
'fx' => 'fx-input',
|
367
|
-
'id' => 'id-input',
|
368
|
-
'links' => 'links-input',
|
369
|
-
'metadata' => 'metadata-input',
|
370
|
-
'reference' => 'reference-input',
|
371
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
372
|
-
'status' => 'status-input',
|
373
|
-
}],
|
374
|
-
meta: {
|
375
|
-
limit: 2,
|
376
|
-
cursors: {},
|
377
|
-
},
|
378
|
-
}.to_json,
|
379
|
-
headers: response_headers
|
380
|
-
)
|
381
|
-
end
|
382
|
-
|
383
|
-
it 'automatically makes the extra requests' do
|
384
|
-
expect(client.payments.all.to_a.length).to eq(2)
|
385
|
-
expect(first_response_stub).to have_been_requested
|
386
|
-
expect(second_response_stub).to have_been_requested
|
387
|
-
end
|
388
|
-
|
389
|
-
describe 'retry behaviour' do
|
390
|
-
before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
|
391
|
-
|
392
|
-
it 'retries timeouts' do
|
393
|
-
first_response_stub = stub_request(:get, %r{.*api.gocardless.com/payments$}).to_return(
|
394
|
-
body: {
|
395
|
-
'payments' => [{
|
396
|
-
|
397
|
-
'amount' => 'amount-input',
|
398
|
-
'amount_refunded' => 'amount_refunded-input',
|
399
|
-
'charge_date' => 'charge_date-input',
|
400
|
-
'created_at' => 'created_at-input',
|
401
|
-
'currency' => 'currency-input',
|
402
|
-
'description' => 'description-input',
|
403
|
-
'fx' => 'fx-input',
|
404
|
-
'id' => 'id-input',
|
405
|
-
'links' => 'links-input',
|
406
|
-
'metadata' => 'metadata-input',
|
407
|
-
'reference' => 'reference-input',
|
408
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
409
|
-
'status' => 'status-input',
|
410
|
-
}],
|
411
|
-
meta: {
|
412
|
-
cursors: { after: 'AB345' },
|
413
|
-
limit: 1,
|
414
|
-
},
|
415
|
-
}.to_json,
|
416
|
-
headers: response_headers
|
417
|
-
)
|
418
|
-
|
419
|
-
second_response_stub = stub_request(:get, %r{.*api.gocardless.com/payments\?after=AB345}).
|
420
|
-
to_timeout.then.
|
421
|
-
to_return(
|
422
|
-
body: {
|
423
|
-
'payments' => [{
|
424
|
-
|
425
|
-
'amount' => 'amount-input',
|
426
|
-
'amount_refunded' => 'amount_refunded-input',
|
427
|
-
'charge_date' => 'charge_date-input',
|
428
|
-
'created_at' => 'created_at-input',
|
429
|
-
'currency' => 'currency-input',
|
430
|
-
'description' => 'description-input',
|
431
|
-
'fx' => 'fx-input',
|
432
|
-
'id' => 'id-input',
|
433
|
-
'links' => 'links-input',
|
434
|
-
'metadata' => 'metadata-input',
|
435
|
-
'reference' => 'reference-input',
|
436
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
437
|
-
'status' => 'status-input',
|
438
|
-
}],
|
439
|
-
meta: {
|
440
|
-
limit: 2,
|
441
|
-
cursors: {},
|
442
|
-
},
|
443
|
-
}.to_json,
|
444
|
-
headers: response_headers
|
445
|
-
)
|
446
|
-
|
447
|
-
client.payments.all.to_a
|
448
|
-
|
449
|
-
expect(first_response_stub).to have_been_requested
|
450
|
-
expect(second_response_stub).to have_been_requested.twice
|
451
|
-
end
|
452
|
-
|
453
|
-
it 'retries 5XX errors' do
|
454
|
-
first_response_stub = stub_request(:get, %r{.*api.gocardless.com/payments$}).to_return(
|
455
|
-
body: {
|
456
|
-
'payments' => [{
|
457
|
-
|
458
|
-
'amount' => 'amount-input',
|
459
|
-
'amount_refunded' => 'amount_refunded-input',
|
460
|
-
'charge_date' => 'charge_date-input',
|
461
|
-
'created_at' => 'created_at-input',
|
462
|
-
'currency' => 'currency-input',
|
463
|
-
'description' => 'description-input',
|
464
|
-
'fx' => 'fx-input',
|
465
|
-
'id' => 'id-input',
|
466
|
-
'links' => 'links-input',
|
467
|
-
'metadata' => 'metadata-input',
|
468
|
-
'reference' => 'reference-input',
|
469
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
470
|
-
'status' => 'status-input',
|
471
|
-
}],
|
472
|
-
meta: {
|
473
|
-
cursors: { after: 'AB345' },
|
474
|
-
limit: 1,
|
475
|
-
},
|
476
|
-
}.to_json,
|
477
|
-
headers: response_headers
|
478
|
-
)
|
479
|
-
|
480
|
-
second_response_stub = stub_request(:get, %r{.*api.gocardless.com/payments\?after=AB345}).
|
481
|
-
to_return(
|
482
|
-
status: 502,
|
483
|
-
body: '<html><body>Response from Cloudflare</body></html>',
|
484
|
-
headers: { 'Content-Type' => 'text/html' }
|
485
|
-
).then.to_return(
|
486
|
-
body: {
|
487
|
-
'payments' => [{
|
488
|
-
|
489
|
-
'amount' => 'amount-input',
|
490
|
-
'amount_refunded' => 'amount_refunded-input',
|
491
|
-
'charge_date' => 'charge_date-input',
|
492
|
-
'created_at' => 'created_at-input',
|
493
|
-
'currency' => 'currency-input',
|
494
|
-
'description' => 'description-input',
|
495
|
-
'fx' => 'fx-input',
|
496
|
-
'id' => 'id-input',
|
497
|
-
'links' => 'links-input',
|
498
|
-
'metadata' => 'metadata-input',
|
499
|
-
'reference' => 'reference-input',
|
500
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
501
|
-
'status' => 'status-input',
|
502
|
-
}],
|
503
|
-
meta: {
|
504
|
-
limit: 2,
|
505
|
-
cursors: {},
|
506
|
-
},
|
507
|
-
}.to_json,
|
508
|
-
headers: response_headers
|
509
|
-
)
|
510
|
-
|
511
|
-
client.payments.all.to_a
|
512
|
-
|
513
|
-
expect(first_response_stub).to have_been_requested
|
514
|
-
expect(second_response_stub).to have_been_requested.twice
|
515
|
-
end
|
516
|
-
end
|
517
|
-
end
|
518
|
-
|
519
|
-
describe '#get' do
|
520
|
-
let(:id) { 'ID123' }
|
521
|
-
|
522
|
-
subject(:get_response) { client.payments.get(id) }
|
523
|
-
|
524
|
-
context 'passing in a custom header' do
|
525
|
-
let!(:stub) do
|
526
|
-
stub_url = '/payments/:identity'.gsub(':identity', id)
|
527
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
528
|
-
with(headers: { 'Foo' => 'Bar' }).
|
529
|
-
to_return(
|
530
|
-
body: {
|
531
|
-
'payments' => {
|
532
|
-
|
533
|
-
'amount' => 'amount-input',
|
534
|
-
'amount_refunded' => 'amount_refunded-input',
|
535
|
-
'charge_date' => 'charge_date-input',
|
536
|
-
'created_at' => 'created_at-input',
|
537
|
-
'currency' => 'currency-input',
|
538
|
-
'description' => 'description-input',
|
539
|
-
'fx' => 'fx-input',
|
540
|
-
'id' => 'id-input',
|
541
|
-
'links' => 'links-input',
|
542
|
-
'metadata' => 'metadata-input',
|
543
|
-
'reference' => 'reference-input',
|
544
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
545
|
-
'status' => 'status-input',
|
546
|
-
},
|
547
|
-
}.to_json,
|
548
|
-
headers: response_headers
|
549
|
-
)
|
550
|
-
end
|
551
|
-
|
552
|
-
subject(:get_response) do
|
553
|
-
client.payments.get(id, headers: {
|
554
|
-
'Foo' => 'Bar',
|
555
|
-
})
|
556
|
-
end
|
557
|
-
|
558
|
-
it 'includes the header' do
|
559
|
-
get_response
|
560
|
-
expect(stub).to have_been_requested
|
561
|
-
end
|
562
|
-
end
|
563
|
-
|
564
|
-
context 'when there is a payment to return' do
|
565
|
-
before do
|
566
|
-
stub_url = '/payments/:identity'.gsub(':identity', id)
|
567
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
568
|
-
body: {
|
569
|
-
'payments' => {
|
570
|
-
|
571
|
-
'amount' => 'amount-input',
|
572
|
-
'amount_refunded' => 'amount_refunded-input',
|
573
|
-
'charge_date' => 'charge_date-input',
|
574
|
-
'created_at' => 'created_at-input',
|
575
|
-
'currency' => 'currency-input',
|
576
|
-
'description' => 'description-input',
|
577
|
-
'fx' => 'fx-input',
|
578
|
-
'id' => 'id-input',
|
579
|
-
'links' => 'links-input',
|
580
|
-
'metadata' => 'metadata-input',
|
581
|
-
'reference' => 'reference-input',
|
582
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
583
|
-
'status' => 'status-input',
|
584
|
-
},
|
585
|
-
}.to_json,
|
586
|
-
headers: response_headers
|
587
|
-
)
|
588
|
-
end
|
589
|
-
|
590
|
-
it 'wraps the response in a resource' do
|
591
|
-
expect(get_response).to be_a(GoCardlessPro::Resources::Payment)
|
592
|
-
end
|
593
|
-
end
|
594
|
-
|
595
|
-
context 'when nothing is returned' do
|
596
|
-
before do
|
597
|
-
stub_url = '/payments/:identity'.gsub(':identity', id)
|
598
|
-
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
599
|
-
body: '',
|
600
|
-
headers: response_headers
|
601
|
-
)
|
602
|
-
end
|
603
|
-
|
604
|
-
it 'returns nil' do
|
605
|
-
expect(get_response).to be_nil
|
606
|
-
end
|
607
|
-
end
|
608
|
-
|
609
|
-
context "when an ID is specified which can't be included in a valid URI" do
|
610
|
-
let(:id) { '`' }
|
611
|
-
|
612
|
-
it "doesn't raise an error" do
|
613
|
-
expect { get_response }.to_not raise_error(/bad URI/)
|
614
|
-
end
|
615
|
-
end
|
616
|
-
|
617
|
-
describe 'retry behaviour' do
|
618
|
-
before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
|
619
|
-
|
620
|
-
it 'retries timeouts' do
|
621
|
-
stub_url = '/payments/:identity'.gsub(':identity', id)
|
622
|
-
|
623
|
-
stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
624
|
-
to_timeout.then.to_return(status: 200, headers: response_headers)
|
625
|
-
|
626
|
-
get_response
|
627
|
-
expect(stub).to have_been_requested.twice
|
628
|
-
end
|
629
|
-
|
630
|
-
it 'retries 5XX errors, other than 500s' do
|
631
|
-
stub_url = '/payments/:identity'.gsub(':identity', id)
|
632
|
-
|
633
|
-
stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
634
|
-
to_return(status: 502,
|
635
|
-
headers: { 'Content-Type' => 'text/html' },
|
636
|
-
body: '<html><body>Response from Cloudflare</body></html>').
|
637
|
-
then.to_return(status: 200, headers: response_headers)
|
638
|
-
|
639
|
-
get_response
|
640
|
-
expect(stub).to have_been_requested.twice
|
641
|
-
end
|
642
|
-
|
643
|
-
it 'retries 500 errors returned by the API' do
|
644
|
-
stub_url = '/payments/:identity'.gsub(':identity', id)
|
645
|
-
|
646
|
-
gocardless_error = {
|
647
|
-
'error' => {
|
648
|
-
'message' => 'Internal server error',
|
649
|
-
'documentation_url' => 'https://developer.gocardless.com/#gocardless',
|
650
|
-
'errors' => [{
|
651
|
-
'message' => 'Internal server error',
|
652
|
-
'reason' => 'internal_server_error',
|
653
|
-
}],
|
654
|
-
'type' => 'gocardless',
|
655
|
-
'code' => 500,
|
656
|
-
'request_id' => 'dummy_request_id',
|
657
|
-
'id' => 'dummy_exception_id',
|
658
|
-
},
|
659
|
-
}
|
660
|
-
|
661
|
-
stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
662
|
-
to_return(status: 500,
|
663
|
-
headers: response_headers,
|
664
|
-
body: gocardless_error.to_json).
|
665
|
-
then.to_return(status: 200, headers: response_headers)
|
666
|
-
|
667
|
-
get_response
|
668
|
-
expect(stub).to have_been_requested.twice
|
669
|
-
end
|
670
|
-
end
|
671
|
-
end
|
672
|
-
|
673
|
-
describe '#update' do
|
674
|
-
subject(:put_update_response) { client.payments.update(id, params: update_params) }
|
675
|
-
let(:id) { 'ABC123' }
|
676
|
-
|
677
|
-
context 'with a valid request' do
|
678
|
-
let(:update_params) { { 'hello' => 'world' } }
|
679
|
-
|
680
|
-
let!(:stub) do
|
681
|
-
stub_url = '/payments/:identity'.gsub(':identity', id)
|
682
|
-
stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
|
683
|
-
body: {
|
684
|
-
'payments' => {
|
685
|
-
|
686
|
-
'amount' => 'amount-input',
|
687
|
-
'amount_refunded' => 'amount_refunded-input',
|
688
|
-
'charge_date' => 'charge_date-input',
|
689
|
-
'created_at' => 'created_at-input',
|
690
|
-
'currency' => 'currency-input',
|
691
|
-
'description' => 'description-input',
|
692
|
-
'fx' => 'fx-input',
|
693
|
-
'id' => 'id-input',
|
694
|
-
'links' => 'links-input',
|
695
|
-
'metadata' => 'metadata-input',
|
696
|
-
'reference' => 'reference-input',
|
697
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
698
|
-
'status' => 'status-input',
|
699
|
-
},
|
700
|
-
}.to_json,
|
701
|
-
headers: response_headers
|
702
|
-
)
|
703
|
-
end
|
704
|
-
|
705
|
-
it 'updates and returns the resource' do
|
706
|
-
expect(put_update_response).to be_a(GoCardlessPro::Resources::Payment)
|
707
|
-
expect(stub).to have_been_requested
|
708
|
-
end
|
709
|
-
|
710
|
-
describe 'retry behaviour' do
|
711
|
-
before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
|
712
|
-
|
713
|
-
it 'retries timeouts' do
|
714
|
-
stub_url = '/payments/:identity'.gsub(':identity', id)
|
715
|
-
stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
|
716
|
-
to_timeout.then.to_return(status: 200, headers: response_headers)
|
717
|
-
|
718
|
-
put_update_response
|
719
|
-
expect(stub).to have_been_requested.twice
|
720
|
-
end
|
721
|
-
|
722
|
-
it 'retries 5XX errors' do
|
723
|
-
stub_url = '/payments/:identity'.gsub(':identity', id)
|
724
|
-
stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
|
725
|
-
to_return(status: 502,
|
726
|
-
headers: { 'Content-Type' => 'text/html' },
|
727
|
-
body: '<html><body>Response from Cloudflare</body></html>').
|
728
|
-
then.to_return(status: 200, headers: response_headers)
|
729
|
-
|
730
|
-
put_update_response
|
731
|
-
expect(stub).to have_been_requested.twice
|
732
|
-
end
|
733
|
-
end
|
734
|
-
end
|
735
|
-
end
|
736
|
-
|
737
|
-
describe '#cancel' do
|
738
|
-
subject(:post_response) { client.payments.cancel(resource_id) }
|
739
|
-
|
740
|
-
let(:resource_id) { 'ABC123' }
|
741
|
-
|
742
|
-
let!(:stub) do
|
743
|
-
# /payments/%v/actions/cancel
|
744
|
-
stub_url = '/payments/:identity/actions/cancel'.gsub(':identity', resource_id)
|
745
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
746
|
-
|
747
|
-
body: {
|
748
|
-
'payments' => {
|
749
|
-
|
750
|
-
'amount' => 'amount-input',
|
751
|
-
'amount_refunded' => 'amount_refunded-input',
|
752
|
-
'charge_date' => 'charge_date-input',
|
753
|
-
'created_at' => 'created_at-input',
|
754
|
-
'currency' => 'currency-input',
|
755
|
-
'description' => 'description-input',
|
756
|
-
'fx' => 'fx-input',
|
757
|
-
'id' => 'id-input',
|
758
|
-
'links' => 'links-input',
|
759
|
-
'metadata' => 'metadata-input',
|
760
|
-
'reference' => 'reference-input',
|
761
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
762
|
-
'status' => 'status-input',
|
763
|
-
},
|
764
|
-
}.to_json,
|
765
|
-
|
766
|
-
headers: response_headers
|
767
|
-
)
|
768
|
-
end
|
769
|
-
|
770
|
-
it 'wraps the response and calls the right endpoint' do
|
771
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::Payment)
|
772
|
-
|
773
|
-
expect(stub).to have_been_requested
|
774
|
-
end
|
775
|
-
|
776
|
-
describe 'retry behaviour' do
|
777
|
-
it "doesn't retry errors" do
|
778
|
-
stub_url = '/payments/:identity/actions/cancel'.gsub(':identity', resource_id)
|
779
|
-
stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
780
|
-
to_timeout
|
781
|
-
|
782
|
-
expect { post_response }.to raise_error(Faraday::ConnectionFailed)
|
783
|
-
expect(stub).to have_been_requested
|
784
|
-
end
|
785
|
-
end
|
786
|
-
|
787
|
-
context 'when the request needs a body and custom header' do
|
788
|
-
let(:body) { { foo: 'bar' } }
|
789
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
790
|
-
subject(:post_response) { client.payments.cancel(resource_id, body, headers) }
|
791
|
-
|
792
|
-
let(:resource_id) { 'ABC123' }
|
793
|
-
|
794
|
-
let!(:stub) do
|
795
|
-
# /payments/%v/actions/cancel
|
796
|
-
stub_url = '/payments/:identity/actions/cancel'.gsub(':identity', resource_id)
|
797
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
798
|
-
with(
|
799
|
-
body: { foo: 'bar' },
|
800
|
-
headers: { 'Foo' => 'Bar' }
|
801
|
-
).to_return(
|
802
|
-
body: {
|
803
|
-
'payments' => {
|
804
|
-
|
805
|
-
'amount' => 'amount-input',
|
806
|
-
'amount_refunded' => 'amount_refunded-input',
|
807
|
-
'charge_date' => 'charge_date-input',
|
808
|
-
'created_at' => 'created_at-input',
|
809
|
-
'currency' => 'currency-input',
|
810
|
-
'description' => 'description-input',
|
811
|
-
'fx' => 'fx-input',
|
812
|
-
'id' => 'id-input',
|
813
|
-
'links' => 'links-input',
|
814
|
-
'metadata' => 'metadata-input',
|
815
|
-
'reference' => 'reference-input',
|
816
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
817
|
-
'status' => 'status-input',
|
818
|
-
},
|
819
|
-
}.to_json,
|
820
|
-
headers: response_headers
|
821
|
-
)
|
822
|
-
end
|
823
|
-
end
|
824
|
-
end
|
825
|
-
|
826
|
-
describe '#retry' do
|
827
|
-
subject(:post_response) { client.payments.retry(resource_id) }
|
828
|
-
|
829
|
-
let(:resource_id) { 'ABC123' }
|
830
|
-
|
831
|
-
let!(:stub) do
|
832
|
-
# /payments/%v/actions/retry
|
833
|
-
stub_url = '/payments/:identity/actions/retry'.gsub(':identity', resource_id)
|
834
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
835
|
-
|
836
|
-
body: {
|
837
|
-
'payments' => {
|
838
|
-
|
839
|
-
'amount' => 'amount-input',
|
840
|
-
'amount_refunded' => 'amount_refunded-input',
|
841
|
-
'charge_date' => 'charge_date-input',
|
842
|
-
'created_at' => 'created_at-input',
|
843
|
-
'currency' => 'currency-input',
|
844
|
-
'description' => 'description-input',
|
845
|
-
'fx' => 'fx-input',
|
846
|
-
'id' => 'id-input',
|
847
|
-
'links' => 'links-input',
|
848
|
-
'metadata' => 'metadata-input',
|
849
|
-
'reference' => 'reference-input',
|
850
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
851
|
-
'status' => 'status-input',
|
852
|
-
},
|
853
|
-
}.to_json,
|
854
|
-
|
855
|
-
headers: response_headers
|
856
|
-
)
|
857
|
-
end
|
858
|
-
|
859
|
-
it 'wraps the response and calls the right endpoint' do
|
860
|
-
expect(post_response).to be_a(GoCardlessPro::Resources::Payment)
|
861
|
-
|
862
|
-
expect(stub).to have_been_requested
|
863
|
-
end
|
864
|
-
|
865
|
-
describe 'retry behaviour' do
|
866
|
-
it "doesn't retry errors" do
|
867
|
-
stub_url = '/payments/:identity/actions/retry'.gsub(':identity', resource_id)
|
868
|
-
stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
869
|
-
to_timeout
|
870
|
-
|
871
|
-
expect { post_response }.to raise_error(Faraday::ConnectionFailed)
|
872
|
-
expect(stub).to have_been_requested
|
873
|
-
end
|
874
|
-
end
|
875
|
-
|
876
|
-
context 'when the request needs a body and custom header' do
|
877
|
-
let(:body) { { foo: 'bar' } }
|
878
|
-
let(:headers) { { 'Foo' => 'Bar' } }
|
879
|
-
subject(:post_response) { client.payments.retry(resource_id, body, headers) }
|
880
|
-
|
881
|
-
let(:resource_id) { 'ABC123' }
|
882
|
-
|
883
|
-
let!(:stub) do
|
884
|
-
# /payments/%v/actions/retry
|
885
|
-
stub_url = '/payments/:identity/actions/retry'.gsub(':identity', resource_id)
|
886
|
-
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
887
|
-
with(
|
888
|
-
body: { foo: 'bar' },
|
889
|
-
headers: { 'Foo' => 'Bar' }
|
890
|
-
).to_return(
|
891
|
-
body: {
|
892
|
-
'payments' => {
|
893
|
-
|
894
|
-
'amount' => 'amount-input',
|
895
|
-
'amount_refunded' => 'amount_refunded-input',
|
896
|
-
'charge_date' => 'charge_date-input',
|
897
|
-
'created_at' => 'created_at-input',
|
898
|
-
'currency' => 'currency-input',
|
899
|
-
'description' => 'description-input',
|
900
|
-
'fx' => 'fx-input',
|
901
|
-
'id' => 'id-input',
|
902
|
-
'links' => 'links-input',
|
903
|
-
'metadata' => 'metadata-input',
|
904
|
-
'reference' => 'reference-input',
|
905
|
-
'retry_if_possible' => 'retry_if_possible-input',
|
906
|
-
'status' => 'status-input',
|
907
|
-
},
|
908
|
-
}.to_json,
|
909
|
-
headers: response_headers
|
910
|
-
)
|
911
|
-
end
|
912
|
-
end
|
913
|
-
end
|
914
|
-
end
|