gocardless_pro 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -0
  3. data/README.md +71 -28
  4. data/gocardless_pro.gemspec +1 -1
  5. data/lib/gocardless_pro/api_service.rb +4 -2
  6. data/lib/gocardless_pro/client.rb +2 -1
  7. data/lib/gocardless_pro/error.rb +12 -1
  8. data/lib/gocardless_pro/resources/mandate.rb +3 -0
  9. data/lib/gocardless_pro/resources/payout.rb +3 -0
  10. data/lib/gocardless_pro/resources/redirect_flow.rb +15 -14
  11. data/lib/gocardless_pro/services/bank_details_lookups_service.rb +10 -0
  12. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +5 -2
  13. data/lib/gocardless_pro/services/creditors_service.rb +5 -2
  14. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +7 -3
  15. data/lib/gocardless_pro/services/customers_service.rb +5 -2
  16. data/lib/gocardless_pro/services/events_service.rb +2 -1
  17. data/lib/gocardless_pro/services/mandate_pdfs_service.rb +2 -1
  18. data/lib/gocardless_pro/services/mandates_service.rb +10 -5
  19. data/lib/gocardless_pro/services/payments_service.rb +11 -6
  20. data/lib/gocardless_pro/services/payouts_service.rb +2 -1
  21. data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -3
  22. data/lib/gocardless_pro/services/refunds_service.rb +5 -2
  23. data/lib/gocardless_pro/services/subscriptions_service.rb +7 -3
  24. data/lib/gocardless_pro/version.rb +1 -1
  25. data/spec/api_response_spec.rb +4 -4
  26. data/spec/api_service_spec.rb +41 -43
  27. data/spec/client_spec.rb +2 -2
  28. data/spec/error_spec.rb +27 -18
  29. data/spec/resources/bank_details_lookup_spec.rb +19 -34
  30. data/spec/resources/creditor_bank_account_spec.rb +54 -99
  31. data/spec/resources/creditor_spec.rb +66 -115
  32. data/spec/resources/customer_bank_account_spec.rb +54 -99
  33. data/spec/resources/customer_spec.rb +71 -138
  34. data/spec/resources/event_spec.rb +74 -107
  35. data/spec/resources/mandate_pdf_spec.rb +15 -26
  36. data/spec/resources/mandate_spec.rb +54 -87
  37. data/spec/resources/payment_spec.rb +70 -119
  38. data/spec/resources/payout_spec.rb +50 -79
  39. data/spec/resources/redirect_flow_spec.rb +58 -95
  40. data/spec/resources/refund_spec.rb +42 -75
  41. data/spec/resources/subscription_spec.rb +82 -155
  42. data/spec/response_spec.rb +45 -46
  43. data/spec/services/bank_details_lookups_service_spec.rb +55 -60
  44. data/spec/services/creditor_bank_accounts_service_spec.rb +303 -347
  45. data/spec/services/creditors_service_spec.rb +290 -333
  46. data/spec/services/customer_bank_accounts_service_spec.rb +332 -380
  47. data/spec/services/customers_service_spec.rb +347 -400
  48. data/spec/services/events_service_spec.rb +154 -184
  49. data/spec/services/mandate_pdfs_service_spec.rb +52 -57
  50. data/spec/services/mandates_service_spec.rb +374 -410
  51. data/spec/services/payments_service_spec.rb +404 -461
  52. data/spec/services/payouts_service_spec.rb +161 -184
  53. data/spec/services/redirect_flows_service_spec.rb +188 -205
  54. data/spec/services/refunds_service_spec.rb +245 -280
  55. data/spec/services/subscriptions_service_spec.rb +423 -485
  56. data/spec/spec_helper.rb +46 -48
  57. metadata +22 -20
@@ -3,221 +3,191 @@ require 'spec_helper'
3
3
  describe GoCardlessPro::Services::EventsService do
4
4
  let(:client) do
