gocardless_pro 2.41.0 → 2.41.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gocardless_pro/api_service.rb +4 -5
  3. data/lib/gocardless_pro/client.rb +3 -3
  4. data/lib/gocardless_pro/error/invalid_state_error.rb +1 -0
  5. data/lib/gocardless_pro/error.rb +1 -0
  6. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +7 -9
  7. data/lib/gocardless_pro/request.rb +5 -7
  8. data/lib/gocardless_pro/resources/bank_authorisation.rb +0 -2
  9. data/lib/gocardless_pro/resources/bank_details_lookup.rb +0 -2
  10. data/lib/gocardless_pro/resources/billing_request.rb +0 -2
  11. data/lib/gocardless_pro/resources/billing_request_flow.rb +0 -2
  12. data/lib/gocardless_pro/resources/billing_request_template.rb +0 -2
  13. data/lib/gocardless_pro/resources/block.rb +0 -2
  14. data/lib/gocardless_pro/resources/creditor.rb +0 -2
  15. data/lib/gocardless_pro/resources/creditor_bank_account.rb +0 -2
  16. data/lib/gocardless_pro/resources/currency_exchange_rate.rb +0 -2
  17. data/lib/gocardless_pro/resources/customer.rb +0 -2
  18. data/lib/gocardless_pro/resources/customer_bank_account.rb +0 -2
  19. data/lib/gocardless_pro/resources/customer_notification.rb +0 -2
  20. data/lib/gocardless_pro/resources/event.rb +0 -2
  21. data/lib/gocardless_pro/resources/instalment_schedule.rb +0 -2
  22. data/lib/gocardless_pro/resources/institution.rb +0 -2
  23. data/lib/gocardless_pro/resources/mandate.rb +0 -2
  24. data/lib/gocardless_pro/resources/mandate_import.rb +0 -2
  25. data/lib/gocardless_pro/resources/mandate_import_entry.rb +0 -2
  26. data/lib/gocardless_pro/resources/mandate_pdf.rb +0 -2
  27. data/lib/gocardless_pro/resources/payer_authorisation.rb +0 -2
  28. data/lib/gocardless_pro/resources/payment.rb +0 -2
  29. data/lib/gocardless_pro/resources/payout.rb +0 -2
  30. data/lib/gocardless_pro/resources/payout_item.rb +0 -2
  31. data/lib/gocardless_pro/resources/redirect_flow.rb +0 -2
  32. data/lib/gocardless_pro/resources/refund.rb +0 -2
  33. data/lib/gocardless_pro/resources/scenario_simulator.rb +0 -2
  34. data/lib/gocardless_pro/resources/scheme_identifier.rb +0 -2
  35. data/lib/gocardless_pro/resources/subscription.rb +0 -2
  36. data/lib/gocardless_pro/resources/tax_rate.rb +0 -2
  37. data/lib/gocardless_pro/resources/verification_detail.rb +0 -2
  38. data/lib/gocardless_pro/resources/webhook.rb +0 -2
  39. data/lib/gocardless_pro/services/bank_authorisations_service.rb +3 -1
  40. data/lib/gocardless_pro/services/billing_request_flows_service.rb +3 -1
  41. data/lib/gocardless_pro/services/billing_request_templates_service.rb +6 -2
  42. data/lib/gocardless_pro/services/billing_requests_service.rb +27 -9
  43. data/lib/gocardless_pro/services/blocks_service.rb +9 -3
  44. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +6 -2
  45. data/lib/gocardless_pro/services/creditors_service.rb +9 -3
  46. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +9 -3
  47. data/lib/gocardless_pro/services/customer_notifications_service.rb +3 -1
  48. data/lib/gocardless_pro/services/customers_service.rb +9 -3
  49. data/lib/gocardless_pro/services/events_service.rb +3 -1
  50. data/lib/gocardless_pro/services/instalment_schedules_service.rb +9 -3
  51. data/lib/gocardless_pro/services/mandate_imports_service.rb +9 -3
  52. data/lib/gocardless_pro/services/mandates_service.rb +12 -4
  53. data/lib/gocardless_pro/services/payer_authorisations_service.rb +12 -4
  54. data/lib/gocardless_pro/services/payments_service.rb +12 -4
  55. data/lib/gocardless_pro/services/payouts_service.rb +6 -2
  56. data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -2
  57. data/lib/gocardless_pro/services/refunds_service.rb +6 -2
  58. data/lib/gocardless_pro/services/scenario_simulators_service.rb +3 -1
  59. data/lib/gocardless_pro/services/scheme_identifiers_service.rb +3 -1
  60. data/lib/gocardless_pro/services/subscriptions_service.rb +15 -5
  61. data/lib/gocardless_pro/services/tax_rates_service.rb +3 -1
  62. data/lib/gocardless_pro/services/webhooks_service.rb +6 -2
  63. data/lib/gocardless_pro/version.rb +1 -2
  64. data/lib/gocardless_pro/webhook.rb +5 -4
  65. data/lib/gocardless_pro.rb +2 -4
  66. metadata +5 -195
  67. data/.github/workflows/tests.yml +0 -40
  68. data/.gitignore +0 -1
  69. data/.rspec +0 -2
  70. data/.rubocop.yml +0 -5
  71. data/.travis.yml +0 -10
  72. data/Gemfile +0 -10
  73. data/demo.rb +0 -9
  74. data/gocardless_pro.gemspec +0 -39
  75. data/spec/api_response_spec.rb +0 -28
  76. data/spec/api_service_spec.rb +0 -188
  77. data/spec/client_spec.rb +0 -19
  78. data/spec/error_spec.rb +0 -53
  79. data/spec/middlewares/raise_gocardless_errors_spec.rb +0 -127
  80. data/spec/resources/bank_authorisation_spec.rb +0 -259
  81. data/spec/resources/bank_details_lookup_spec.rb +0 -121
  82. data/spec/resources/billing_request_flow_spec.rb +0 -257
  83. data/spec/resources/billing_request_spec.rb +0 -962
  84. data/spec/resources/billing_request_template_spec.rb +0 -515
  85. data/spec/resources/block_spec.rb +0 -577
  86. data/spec/resources/creditor_bank_account_spec.rb +0 -472
  87. data/spec/resources/creditor_spec.rb +0 -659
  88. data/spec/resources/currency_exchange_rate_spec.rb +0 -103
  89. data/spec/resources/customer_bank_account_spec.rb +0 -509
  90. data/spec/resources/customer_notification_spec.rb +0 -75
  91. data/spec/resources/customer_spec.rb +0 -616
  92. data/spec/resources/event_spec.rb +0 -210
  93. data/spec/resources/instalment_schedule_spec.rb +0 -636
  94. data/spec/resources/institution_spec.rb +0 -113
  95. data/spec/resources/mandate_import_entry_spec.rb +0 -206
  96. data/spec/resources/mandate_import_spec.rb +0 -344
  97. data/spec/resources/mandate_pdf_spec.rb +0 -117
  98. data/spec/resources/mandate_spec.rb +0 -600
  99. data/spec/resources/payer_authorisation_spec.rb +0 -422
  100. data/spec/resources/payment_spec.rb +0 -617
  101. data/spec/resources/payout_item_spec.rb +0 -101
  102. data/spec/resources/payout_spec.rb +0 -284
  103. data/spec/resources/redirect_flow_spec.rb +0 -347
  104. data/spec/resources/refund_spec.rb +0 -409
  105. data/spec/resources/scenario_simulator_spec.rb +0 -65
  106. data/spec/resources/scheme_identifier_spec.rb +0 -484
  107. data/spec/resources/subscription_spec.rb +0 -828
  108. data/spec/resources/tax_rate_spec.rb +0 -198
  109. data/spec/resources/verification_detail_spec.rb +0 -145
  110. data/spec/resources/webhook_spec.rb +0 -325
  111. data/spec/response_spec.rb +0 -34
  112. data/spec/services/bank_authorisations_service_spec.rb +0 -353
  113. data/spec/services/bank_details_lookups_service_spec.rb +0 -144
  114. data/spec/services/billing_request_flows_service_spec.rb +0 -291
  115. data/spec/services/billing_request_templates_service_spec.rb +0 -806
  116. data/spec/services/billing_requests_service_spec.rb +0 -1288
  117. data/spec/services/blocks_service_spec.rb +0 -840
  118. data/spec/services/creditor_bank_accounts_service_spec.rb +0 -725
  119. data/spec/services/creditors_service_spec.rb +0 -977
  120. data/spec/services/currency_exchange_rates_service_spec.rb +0 -223
  121. data/spec/services/customer_bank_accounts_service_spec.rb +0 -787
  122. data/spec/services/customer_notifications_service_spec.rb +0 -86
  123. data/spec/services/customers_service_spec.rb +0 -922
  124. data/spec/services/events_service_spec.rb +0 -401
  125. data/spec/services/instalment_schedules_service_spec.rb +0 -945
  126. data/spec/services/institutions_service_spec.rb +0 -241
  127. data/spec/services/mandate_import_entries_service_spec.rb +0 -345
  128. data/spec/services/mandate_imports_service_spec.rb +0 -460
  129. data/spec/services/mandate_pdfs_service_spec.rb +0 -140
  130. data/spec/services/mandates_service_spec.rb +0 -893
  131. data/spec/services/payer_authorisations_service_spec.rb +0 -563
  132. data/spec/services/payments_service_spec.rb +0 -914
  133. data/spec/services/payout_items_service_spec.rb +0 -221
  134. data/spec/services/payouts_service_spec.rb +0 -520
  135. data/spec/services/redirect_flows_service_spec.rb +0 -452
  136. data/spec/services/refunds_service_spec.rb +0 -668
  137. data/spec/services/scenario_simulators_service_spec.rb +0 -76
  138. data/spec/services/scheme_identifiers_service_spec.rb +0 -754
  139. data/spec/services/subscriptions_service_spec.rb +0 -1164
  140. data/spec/services/tax_rates_service_spec.rb +0 -381
  141. data/spec/services/verification_details_service_spec.rb +0 -168
  142. data/spec/services/webhooks_service_spec.rb +0 -547
  143. data/spec/spec_helper.rb +0 -90
  144. data/spec/webhook_spec.rb +0 -122
