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