5
5
  GoCardlessPro::Client.new(
6
- access_token: "SECRET_TOKEN"
6
+ access_token: 'SECRET_TOKEN'
7
7
  )
8
8
  end
9
9
 
10
-
11
-
12
-
13
-
10
+ describe '#list' do
11
+ describe 'with no filters' do
12
+ subject(:get_list_response) { client.events.list }
14
13
 
15
-
16
- describe "#list" do
17
- describe "with no filters" do
18
- subject(:get_list_response) { client.events.list }
19
-
20
- before do
21
- stub_request(:get, %r(.*api.gocardless.com/events)).to_return(
22
- body: {
23
- "events" => [{
24
-
25
- "action" => "action-input",
26
- "created_at" => "created_at-input",
27
- "details" => "details-input",
28
- "id" => "id-input",
29
- "links" => "links-input",
30
- "metadata" => "metadata-input",
31
- "resource_type" => "resource_type-input",
32
- }],
33
- meta: {
34
- cursors: {
35
- before: nil,
36
- after: "ABC123"
37
- }
38
- }
39
- }.to_json,
40
- :headers => {'Content-Type' => 'application/json'}
41
- )
42
- end
43
-
44
- it "wraps each item in the resource class" do
45
- expect(get_list_response.records.map { |x| x.class }.uniq.first).to eq(GoCardlessPro::Resources::Event)
46
-
47
-
48
-
49
- expect(get_list_response.records.first.action).to eq("action-input")
50
-
51
-
52
-
53
- expect(get_list_response.records.first.created_at).to eq("created_at-input")
54
-
55
-
56
-
57
- expect(get_list_response.records.first.details).to eq("details-input")
58
-
59
-
60
-
61
- expect(get_list_response.records.first.id).to eq("id-input")
62
-
63
-
64
-
65
-
66
-
67
- expect(get_list_response.records.first.metadata).to eq("metadata-input")
68
-
69
-
70
-
71
- expect(get_list_response.records.first.resource_type).to eq("resource_type-input")
72
-
73
-
74
- end
75
-
76
- it "exposes the cursors for before and after" do
77
- expect(get_list_response.before).to eq(nil)
78
- expect(get_list_response.after).to eq("ABC123")
79
- end
80
-
81
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
82
- end
83
- end
84
-
85
- describe "#all" do
86
- let!(:first_response_stub) do
87
- stub_request(:get, %r(.*api.gocardless.com/events$)).to_return(
14
+ before do
15
+ stub_request(:get, %r{.*api.gocardless.com/events}).to_return(
88
16
  body: {
89
- "events" => [{
90
-
91
- "action" => "action-input",
92
- "created_at" => "created_at-input",
93
- "details" => "details-input",
94
- "id" => "id-input",
95
- "links" => "links-input",
96
- "metadata" => "metadata-input",
97
- "resource_type" => "resource_type-input",
17
+ 'events' => [{
18
+
19
+ 'action' => 'action-input',
20
+ 'created_at' => 'created_at-input',
21
+ 'details' => 'details-input',
22
+ 'id' => 'id-input',
23
+ 'links' => 'links-input',
24
+ 'metadata' => 'metadata-input',
25
+ 'resource_type' => 'resource_type-input'
98
26
  }],
99
27
  meta: {
100
- cursors: { after: 'AB345' },
101
- limit: 1
28
+ cursors: {
29
+ before: nil,
30
+ after: 'ABC123'
31
+ }
102
32
  }
103
33
  }.to_json,
104
- :headers => {'Content-Type' => 'application/json'}
34
+ headers: { 'Content-Type' => 'application/json' }
105
35
  )
106
36
  end
107
37
 
108
- let!(:second_response_stub) do
109
- stub_request(:get, %r(.*api.gocardless.com/events\?after=AB345)).to_return(
110
- body: {
111
- "events" => [{
112
-
113
- "action" => "action-input",
114
- "created_at" => "created_at-input",
115
- "details" => "details-input",
116
- "id" => "id-input",
117
- "links" => "links-input",
118
- "metadata" => "metadata-input",
119
- "resource_type" => "resource_type-input",
120
- }],
121
- meta: {
122
- limit: 2,
123
- cursors: {}
124
- }
125
- }.to_json,
126
- :headers => {'Content-Type' => 'application/json'}
127
- )
38
+ it 'wraps each item in the resource class' do
39
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Event)
40
+
41
+ expect(get_list_response.records.first.action).to eq('action-input')
42
+
43
+ expect(get_list_response.records.first.created_at).to eq('created_at-input')
44
+
45
+ expect(get_list_response.records.first.details).to eq('details-input')
46
+
47
+ expect(get_list_response.records.first.id).to eq('id-input')
48
+
49
+ expect(get_list_response.records.first.metadata).to eq('metadata-input')
50
+
51
+ expect(get_list_response.records.first.resource_type).to eq('resource_type-input')
128
52
  end
129
53
 
130
- it "automatically makes the extra requests" do
131
- expect(client.events.all.to_a.length).to eq(2)
132
- expect(first_response_stub).to have_been_requested
133
- expect(second_response_stub).to have_been_requested
54
+ it 'exposes the cursors for before and after' do
55
+ expect(get_list_response.before).to eq(nil)
56
+ expect(get_list_response.after).to eq('ABC123')
134
57
  end
58
+
59
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
60
+ end
61
+ end
62
+
63
+ describe '#all' do
64
+ let!(:first_response_stub) do
65
+ stub_request(:get, %r{.*api.gocardless.com/events$}).to_return(
66
+ body: {
67
+ 'events' => [{
68
+
69
+ 'action' => 'action-input',
70
+ 'created_at' => 'created_at-input',
71
+ 'details' => 'details-input',
72
+ 'id' => 'id-input',
73
+ 'links' => 'links-input',
74
+ 'metadata' => 'metadata-input',
75
+ 'resource_type' => 'resource_type-input'
76
+ }],
77
+ meta: {
78
+ cursors: { after: 'AB345' },
79
+ limit: 1
80
+ }
81
+ }.to_json,
82
+ headers: { 'Content-Type' => 'application/json' }
83
+ )
135
84
  end
136
85
 
137
-
138
-
139
-
86
+ let!(:second_response_stub) do
87
+ stub_request(:get, %r{.*api.gocardless.com/events\?after=AB345}).to_return(
88
+ body: {
89
+ 'events' => [{
90
+
91
+ 'action' => 'action-input',
92
+ 'created_at' => 'created_at-input',
93
+ 'details' => 'details-input',
94
+ 'id' => 'id-input',
95
+ 'links' => 'links-input',
96
+ 'metadata' => 'metadata-input',
97
+ 'resource_type' => 'resource_type-input'
98
+ }],
99
+ meta: {
100
+ limit: 2,
101
+ cursors: {}
102
+ }
103
+ }.to_json,
104
+ headers: { 'Content-Type' => 'application/json' }
105
+ )
106
+ end
107
+
108
+ it 'automatically makes the extra requests' do
109
+ expect(client.events.all.to_a.length).to eq(2)
110
+ expect(first_response_stub).to have_been_requested
111
+ expect(second_response_stub).to have_been_requested
112
+ end
113
+ end
140
114
 
141
-
142
- describe "#get" do
143
- let(:id) { "ID123" }
115
+ describe '#get' do
116
+ let(:id) { 'ID123' }
144
117
 
145
- subject(:get_response) { client.events.get(id) }
118
+ subject(:get_response) { client.events.get(id) }
146
119
 
147
- context "passing in a custom header" do
148
- let!(:stub) do
149
- stub_url = "/events/:identity".gsub(':identity', id)
150
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).
151
- with(headers: { 'Foo' => 'Bar' }).
152
- to_return(
120
+ context 'passing in a custom header' do
121
+ let!(:stub) do
122
+ stub_url = '/events/:identity'.gsub(':identity', id)
123
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/)
124
+ .with(headers: { 'Foo' => 'Bar' })
125
+ .to_return(
153
126
  body: {
154
- "events" => {
155
-
156
- "action" => "action-input",
157
- "created_at" => "created_at-input",
158
- "details" => "details-input",
159
- "id" => "id-input",
160
- "links" => "links-input",
161
- "metadata" => "metadata-input",
162
- "resource_type" => "resource_type-input",
127
+ 'events' => {
128
+
129
+ 'action' => 'action-input',
130
+ 'created_at' => 'created_at-input',
131
+ 'details' => 'details-input',
132
+ 'id' => 'id-input',
133
+ 'links' => 'links-input',
134
+ 'metadata' => 'metadata-input',
135
+ 'resource_type' => 'resource_type-input'
163
136
  }
164
137
  }.to_json,
165
- :headers => {'Content-Type' => 'application/json'}
138
+ headers: { 'Content-Type' => 'application/json' }
166
139
  )
167
- end
168
-
169
- subject(:get_response) do
170
- client.events.get(id, headers: {
171
- 'Foo' => 'Bar'
172
- })
173
- end
174
-
175
- it "includes the header" do
176
- get_response
177
- expect(stub).to have_been_requested
178
- end
179
140
  end
180
141
 
181
- context "when there is a event to return" do
182
- before do
183
- stub_url = "/events/:identity".gsub(':identity', id)
184
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
185
- body: {
186
- "events" => {
187
-
188
- "action" => "action-input",
189
- "created_at" => "created_at-input",
190
- "details" => "details-input",
191
- "id" => "id-input",
192
- "links" => "links-input",
193
- "metadata" => "metadata-input",
194
- "resource_type" => "resource_type-input",
195
- }
196
- }.to_json,
197
- :headers => {'Content-Type' => 'application/json'}
198
- )
199
- end
142
+ subject(:get_response) do
143
+ client.events.get(id, headers: {
144
+ 'Foo' => 'Bar'
145
+ })
146
+ end
200
147
 
201
- it "wraps the response in a resource" do
202
- expect(get_response).to be_a(GoCardlessPro::Resources::Event)
203
- end
148
+ it 'includes the header' do
149
+ get_response
150
+ expect(stub).to have_been_requested
204
151
  end
152
+ end
205
153
 
206
- context "when nothing is returned" do
207
- before do
208
- stub_url = "/events/:identity".gsub(':identity', id)
209
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
210
- body: "",
211
- headers: { 'Content-Type' => 'application/json' }
212
- )
213
- end
154
+ context 'when there is a event to return' do
155
+ before do
156
+ stub_url = '/events/:identity'.gsub(':identity', id)
157
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
158
+ body: {
159
+ 'events' => {
160
+
161
+ 'action' => 'action-input',
162
+ 'created_at' => 'created_at-input',
163
+ 'details' => 'details-input',
164
+ 'id' => 'id-input',
165
+ 'links' => 'links-input',
166
+ 'metadata' => 'metadata-input',
167
+ 'resource_type' => 'resource_type-input'
168
+ }
169
+ }.to_json,
170
+ headers: { 'Content-Type' => 'application/json' }
171
+ )
172
+ end
214
173
 
