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,198 @@ require 'spec_helper'
|
|
3
3
|
describe GoCardlessPro::Services::PayoutsService 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.payouts.list }
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
describe "with no filters" do
|
18
|
-
subject(:get_list_response) { client.payouts.list }
|
19
|
-
|
20
|
-
before do
|
21
|
-
stub_request(:get, %r(.*api.gocardless.com/payouts)).to_return(
|
22
|
-
body: {
|
23
|
-
"payouts" => [{
|
24
|
-
|
25
|
-
"amount" => "amount-input",
|
26
|
-
"created_at" => "created_at-input",
|
27
|
-
"currency" => "currency-input",
|
28
|
-
"id" => "id-input",
|
29
|
-
"links" => "links-input",
|
30
|
-
"reference" => "reference-input",
|
31
|
-
"status" => "status-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::Payout)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
expect(get_list_response.records.first.amount).to eq("amount-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.currency).to eq("currency-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.reference).to eq("reference-input")
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
expect(get_list_response.records.first.status).to eq("status-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/payouts$)).to_return(
|
14
|
+
before do
|
15
|
+
stub_request(:get, %r{.*api.gocardless.com/payouts}).to_return(
|
88
16
|
body: {
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
17
|
+
'payouts' => [{
|
18
|
+
|
19
|
+
'amount' => 'amount-input',
|
20
|
+
'arrival_date' => 'arrival_date-input',
|
21
|
+
'created_at' => 'created_at-input',
|
22
|
+
'currency' => 'currency-input',
|
23
|
+
'id' => 'id-input',
|
24
|
+
'links' => 'links-input',
|
25
|
+
'reference' => 'reference-input',
|
26
|
+
'status' => 'status-input'
|
98
27
|
}],
|
99
28
|
meta: {
|
100
|
-
cursors: {
|
101
|
-
|
29
|
+
cursors: {
|
30
|
+
before: nil,
|
31
|
+
after: 'ABC123'
|
32
|
+
}
|
102
33
|
}
|
103
34
|
}.to_json,
|
104
|
-
:
|
35
|
+
headers: { 'Content-Type' => 'application/json' }
|
105
36
|
)
|
106
37
|
end
|
107
38
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
}
|
125
|
-
}.to_json,
|
126
|
-
:headers => {'Content-Type' => 'application/json'}
|
127
|
-
)
|
39
|
+
it 'wraps each item in the resource class' do
|
40
|
+
expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Payout)
|
41
|
+
|
42
|
+
expect(get_list_response.records.first.amount).to eq('amount-input')
|
43
|
+
|
44
|
+
expect(get_list_response.records.first.arrival_date).to eq('arrival_date-input')
|
45
|
+
|
46
|
+
expect(get_list_response.records.first.created_at).to eq('created_at-input')
|
47
|
+
|
48
|
+
expect(get_list_response.records.first.currency).to eq('currency-input')
|
49
|
+
|
50
|
+
expect(get_list_response.records.first.id).to eq('id-input')
|
51
|
+
|
52
|
+
expect(get_list_response.records.first.reference).to eq('reference-input')
|
53
|
+
|
54
|
+
expect(get_list_response.records.first.status).to eq('status-input')
|
128
55
|
end
|
129
56
|
|
130
|
-
it
|
131
|
-
expect(
|
132
|
-
expect(
|
133
|
-
expect(second_response_stub).to have_been_requested
|
57
|
+
it 'exposes the cursors for before and after' do
|
58
|
+
expect(get_list_response.before).to eq(nil)
|
59
|
+
expect(get_list_response.after).to eq('ABC123')
|
134
60
|
end
|
61
|
+
|
62
|
+
specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
|
135
63
|
end
|
64
|
+
end
|
136
65
|
|
137
|
-
|
138
|
-
|
139
|
-
|
66
|
+
describe '#all' do
|
67
|
+
let!(:first_response_stub) do
|
68
|
+
stub_request(:get, %r{.*api.gocardless.com/payouts$}).to_return(
|
69
|
+
body: {
|
70
|
+
'payouts' => [{
|
71
|
+
|
72
|
+
'amount' => 'amount-input',
|
73
|
+
'arrival_date' => 'arrival_date-input',
|
74
|
+
'created_at' => 'created_at-input',
|
75
|
+
'currency' => 'currency-input',
|
76
|
+
'id' => 'id-input',
|
77
|
+
'links' => 'links-input',
|
78
|
+
'reference' => 'reference-input',
|
79
|
+
'status' => 'status-input'
|
80
|
+
}],
|
81
|
+
meta: {
|
82
|
+
cursors: { after: 'AB345' },
|
83
|
+
limit: 1
|
84
|
+
}
|
85
|
+
}.to_json,
|
86
|
+
headers: { 'Content-Type' => 'application/json' }
|
87
|
+
)
|
88
|
+
end
|
140
89
|
|
141
|
-
|
142
|
-
|
143
|
-
|
90
|
+
let!(:second_response_stub) do
|
91
|
+
stub_request(:get, %r{.*api.gocardless.com/payouts\?after=AB345}).to_return(
|
92
|
+
body: {
|
93
|
+
'payouts' => [{
|
94
|
+
|
95
|
+
'amount' => 'amount-input',
|
96
|
+
'arrival_date' => 'arrival_date-input',
|
97
|
+
'created_at' => 'created_at-input',
|
98
|
+
'currency' => 'currency-input',
|
99
|
+
'id' => 'id-input',
|
100
|
+
'links' => 'links-input',
|
101
|
+
'reference' => 'reference-input',
|
102
|
+
'status' => 'status-input'
|
103
|
+
}],
|
104
|
+
meta: {
|
105
|
+
limit: 2,
|
106
|
+
cursors: {}
|
107
|
+
}
|
108
|
+
}.to_json,
|
109
|
+
headers: { 'Content-Type' => 'application/json' }
|
110
|
+
)
|
111
|
+
end
|
144
112
|
|
145
|
-
|
113
|
+
it 'automatically makes the extra requests' do
|
114
|
+
expect(client.payouts.all.to_a.length).to eq(2)
|
115
|
+
expect(first_response_stub).to have_been_requested
|
116
|
+
expect(second_response_stub).to have_been_requested
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#get' do
|
121
|
+
let(:id) { 'ID123' }
|
146
122
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
123
|
+
subject(:get_response) { client.payouts.get(id) }
|
124
|
+
|
125
|
+
context 'passing in a custom header' do
|
126
|
+
let!(:stub) do
|
127
|
+
stub_url = '/payouts/:identity'.gsub(':identity', id)
|
128
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/)
|
129
|
+
.with(headers: { 'Foo' => 'Bar' })
|
130
|
+
.to_return(
|
153
131
|
body: {
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
132
|
+
'payouts' => {
|
133
|
+
|
134
|
+
'amount' => 'amount-input',
|
135
|
+
'arrival_date' => 'arrival_date-input',
|
136
|
+
'created_at' => 'created_at-input',
|
137
|
+
'currency' => 'currency-input',
|
138
|
+
'id' => 'id-input',
|
139
|
+
'links' => 'links-input',
|
140
|
+
'reference' => 'reference-input',
|
141
|
+
'status' => 'status-input'
|
163
142
|
}
|
164
143
|
}.to_json,
|
165
|
-
:
|
144
|
+
headers: { 'Content-Type' => 'application/json' }
|
166
145
|
)
|
167
|
-
end
|
168
|
-
|
169
|
-
subject(:get_response) do
|
170
|
-
client.payouts.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
146
|
end
|
180
147
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
"payouts" => {
|
187
|
-
|
188
|
-
"amount" => "amount-input",
|
189
|
-
"created_at" => "created_at-input",
|
190
|
-
"currency" => "currency-input",
|
191
|
-
"id" => "id-input",
|
192
|
-
"links" => "links-input",
|
193
|
-
"reference" => "reference-input",
|
194
|
-
"status" => "status-input",
|
195
|
-
}
|
196
|
-
}.to_json,
|
197
|
-
:headers => {'Content-Type' => 'application/json'}
|
198
|
-
)
|
199
|
-
end
|
148
|
+
subject(:get_response) do
|
149
|
+
client.payouts.get(id, headers: {
|
150
|
+
'Foo' => 'Bar'
|
151
|
+
})
|
152
|
+
end
|
200
153
|
|
201
|
-
|
202
|
-
|
203
|
-
|
154
|
+
it 'includes the header' do
|
155
|
+
get_response
|
156
|
+
expect(stub).to have_been_requested
|
204
157
|
end
|
158
|
+
end
|
205
159
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
160
|
+
context 'when there is a payout to return' do
|
161
|
+
before do
|
162
|
+
stub_url = '/payouts/:identity'.gsub(':identity', id)
|
163
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
164
|
+
body: {
|
165
|
+
'payouts' => {
|
166
|
+
|
167
|
+
'amount' => 'amount-input',
|
168
|
+
'arrival_date' => 'arrival_date-input',
|
169
|
+
'created_at' => 'created_at-input',
|
170
|
+
'currency' => 'currency-input',
|
171
|
+
'id' => 'id-input',
|
172
|
+
'links' => 'links-input',
|
173
|
+
'reference' => 'reference-input',
|
174
|
+
'status' => 'status-input'
|
175
|
+
}
|
176
|
+
}.to_json,
|
177
|
+
headers: { 'Content-Type' => 'application/json' }
|
178
|
+
)
|
179
|
+
end
|
214
180
|
|
215
|
-
|
216
|
-
|
217
|
-
end
|
181
|
+
it 'wraps the response in a resource' do
|
182
|
+
expect(get_response).to be_a(GoCardlessPro::Resources::Payout)
|
218
183
|
end
|
219
184
|
end
|
220
185
|
|
221
|
-
|
222
|
-
|
186
|
+
context 'when nothing is returned' do
|
187
|
+
before do
|
188
|
+
stub_url = '/payouts/:identity'.gsub(':identity', id)
|
189
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
190
|
+
body: '',
|
191
|
+
headers: { 'Content-Type' => 'application/json' }
|
192
|
+
)
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'returns nil' do
|
196
|
+
expect(get_response).to be_nil
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
223
200
|
end
|
@@ -3,256 +3,239 @@ require 'spec_helper'
|
|
3
3
|
describe GoCardlessPro::Services::RedirectFlowsService 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.redirect_flows.create(params: new_resource) }
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
12
|
+
context 'with a valid request' do
|
13
|
+
let(:new_resource) do
|
14
|
+
{
|
15
|
+
|
16
|
+
'created_at' => 'created_at-input',
|
17
|
+
'description' => 'description-input',
|
18
|
+
'id' => 'id-input',
|
19
|
+
'links' => 'links-input',
|
20
|
+
'redirect_url' => 'redirect_url-input',
|
21
|
+
'scheme' => 'scheme-input',
|
22
|
+
'session_token' => 'session_token-input',
|
23
|
+
'success_redirect_url' => 'success_redirect_url-input'
|
24
|
+
}
|
25
|
+
end
|
32
26
|
|
33
|
-
|
34
|
-
|
35
|
-
with(
|
27
|
+
before do
|
28
|
+
stub_request(:post, %r{.*api.gocardless.com/redirect_flows})
|
29
|
+
.with(
|
36
30
|
body: {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
31
|
+
'redirect_flows' => {
|
32
|
+
|
33
|
+
'created_at' => 'created_at-input',
|
34
|
+
'description' => 'description-input',
|
35
|
+
'id' => 'id-input',
|
36
|
+
'links' => 'links-input',
|
37
|
+
'redirect_url' => 'redirect_url-input',
|
38
|
+
'scheme' => 'scheme-input',
|
39
|
+
'session_token' => 'session_token-input',
|
40
|
+
'success_redirect_url' => 'success_redirect_url-input'
|
41
|
+
}
|
48
42
|
}
|
49
|
-
)
|
50
|
-
to_return(
|
43
|
+
)
|
44
|
+
.to_return(
|
51
45
|
body: {
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
46
|
+
'redirect_flows' =>
|
47
|
+
|
48
|
+
{
|
49
|
+
|
50
|
+
'created_at' => 'created_at-input',
|
51
|
+
'description' => 'description-input',
|
52
|
+
'id' => 'id-input',
|
53
|
+
'links' => 'links-input',
|
54
|
+
'redirect_url' => 'redirect_url-input',
|
55
|
+
'scheme' => 'scheme-input',
|
56
|
+
'session_token' => 'session_token-input',
|
57
|
+
'success_redirect_url' => 'success_redirect_url-input'
|
62
58
|
}
|
59
|
+
|
63
60
|
}.to_json,
|
64
|
-
:
|
61
|
+
headers: { 'Content-Type' => 'application/json' }
|
65
62
|
)
|
66
|
-
|
63
|
+
end
|
67
64
|
|
68
|
-
|
69
|
-
|
70
|
-
end
|
65
|
+
it 'creates and returns the resource' do
|
66
|
+
expect(post_create_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
|
71
67
|
end
|
68
|
+
end
|
72
69
|
|
73
|
-
|
74
|
-
|
70
|
+
context 'with a request that returns a validation error' do
|
71
|
+
let(:new_resource) { {} }
|
75
72
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
73
|
+
before do
|
74
|
+
stub_request(:post, %r{.*api.gocardless.com/redirect_flows}).to_return(
|
75
|
+
body: {
|
76
|
+
error: {
|
77
|
+
type: 'validation_failed',
|
78
|
+
code: 422,
|
79
|
+
errors: [
|
80
|
+
{ message: 'test error message', field: 'test_field' }
|
81
|
+
]
|
82
|
+
}
|
83
|
+
}.to_json,
|
84
|
+
headers: { 'Content-Type' => 'application/json' },
|
85
|
+
status: 422
|
86
|
+
)
|
87
|
+
end
|
91
88
|
|
92
|
-
|
93
|
-
|
94
|
-
end
|
89
|
+
it 'throws the correct error' do
|
90
|
+
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
95
91
|
end
|
96
92
|
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
describe "#get" do
|
103
|
-
let(:id) { "ID123" }
|
104
|
-
|
105
|
-
subject(:get_response) { client.redirect_flows.get(id) }
|
106
|
-
|
107
|
-
context "passing in a custom header" do
|
108
|
-
let!(:stub) do
|
109
|
-
stub_url = "/redirect_flows/:identity".gsub(':identity', id)
|
110
|
-
stub_request(:get, %r(.*api.gocardless.com#{stub_url})).
|
111
|
-
with(headers: { 'Foo' => 'Bar' }).
|
112
|
-
to_return(
|
113
|
-
body: {
|
114
|
-
"redirect_flows" => {
|
115
|
-
|
116
|
-
"created_at" => "created_at-input",
|
117
|
-
"description" => "description-input",
|
118
|
-
"id" => "id-input",
|
119
|
-
"links" => "links-input",
|
120
|
-
"redirect_url" => "redirect_url-input",
|
121
|
-
"scheme" => "scheme-input",
|
122
|
-
"session_token" => "session_token-input",
|
123
|
-
"success_redirect_url" => "success_redirect_url-input",
|
124
|
-
}
|
125
|
-
}.to_json,
|
126
|
-
:headers => {'Content-Type' => 'application/json'}
|
127
|
-
)
|
128
|
-
end
|
129
|
-
|
130
|
-
subject(:get_response) do
|
131
|
-
client.redirect_flows.get(id, headers: {
|
132
|
-
'Foo' => 'Bar'
|
133
|
-
})
|
134
|
-
end
|
135
|
-
|
136
|
-
it "includes the header" do
|
137
|
-
get_response
|
138
|
-
expect(stub).to have_been_requested
|
139
|
-
end
|
140
|
-
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#get' do
|
96
|
+
let(:id) { 'ID123' }
|
141
97
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
98
|
+
subject(:get_response) { client.redirect_flows.get(id) }
|
99
|
+
|
100
|
+
context 'passing in a custom header' do
|
101
|
+
let!(:stub) do
|
102
|
+
stub_url = '/redirect_flows/:identity'.gsub(':identity', id)
|
103
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/)
|
104
|
+
.with(headers: { 'Foo' => 'Bar' })
|
105
|
+
.to_return(
|
146
106
|
body: {
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
107
|
+
'redirect_flows' => {
|
108
|
+
|
109
|
+
'created_at' => 'created_at-input',
|
110
|
+
'description' => 'description-input',
|
111
|
+
'id' => 'id-input',
|
112
|
+
'links' => 'links-input',
|
113
|
+
'redirect_url' => 'redirect_url-input',
|
114
|
+
'scheme' => 'scheme-input',
|
115
|
+
'session_token' => 'session_token-input',
|
116
|
+
'success_redirect_url' => 'success_redirect_url-input'
|
157
117
|
}
|
158
118
|
}.to_json,
|
159
|
-
:
|
119
|
+
headers: { 'Content-Type' => 'application/json' }
|
160
120
|
)
|
161
|
-
end
|
162
|
-
|
163
|
-
it "wraps the response in a resource" do
|
164
|
-
expect(get_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
|
165
|
-
end
|
166
121
|
end
|
167
122
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
headers: { 'Content-Type' => 'application/json' }
|
174
|
-
)
|
175
|
-
end
|
123
|
+
subject(:get_response) do
|
124
|
+
client.redirect_flows.get(id, headers: {
|
125
|
+
'Foo' => 'Bar'
|
126
|
+
})
|
127
|
+
end
|
176
128
|
|
177
|
-
|
178
|
-
|
179
|
-
|
129
|
+
it 'includes the header' do
|
130
|
+
get_response
|
131
|
+
expect(stub).to have_been_requested
|
180
132
|
end
|
181
133
|
end
|
182
134
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
describe "#complete" do
|
189
|
-
|
190
|
-
|
191
|
-
subject(:post_response) { client.redirect_flows.complete(resource_id) }
|
192
|
-
|
193
|
-
let(:resource_id) { "ABC123" }
|
194
|
-
|
195
|
-
let!(:stub) do
|
196
|
-
# /redirect_flows/%v/actions/complete
|
197
|
-
stub_url = "/redirect_flows/:identity/actions/complete".gsub(':identity', resource_id)
|
198
|
-
stub_request(:post, %r(.*api.gocardless.com#{stub_url})).to_return(
|
135
|
+
context 'when there is a redirect_flow to return' do
|
136
|
+
before do
|
137
|
+
stub_url = '/redirect_flows/:identity'.gsub(':identity', id)
|
138
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
199
139
|
body: {
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
140
|
+
'redirect_flows' => {
|
141
|
+
|
142
|
+
'created_at' => 'created_at-input',
|
143
|
+
'description' => 'description-input',
|
144
|
+
'id' => 'id-input',
|
145
|
+
'links' => 'links-input',
|
146
|
+
'redirect_url' => 'redirect_url-input',
|
147
|
+
'scheme' => 'scheme-input',
|
148
|
+
'session_token' => 'session_token-input',
|
149
|
+
'success_redirect_url' => 'success_redirect_url-input'
|
210
150
|
}
|
211
151
|
}.to_json,
|
212
|
-
headers: {'Content-Type' => 'application/json'}
|
152
|
+
headers: { 'Content-Type' => 'application/json' }
|
213
153
|
)
|
214
154
|
end
|
215
155
|
|
216
|
-
it
|
217
|
-
expect(
|
156
|
+
it 'wraps the response in a resource' do
|
157
|
+
expect(get_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
|
158
|
+
end
|
159
|
+
end
|
218
160
|
|
219
|
-
|
161
|
+
context 'when nothing is returned' do
|
162
|
+
before do
|
163
|
+
stub_url = '/redirect_flows/:identity'.gsub(':identity', id)
|
164
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
165
|
+
body: '',
|
166
|
+
headers: { 'Content-Type' => 'application/json' }
|
167
|
+
)
|
220
168
|
end
|
221
169
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
170
|
+
it 'returns nil' do
|
171
|
+
expect(get_response).to be_nil
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe '#complete' do
|
177
|
+
subject(:post_response) { client.redirect_flows.complete(resource_id) }
|
178
|
+
|
179
|
+
let(:resource_id) { 'ABC123' }
|
180
|
+
|
181
|
+
let!(:stub) do
|
182
|
+
# /redirect_flows/%v/actions/complete
|
183
|
+
stub_url = '/redirect_flows/:identity/actions/complete'.gsub(':identity', resource_id)
|
184
|
+
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
185
|
+
body: {
|
186
|
+
'redirect_flows' => {
|
187
|
+
|
188
|
+
'created_at' => 'created_at-input',
|
189
|
+
'description' => 'description-input',
|
190
|
+
'id' => 'id-input',
|
191
|
+
'links' => 'links-input',
|
192
|
+
'redirect_url' => 'redirect_url-input',
|
193
|
+
'scheme' => 'scheme-input',
|
194
|
+
'session_token' => 'session_token-input',
|
195
|
+
'success_redirect_url' => 'success_redirect_url-input'
|
196
|
+
}
|
197
|
+
}.to_json,
|
198
|
+
headers: { 'Content-Type' => 'application/json' }
|
199
|
+
)
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'wraps the response and calls the right endpoint' do
|
203
|
+
expect(post_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
|
204
|
+
|
205
|
+
expect(stub).to have_been_requested
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'when the request needs a body and custom header' do
|
209
|
+
let(:body) { { foo: 'bar' } }
|
210
|
+
let(:headers) { { 'Foo' => 'Bar' } }
|
211
|
+
subject(:post_response) { client.redirect_flows.complete(resource_id, body, headers) }
|
212
|
+
|
213
|
+
let(:resource_id) { 'ABC123' }
|
214
|
+
|
215
|
+
let!(:stub) do
|
216
|
+
# /redirect_flows/%v/actions/complete
|
217
|
+
stub_url = '/redirect_flows/:identity/actions/complete'.gsub(':identity', resource_id)
|
218
|
+
stub_request(:post, /.*api.gocardless.com#{stub_url}/)
|
219
|
+
.with(
|
235
220
|
body: { foo: 'bar' },
|
236
221
|
headers: { 'Foo' => 'Bar' }
|
237
222
|
).to_return(
|
238
223
|
body: {
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
224
|
+
'redirect_flows' => {
|
225
|
+
|
226
|
+
'created_at' => 'created_at-input',
|
227
|
+
'description' => 'description-input',
|
228
|
+
'id' => 'id-input',
|
229
|
+
'links' => 'links-input',
|
230
|
+
'redirect_url' => 'redirect_url-input',
|
231
|
+
'scheme' => 'scheme-input',
|
232
|
+
'session_token' => 'session_token-input',
|
233
|
+
'success_redirect_url' => 'success_redirect_url-input'
|
249
234
|
}
|
250
235
|
}.to_json,
|
251
|
-
headers: {'Content-Type' => 'application/json'}
|
236
|
+
headers: { 'Content-Type' => 'application/json' }
|
252
237
|
)
|
253
|
-
end
|
254
238
|
end
|
255
239
|
end
|
256
|
-
|
257
|
-
|
240
|
+
end
|
258
241
|
end
|