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,659 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Resources::Creditor 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.creditors.create(params: new_resource) }
14
- context 'with a valid request' do
15
- let(:new_resource) do
16
- {
17
-
18
- 'activated' => 'activated-input',
19
- 'address_line1' => 'address_line1-input',
20
- 'address_line2' => 'address_line2-input',
21
- 'address_line3' => 'address_line3-input',
22
- 'can_create_refunds' => 'can_create_refunds-input',
23
- 'city' => 'city-input',
24
- 'country_code' => 'country_code-input',
25
- 'created_at' => 'created_at-input',
26
- 'creditor_type' => 'creditor_type-input',
27
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
28
- 'fx_payout_currency' => 'fx_payout_currency-input',
29
- 'id' => 'id-input',
30
- 'links' => 'links-input',
31
- 'logo_url' => 'logo_url-input',
32
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
33
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
34
- 'name' => 'name-input',
35
- 'postal_code' => 'postal_code-input',
36
- 'region' => 'region-input',
37
- 'scheme_identifiers' => 'scheme_identifiers-input',
38
- 'verification_status' => 'verification_status-input',
39
- }
40
- end
41
-
42
- before do
43
- stub_request(:post, %r{.*api.gocardless.com/creditors}).
44
- with(
45
- body: {
46
- 'creditors' => {
47
-
48
- 'activated' => 'activated-input',
49
- 'address_line1' => 'address_line1-input',
50
- 'address_line2' => 'address_line2-input',
51
- 'address_line3' => 'address_line3-input',
52
- 'can_create_refunds' => 'can_create_refunds-input',
53
- 'city' => 'city-input',
54
- 'country_code' => 'country_code-input',
55
- 'created_at' => 'created_at-input',
56
- 'creditor_type' => 'creditor_type-input',
57
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
58
- 'fx_payout_currency' => 'fx_payout_currency-input',
59
- 'id' => 'id-input',
60
- 'links' => 'links-input',
61
- 'logo_url' => 'logo_url-input',
62
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
63
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
64
- 'name' => 'name-input',
65
- 'postal_code' => 'postal_code-input',
66
- 'region' => 'region-input',
67
- 'scheme_identifiers' => 'scheme_identifiers-input',
68
- 'verification_status' => 'verification_status-input',
69
- },
70
- }
71
- ).
72
- to_return(
73
- body: {
74
- 'creditors' =>
75
-
76
- {
77
-
78
- 'activated' => 'activated-input',
79
- 'address_line1' => 'address_line1-input',
80
- 'address_line2' => 'address_line2-input',
81
- 'address_line3' => 'address_line3-input',
82
- 'can_create_refunds' => 'can_create_refunds-input',
83
- 'city' => 'city-input',
84
- 'country_code' => 'country_code-input',
85
- 'created_at' => 'created_at-input',
86
- 'creditor_type' => 'creditor_type-input',
87
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
88
- 'fx_payout_currency' => 'fx_payout_currency-input',
89
- 'id' => 'id-input',
90
- 'links' => 'links-input',
91
- 'logo_url' => 'logo_url-input',
92
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
93
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
94
- 'name' => 'name-input',
95
- 'postal_code' => 'postal_code-input',
96
- 'region' => 'region-input',
97
- 'scheme_identifiers' => 'scheme_identifiers-input',
98
- 'verification_status' => 'verification_status-input',
99
- },
100
-
101
- }.to_json,
102
- headers: response_headers
103
- )
104
- end
105
-
106
- it 'creates and returns the resource' do
107
- expect(post_create_response).to be_a(GoCardlessPro::Resources::Creditor)
108
- end
109
- end
110
-
111
- context 'with a request that returns a validation error' do
112
- let(:new_resource) { {} }
113
-
114
- before do
115
- stub_request(:post, %r{.*api.gocardless.com/creditors}).to_return(
116
- body: {
117
- error: {
118
- type: 'validation_failed',
119
- code: 422,
120
- errors: [
121
- { message: 'test error message', field: 'test_field' },
122
- ],
123
- },
124
- }.to_json,
125
- headers: response_headers,
126
- status: 422
127
- )
128
- end
129
-
130
- it 'throws the correct error' do
131
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
132
- end
133
- end
134
-
135
- context 'with a request that returns an idempotent creation conflict error' do
136
- let(:id) { 'ID123' }
137
-
138
- let(:new_resource) do
139
- {
140
-
141
- 'activated' => 'activated-input',
142
- 'address_line1' => 'address_line1-input',
143
- 'address_line2' => 'address_line2-input',
144
- 'address_line3' => 'address_line3-input',
145
- 'can_create_refunds' => 'can_create_refunds-input',
146
- 'city' => 'city-input',
147
- 'country_code' => 'country_code-input',
148
- 'created_at' => 'created_at-input',
149
- 'creditor_type' => 'creditor_type-input',
150
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
151
- 'fx_payout_currency' => 'fx_payout_currency-input',
152
- 'id' => 'id-input',
153
- 'links' => 'links-input',
154
- 'logo_url' => 'logo_url-input',
155
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
156
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
157
- 'name' => 'name-input',
158
- 'postal_code' => 'postal_code-input',
159
- 'region' => 'region-input',
160
- 'scheme_identifiers' => 'scheme_identifiers-input',
161
- 'verification_status' => 'verification_status-input',
162
- }
163
- end
164
-
165
- let!(:post_stub) do
166
- stub_request(:post, %r{.*api.gocardless.com/creditors}).to_return(
167
- body: {
168
- error: {
169
- type: 'invalid_state',
170
- code: 409,
171
- errors: [
172
- {
173
- message: 'A resource has already been created with this idempotency key',
174
- reason: 'idempotent_creation_conflict',
175
- links: {
176
- conflicting_resource_id: id,
177
- },
178
- },
179
- ],
180
- },
181
- }.to_json,
182
- headers: response_headers,
183
- status: 409
184
- )
185
- end
186
-
187
- let!(:get_stub) do
188
- stub_url = "/creditors/#{id}"
189
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
190
- to_return(
191
- body: {
192
- 'creditors' => {
193
-
194
- 'activated' => 'activated-input',
195
- 'address_line1' => 'address_line1-input',
196
- 'address_line2' => 'address_line2-input',
197
- 'address_line3' => 'address_line3-input',
198
- 'can_create_refunds' => 'can_create_refunds-input',
199
- 'city' => 'city-input',
200
- 'country_code' => 'country_code-input',
201
- 'created_at' => 'created_at-input',
202
- 'creditor_type' => 'creditor_type-input',
203
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
204
- 'fx_payout_currency' => 'fx_payout_currency-input',
205
- 'id' => 'id-input',
206
- 'links' => 'links-input',
207
- 'logo_url' => 'logo_url-input',
208
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
209
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
210
- 'name' => 'name-input',
211
- 'postal_code' => 'postal_code-input',
212
- 'region' => 'region-input',
213
- 'scheme_identifiers' => 'scheme_identifiers-input',
214
- 'verification_status' => 'verification_status-input',
215
- },
216
- }.to_json,
217
- headers: response_headers
218
- )
219
- end
220
-
221
- it 'fetches the already-created resource' do
222
- post_create_response
223
- expect(post_stub).to have_been_requested
224
- expect(get_stub).to have_been_requested
225
- end
226
- end
227
- end
228
-
229
- describe '#list' do
230
- describe 'with no filters' do
231
- subject(:get_list_response) { client.creditors.list }
232
-
233
- before do
234
- stub_request(:get, %r{.*api.gocardless.com/creditors}).to_return(
235
- body: {
236
- 'creditors' => [{
237
-
238
- 'activated' => 'activated-input',
239
- 'address_line1' => 'address_line1-input',
240
- 'address_line2' => 'address_line2-input',
241
- 'address_line3' => 'address_line3-input',
242
- 'can_create_refunds' => 'can_create_refunds-input',
243
- 'city' => 'city-input',
244
- 'country_code' => 'country_code-input',
245
- 'created_at' => 'created_at-input',
246
- 'creditor_type' => 'creditor_type-input',
247
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
248
- 'fx_payout_currency' => 'fx_payout_currency-input',
249
- 'id' => 'id-input',
250
- 'links' => 'links-input',
251
- 'logo_url' => 'logo_url-input',
252
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
253
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
254
- 'name' => 'name-input',
255
- 'postal_code' => 'postal_code-input',
256
- 'region' => 'region-input',
257
- 'scheme_identifiers' => 'scheme_identifiers-input',
258
- 'verification_status' => 'verification_status-input',
259
- }],
260
- meta: {
261
- cursors: {
262
- before: nil,
263
- after: 'ABC123',
264
- },
265
- },
266
- }.to_json,
267
- headers: response_headers
268
- )
269
- end
270
-
271
- it 'wraps each item in the resource class' do
272
- expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Creditor)
273
-
274
- expect(get_list_response.records.first.activated).to eq('activated-input')
275
-
276
- expect(get_list_response.records.first.address_line1).to eq('address_line1-input')
277
-
278
- expect(get_list_response.records.first.address_line2).to eq('address_line2-input')
279
-
280
- expect(get_list_response.records.first.address_line3).to eq('address_line3-input')
281
-
282
- expect(get_list_response.records.first.can_create_refunds).to eq('can_create_refunds-input')
283
-
284
- expect(get_list_response.records.first.city).to eq('city-input')
285
-
286
- expect(get_list_response.records.first.country_code).to eq('country_code-input')
287
-
288
- expect(get_list_response.records.first.created_at).to eq('created_at-input')
289
-
290
- expect(get_list_response.records.first.creditor_type).to eq('creditor_type-input')
291
-
292
- expect(get_list_response.records.first.custom_payment_pages_enabled).to eq('custom_payment_pages_enabled-input')
293
-
294
- expect(get_list_response.records.first.fx_payout_currency).to eq('fx_payout_currency-input')
295
-
296
- expect(get_list_response.records.first.id).to eq('id-input')
297
-
298
- expect(get_list_response.records.first.logo_url).to eq('logo_url-input')
299
-
300
- expect(get_list_response.records.first.mandate_imports_enabled).to eq('mandate_imports_enabled-input')
301
-
302
- expect(get_list_response.records.first.merchant_responsible_for_notifications).to eq('merchant_responsible_for_notifications-input')
303
-
304
- expect(get_list_response.records.first.name).to eq('name-input')
305
-
306
- expect(get_list_response.records.first.postal_code).to eq('postal_code-input')
307
-
308
- expect(get_list_response.records.first.region).to eq('region-input')
309
-
310
- expect(get_list_response.records.first.scheme_identifiers).to eq('scheme_identifiers-input')
311
-
312
- expect(get_list_response.records.first.verification_status).to eq('verification_status-input')
313
- end
314
-
315
- it 'exposes the cursors for before and after' do
316
- expect(get_list_response.before).to eq(nil)
317
- expect(get_list_response.after).to eq('ABC123')
318
- end
319
-
320
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
321
- end
322
- end
323
-
324
- describe '#all' do
325
- let!(:first_response_stub) do
326
- stub_request(:get, %r{.*api.gocardless.com/creditors$}).to_return(
327
- body: {
328
- 'creditors' => [{
329
-
330
- 'activated' => 'activated-input',
331
- 'address_line1' => 'address_line1-input',
332
- 'address_line2' => 'address_line2-input',
333
- 'address_line3' => 'address_line3-input',
334
- 'can_create_refunds' => 'can_create_refunds-input',
335
- 'city' => 'city-input',
336
- 'country_code' => 'country_code-input',
337
- 'created_at' => 'created_at-input',
338
- 'creditor_type' => 'creditor_type-input',
339
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
340
- 'fx_payout_currency' => 'fx_payout_currency-input',
341
- 'id' => 'id-input',
342
- 'links' => 'links-input',
343
- 'logo_url' => 'logo_url-input',
344
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
345
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
346
- 'name' => 'name-input',
347
- 'postal_code' => 'postal_code-input',
348
- 'region' => 'region-input',
349
- 'scheme_identifiers' => 'scheme_identifiers-input',
350
- 'verification_status' => 'verification_status-input',
351
- }],
352
- meta: {
353
- cursors: { after: 'AB345' },
354
- limit: 1,
355
- },
356
- }.to_json,
357
- headers: response_headers
358
- )
359
- end
360
-
361
- let!(:second_response_stub) do
362
- stub_request(:get, %r{.*api.gocardless.com/creditors\?after=AB345}).to_return(
363
- body: {
364
- 'creditors' => [{
365
-
366
- 'activated' => 'activated-input',
367
- 'address_line1' => 'address_line1-input',
368
- 'address_line2' => 'address_line2-input',
369
- 'address_line3' => 'address_line3-input',
370
- 'can_create_refunds' => 'can_create_refunds-input',
371
- 'city' => 'city-input',
372
- 'country_code' => 'country_code-input',
373
- 'created_at' => 'created_at-input',
374
- 'creditor_type' => 'creditor_type-input',
375
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
376
- 'fx_payout_currency' => 'fx_payout_currency-input',
377
- 'id' => 'id-input',
378
- 'links' => 'links-input',
379
- 'logo_url' => 'logo_url-input',
380
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
381
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
382
- 'name' => 'name-input',
383
- 'postal_code' => 'postal_code-input',
384
- 'region' => 'region-input',
385
- 'scheme_identifiers' => 'scheme_identifiers-input',
386
- 'verification_status' => 'verification_status-input',
387
- }],
388
- meta: {
389
- limit: 2,
390
- cursors: {},
391
- },
392
- }.to_json,
393
- headers: response_headers
394
- )
395
- end
396
-
397
- it 'automatically makes the extra requests' do
398
- expect(client.creditors.all.to_a.length).to eq(2)
399
- expect(first_response_stub).to have_been_requested
400
- expect(second_response_stub).to have_been_requested
401
- end
402
- end
403
-
404
- describe '#get' do
405
- let(:id) { 'ID123' }
406
-
407
- subject(:get_response) { client.creditors.get(id) }
408
-
409
- context 'passing in a custom header' do
410
- let!(:stub) do
411
- stub_url = '/creditors/:identity'.gsub(':identity', id)
412
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
413
- with(headers: { 'Foo' => 'Bar' }).
414
- to_return(
415
- body: {
416
- 'creditors' => {
417
-
418
- 'activated' => 'activated-input',
419
- 'address_line1' => 'address_line1-input',
420
- 'address_line2' => 'address_line2-input',
421
- 'address_line3' => 'address_line3-input',
422
- 'can_create_refunds' => 'can_create_refunds-input',
423
- 'city' => 'city-input',
424
- 'country_code' => 'country_code-input',
425
- 'created_at' => 'created_at-input',
426
- 'creditor_type' => 'creditor_type-input',
427
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
428
- 'fx_payout_currency' => 'fx_payout_currency-input',
429
- 'id' => 'id-input',
430
- 'links' => 'links-input',
431
- 'logo_url' => 'logo_url-input',
432
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
433
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
434
- 'name' => 'name-input',
435
- 'postal_code' => 'postal_code-input',
436
- 'region' => 'region-input',
437
- 'scheme_identifiers' => 'scheme_identifiers-input',
438
- 'verification_status' => 'verification_status-input',
439
- },
440
- }.to_json,
441
- headers: response_headers
442
- )
443
- end
444
-
445
- subject(:get_response) do
446
- client.creditors.get(id, headers: {
447
- 'Foo' => 'Bar',
448
- })
449
- end
450
-
451
- it 'includes the header' do
452
- get_response
453
- expect(stub).to have_been_requested
454
- end
455
- end
456
-
457
- context 'when there is a creditor to return' do
458
- before do
459
- stub_url = '/creditors/:identity'.gsub(':identity', id)
460
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
461
- body: {
462
- 'creditors' => {
463
-
464
- 'activated' => 'activated-input',
465
- 'address_line1' => 'address_line1-input',
466
- 'address_line2' => 'address_line2-input',
467
- 'address_line3' => 'address_line3-input',
468
- 'can_create_refunds' => 'can_create_refunds-input',
469
- 'city' => 'city-input',
470
- 'country_code' => 'country_code-input',
471
- 'created_at' => 'created_at-input',
472
- 'creditor_type' => 'creditor_type-input',
473
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
474
- 'fx_payout_currency' => 'fx_payout_currency-input',
475
- 'id' => 'id-input',
476
- 'links' => 'links-input',
477
- 'logo_url' => 'logo_url-input',
478
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
479
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
480
- 'name' => 'name-input',
481
- 'postal_code' => 'postal_code-input',
482
- 'region' => 'region-input',
483
- 'scheme_identifiers' => 'scheme_identifiers-input',
484
- 'verification_status' => 'verification_status-input',
485
- },
486
- }.to_json,
487
- headers: response_headers
488
- )
489
- end
490
-
491
- it 'wraps the response in a resource' do
492
- expect(get_response).to be_a(GoCardlessPro::Resources::Creditor)
493
- end
494
- end
495
-
496
- context 'when nothing is returned' do
497
- before do
498
- stub_url = '/creditors/:identity'.gsub(':identity', id)
499
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
500
- body: '',
501
- headers: response_headers
502
- )
503
- end
504
-
505
- it 'returns nil' do
506
- expect(get_response).to be_nil
507
- end
508
- end
509
-
510
- context "when an ID is specified which can't be included in a valid URI" do
511
- let(:id) { '`' }
512
-
513
- it "doesn't raise an error" do
514
- expect { get_response }.to_not raise_error(/bad URI/)
515
- end
516
- end
517
- end
518
-
519
- describe '#update' do
520
- subject(:put_update_response) { client.creditors.update(id, params: update_params) }
521
- let(:id) { 'ABC123' }
522
-
523
- context 'with a valid request' do
524
- let(:update_params) { { 'hello' => 'world' } }
525
-
526
- let!(:stub) do
527
- stub_url = '/creditors/:identity'.gsub(':identity', id)
528
- stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
529
- body: {
530
- 'creditors' => {
531
-
532
- 'activated' => 'activated-input',
533
- 'address_line1' => 'address_line1-input',
534
- 'address_line2' => 'address_line2-input',
535
- 'address_line3' => 'address_line3-input',
536
- 'can_create_refunds' => 'can_create_refunds-input',
537
- 'city' => 'city-input',
538
- 'country_code' => 'country_code-input',
539
- 'created_at' => 'created_at-input',
540
- 'creditor_type' => 'creditor_type-input',
541
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
542
- 'fx_payout_currency' => 'fx_payout_currency-input',
543
- 'id' => 'id-input',
544
- 'links' => 'links-input',
545
- 'logo_url' => 'logo_url-input',
546
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
547
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
548
- 'name' => 'name-input',
549
- 'postal_code' => 'postal_code-input',
550
- 'region' => 'region-input',
551
- 'scheme_identifiers' => 'scheme_identifiers-input',
552
- 'verification_status' => 'verification_status-input',
553
- },
554
- }.to_json,
555
- headers: response_headers
556
- )
557
- end
558
-
559
- it 'updates and returns the resource' do
560
- expect(put_update_response).to be_a(GoCardlessPro::Resources::Creditor)
561
- expect(stub).to have_been_requested
562
- end
563
- end
564
- end
565
-
566
- describe '#apply_scheme_identifier' do
567
- subject(:post_response) { client.creditors.apply_scheme_identifier(resource_id) }
568
-
569
- let(:resource_id) { 'ABC123' }
570
-
571
- let!(:stub) do
572
- # /creditors/%v/actions/apply_scheme_identifier
573
- stub_url = '/creditors/:identity/actions/apply_scheme_identifier'.gsub(':identity', resource_id)
574
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
575
-
576
- body: {
577
- 'creditors' => {
578
-
579
- 'activated' => 'activated-input',
580
- 'address_line1' => 'address_line1-input',
581
- 'address_line2' => 'address_line2-input',
582
- 'address_line3' => 'address_line3-input',
583
- 'can_create_refunds' => 'can_create_refunds-input',
584
- 'city' => 'city-input',
585
- 'country_code' => 'country_code-input',
586
- 'created_at' => 'created_at-input',
587
- 'creditor_type' => 'creditor_type-input',
588
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
589
- 'fx_payout_currency' => 'fx_payout_currency-input',
590
- 'id' => 'id-input',
591
- 'links' => 'links-input',
592
- 'logo_url' => 'logo_url-input',
593
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
594
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
595
- 'name' => 'name-input',
596
- 'postal_code' => 'postal_code-input',
597
- 'region' => 'region-input',
598
- 'scheme_identifiers' => 'scheme_identifiers-input',
599
- 'verification_status' => 'verification_status-input',
600
- },
601
- }.to_json,
602
-
603
- headers: response_headers
604
- )
605
- end
606
-
607
- it 'wraps the response and calls the right endpoint' do
608
- expect(post_response).to be_a(GoCardlessPro::Resources::Creditor)
609
-
610
- expect(stub).to have_been_requested
611
- end
612
-
613
- context 'when the request needs a body and custom header' do
614
- let(:body) { { foo: 'bar' } }
615
- let(:headers) { { 'Foo' => 'Bar' } }
616
- subject(:post_response) { client.creditors.apply_scheme_identifier(resource_id, body, headers) }
617
-
618
- let(:resource_id) { 'ABC123' }
619
-
620
- let!(:stub) do
621
- # /creditors/%v/actions/apply_scheme_identifier
622
- stub_url = '/creditors/:identity/actions/apply_scheme_identifier'.gsub(':identity', resource_id)
623
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
624
- with(
625
- body: { foo: 'bar' },
626
- headers: { 'Foo' => 'Bar' }
627
- ).to_return(
628
- body: {
629
- 'creditors' => {
630
-
631
- 'activated' => 'activated-input',
632
- 'address_line1' => 'address_line1-input',
633
- 'address_line2' => 'address_line2-input',
634
- 'address_line3' => 'address_line3-input',
635
- 'can_create_refunds' => 'can_create_refunds-input',
636
- 'city' => 'city-input',
637
- 'country_code' => 'country_code-input',
638
- 'created_at' => 'created_at-input',
639
- 'creditor_type' => 'creditor_type-input',
640
- 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
641
- 'fx_payout_currency' => 'fx_payout_currency-input',
642
- 'id' => 'id-input',
643
- 'links' => 'links-input',
644
- 'logo_url' => 'logo_url-input',
645
- 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
646
- 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
647
- 'name' => 'name-input',
648
- 'postal_code' => 'postal_code-input',
649
- 'region' => 'region-input',
650
- 'scheme_identifiers' => 'scheme_identifiers-input',
651
- 'verification_status' => 'verification_status-input',
652
- },
653
- }.to_json,
654
- headers: response_headers
655
- )
656
- end
657
- end
658
- end
659
- end