215
- it "returns nil" do
216
- expect(get_response).to be_nil
217
- end
174
+ it 'wraps the response in a resource' do
175
+ expect(get_response).to be_a(GoCardlessPro::Resources::Event)
218
176
  end
219
177
  end
220
178
 
221
-
222
-
179
+ context 'when nothing is returned' do
180
+ before do
181
+ stub_url = '/events/:identity'.gsub(':identity', id)
182
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
183
+ body: '',
184
+ headers: { 'Content-Type' => 'application/json' }
185
+ )
186
+ end
187
+
188
+ it 'returns nil' do
189
+ expect(get_response).to be_nil
190
+ end
191
+ end
192
+ end
223
193
  end
@@ -3,79 +3,74 @@ require 'spec_helper'
3
3
  describe GoCardlessPro::Services::MandatePdfsService do
4
4
  let(:client) do
5
5
  GoCardlessPro::Client.new(
6
- access_token: "SECRET_TOKEN"
6
+ access_token: 'SECRET_TOKEN'
7
7
  )
8
8
  end
9
9
 
10
-
11
-
12
-
13
-
14
-
15
-
16
- describe "#create" do
10
+ describe '#create' do
17
11
  subject(:post_create_response) { client.mandate_pdfs.create(params: new_resource) }
18
- context "with a valid request" do
19
- let(:new_resource) do
20
- {
21
-
22
- "expires_at" => "expires_at-input",
23
- "url" => "url-input",
24
- }
25
- end
12
+ context 'with a valid request' do
13
+ let(:new_resource) do
14
+ {
15
+
16
+ 'expires_at' => 'expires_at-input',
17
+ 'url' => 'url-input'
18
+ }
19
+ end
26
20
 
