gocardless_pro 2.24.0 → 2.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -4
  3. data/lib/gocardless_pro/api_service.rb +4 -0
  4. data/lib/gocardless_pro/client.rb +46 -1
  5. data/lib/gocardless_pro/error/authentication_error.rb +4 -0
  6. data/lib/gocardless_pro/error/permission_error.rb +4 -0
  7. data/lib/gocardless_pro/error/rate_limit_error.rb +4 -0
  8. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +12 -1
  9. data/lib/gocardless_pro/resources/bank_authorisation.rb +81 -0
  10. data/lib/gocardless_pro/resources/billing_request.rb +108 -0
  11. data/lib/gocardless_pro/resources/billing_request_flow.rb +72 -0
  12. data/lib/gocardless_pro/resources/billing_request_template.rb +68 -0
  13. data/lib/gocardless_pro/resources/block.rb +66 -0
  14. data/lib/gocardless_pro/resources/creditor.rb +2 -3
  15. data/lib/gocardless_pro/resources/event.rb +20 -0
  16. data/lib/gocardless_pro/resources/institution.rb +47 -0
  17. data/lib/gocardless_pro/resources/payer_authorisation.rb +131 -0
  18. data/lib/gocardless_pro/resources/payout_item.rb +4 -0
  19. data/lib/gocardless_pro/resources/redirect_flow.rb +2 -0
  20. data/lib/gocardless_pro/resources/scenario_simulator.rb +42 -0
  21. data/lib/gocardless_pro/resources/webhook.rb +62 -0
  22. data/lib/gocardless_pro/services/bank_authorisations_service.rb +80 -0
  23. data/lib/gocardless_pro/services/billing_request_flows_service.rb +70 -0
  24. data/lib/gocardless_pro/services/billing_request_templates_service.rb +131 -0
  25. data/lib/gocardless_pro/services/billing_requests_service.rb +352 -0
  26. data/lib/gocardless_pro/services/blocks_service.rb +223 -0
  27. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +1 -5
  28. data/lib/gocardless_pro/services/creditors_service.rb +1 -3
  29. data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +1 -1
  30. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +1 -5
  31. data/lib/gocardless_pro/services/customers_service.rb +1 -3
  32. data/lib/gocardless_pro/services/events_service.rb +1 -1
  33. data/lib/gocardless_pro/services/instalment_schedules_service.rb +1 -7
  34. data/lib/gocardless_pro/services/institutions_service.rb +56 -0
  35. data/lib/gocardless_pro/services/mandate_import_entries_service.rb +1 -1
  36. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -6
  37. data/lib/gocardless_pro/services/mandates_service.rb +1 -7
  38. data/lib/gocardless_pro/services/payer_authorisations_service.rb +202 -0
  39. data/lib/gocardless_pro/services/payments_service.rb +1 -7
  40. data/lib/gocardless_pro/services/payout_items_service.rb +1 -1
  41. data/lib/gocardless_pro/services/payouts_service.rb +1 -1
  42. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -4
  43. data/lib/gocardless_pro/services/refunds_service.rb +1 -3
  44. data/lib/gocardless_pro/services/scenario_simulators_service.rb +170 -0
  45. data/lib/gocardless_pro/services/subscriptions_service.rb +10 -13
  46. data/lib/gocardless_pro/services/tax_rates_service.rb +1 -1
  47. data/lib/gocardless_pro/services/webhooks_service.rb +111 -0
  48. data/lib/gocardless_pro/version.rb +1 -1
  49. data/lib/gocardless_pro.rb +30 -0
  50. data/spec/api_service_spec.rb +12 -1
  51. data/spec/middlewares/raise_gocardless_errors_spec.rb +30 -0
  52. data/spec/resources/bank_authorisation_spec.rb +259 -0
  53. data/spec/resources/billing_request_flow_spec.rb +219 -0
  54. data/spec/resources/billing_request_spec.rb +782 -0
  55. data/spec/resources/billing_request_template_spec.rb +502 -0
  56. data/spec/resources/block_spec.rb +560 -0
  57. data/spec/resources/institution_spec.rb +108 -0
  58. data/spec/resources/payer_authorisation_spec.rb +418 -0
  59. data/spec/resources/redirect_flow_spec.rb +9 -0
  60. data/spec/resources/scenario_simulator_spec.rb +63 -0
  61. data/spec/resources/webhook_spec.rb +323 -0
  62. data/spec/services/bank_authorisations_service_spec.rb +353 -0
  63. data/spec/services/billing_request_flows_service_spec.rb +253 -0
  64. data/spec/services/billing_request_templates_service_spec.rb +789 -0
  65. data/spec/services/billing_requests_service_spec.rb +1082 -0
  66. data/spec/services/blocks_service_spec.rb +823 -0
  67. data/spec/services/creditor_bank_accounts_service_spec.rb +0 -13
  68. data/spec/services/creditors_service_spec.rb +0 -13
  69. data/spec/services/customer_bank_accounts_service_spec.rb +0 -13
  70. data/spec/services/customers_service_spec.rb +0 -13
  71. data/spec/services/instalment_schedules_service_spec.rb +0 -26
  72. data/spec/services/institutions_service_spec.rb +232 -0
  73. data/spec/services/mandate_imports_service_spec.rb +0 -13
  74. data/spec/services/mandates_service_spec.rb +0 -13
  75. data/spec/services/payer_authorisations_service_spec.rb +559 -0
  76. data/spec/services/payments_service_spec.rb +0 -13
  77. data/spec/services/redirect_flows_service_spec.rb +9 -13
  78. data/spec/services/refunds_service_spec.rb +0 -13
  79. data/spec/services/scenario_simulators_service_spec.rb +74 -0
  80. data/spec/services/subscriptions_service_spec.rb +0 -13
  81. data/spec/services/webhooks_service_spec.rb +545 -0
  82. metadata +64 -7