@@ -1,291 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Services::BillingRequestFlowsService 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.billing_request_flows.create(params: new_resource) }
14
- context 'with a valid request' do
15
- let(:new_resource) do
16
- {
17
-
18
- 'authorisation_url' => 'authorisation_url-input',
19
- 'auto_fulfil' => 'auto_fulfil-input',
20
- 'created_at' => 'created_at-input',
21
- 'exit_uri' => 'exit_uri-input',
22
- 'expires_at' => 'expires_at-input',
23
- 'id' => 'id-input',
24
- 'language' => 'language-input',
25
- 'links' => 'links-input',
26
- 'lock_bank_account' => 'lock_bank_account-input',
27
- 'lock_currency' => 'lock_currency-input',
28
- 'lock_customer_details' => 'lock_customer_details-input',
29
- 'prefilled_bank_account' => 'prefilled_bank_account-input',
30
- 'prefilled_customer' => 'prefilled_customer-input',
31
- 'redirect_uri' => 'redirect_uri-input',
32
- 'session_token' => 'session_token-input',
33
- 'show_redirect_buttons' => 'show_redirect_buttons-input',
34
- }
35
- end
36
-
37
- before do
38
- stub_request(:post, %r{.*api.gocardless.com/billing_request_flows}).
39
- with(
40
- body: {
41
- 'billing_request_flows' => {
42
-
43
- 'authorisation_url' => 'authorisation_url-input',
44
- 'auto_fulfil' => 'auto_fulfil-input',
45
- 'created_at' => 'created_at-input',
46
- 'exit_uri' => 'exit_uri-input',
47
- 'expires_at' => 'expires_at-input',
48
- 'id' => 'id-input',
49
- 'language' => 'language-input',
50
- 'links' => 'links-input',
51
- 'lock_bank_account' => 'lock_bank_account-input',
52
- 'lock_currency' => 'lock_currency-input',
53
- 'lock_customer_details' => 'lock_customer_details-input',
54
- 'prefilled_bank_account' => 'prefilled_bank_account-input',
55
- 'prefilled_customer' => 'prefilled_customer-input',
56
- 'redirect_uri' => 'redirect_uri-input',
57
- 'session_token' => 'session_token-input',
58
- 'show_redirect_buttons' => 'show_redirect_buttons-input',
59
- },
60
- }
61
- ).
62
- to_return(
63
- body: {
64
- 'billing_request_flows' =>
65
-
66
- {
67
-
68
- 'authorisation_url' => 'authorisation_url-input',
69
- 'auto_fulfil' => 'auto_fulfil-input',
70
- 'created_at' => 'created_at-input',
71
- 'exit_uri' => 'exit_uri-input',
72
- 'expires_at' => 'expires_at-input',
73
- 'id' => 'id-input',
74
- 'language' => 'language-input',
75
- 'links' => 'links-input',
76
- 'lock_bank_account' => 'lock_bank_account-input',
77
- 'lock_currency' => 'lock_currency-input',
78
- 'lock_customer_details' => 'lock_customer_details-input',
79
- 'prefilled_bank_account' => 'prefilled_bank_account-input',
80
- 'prefilled_customer' => 'prefilled_customer-input',
81
- 'redirect_uri' => 'redirect_uri-input',
82
- 'session_token' => 'session_token-input',
83
- 'show_redirect_buttons' => 'show_redirect_buttons-input',
84
- },
85
-
86
- }.to_json,
87
- headers: response_headers
88
- )
89
- end
90
-
91
- it 'creates and returns the resource' do
92
- expect(post_create_response).to be_a(GoCardlessPro::Resources::BillingRequestFlow)
93
- end
94
-
95
- describe 'retry behaviour' do
96
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
97
-
98
- it 'retries timeouts' do
99
- stub = stub_request(:post, %r{.*api.gocardless.com/billing_request_flows}).
100
- to_timeout.then.to_return(status: 200, headers: response_headers)
101
-
102
- post_create_response
103
- expect(stub).to have_been_requested.twice
104
- end
105
-
106
- it 'retries 5XX errors' do
107
- stub = stub_request(:post, %r{.*api.gocardless.com/billing_request_flows}).
108
- to_return(status: 502,
109
- headers: { 'Content-Type' => 'text/html' },
110
- body: '<html><body>Response from Cloudflare</body></html>').
111
- then.to_return(status: 200, headers: response_headers)
112
-
113
- post_create_response
114
- expect(stub).to have_been_requested.twice
115
- end
116
- end
117
- end
118
-
119
- context 'with a request that returns a validation error' do
120
- let(:new_resource) { {} }
121
-
122
- before do
123
- stub_request(:post, %r{.*api.gocardless.com/billing_request_flows}).to_return(
124
- body: {
125
- error: {
126
- type: 'validation_failed',
127
- code: 422,
128
- errors: [
129
- { message: 'test error message', field: 'test_field' },
130
- ],
131
- },
132
- }.to_json,
133
- headers: response_headers,
134
- status: 422
135
- )
136
- end
137
-
138
- it 'throws the correct error' do
139
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
140
- end
141
- end
142
-
143
- context 'with a request that returns an idempotent creation conflict error' do
144
- let(:id) { 'ID123' }
145
-
146
- let(:new_resource) do
147
- {
148
-
149
- 'authorisation_url' => 'authorisation_url-input',
150
- 'auto_fulfil' => 'auto_fulfil-input',
151
- 'created_at' => 'created_at-input',
152
- 'exit_uri' => 'exit_uri-input',
153
- 'expires_at' => 'expires_at-input',
154
- 'id' => 'id-input',
155
- 'language' => 'language-input',
156
- 'links' => 'links-input',
157
- 'lock_bank_account' => 'lock_bank_account-input',
158
- 'lock_currency' => 'lock_currency-input',
159
- 'lock_customer_details' => 'lock_customer_details-input',
160
- 'prefilled_bank_account' => 'prefilled_bank_account-input',
161
- 'prefilled_customer' => 'prefilled_customer-input',
162
- 'redirect_uri' => 'redirect_uri-input',
163
- 'session_token' => 'session_token-input',
164
- 'show_redirect_buttons' => 'show_redirect_buttons-input',
165
- }
166
- end
167
-
168
- let!(:post_stub) do
169
- stub_request(:post, %r{.*api.gocardless.com/billing_request_flows}).to_return(
170
- body: {
171
- error: {
172
- type: 'invalid_state',
173
- code: 409,
174
- errors: [
175
- {
176
- message: 'A resource has already been created with this idempotency key',
177
- reason: 'idempotent_creation_conflict',
178
- links: {
179
- conflicting_resource_id: id,
180
- },
181
- },
182
- ],
183
- },
184
- }.to_json,
185
- headers: response_headers,
186
- status: 409
187
- )
188
- end
189
-
190
- it 'raises an InvalidStateError' do
191
- expect { post_create_response }.to raise_error(GoCardlessPro::InvalidStateError)
192
- expect(post_stub).to have_been_requested
193
- end
194
- end
195
- end
196
-
197
- describe '#initialise' do
198
- subject(:post_response) { client.billing_request_flows.initialise(resource_id) }
199
-
200
- let(:resource_id) { 'ABC123' }
201
-
202
- let!(:stub) do
203
- # /billing_request_flows/%v/actions/initialise
204
- stub_url = '/billing_request_flows/:identity/actions/initialise'.gsub(':identity', resource_id)
205
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
206
-
207
- body: {
208
- 'billing_request_flows' => {
209
-
210
- 'authorisation_url' => 'authorisation_url-input',
211
- 'auto_fulfil' => 'auto_fulfil-input',
212
- 'created_at' => 'created_at-input',
213
- 'exit_uri' => 'exit_uri-input',
214
- 'expires_at' => 'expires_at-input',
215
- 'id' => 'id-input',
216
- 'language' => 'language-input',
217
- 'links' => 'links-input',
218
- 'lock_bank_account' => 'lock_bank_account-input',
219
- 'lock_currency' => 'lock_currency-input',
220
- 'lock_customer_details' => 'lock_customer_details-input',
221
- 'prefilled_bank_account' => 'prefilled_bank_account-input',
222
- 'prefilled_customer' => 'prefilled_customer-input',
223
- 'redirect_uri' => 'redirect_uri-input',
224
- 'session_token' => 'session_token-input',
225
- 'show_redirect_buttons' => 'show_redirect_buttons-input',
226
- },
227
- }.to_json,
228
-
229
- headers: response_headers
230
- )
231
- end
232
-
233
- it 'wraps the response and calls the right endpoint' do
234
- expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequestFlow)
235
-
236
- expect(stub).to have_been_requested
237
- end
238
-
239
- describe 'retry behaviour' do
240
- it "doesn't retry errors" do
241
- stub_url = '/billing_request_flows/:identity/actions/initialise'.gsub(':identity', resource_id)
242
- stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
243
- to_timeout
244
-
245
- expect { post_response }.to raise_error(Faraday::ConnectionFailed)
246
- expect(stub).to have_been_requested
247
- end
248
- end
249
-
250
- context 'when the request needs a body and custom header' do
251
- let(:body) { { foo: 'bar' } }
252
- let(:headers) { { 'Foo' => 'Bar' } }
253
- subject(:post_response) { client.billing_request_flows.initialise(resource_id, body, headers) }
254
-
255
- let(:resource_id) { 'ABC123' }
256
-
257
- let!(:stub) do
258
- # /billing_request_flows/%v/actions/initialise
259
- stub_url = '/billing_request_flows/:identity/actions/initialise'.gsub(':identity', resource_id)
260
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
261
- with(
262
- body: { foo: 'bar' },
263
- headers: { 'Foo' => 'Bar' }
264
- ).to_return(
265
- body: {
266
- 'billing_request_flows' => {
267
-
268
- 'authorisation_url' => 'authorisation_url-input',
269
- 'auto_fulfil' => 'auto_fulfil-input',
270
- 'created_at' => 'created_at-input',
271
- 'exit_uri' => 'exit_uri-input',
272
- 'expires_at' => 'expires_at-input',
273
- 'id' => 'id-input',
274
- 'language' => 'language-input',
275
- 'links' => 'links-input',
276
- 'lock_bank_account' => 'lock_bank_account-input',
277
- 'lock_currency' => 'lock_currency-input',
278
- 'lock_customer_details' => 'lock_customer_details-input',
279
- 'prefilled_bank_account' => 'prefilled_bank_account-input',
280
- 'prefilled_customer' => 'prefilled_customer-input',
281
- 'redirect_uri' => 'redirect_uri-input',
282
- 'session_token' => 'session_token-input',
283
- 'show_redirect_buttons' => 'show_redirect_buttons-input',
284
- },
285
- }.to_json,
286
- headers: response_headers
287
- )
288
- end
289
- end
290
- end
291
- end