27
- before do
28
- stub_request(:post, %r(.*api.gocardless.com/mandate_pdfs)).
29
- with(
21
+ before do
22
+ stub_request(:post, %r{.*api.gocardless.com/mandate_pdfs})
23
+ .with(
30
24
  body: {
31
- "mandate_pdfs" => {
32
-
33
- "expires_at" => "expires_at-input",
34
- "url" => "url-input",
35
- }
25
+ 'mandate_pdfs' => {
26
+
27
+ 'expires_at' => 'expires_at-input',
28
+ 'url' => 'url-input'
29
+ }
36
30
  }
37
- ).
38
- to_return(
31
+ )
32
+ .to_return(
39
33
  body: {
40
- "mandate_pdfs" => {
41
-
42
- "expires_at" => "expires_at-input",
43
- "url" => "url-input",
34
+ 'mandate_pdfs' =>
35
+
36
+ {
37
+
38
+ 'expires_at' => 'expires_at-input',
39
+ 'url' => 'url-input'
44
40
  }
41
+
45
42
  }.to_json,
46
- :headers => {'Content-Type' => 'application/json'}
43
+ headers: { 'Content-Type' => 'application/json' }
47
44
  )
48
- end
45
+ end
49
46
 
50
- it "creates and returns the resource" do
51
- expect(post_create_response).to be_a(GoCardlessPro::Resources::MandatePdf)
52
- end
47
+ it 'creates and returns the resource' do
48
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::MandatePdf)
53
49
  end
50
+ end
54
51
 
55
- context "with a request that returns a validation error" do
56
- let(:new_resource) { {} }
52
+ context 'with a request that returns a validation error' do
53
+ let(:new_resource) { {} }
57
54
 
58
- before do
59
- stub_request(:post, %r(.*api.gocardless.com/mandate_pdfs)).to_return(
60
- body: {
61
- error: {
62
- type: 'validation_failed',
63
- code: 422,
64
- errors: [
65
- { message: 'test error message', field: 'test_field' }
66
- ]
67
- }
68
- }.to_json,
69
- headers: {'Content-Type' => 'application/json'},
70
- status: 422
71
- )
72
- end
55
+ before do
56
+ stub_request(:post, %r{.*api.gocardless.com/mandate_pdfs}).to_return(
57
+ body: {
58
+ error: {
59
+ type: 'validation_failed',
60
+ code: 422,
61
+ errors: [
62
+ { message: 'test error message', field: 'test_field' }
63
+ ]
64
+ }
65
+ }.to_json,
66
+ headers: { 'Content-Type' => 'application/json' },
67
+ status: 422
68
+ )
69
+ end
73
70
 
74
- it "throws the correct error" do
75
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
76
- end
71
+ it 'throws the correct error' do
72
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
77
73
  end
78
74
  end
79
-
80
-
75
+ end
81
76
  end