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,828 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Resources::Subscription 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
- end
107
-
108
- context 'with a request that returns a validation error' do
109
- let(:new_resource) { {} }
110
-
111
- before do
112
- stub_request(:post, %r{.*api.gocardless.com/subscriptions}).to_return(
113
- body: {
114
- error: {
115
- type: 'validation_failed',
116
- code: 422,
117
- errors: [
118
- { message: 'test error message', field: 'test_field' },
119
- ],
120
- },
121
- }.to_json,
122
- headers: response_headers,
123
- status: 422
124
- )
125
- end
126
-
127
- it 'throws the correct error' do
128
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
129
- end
130
- end
131
-
132
- context 'with a request that returns an idempotent creation conflict error' do
133
- let(:id) { 'ID123' }
134
-
135
- let(:new_resource) do
136
- {
137
-
138
- 'amount' => 'amount-input',
139
- 'app_fee' => 'app_fee-input',
140
- 'count' => 'count-input',
141
- 'created_at' => 'created_at-input',
142
- 'currency' => 'currency-input',
143
- 'day_of_month' => 'day_of_month-input',
144
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
145
- 'end_date' => 'end_date-input',
146
- 'id' => 'id-input',
147
- 'interval' => 'interval-input',
148
- 'interval_unit' => 'interval_unit-input',
149
- 'links' => 'links-input',
150
- 'metadata' => 'metadata-input',
151
- 'month' => 'month-input',
152
- 'name' => 'name-input',
153
- 'payment_reference' => 'payment_reference-input',
154
- 'retry_if_possible' => 'retry_if_possible-input',
155
- 'start_date' => 'start_date-input',
156
- 'status' => 'status-input',
157
- 'upcoming_payments' => 'upcoming_payments-input',
158
- }
159
- end
160
-
161
- let!(:post_stub) do
162
- stub_request(:post, %r{.*api.gocardless.com/subscriptions}).to_return(
163
- body: {
164
- error: {
165
- type: 'invalid_state',
166
- code: 409,
167
- errors: [
168
- {
169
- message: 'A resource has already been created with this idempotency key',
170
- reason: 'idempotent_creation_conflict',
171
- links: {
172
- conflicting_resource_id: id,
173
- },
174
- },
175
- ],
176
- },
177
- }.to_json,
178
- headers: response_headers,
179
- status: 409
180
- )
181
- end
182
-
183
- let!(:get_stub) do
184
- stub_url = "/subscriptions/#{id}"
185
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
186
- to_return(
187
- body: {
188
- 'subscriptions' => {
189
-
190
- 'amount' => 'amount-input',
191
- 'app_fee' => 'app_fee-input',
192
- 'count' => 'count-input',
193
- 'created_at' => 'created_at-input',
194
- 'currency' => 'currency-input',
195
- 'day_of_month' => 'day_of_month-input',
196
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
197
- 'end_date' => 'end_date-input',
198
- 'id' => 'id-input',
199
- 'interval' => 'interval-input',
200
- 'interval_unit' => 'interval_unit-input',
201
- 'links' => 'links-input',
202
- 'metadata' => 'metadata-input',
203
- 'month' => 'month-input',
204
- 'name' => 'name-input',
205
- 'payment_reference' => 'payment_reference-input',
206
- 'retry_if_possible' => 'retry_if_possible-input',
207
- 'start_date' => 'start_date-input',
208
- 'status' => 'status-input',
209
- 'upcoming_payments' => 'upcoming_payments-input',
210
- },
211
- }.to_json,
212
- headers: response_headers
213
- )
214
- end
215
-
216
- it 'fetches the already-created resource' do
217
- post_create_response
218
- expect(post_stub).to have_been_requested
219
- expect(get_stub).to have_been_requested
220
- end
221
- end
222
- end
223
-
224
- describe '#list' do
225
- describe 'with no filters' do
226
- subject(:get_list_response) { client.subscriptions.list }
227
-
228
- before do
229
- stub_request(:get, %r{.*api.gocardless.com/subscriptions}).to_return(
230
- body: {
231
- 'subscriptions' => [{
232
-
233
- 'amount' => 'amount-input',
234
- 'app_fee' => 'app_fee-input',
235
- 'count' => 'count-input',
236
- 'created_at' => 'created_at-input',
237
- 'currency' => 'currency-input',
238
- 'day_of_month' => 'day_of_month-input',
239
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
240
- 'end_date' => 'end_date-input',
241
- 'id' => 'id-input',
242
- 'interval' => 'interval-input',
243
- 'interval_unit' => 'interval_unit-input',
244
- 'links' => 'links-input',
245
- 'metadata' => 'metadata-input',
246
- 'month' => 'month-input',
247
- 'name' => 'name-input',
248
- 'payment_reference' => 'payment_reference-input',
249
- 'retry_if_possible' => 'retry_if_possible-input',
250
- 'start_date' => 'start_date-input',
251
- 'status' => 'status-input',
252
- 'upcoming_payments' => 'upcoming_payments-input',
253
- }],
254
- meta: {
255
- cursors: {
256
- before: nil,
257
- after: 'ABC123',
258
- },
259
- },
260
- }.to_json,
261
- headers: response_headers
262
- )
263
- end
264
-
265
- it 'wraps each item in the resource class' do
266
- expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Subscription)
267
-
268
- expect(get_list_response.records.first.amount).to eq('amount-input')
269
-
270
- expect(get_list_response.records.first.app_fee).to eq('app_fee-input')
271
-
272
- expect(get_list_response.records.first.count).to eq('count-input')
273
-
274
- expect(get_list_response.records.first.created_at).to eq('created_at-input')
275
-
276
- expect(get_list_response.records.first.currency).to eq('currency-input')
277
-
278
- expect(get_list_response.records.first.day_of_month).to eq('day_of_month-input')
279
-
280
- expect(get_list_response.records.first.earliest_charge_date_after_resume).to eq('earliest_charge_date_after_resume-input')
281
-
282
- expect(get_list_response.records.first.end_date).to eq('end_date-input')
283
-
284
- expect(get_list_response.records.first.id).to eq('id-input')
285
-
286
- expect(get_list_response.records.first.interval).to eq('interval-input')
287
-
288
- expect(get_list_response.records.first.interval_unit).to eq('interval_unit-input')
289
-
290
- expect(get_list_response.records.first.metadata).to eq('metadata-input')
291
-
292
- expect(get_list_response.records.first.month).to eq('month-input')
293
-
294
- expect(get_list_response.records.first.name).to eq('name-input')
295
-
296
- expect(get_list_response.records.first.payment_reference).to eq('payment_reference-input')
297
-
298
- expect(get_list_response.records.first.retry_if_possible).to eq('retry_if_possible-input')
299
-
300
- expect(get_list_response.records.first.start_date).to eq('start_date-input')
301
-
302
- expect(get_list_response.records.first.status).to eq('status-input')
303
-
304
- expect(get_list_response.records.first.upcoming_payments).to eq('upcoming_payments-input')
305
- end
306
-
307
- it 'exposes the cursors for before and after' do
308
- expect(get_list_response.before).to eq(nil)
309
- expect(get_list_response.after).to eq('ABC123')
310
- end
311
-
312
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
313
- end
314
- end
315
-
316
- describe '#all' do
317
- let!(:first_response_stub) do
318
- stub_request(:get, %r{.*api.gocardless.com/subscriptions$}).to_return(
319
- body: {
320
- 'subscriptions' => [{
321
-
322
- 'amount' => 'amount-input',
323
- 'app_fee' => 'app_fee-input',
324
- 'count' => 'count-input',
325
- 'created_at' => 'created_at-input',
326
- 'currency' => 'currency-input',
327
- 'day_of_month' => 'day_of_month-input',
328
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
329
- 'end_date' => 'end_date-input',
330
- 'id' => 'id-input',
331
- 'interval' => 'interval-input',
332
- 'interval_unit' => 'interval_unit-input',
333
- 'links' => 'links-input',
334
- 'metadata' => 'metadata-input',
335
- 'month' => 'month-input',
336
- 'name' => 'name-input',
337
- 'payment_reference' => 'payment_reference-input',
338
- 'retry_if_possible' => 'retry_if_possible-input',
339
- 'start_date' => 'start_date-input',
340
- 'status' => 'status-input',
341
- 'upcoming_payments' => 'upcoming_payments-input',
342
- }],
343
- meta: {
344
- cursors: { after: 'AB345' },
345
- limit: 1,
346
- },
347
- }.to_json,
348
- headers: response_headers
349
- )
350
- end
351
-
352
- let!(:second_response_stub) do
353
- stub_request(:get, %r{.*api.gocardless.com/subscriptions\?after=AB345}).to_return(
354
- body: {
355
- 'subscriptions' => [{
356
-
357
- 'amount' => 'amount-input',
358
- 'app_fee' => 'app_fee-input',
359
- 'count' => 'count-input',
360
- 'created_at' => 'created_at-input',
361
- 'currency' => 'currency-input',
362
- 'day_of_month' => 'day_of_month-input',
363
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
364
- 'end_date' => 'end_date-input',
365
- 'id' => 'id-input',
366
- 'interval' => 'interval-input',
367
- 'interval_unit' => 'interval_unit-input',
368
- 'links' => 'links-input',
369
- 'metadata' => 'metadata-input',
370
- 'month' => 'month-input',
371
- 'name' => 'name-input',
372
- 'payment_reference' => 'payment_reference-input',
373
- 'retry_if_possible' => 'retry_if_possible-input',
374
- 'start_date' => 'start_date-input',
375
- 'status' => 'status-input',
376
- 'upcoming_payments' => 'upcoming_payments-input',
377
- }],
378
- meta: {
379
- limit: 2,
380
- cursors: {},
381
- },
382
- }.to_json,
383
- headers: response_headers
384
- )
385
- end
386
-
387
- it 'automatically makes the extra requests' do
388
- expect(client.subscriptions.all.to_a.length).to eq(2)
389
- expect(first_response_stub).to have_been_requested
390
- expect(second_response_stub).to have_been_requested
391
- end
392
- end
393
-
394
- describe '#get' do
395
- let(:id) { 'ID123' }
396
-
397
- subject(:get_response) { client.subscriptions.get(id) }
398
-
399
- context 'passing in a custom header' do
400
- let!(:stub) do
401
- stub_url = '/subscriptions/:identity'.gsub(':identity', id)
402
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
403
- with(headers: { 'Foo' => 'Bar' }).
404
- to_return(
405
- body: {
406
- 'subscriptions' => {
407
-
408
- 'amount' => 'amount-input',
409
- 'app_fee' => 'app_fee-input',
410
- 'count' => 'count-input',
411
- 'created_at' => 'created_at-input',
412
- 'currency' => 'currency-input',
413
- 'day_of_month' => 'day_of_month-input',
414
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
415
- 'end_date' => 'end_date-input',
416
- 'id' => 'id-input',
417
- 'interval' => 'interval-input',
418
- 'interval_unit' => 'interval_unit-input',
419
- 'links' => 'links-input',
420
- 'metadata' => 'metadata-input',
421
- 'month' => 'month-input',
422
- 'name' => 'name-input',
423
- 'payment_reference' => 'payment_reference-input',
424
- 'retry_if_possible' => 'retry_if_possible-input',
425
- 'start_date' => 'start_date-input',
426
- 'status' => 'status-input',
427
- 'upcoming_payments' => 'upcoming_payments-input',
428
- },
429
- }.to_json,
430
- headers: response_headers
431
- )
432
- end
433
-
434
- subject(:get_response) do
435
- client.subscriptions.get(id, headers: {
436
- 'Foo' => 'Bar',
437
- })
438
- end
439
-
440
- it 'includes the header' do
441
- get_response
442
- expect(stub).to have_been_requested
443
- end
444
- end
445
-
446
- context 'when there is a subscription to return' do
447
- before do
448
- stub_url = '/subscriptions/:identity'.gsub(':identity', id)
449
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
450
- body: {
451
- 'subscriptions' => {
452
-
453
- 'amount' => 'amount-input',
454
- 'app_fee' => 'app_fee-input',
455
- 'count' => 'count-input',
456
- 'created_at' => 'created_at-input',
457
- 'currency' => 'currency-input',
458
- 'day_of_month' => 'day_of_month-input',
459
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
460
- 'end_date' => 'end_date-input',
461
- 'id' => 'id-input',
462
- 'interval' => 'interval-input',
463
- 'interval_unit' => 'interval_unit-input',
464
- 'links' => 'links-input',
465
- 'metadata' => 'metadata-input',
466
- 'month' => 'month-input',
467
- 'name' => 'name-input',
468
- 'payment_reference' => 'payment_reference-input',
469
- 'retry_if_possible' => 'retry_if_possible-input',
470
- 'start_date' => 'start_date-input',
471
- 'status' => 'status-input',
472
- 'upcoming_payments' => 'upcoming_payments-input',
473
- },
474
- }.to_json,
475
- headers: response_headers
476
- )
477
- end
478
-
479
- it 'wraps the response in a resource' do
480
- expect(get_response).to be_a(GoCardlessPro::Resources::Subscription)
481
- end
482
- end
483
-
484
- context 'when nothing is returned' do
485
- before do
486
- stub_url = '/subscriptions/:identity'.gsub(':identity', id)
487
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
488
- body: '',
489
- headers: response_headers
490
- )
491
- end
492
-
493
- it 'returns nil' do
494
- expect(get_response).to be_nil
495
- end
496
- end
497
-
498
- context "when an ID is specified which can't be included in a valid URI" do
499
- let(:id) { '`' }
500
-
501
- it "doesn't raise an error" do
502
- expect { get_response }.to_not raise_error(/bad URI/)
503
- end
504
- end
505
- end
506
-
507
- describe '#update' do
508
- subject(:put_update_response) { client.subscriptions.update(id, params: update_params) }
509
- let(:id) { 'ABC123' }
510
-
511
- context 'with a valid request' do
512
- let(:update_params) { { 'hello' => 'world' } }
513
-
514
- let!(:stub) do
515
- stub_url = '/subscriptions/:identity'.gsub(':identity', id)
516
- stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
517
- body: {
518
- 'subscriptions' => {
519
-
520
- 'amount' => 'amount-input',
521
- 'app_fee' => 'app_fee-input',
522
- 'count' => 'count-input',
523
- 'created_at' => 'created_at-input',
524
- 'currency' => 'currency-input',
525
- 'day_of_month' => 'day_of_month-input',
526
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
527
- 'end_date' => 'end_date-input',
528
- 'id' => 'id-input',
529
- 'interval' => 'interval-input',
530
- 'interval_unit' => 'interval_unit-input',
531
- 'links' => 'links-input',
532
- 'metadata' => 'metadata-input',
533
- 'month' => 'month-input',
534
- 'name' => 'name-input',
535
- 'payment_reference' => 'payment_reference-input',
536
- 'retry_if_possible' => 'retry_if_possible-input',
537
- 'start_date' => 'start_date-input',
538
- 'status' => 'status-input',
539
- 'upcoming_payments' => 'upcoming_payments-input',
540
- },
541
- }.to_json,
542
- headers: response_headers
543
- )
544
- end
545
-
546
- it 'updates and returns the resource' do
547
- expect(put_update_response).to be_a(GoCardlessPro::Resources::Subscription)
548
- expect(stub).to have_been_requested
549
- end
550
- end
551
- end
552
-
553
- describe '#pause' do
554
- subject(:post_response) { client.subscriptions.pause(resource_id) }
555
-
556
- let(:resource_id) { 'ABC123' }
557
-
558
- let!(:stub) do
559
- # /subscriptions/%v/actions/pause
560
- stub_url = '/subscriptions/:identity/actions/pause'.gsub(':identity', resource_id)
561
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
562
-
563
- body: {
564
- 'subscriptions' => {
565
-
566
- 'amount' => 'amount-input',
567
- 'app_fee' => 'app_fee-input',
568
- 'count' => 'count-input',
569
- 'created_at' => 'created_at-input',
570
- 'currency' => 'currency-input',
571
- 'day_of_month' => 'day_of_month-input',
572
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
573
- 'end_date' => 'end_date-input',
574
- 'id' => 'id-input',
575
- 'interval' => 'interval-input',
576
- 'interval_unit' => 'interval_unit-input',
577
- 'links' => 'links-input',
578
- 'metadata' => 'metadata-input',
579
- 'month' => 'month-input',
580
- 'name' => 'name-input',
581
- 'payment_reference' => 'payment_reference-input',
582
- 'retry_if_possible' => 'retry_if_possible-input',
583
- 'start_date' => 'start_date-input',
584
- 'status' => 'status-input',
585
- 'upcoming_payments' => 'upcoming_payments-input',
586
- },
587
- }.to_json,
588
-
589
- headers: response_headers
590
- )
591
- end
592
-
593
- it 'wraps the response and calls the right endpoint' do
594
- expect(post_response).to be_a(GoCardlessPro::Resources::Subscription)
595
-
596
- expect(stub).to have_been_requested
597
- end
598
-
599
- context 'when the request needs a body and custom header' do
600
- let(:body) { { foo: 'bar' } }
601
- let(:headers) { { 'Foo' => 'Bar' } }
602
- subject(:post_response) { client.subscriptions.pause(resource_id, body, headers) }
603
-
604
- let(:resource_id) { 'ABC123' }
605
-
606
- let!(:stub) do
607
- # /subscriptions/%v/actions/pause
608
- stub_url = '/subscriptions/:identity/actions/pause'.gsub(':identity', resource_id)
609
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
610
- with(
611
- body: { foo: 'bar' },
612
- headers: { 'Foo' => 'Bar' }
613
- ).to_return(
614
- body: {
615
- 'subscriptions' => {
616
-
617
- 'amount' => 'amount-input',
618
- 'app_fee' => 'app_fee-input',
619
- 'count' => 'count-input',
620
- 'created_at' => 'created_at-input',
621
- 'currency' => 'currency-input',
622
- 'day_of_month' => 'day_of_month-input',
623
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
624
- 'end_date' => 'end_date-input',
625
- 'id' => 'id-input',
626
- 'interval' => 'interval-input',
627
- 'interval_unit' => 'interval_unit-input',
628
- 'links' => 'links-input',
629
- 'metadata' => 'metadata-input',
630
- 'month' => 'month-input',
631
- 'name' => 'name-input',
632
- 'payment_reference' => 'payment_reference-input',
633
- 'retry_if_possible' => 'retry_if_possible-input',
634
- 'start_date' => 'start_date-input',
635
- 'status' => 'status-input',
636
- 'upcoming_payments' => 'upcoming_payments-input',
637
- },
638
- }.to_json,
639
- headers: response_headers
640
- )
641
- end
642
- end
643
- end
644
-
645
- describe '#resume' do
646
- subject(:post_response) { client.subscriptions.resume(resource_id) }
647
-
648
- let(:resource_id) { 'ABC123' }
649
-
650
- let!(:stub) do
651
- # /subscriptions/%v/actions/resume
652
- stub_url = '/subscriptions/:identity/actions/resume'.gsub(':identity', resource_id)
653
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
654
-
655
- body: {
656
- 'subscriptions' => {
657
-
658
- 'amount' => 'amount-input',
659
- 'app_fee' => 'app_fee-input',
660
- 'count' => 'count-input',
661
- 'created_at' => 'created_at-input',
662
- 'currency' => 'currency-input',
663
- 'day_of_month' => 'day_of_month-input',
664
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
665
- 'end_date' => 'end_date-input',
666
- 'id' => 'id-input',
667
- 'interval' => 'interval-input',
668
- 'interval_unit' => 'interval_unit-input',
669
- 'links' => 'links-input',
670
- 'metadata' => 'metadata-input',
671
- 'month' => 'month-input',
672
- 'name' => 'name-input',
673
- 'payment_reference' => 'payment_reference-input',
674
- 'retry_if_possible' => 'retry_if_possible-input',
675
- 'start_date' => 'start_date-input',
676
- 'status' => 'status-input',
677
- 'upcoming_payments' => 'upcoming_payments-input',
678
- },
679
- }.to_json,
680
-
681
- headers: response_headers
682
- )
683
- end
684
-
685
- it 'wraps the response and calls the right endpoint' do
686
- expect(post_response).to be_a(GoCardlessPro::Resources::Subscription)
687
-
688
- expect(stub).to have_been_requested
689
- end
690
-
691
- context 'when the request needs a body and custom header' do
692
- let(:body) { { foo: 'bar' } }
693
- let(:headers) { { 'Foo' => 'Bar' } }
694
- subject(:post_response) { client.subscriptions.resume(resource_id, body, headers) }
695
-
696
- let(:resource_id) { 'ABC123' }
697
-
698
- let!(:stub) do
699
- # /subscriptions/%v/actions/resume
700
- stub_url = '/subscriptions/:identity/actions/resume'.gsub(':identity', resource_id)
701
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
702
- with(
703
- body: { foo: 'bar' },
704
- headers: { 'Foo' => 'Bar' }
705
- ).to_return(
706
- body: {
707
- 'subscriptions' => {
708
-
709
- 'amount' => 'amount-input',
710
- 'app_fee' => 'app_fee-input',
711
- 'count' => 'count-input',
712
- 'created_at' => 'created_at-input',
713
- 'currency' => 'currency-input',
714
- 'day_of_month' => 'day_of_month-input',
715
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
716
- 'end_date' => 'end_date-input',
717
- 'id' => 'id-input',
718
- 'interval' => 'interval-input',
719
- 'interval_unit' => 'interval_unit-input',
720
- 'links' => 'links-input',
721
- 'metadata' => 'metadata-input',
722
- 'month' => 'month-input',
723
- 'name' => 'name-input',
724
- 'payment_reference' => 'payment_reference-input',
725
- 'retry_if_possible' => 'retry_if_possible-input',
726
- 'start_date' => 'start_date-input',
727
- 'status' => 'status-input',
728
- 'upcoming_payments' => 'upcoming_payments-input',
729
- },
730
- }.to_json,
731
- headers: response_headers
732
- )
733
- end
734
- end
735
- end
736
-
737
- describe '#cancel' do
738
- subject(:post_response) { client.subscriptions.cancel(resource_id) }
739
-
740
- let(:resource_id) { 'ABC123' }
741
-
742
- let!(:stub) do
743
- # /subscriptions/%v/actions/cancel
744
- stub_url = '/subscriptions/:identity/actions/cancel'.gsub(':identity', resource_id)
745
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
746
-
747
- body: {
748
- 'subscriptions' => {
749
-
750
- 'amount' => 'amount-input',
751
- 'app_fee' => 'app_fee-input',
752
- 'count' => 'count-input',
753
- 'created_at' => 'created_at-input',
754
- 'currency' => 'currency-input',
755
- 'day_of_month' => 'day_of_month-input',
756
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
757
- 'end_date' => 'end_date-input',
758
- 'id' => 'id-input',
759
- 'interval' => 'interval-input',
760
- 'interval_unit' => 'interval_unit-input',
761
- 'links' => 'links-input',
762
- 'metadata' => 'metadata-input',
763
- 'month' => 'month-input',
764
- 'name' => 'name-input',
765
- 'payment_reference' => 'payment_reference-input',
766
- 'retry_if_possible' => 'retry_if_possible-input',
767
- 'start_date' => 'start_date-input',
768
- 'status' => 'status-input',
769
- 'upcoming_payments' => 'upcoming_payments-input',
770
- },
771
- }.to_json,
772
-
773
- headers: response_headers
774
- )
775
- end
776
-
777
- it 'wraps the response and calls the right endpoint' do
778
- expect(post_response).to be_a(GoCardlessPro::Resources::Subscription)
779
-
780
- expect(stub).to have_been_requested
781
- end
782
-
783
- context 'when the request needs a body and custom header' do
784
- let(:body) { { foo: 'bar' } }
785
- let(:headers) { { 'Foo' => 'Bar' } }
786
- subject(:post_response) { client.subscriptions.cancel(resource_id, body, headers) }
787
-
788
- let(:resource_id) { 'ABC123' }
789
-
790
- let!(:stub) do
791
- # /subscriptions/%v/actions/cancel
792
- stub_url = '/subscriptions/:identity/actions/cancel'.gsub(':identity', resource_id)
793
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
794
- with(
795
- body: { foo: 'bar' },
796
- headers: { 'Foo' => 'Bar' }
797
- ).to_return(
798
- body: {
799
- 'subscriptions' => {
800
-
801
- 'amount' => 'amount-input',
802
- 'app_fee' => 'app_fee-input',
803
- 'count' => 'count-input',
804
- 'created_at' => 'created_at-input',
805
- 'currency' => 'currency-input',
806
- 'day_of_month' => 'day_of_month-input',
807
- 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
808
- 'end_date' => 'end_date-input',
809
- 'id' => 'id-input',
810
- 'interval' => 'interval-input',
811
- 'interval_unit' => 'interval_unit-input',
812
- 'links' => 'links-input',
813
- 'metadata' => 'metadata-input',
814
- 'month' => 'month-input',
815
- 'name' => 'name-input',
816
- 'payment_reference' => 'payment_reference-input',
817
- 'retry_if_possible' => 'retry_if_possible-input',
818
- 'start_date' => 'start_date-input',
819
- 'status' => 'status-input',
820
- 'upcoming_payments' => 'upcoming_payments-input',
821
- },
822
- }.to_json,
823
- headers: response_headers
824
- )
825
- end
826
- end
827
- end
828
- end