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