@@ -0,0 +1,219 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Resources::BillingRequestFlow do
4
+ let(:client) do
5
+ GoCardlessPro::Client.new(
6
+ access_token: 'SECRET_TOKEN'
7
+ )
8
+ end
9
+
10
+ let(:response_headers) { { 'Content-Type' => 'application/json' } }
11
+
12
+ describe '#create' do
13
+ subject(:post_create_response) { client.billing_request_flows.create(params: new_resource) }
14
+ context 'with a valid request' do
15
+ let(:new_resource) do
16
+ {
17
+
18
+ 'authorisation_url' => 'authorisation_url-input',
19
+ 'auto_fulfil' => 'auto_fulfil-input',
20
+ 'created_at' => 'created_at-input',
21
+ 'expires_at' => 'expires_at-input',
22
+ 'id' => 'id-input',
23
+ 'links' => 'links-input',
24
+ 'lock_bank_account' => 'lock_bank_account-input',
25
+ 'lock_customer_details' => 'lock_customer_details-input',
26
+ 'redirect_uri' => 'redirect_uri-input',
27
+ 'session_token' => 'session_token-input',
28
+ }
29
+ end
30
+
31
+ before do
32
+ stub_request(:post, %r{.*api.gocardless.com/billing_request_flows}).
33
+ with(
34
+ body: {
35
+ 'billing_request_flows' => {
36
+
37
+ 'authorisation_url' => 'authorisation_url-input',
38
+ 'auto_fulfil' => 'auto_fulfil-input',
39
+ 'created_at' => 'created_at-input',
40
+ 'expires_at' => 'expires_at-input',
41
+ 'id' => 'id-input',
42
+ 'links' => 'links-input',
43
+ 'lock_bank_account' => 'lock_bank_account-input',
44
+ 'lock_customer_details' => 'lock_customer_details-input',
45
+ 'redirect_uri' => 'redirect_uri-input',
46
+ 'session_token' => 'session_token-input',
47
+ },
48
+ }
49
+ ).
50
+ to_return(
51
+ body: {
52
+ 'billing_request_flows' =>
53
+
54
+ {
55
+
56
+ 'authorisation_url' => 'authorisation_url-input',
57
+ 'auto_fulfil' => 'auto_fulfil-input',
58
+ 'created_at' => 'created_at-input',
59
+ 'expires_at' => 'expires_at-input',
60
+ 'id' => 'id-input',
61
+ 'links' => 'links-input',
62
+ 'lock_bank_account' => 'lock_bank_account-input',
63
+ 'lock_customer_details' => 'lock_customer_details-input',
64
+ 'redirect_uri' => 'redirect_uri-input',
65
+ 'session_token' => 'session_token-input',
66
+ },
67
+
68
+ }.to_json,
69
+ headers: response_headers
70
+ )
71
+ end
72
+
73
+ it 'creates and returns the resource' do
74
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::BillingRequestFlow)
75
+ end
76
+ end
77
+
78
+ context 'with a request that returns a validation error' do
79
+ let(:new_resource) { {} }
80
+
81
+ before do
82
+ stub_request(:post, %r{.*api.gocardless.com/billing_request_flows}).to_return(
83
+ body: {
84
+ error: {
85
+ type: 'validation_failed',
86
+ code: 422,
87
+ errors: [
88
+ { message: 'test error message', field: 'test_field' },
89
+ ],
90
+ },
91
+ }.to_json,
92
+ headers: response_headers,
93
+ status: 422
94
+ )
95
+ end
96
+
97
+ it 'throws the correct error' do
98
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
99
+ end
100
+ end
101
+
102
+ context 'with a request that returns an idempotent creation conflict error' do
103
+ let(:id) { 'ID123' }
104
+
105
+ let(:new_resource) do
106
+ {
107
+
108
+ 'authorisation_url' => 'authorisation_url-input',
109
+ 'auto_fulfil' => 'auto_fulfil-input',
110
+ 'created_at' => 'created_at-input',
111
+ 'expires_at' => 'expires_at-input',
112
+ 'id' => 'id-input',
113
+ 'links' => 'links-input',
114
+ 'lock_bank_account' => 'lock_bank_account-input',
115
+ 'lock_customer_details' => 'lock_customer_details-input',
116
+ 'redirect_uri' => 'redirect_uri-input',
117
+ 'session_token' => 'session_token-input',
118
+ }
119
+ end
120
+
121
+ let!(:post_stub) do
122
+ stub_request(:post, %r{.*api.gocardless.com/billing_request_flows}).to_return(
123
+ body: {
124
+ error: {
125
+ type: 'invalid_state',
126
+ code: 409,
127
+ errors: [
128
+ {
129
+ message: 'A resource has already been created with this idempotency key',
130
+ reason: 'idempotent_creation_conflict',
131
+ links: {
132
+ conflicting_resource_id: id,
133
+ },
134
+ },
135
+ ],
136
+ },
137
+ }.to_json,
138
+ headers: response_headers,
139
+ status: 409
140
+ )
141
+ end
142
+
143
+ it 'raises an InvalidStateError' do
144
+ expect { post_create_response }.to raise_error(GoCardlessPro::InvalidStateError)
145
+ expect(post_stub).to have_been_requested
146
+ end
147
+ end
148
+ end
149
+
150
+ describe '#initialise' do
151
+ subject(:post_response) { client.billing_request_flows.initialise(resource_id) }
152
+
153
+ let(:resource_id) { 'ABC123' }
154
+
155
+ let!(:stub) do
156
+ # /billing_request_flows/%v/actions/initialise
157
+ stub_url = '/billing_request_flows/:identity/actions/initialise'.gsub(':identity', resource_id)
158
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
159
+ body: {
160
+ 'billing_request_flows' => {
161
+
162
+ 'authorisation_url' => 'authorisation_url-input',
163
+ 'auto_fulfil' => 'auto_fulfil-input',
164
+ 'created_at' => 'created_at-input',
165
+ 'expires_at' => 'expires_at-input',
166
+ 'id' => 'id-input',
167
+ 'links' => 'links-input',
168
+ 'lock_bank_account' => 'lock_bank_account-input',
169
+ 'lock_customer_details' => 'lock_customer_details-input',
170
+ 'redirect_uri' => 'redirect_uri-input',
171
+ 'session_token' => 'session_token-input',
172
+ },
173
+ }.to_json,
174
+ headers: response_headers
175
+ )
176
+ end
177
+
178
+ it 'wraps the response and calls the right endpoint' do
179
+ expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequestFlow)
180
+
181
+ expect(stub).to have_been_requested
182
+ end
183
+
184
+ context 'when the request needs a body and custom header' do
185
+ let(:body) { { foo: 'bar' } }
186
+ let(:headers) { { 'Foo' => 'Bar' } }
187
+ subject(:post_response) { client.billing_request_flows.initialise(resource_id, body, headers) }
188
+
189
+ let(:resource_id) { 'ABC123' }
190
+
191
+ let!(:stub) do
192
+ # /billing_request_flows/%v/actions/initialise
193
+ stub_url = '/billing_request_flows/:identity/actions/initialise'.gsub(':identity', resource_id)
194
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
195
+ with(
196
+ body: { foo: 'bar' },
197
+ headers: { 'Foo' => 'Bar' }
198
+ ).to_return(
199
+ body: {
200
+ 'billing_request_flows' => {
201
+
202
+ 'authorisation_url' => 'authorisation_url-input',
203
+ 'auto_fulfil' => 'auto_fulfil-input',
204
+ 'created_at' => 'created_at-input',
205
+ 'expires_at' => 'expires_at-input',
206
+ 'id' => 'id-input',
207
+ 'links' => 'links-input',
208
+ 'lock_bank_account' => 'lock_bank_account-input',
209
+ 'lock_customer_details' => 'lock_customer_details-input',
210
+ 'redirect_uri' => 'redirect_uri-input',
211
+ 'session_token' => 'session_token-input',
212
+ },
213
+ }.to_json,
214
+ headers: response_headers
215
+ )
216
+ end
217
+ end
218
+ end
219
+ end