gocardless_pro 2.24.0 → 2.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +23 -4
- data/lib/gocardless_pro/api_service.rb +4 -0
- data/lib/gocardless_pro/client.rb +46 -1
- data/lib/gocardless_pro/error/authentication_error.rb +4 -0
- data/lib/gocardless_pro/error/permission_error.rb +4 -0
- data/lib/gocardless_pro/error/rate_limit_error.rb +4 -0
- data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +12 -1
- data/lib/gocardless_pro/resources/bank_authorisation.rb +81 -0
- data/lib/gocardless_pro/resources/billing_request.rb +108 -0
- data/lib/gocardless_pro/resources/billing_request_flow.rb +72 -0
- data/lib/gocardless_pro/resources/billing_request_template.rb +68 -0
- data/lib/gocardless_pro/resources/block.rb +66 -0
- data/lib/gocardless_pro/resources/creditor.rb +2 -3
- data/lib/gocardless_pro/resources/event.rb +20 -0
- data/lib/gocardless_pro/resources/institution.rb +47 -0
- data/lib/gocardless_pro/resources/payer_authorisation.rb +131 -0
- data/lib/gocardless_pro/resources/payout_item.rb +4 -0
- data/lib/gocardless_pro/resources/redirect_flow.rb +2 -0
- data/lib/gocardless_pro/resources/scenario_simulator.rb +42 -0
- data/lib/gocardless_pro/resources/webhook.rb +62 -0
- data/lib/gocardless_pro/services/bank_authorisations_service.rb +80 -0
- data/lib/gocardless_pro/services/billing_request_flows_service.rb +70 -0
- data/lib/gocardless_pro/services/billing_request_templates_service.rb +131 -0
- data/lib/gocardless_pro/services/billing_requests_service.rb +352 -0
- data/lib/gocardless_pro/services/blocks_service.rb +223 -0
- data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +1 -5
- data/lib/gocardless_pro/services/creditors_service.rb +1 -3
- data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +1 -1
- data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +1 -5
- data/lib/gocardless_pro/services/customers_service.rb +1 -3
- data/lib/gocardless_pro/services/events_service.rb +1 -1
- data/lib/gocardless_pro/services/instalment_schedules_service.rb +1 -7
- data/lib/gocardless_pro/services/institutions_service.rb +56 -0
- data/lib/gocardless_pro/services/mandate_import_entries_service.rb +1 -1
- data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -6
- data/lib/gocardless_pro/services/mandates_service.rb +1 -7
- data/lib/gocardless_pro/services/payer_authorisations_service.rb +202 -0
- data/lib/gocardless_pro/services/payments_service.rb +1 -7
- data/lib/gocardless_pro/services/payout_items_service.rb +1 -1
- data/lib/gocardless_pro/services/payouts_service.rb +1 -1
- data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -4
- data/lib/gocardless_pro/services/refunds_service.rb +1 -3
- data/lib/gocardless_pro/services/scenario_simulators_service.rb +170 -0
- data/lib/gocardless_pro/services/subscriptions_service.rb +10 -13
- data/lib/gocardless_pro/services/tax_rates_service.rb +1 -1
- data/lib/gocardless_pro/services/webhooks_service.rb +111 -0
- data/lib/gocardless_pro/version.rb +1 -1
- data/lib/gocardless_pro.rb +30 -0
- data/spec/api_service_spec.rb +12 -1
- data/spec/middlewares/raise_gocardless_errors_spec.rb +30 -0
- data/spec/resources/bank_authorisation_spec.rb +259 -0
- data/spec/resources/billing_request_flow_spec.rb +219 -0
- data/spec/resources/billing_request_spec.rb +782 -0
- data/spec/resources/billing_request_template_spec.rb +502 -0
- data/spec/resources/block_spec.rb +560 -0
- data/spec/resources/institution_spec.rb +108 -0
- data/spec/resources/payer_authorisation_spec.rb +418 -0
- data/spec/resources/redirect_flow_spec.rb +9 -0
- data/spec/resources/scenario_simulator_spec.rb +63 -0
- data/spec/resources/webhook_spec.rb +323 -0
- data/spec/services/bank_authorisations_service_spec.rb +353 -0
- data/spec/services/billing_request_flows_service_spec.rb +253 -0
- data/spec/services/billing_request_templates_service_spec.rb +789 -0
- data/spec/services/billing_requests_service_spec.rb +1082 -0
- data/spec/services/blocks_service_spec.rb +823 -0
- data/spec/services/creditor_bank_accounts_service_spec.rb +0 -13
- data/spec/services/creditors_service_spec.rb +0 -13
- data/spec/services/customer_bank_accounts_service_spec.rb +0 -13
- data/spec/services/customers_service_spec.rb +0 -13
- data/spec/services/instalment_schedules_service_spec.rb +0 -26
- data/spec/services/institutions_service_spec.rb +232 -0
- data/spec/services/mandate_imports_service_spec.rb +0 -13
- data/spec/services/mandates_service_spec.rb +0 -13
- data/spec/services/payer_authorisations_service_spec.rb +559 -0
- data/spec/services/payments_service_spec.rb +0 -13
- data/spec/services/redirect_flows_service_spec.rb +9 -13
- data/spec/services/refunds_service_spec.rb +0 -13
- data/spec/services/scenario_simulators_service_spec.rb +74 -0
- data/spec/services/subscriptions_service_spec.rb +0 -13
- data/spec/services/webhooks_service_spec.rb +545 -0
- metadata +64 -7
@@ -0,0 +1,502 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GoCardlessPro::Resources::BillingRequestTemplate 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_request_templates.list }
|
15
|
+
|
16
|
+
before do
|
17
|
+
stub_request(:get, %r{.*api.gocardless.com/billing_request_templates}).to_return(
|
18
|
+
body: {
|
19
|
+
'billing_request_templates' => [{
|
20
|
+
|
21
|
+
'authorisation_url' => 'authorisation_url-input',
|
22
|
+
'created_at' => 'created_at-input',
|
23
|
+
'id' => 'id-input',
|
24
|
+
'mandate_request_currency' => 'mandate_request_currency-input',
|
25
|
+
'mandate_request_metadata' => 'mandate_request_metadata-input',
|
26
|
+
'mandate_request_scheme' => 'mandate_request_scheme-input',
|
27
|
+
'mandate_request_verify' => 'mandate_request_verify-input',
|
28
|
+
'metadata' => 'metadata-input',
|
29
|
+
'name' => 'name-input',
|
30
|
+
'payment_request_amount' => 'payment_request_amount-input',
|
31
|
+
'payment_request_currency' => 'payment_request_currency-input',
|
32
|
+
'payment_request_description' => 'payment_request_description-input',
|
33
|
+
'payment_request_metadata' => 'payment_request_metadata-input',
|
34
|
+
'payment_request_scheme' => 'payment_request_scheme-input',
|
35
|
+
'redirect_uri' => 'redirect_uri-input',
|
36
|
+
'updated_at' => 'updated_at-input',
|
37
|
+
}],
|
38
|
+
meta: {
|
39
|
+
cursors: {
|
40
|
+
before: nil,
|
41
|
+
after: 'ABC123',
|
42
|
+
},
|
43
|
+
},
|
44
|
+
}.to_json,
|
45
|
+
headers: response_headers
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'wraps each item in the resource class' do
|
50
|
+
expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::BillingRequestTemplate)
|
51
|
+
|
52
|
+
expect(get_list_response.records.first.authorisation_url).to eq('authorisation_url-input')
|
53
|
+
|
54
|
+
expect(get_list_response.records.first.created_at).to eq('created_at-input')
|
55
|
+
|
56
|
+
expect(get_list_response.records.first.id).to eq('id-input')
|
57
|
+
|
58
|
+
expect(get_list_response.records.first.mandate_request_currency).to eq('mandate_request_currency-input')
|
59
|
+
|
60
|
+
expect(get_list_response.records.first.mandate_request_metadata).to eq('mandate_request_metadata-input')
|
61
|
+
|
62
|
+
expect(get_list_response.records.first.mandate_request_scheme).to eq('mandate_request_scheme-input')
|
63
|
+
|
64
|
+
expect(get_list_response.records.first.mandate_request_verify).to eq('mandate_request_verify-input')
|
65
|
+
|
66
|
+
expect(get_list_response.records.first.metadata).to eq('metadata-input')
|
67
|
+
|
68
|
+
expect(get_list_response.records.first.name).to eq('name-input')
|
69
|
+
|
70
|
+
expect(get_list_response.records.first.payment_request_amount).to eq('payment_request_amount-input')
|
71
|
+
|
72
|
+
expect(get_list_response.records.first.payment_request_currency).to eq('payment_request_currency-input')
|
73
|
+
|
74
|
+
expect(get_list_response.records.first.payment_request_description).to eq('payment_request_description-input')
|
75
|
+
|
76
|
+
expect(get_list_response.records.first.payment_request_metadata).to eq('payment_request_metadata-input')
|
77
|
+
|
78
|
+
expect(get_list_response.records.first.payment_request_scheme).to eq('payment_request_scheme-input')
|
79
|
+
|
80
|
+
expect(get_list_response.records.first.redirect_uri).to eq('redirect_uri-input')
|
81
|
+
|
82
|
+
expect(get_list_response.records.first.updated_at).to eq('updated_at-input')
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'exposes the cursors for before and after' do
|
86
|
+
expect(get_list_response.before).to eq(nil)
|
87
|
+
expect(get_list_response.after).to eq('ABC123')
|
88
|
+
end
|
89
|
+
|
90
|
+
specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#all' do
|
95
|
+
let!(:first_response_stub) do
|
96
|
+
stub_request(:get, %r{.*api.gocardless.com/billing_request_templates$}).to_return(
|
97
|
+
body: {
|
98
|
+
'billing_request_templates' => [{
|
99
|
+
|
100
|
+
'authorisation_url' => 'authorisation_url-input',
|
101
|
+
'created_at' => 'created_at-input',
|
102
|
+
'id' => 'id-input',
|
103
|
+
'mandate_request_currency' => 'mandate_request_currency-input',
|
104
|
+
'mandate_request_metadata' => 'mandate_request_metadata-input',
|
105
|
+
'mandate_request_scheme' => 'mandate_request_scheme-input',
|
106
|
+
'mandate_request_verify' => 'mandate_request_verify-input',
|
107
|
+
'metadata' => 'metadata-input',
|
108
|
+
'name' => 'name-input',
|
109
|
+
'payment_request_amount' => 'payment_request_amount-input',
|
110
|
+
'payment_request_currency' => 'payment_request_currency-input',
|
111
|
+
'payment_request_description' => 'payment_request_description-input',
|
112
|
+
'payment_request_metadata' => 'payment_request_metadata-input',
|
113
|
+
'payment_request_scheme' => 'payment_request_scheme-input',
|
114
|
+
'redirect_uri' => 'redirect_uri-input',
|
115
|
+
'updated_at' => 'updated_at-input',
|
116
|
+
}],
|
117
|
+
meta: {
|
118
|
+
cursors: { after: 'AB345' },
|
119
|
+
limit: 1,
|
120
|
+
},
|
121
|
+
}.to_json,
|
122
|
+
headers: response_headers
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
126
|
+
let!(:second_response_stub) do
|
127
|
+
stub_request(:get, %r{.*api.gocardless.com/billing_request_templates\?after=AB345}).to_return(
|
128
|
+
body: {
|
129
|
+
'billing_request_templates' => [{
|
130
|
+
|
131
|
+
'authorisation_url' => 'authorisation_url-input',
|
132
|
+
'created_at' => 'created_at-input',
|
133
|
+
'id' => 'id-input',
|
134
|
+
'mandate_request_currency' => 'mandate_request_currency-input',
|
135
|
+
'mandate_request_metadata' => 'mandate_request_metadata-input',
|
136
|
+
'mandate_request_scheme' => 'mandate_request_scheme-input',
|
137
|
+
'mandate_request_verify' => 'mandate_request_verify-input',
|
138
|
+
'metadata' => 'metadata-input',
|
139
|
+
'name' => 'name-input',
|
140
|
+
'payment_request_amount' => 'payment_request_amount-input',
|
141
|
+
'payment_request_currency' => 'payment_request_currency-input',
|
142
|
+
'payment_request_description' => 'payment_request_description-input',
|
143
|
+
'payment_request_metadata' => 'payment_request_metadata-input',
|
144
|
+
'payment_request_scheme' => 'payment_request_scheme-input',
|
145
|
+
'redirect_uri' => 'redirect_uri-input',
|
146
|
+
'updated_at' => 'updated_at-input',
|
147
|
+
}],
|
148
|
+
meta: {
|
149
|
+
limit: 2,
|
150
|
+
cursors: {},
|
151
|
+
},
|
152
|
+
}.to_json,
|
153
|
+
headers: response_headers
|
154
|
+
)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'automatically makes the extra requests' do
|
158
|
+
expect(client.billing_request_templates.all.to_a.length).to eq(2)
|
159
|
+
expect(first_response_stub).to have_been_requested
|
160
|
+
expect(second_response_stub).to have_been_requested
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#get' do
|
165
|
+
let(:id) { 'ID123' }
|
166
|
+
|
167
|
+
subject(:get_response) { client.billing_request_templates.get(id) }
|
168
|
+
|
169
|
+
context 'passing in a custom header' do
|
170
|
+
let!(:stub) do
|
171
|
+
stub_url = '/billing_request_templates/:identity'.gsub(':identity', id)
|
172
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
173
|
+
with(headers: { 'Foo' => 'Bar' }).
|
174
|
+
to_return(
|
175
|
+
body: {
|
176
|
+
'billing_request_templates' => {
|
177
|
+
|
178
|
+
'authorisation_url' => 'authorisation_url-input',
|
179
|
+
'created_at' => 'created_at-input',
|
180
|
+
'id' => 'id-input',
|
181
|
+
'mandate_request_currency' => 'mandate_request_currency-input',
|
182
|
+
'mandate_request_metadata' => 'mandate_request_metadata-input',
|
183
|
+
'mandate_request_scheme' => 'mandate_request_scheme-input',
|
184
|
+
'mandate_request_verify' => 'mandate_request_verify-input',
|
185
|
+
'metadata' => 'metadata-input',
|
186
|
+
'name' => 'name-input',
|
187
|
+
'payment_request_amount' => 'payment_request_amount-input',
|
188
|
+
'payment_request_currency' => 'payment_request_currency-input',
|
189
|
+
'payment_request_description' => 'payment_request_description-input',
|
190
|
+
'payment_request_metadata' => 'payment_request_metadata-input',
|
191
|
+
'payment_request_scheme' => 'payment_request_scheme-input',
|
192
|
+
'redirect_uri' => 'redirect_uri-input',
|
193
|
+
'updated_at' => 'updated_at-input',
|
194
|
+
},
|
195
|
+
}.to_json,
|
196
|
+
headers: response_headers
|
197
|
+
)
|
198
|
+
end
|
199
|
+
|
200
|
+
subject(:get_response) do
|
201
|
+
client.billing_request_templates.get(id, headers: {
|
202
|
+
'Foo' => 'Bar',
|
203
|
+
})
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'includes the header' do
|
207
|
+
get_response
|
208
|
+
expect(stub).to have_been_requested
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'when there is a billing_request_template to return' do
|
213
|
+
before do
|
214
|
+
stub_url = '/billing_request_templates/:identity'.gsub(':identity', id)
|
215
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
216
|
+
body: {
|
217
|
+
'billing_request_templates' => {
|
218
|
+
|
219
|
+
'authorisation_url' => 'authorisation_url-input',
|
220
|
+
'created_at' => 'created_at-input',
|
221
|
+
'id' => 'id-input',
|
222
|
+
'mandate_request_currency' => 'mandate_request_currency-input',
|
223
|
+
'mandate_request_metadata' => 'mandate_request_metadata-input',
|
224
|
+
'mandate_request_scheme' => 'mandate_request_scheme-input',
|
225
|
+
'mandate_request_verify' => 'mandate_request_verify-input',
|
226
|
+
'metadata' => 'metadata-input',
|
227
|
+
'name' => 'name-input',
|
228
|
+
'payment_request_amount' => 'payment_request_amount-input',
|
229
|
+
'payment_request_currency' => 'payment_request_currency-input',
|
230
|
+
'payment_request_description' => 'payment_request_description-input',
|
231
|
+
'payment_request_metadata' => 'payment_request_metadata-input',
|
232
|
+
'payment_request_scheme' => 'payment_request_scheme-input',
|
233
|
+
'redirect_uri' => 'redirect_uri-input',
|
234
|
+
'updated_at' => 'updated_at-input',
|
235
|
+
},
|
236
|
+
}.to_json,
|
237
|
+
headers: response_headers
|
238
|
+
)
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'wraps the response in a resource' do
|
242
|
+
expect(get_response).to be_a(GoCardlessPro::Resources::BillingRequestTemplate)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'when nothing is returned' do
|
247
|
+
before do
|
248
|
+
stub_url = '/billing_request_templates/:identity'.gsub(':identity', id)
|
249
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
250
|
+
body: '',
|
251
|
+
headers: response_headers
|
252
|
+
)
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'returns nil' do
|
256
|
+
expect(get_response).to be_nil
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
context "when an ID is specified which can't be included in a valid URI" do
|
261
|
+
let(:id) { '`' }
|
262
|
+
|
263
|
+
it "doesn't raise an error" do
|
264
|
+
expect { get_response }.to_not raise_error(/bad URI/)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe '#create' do
|
270
|
+
subject(:post_create_response) { client.billing_request_templates.create(params: new_resource) }
|
271
|
+
context 'with a valid request' do
|
272
|
+
let(:new_resource) do
|
273
|
+
{
|
274
|
+
|
275
|
+
'authorisation_url' => 'authorisation_url-input',
|
276
|
+
'created_at' => 'created_at-input',
|
277
|
+
'id' => 'id-input',
|
278
|
+
'mandate_request_currency' => 'mandate_request_currency-input',
|
279
|
+
'mandate_request_metadata' => 'mandate_request_metadata-input',
|
280
|
+
'mandate_request_scheme' => 'mandate_request_scheme-input',
|
281
|
+
'mandate_request_verify' => 'mandate_request_verify-input',
|
282
|
+
'metadata' => 'metadata-input',
|
283
|
+
'name' => 'name-input',
|
284
|
+
'payment_request_amount' => 'payment_request_amount-input',
|
285
|
+
'payment_request_currency' => 'payment_request_currency-input',
|
286
|
+
'payment_request_description' => 'payment_request_description-input',
|
287
|
+
'payment_request_metadata' => 'payment_request_metadata-input',
|
288
|
+
'payment_request_scheme' => 'payment_request_scheme-input',
|
289
|
+
'redirect_uri' => 'redirect_uri-input',
|
290
|
+
'updated_at' => 'updated_at-input',
|
291
|
+
}
|
292
|
+
end
|
293
|
+
|
294
|
+
before do
|
295
|
+
stub_request(:post, %r{.*api.gocardless.com/billing_request_templates}).
|
296
|
+
with(
|
297
|
+
body: {
|
298
|
+
'billing_request_templates' => {
|
299
|
+
|
300
|
+
'authorisation_url' => 'authorisation_url-input',
|
301
|
+
'created_at' => 'created_at-input',
|
302
|
+
'id' => 'id-input',
|
303
|
+
'mandate_request_currency' => 'mandate_request_currency-input',
|
304
|
+
'mandate_request_metadata' => 'mandate_request_metadata-input',
|
305
|
+
'mandate_request_scheme' => 'mandate_request_scheme-input',
|
306
|
+
'mandate_request_verify' => 'mandate_request_verify-input',
|
307
|
+
'metadata' => 'metadata-input',
|
308
|
+
'name' => 'name-input',
|
309
|
+
'payment_request_amount' => 'payment_request_amount-input',
|
310
|
+
'payment_request_currency' => 'payment_request_currency-input',
|
311
|
+
'payment_request_description' => 'payment_request_description-input',
|
312
|
+
'payment_request_metadata' => 'payment_request_metadata-input',
|
313
|
+
'payment_request_scheme' => 'payment_request_scheme-input',
|
314
|
+
'redirect_uri' => 'redirect_uri-input',
|
315
|
+
'updated_at' => 'updated_at-input',
|
316
|
+
},
|
317
|
+
}
|
318
|
+
).
|
319
|
+
to_return(
|
320
|
+
body: {
|
321
|
+
'billing_request_templates' =>
|
322
|
+
|
323
|
+
{
|
324
|
+
|
325
|
+
'authorisation_url' => 'authorisation_url-input',
|
326
|
+
'created_at' => 'created_at-input',
|
327
|
+
'id' => 'id-input',
|
328
|
+
'mandate_request_currency' => 'mandate_request_currency-input',
|
329
|
+
'mandate_request_metadata' => 'mandate_request_metadata-input',
|
330
|
+
'mandate_request_scheme' => 'mandate_request_scheme-input',
|
331
|
+
'mandate_request_verify' => 'mandate_request_verify-input',
|
332
|
+
'metadata' => 'metadata-input',
|
333
|
+
'name' => 'name-input',
|
334
|
+
'payment_request_amount' => 'payment_request_amount-input',
|
335
|
+
'payment_request_currency' => 'payment_request_currency-input',
|
336
|
+
'payment_request_description' => 'payment_request_description-input',
|
337
|
+
'payment_request_metadata' => 'payment_request_metadata-input',
|
338
|
+
'payment_request_scheme' => 'payment_request_scheme-input',
|
339
|
+
'redirect_uri' => 'redirect_uri-input',
|
340
|
+
'updated_at' => 'updated_at-input',
|
341
|
+
},
|
342
|
+
|
343
|
+
}.to_json,
|
344
|
+
headers: response_headers
|
345
|
+
)
|
346
|
+
end
|
347
|
+
|
348
|
+
it 'creates and returns the resource' do
|
349
|
+
expect(post_create_response).to be_a(GoCardlessPro::Resources::BillingRequestTemplate)
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
context 'with a request that returns a validation error' do
|
354
|
+
let(:new_resource) { {} }
|
355
|
+
|
356
|
+
before do
|
357
|
+
stub_request(:post, %r{.*api.gocardless.com/billing_request_templates}).to_return(
|
358
|
+
body: {
|
359
|
+
error: {
|
360
|
+
type: 'validation_failed',
|
361
|
+
code: 422,
|
362
|
+
errors: [
|
363
|
+
{ message: 'test error message', field: 'test_field' },
|
364
|
+
],
|
365
|
+
},
|
366
|
+
}.to_json,
|
367
|
+
headers: response_headers,
|
368
|
+
status: 422
|
369
|
+
)
|
370
|
+
end
|
371
|
+
|
372
|
+
it 'throws the correct error' do
|
373
|
+
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
context 'with a request that returns an idempotent creation conflict error' do
|
378
|
+
let(:id) { 'ID123' }
|
379
|
+
|
380
|
+
let(:new_resource) do
|
381
|
+
{
|
382
|
+
|
383
|
+
'authorisation_url' => 'authorisation_url-input',
|
384
|
+
'created_at' => 'created_at-input',
|
385
|
+
'id' => 'id-input',
|
386
|
+
'mandate_request_currency' => 'mandate_request_currency-input',
|
387
|
+
'mandate_request_metadata' => 'mandate_request_metadata-input',
|
388
|
+
'mandate_request_scheme' => 'mandate_request_scheme-input',
|
389
|
+
'mandate_request_verify' => 'mandate_request_verify-input',
|
390
|
+
'metadata' => 'metadata-input',
|
391
|
+
'name' => 'name-input',
|
392
|
+
'payment_request_amount' => 'payment_request_amount-input',
|
393
|
+
'payment_request_currency' => 'payment_request_currency-input',
|
394
|
+
'payment_request_description' => 'payment_request_description-input',
|
395
|
+
'payment_request_metadata' => 'payment_request_metadata-input',
|
396
|
+
'payment_request_scheme' => 'payment_request_scheme-input',
|
397
|
+
'redirect_uri' => 'redirect_uri-input',
|
398
|
+
'updated_at' => 'updated_at-input',
|
399
|
+
}
|
400
|
+
end
|
401
|
+
|
402
|
+
let!(:post_stub) do
|
403
|
+
stub_request(:post, %r{.*api.gocardless.com/billing_request_templates}).to_return(
|
404
|
+
body: {
|
405
|
+
error: {
|
406
|
+
type: 'invalid_state',
|
407
|
+
code: 409,
|
408
|
+
errors: [
|
409
|
+
{
|
410
|
+
message: 'A resource has already been created with this idempotency key',
|
411
|
+
reason: 'idempotent_creation_conflict',
|
412
|
+
links: {
|
413
|
+
conflicting_resource_id: id,
|
414
|
+
},
|
415
|
+
},
|
416
|
+
],
|
417
|
+
},
|
418
|
+
}.to_json,
|
419
|
+
headers: response_headers,
|
420
|
+
status: 409
|
421
|
+
)
|
422
|
+
end
|
423
|
+
|
424
|
+
let!(:get_stub) do
|
425
|
+
stub_url = "/billing_request_templates/#{id}"
|
426
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
427
|
+
to_return(
|
428
|
+
body: {
|
429
|
+
'billing_request_templates' => {
|
430
|
+
|
431
|
+
'authorisation_url' => 'authorisation_url-input',
|
432
|
+
'created_at' => 'created_at-input',
|
433
|
+
'id' => 'id-input',
|
434
|
+
'mandate_request_currency' => 'mandate_request_currency-input',
|
435
|
+
'mandate_request_metadata' => 'mandate_request_metadata-input',
|
436
|
+
'mandate_request_scheme' => 'mandate_request_scheme-input',
|
437
|
+
'mandate_request_verify' => 'mandate_request_verify-input',
|
438
|
+
'metadata' => 'metadata-input',
|
439
|
+
'name' => 'name-input',
|
440
|
+
'payment_request_amount' => 'payment_request_amount-input',
|
441
|
+
'payment_request_currency' => 'payment_request_currency-input',
|
442
|
+
'payment_request_description' => 'payment_request_description-input',
|
443
|
+
'payment_request_metadata' => 'payment_request_metadata-input',
|
444
|
+
'payment_request_scheme' => 'payment_request_scheme-input',
|
445
|
+
'redirect_uri' => 'redirect_uri-input',
|
446
|
+
'updated_at' => 'updated_at-input',
|
447
|
+
},
|
448
|
+
}.to_json,
|
449
|
+
headers: response_headers
|
450
|
+
)
|
451
|
+
end
|
452
|
+
|
453
|
+
it 'fetches the already-created resource' do
|
454
|
+
post_create_response
|
455
|
+
expect(post_stub).to have_been_requested
|
456
|
+
expect(get_stub).to have_been_requested
|
457
|
+
end
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
describe '#update' do
|
462
|
+
subject(:put_update_response) { client.billing_request_templates.update(id, params: update_params) }
|
463
|
+
let(:id) { 'ABC123' }
|
464
|
+
|
465
|
+
context 'with a valid request' do
|
466
|
+
let(:update_params) { { 'hello' => 'world' } }
|
467
|
+
|
468
|
+
let!(:stub) do
|
469
|
+
stub_url = '/billing_request_templates/:identity'.gsub(':identity', id)
|
470
|
+
stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
|
471
|
+
body: {
|
472
|
+
'billing_request_templates' => {
|
473
|
+
|
474
|
+
'authorisation_url' => 'authorisation_url-input',
|
475
|
+
'created_at' => 'created_at-input',
|
476
|
+
'id' => 'id-input',
|
477
|
+
'mandate_request_currency' => 'mandate_request_currency-input',
|
478
|
+
'mandate_request_metadata' => 'mandate_request_metadata-input',
|
479
|
+
'mandate_request_scheme' => 'mandate_request_scheme-input',
|
480
|
+
'mandate_request_verify' => 'mandate_request_verify-input',
|
481
|
+
'metadata' => 'metadata-input',
|
482
|
+
'name' => 'name-input',
|
483
|
+
'payment_request_amount' => 'payment_request_amount-input',
|
484
|
+
'payment_request_currency' => 'payment_request_currency-input',
|
485
|
+
'payment_request_description' => 'payment_request_description-input',
|
486
|
+
'payment_request_metadata' => 'payment_request_metadata-input',
|
487
|
+
'payment_request_scheme' => 'payment_request_scheme-input',
|
488
|
+
'redirect_uri' => 'redirect_uri-input',
|
489
|
+
'updated_at' => 'updated_at-input',
|
490
|
+
},
|
491
|
+
}.to_json,
|
492
|
+
headers: response_headers
|
493
|
+
)
|
494
|
+
end
|
495
|
+
|
496
|
+
it 'updates and returns the resource' do
|
497
|
+
expect(put_update_response).to be_a(GoCardlessPro::Resources::BillingRequestTemplate)
|
498
|
+
expect(stub).to have_been_requested
|
499
|
+
end
|
500
|
+
end
|
501
|
+
end
|
502
|
+
end
|