gocardless_pro 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -0
- data/README.md +71 -28
- data/gocardless_pro.gemspec +1 -1
- data/lib/gocardless_pro/api_service.rb +4 -2
- data/lib/gocardless_pro/client.rb +2 -1
- data/lib/gocardless_pro/error.rb +12 -1
- data/lib/gocardless_pro/resources/mandate.rb +3 -0
- data/lib/gocardless_pro/resources/payout.rb +3 -0
- data/lib/gocardless_pro/resources/redirect_flow.rb +15 -14
- data/lib/gocardless_pro/services/bank_details_lookups_service.rb +10 -0
- data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +5 -2
- data/lib/gocardless_pro/services/creditors_service.rb +5 -2
- data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +7 -3
- data/lib/gocardless_pro/services/customers_service.rb +5 -2
- data/lib/gocardless_pro/services/events_service.rb +2 -1
- data/lib/gocardless_pro/services/mandate_pdfs_service.rb +2 -1
- data/lib/gocardless_pro/services/mandates_service.rb +10 -5
- data/lib/gocardless_pro/services/payments_service.rb +11 -6
- data/lib/gocardless_pro/services/payouts_service.rb +2 -1
- data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -3
- data/lib/gocardless_pro/services/refunds_service.rb +5 -2
- data/lib/gocardless_pro/services/subscriptions_service.rb +7 -3
- data/lib/gocardless_pro/version.rb +1 -1
- data/spec/api_response_spec.rb +4 -4
- data/spec/api_service_spec.rb +41 -43
- data/spec/client_spec.rb +2 -2
- data/spec/error_spec.rb +27 -18
- data/spec/resources/bank_details_lookup_spec.rb +19 -34
- data/spec/resources/creditor_bank_account_spec.rb +54 -99
- data/spec/resources/creditor_spec.rb +66 -115
- data/spec/resources/customer_bank_account_spec.rb +54 -99
- data/spec/resources/customer_spec.rb +71 -138
- data/spec/resources/event_spec.rb +74 -107
- data/spec/resources/mandate_pdf_spec.rb +15 -26
- data/spec/resources/mandate_spec.rb +54 -87
- data/spec/resources/payment_spec.rb +70 -119
- data/spec/resources/payout_spec.rb +50 -79
- data/spec/resources/redirect_flow_spec.rb +58 -95
- data/spec/resources/refund_spec.rb +42 -75
- data/spec/resources/subscription_spec.rb +82 -155
- data/spec/response_spec.rb +45 -46
- data/spec/services/bank_details_lookups_service_spec.rb +55 -60
- data/spec/services/creditor_bank_accounts_service_spec.rb +303 -347
- data/spec/services/creditors_service_spec.rb +290 -333
- data/spec/services/customer_bank_accounts_service_spec.rb +332 -380
- data/spec/services/customers_service_spec.rb +347 -400
- data/spec/services/events_service_spec.rb +154 -184
- data/spec/services/mandate_pdfs_service_spec.rb +52 -57
- data/spec/services/mandates_service_spec.rb +374 -410
- data/spec/services/payments_service_spec.rb +404 -461
- data/spec/services/payouts_service_spec.rb +161 -184
- data/spec/services/redirect_flows_service_spec.rb +188 -205
- data/spec/services/refunds_service_spec.rb +245 -280
- data/spec/services/subscriptions_service_spec.rb +423 -485
- data/spec/spec_helper.rb +46 -48
- 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:
|
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
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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: {
|
101
|
-
|
28
|
+
cursors: {
|
29
|
+
before: nil,
|
30
|
+
after: 'ABC123'
|
31
|
+
}
|
102
32
|
}
|
103
33
|
}.to_json,
|
104
|
-
:
|
34
|
+
headers: { 'Content-Type' => 'application/json' }
|
105
35
|
)
|
106
36
|
end
|
107
37
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
131
|
-
expect(
|
132
|
-
expect(
|
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
|
-
|
143
|
-
let(:id) { "ID123" }
|
115
|
+
describe '#get' do
|
116
|
+
let(:id) { 'ID123' }
|
144
117
|
|
145
|
-
|
118
|
+
subject(:get_response) { client.events.get(id) }
|
146
119
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
-
:
|
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
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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
|
-
|
202
|
-
|
203
|
-
|
148
|
+
it 'includes the header' do
|
149
|
+
get_response
|
150
|
+
expect(stub).to have_been_requested
|
204
151
|
end
|
152
|
+
end
|
205
153
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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
|
-
|
216
|
-
|
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:
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
with(
|
21
|
+
before do
|
22
|
+
stub_request(:post, %r{.*api.gocardless.com/mandate_pdfs})
|
23
|
+
.with(
|
30
24
|
body: {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
'mandate_pdfs' =>
|
35
|
+
|
36
|
+
{
|
37
|
+
|
38
|
+
'expires_at' => 'expires_at-input',
|
39
|
+
'url' => 'url-input'
|
44
40
|
}
|
41
|
+
|
45
42
|
}.to_json,
|
46
|
-
:
|
43
|
+
headers: { 'Content-Type' => 'application/json' }
|
47
44
|
)
|
48
|
-
|
45
|
+
end
|
49
46
|
|
50
|
-
|
51
|
-
|
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
|
-
|
56
|
-
|
52
|
+
context 'with a request that returns a validation error' do
|
53
|
+
let(:new_resource) { {} }
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
75
|
-
|
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
|