gocardless_pro 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +146 -0
- data/circle.yml +3 -0
- data/demo.rb +9 -0
- data/gocardless_pro.gemspec +26 -0
- data/lib/gocardless_pro.rb +73 -0
- data/lib/gocardless_pro/api_service.rb +58 -0
- data/lib/gocardless_pro/client.rb +135 -0
- data/lib/gocardless_pro/error.rb +42 -0
- data/lib/gocardless_pro/error/gocardless_error.rb +5 -0
- data/lib/gocardless_pro/error/invalid_api_usage_error.rb +5 -0
- data/lib/gocardless_pro/error/invalid_state_error.rb +5 -0
- data/lib/gocardless_pro/error/validation_error.rb +5 -0
- data/lib/gocardless_pro/list_response.rb +29 -0
- data/lib/gocardless_pro/paginator.rb +43 -0
- data/lib/gocardless_pro/request.rb +69 -0
- data/lib/gocardless_pro/resources/creditor.rb +84 -0
- data/lib/gocardless_pro/resources/creditor_bank_account.rb +78 -0
- data/lib/gocardless_pro/resources/customer.rb +75 -0
- data/lib/gocardless_pro/resources/customer_bank_account.rb +80 -0
- data/lib/gocardless_pro/resources/event.rb +75 -0
- data/lib/gocardless_pro/resources/helper.rb +29 -0
- data/lib/gocardless_pro/resources/mandate.rb +70 -0
- data/lib/gocardless_pro/resources/payment.rb +87 -0
- data/lib/gocardless_pro/resources/payout.rb +66 -0
- data/lib/gocardless_pro/resources/redirect_flow.rb +106 -0
- data/lib/gocardless_pro/resources/refund.rb +71 -0
- data/lib/gocardless_pro/resources/subscription.rb +155 -0
- data/lib/gocardless_pro/response.rb +77 -0
- data/lib/gocardless_pro/services/base_service.rb +28 -0
- data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +119 -0
- data/lib/gocardless_pro/services/creditors_service.rb +113 -0
- data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +154 -0
- data/lib/gocardless_pro/services/customers_service.rb +113 -0
- data/lib/gocardless_pro/services/events_service.rb +80 -0
- data/lib/gocardless_pro/services/helpers_service.rb +99 -0
- data/lib/gocardless_pro/services/mandates_service.rb +173 -0
- data/lib/gocardless_pro/services/payments_service.rb +168 -0
- data/lib/gocardless_pro/services/payouts_service.rb +82 -0
- data/lib/gocardless_pro/services/redirect_flows_service.rb +98 -0
- data/lib/gocardless_pro/services/refunds_service.rb +132 -0
- data/lib/gocardless_pro/services/subscriptions_service.rb +134 -0
- data/lib/gocardless_pro/version.rb +8 -0
- data/spec/api_service_spec.rb +73 -0
- data/spec/client_spec.rb +19 -0
- data/spec/error_spec.rb +44 -0
- data/spec/resources/creditor_bank_account_spec.rb +109 -0
- data/spec/resources/creditor_spec.rb +125 -0
- data/spec/resources/customer_bank_account_spec.rb +109 -0
- data/spec/resources/customer_spec.rb +135 -0
- data/spec/resources/event_spec.rb +113 -0
- data/spec/resources/helper_spec.rb +23 -0
- data/spec/resources/mandate_spec.rb +97 -0
- data/spec/resources/payment_spec.rb +129 -0
- data/spec/resources/payout_spec.rb +89 -0
- data/spec/resources/redirect_flow_spec.rb +97 -0
- data/spec/resources/refund_spec.rb +77 -0
- data/spec/resources/subscription_spec.rb +165 -0
- data/spec/response_spec.rb +89 -0
- data/spec/services/creditor_bank_accounts_service_spec.rb +413 -0
- data/spec/services/creditors_service_spec.rb +388 -0
- data/spec/services/customer_bank_accounts_service_spec.rb +452 -0
- data/spec/services/customers_service_spec.rb +429 -0
- data/spec/services/events_service_spec.rb +217 -0
- data/spec/services/helpers_service_spec.rb +122 -0
- data/spec/services/mandates_service_spec.rb +495 -0
- data/spec/services/payments_service_spec.rb +546 -0
- data/spec/services/payouts_service_spec.rb +217 -0
- data/spec/services/redirect_flows_service_spec.rb +254 -0
- data/spec/services/refunds_service_spec.rb +323 -0
- data/spec/services/subscriptions_service_spec.rb +557 -0
- data/spec/spec_helper.rb +91 -0
- metadata +224 -0
@@ -0,0 +1,217 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GoCardlessPro::Services::PayoutsService do
|
4
|
+
let(:client) do
|
5
|
+
GoCardlessPro::Client.new(
|
6
|
+
access_token: "SECRET_TOKEN"
|
7
|
+
)
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
describe "#list" do
|
16
|
+
describe "with no filters" do
|
17
|
+
subject(:get_list_response) { client.payouts.list }
|
18
|
+
|
19
|
+
before do
|
20
|
+
stub_request(:get, /.*api.gocardless.com\/payouts/).to_return(
|
21
|
+
body: {
|
22
|
+
payouts: [{
|
23
|
+
|
24
|
+
"amount" => "amount-input",
|
25
|
+
"created_at" => "created_at-input",
|
26
|
+
"currency" => "currency-input",
|
27
|
+
"id" => "id-input",
|
28
|
+
"links" => "links-input",
|
29
|
+
"reference" => "reference-input",
|
30
|
+
"status" => "status-input",
|
31
|
+
}],
|
32
|
+
meta: {
|
33
|
+
cursors: {
|
34
|
+
before: nil,
|
35
|
+
after: "ABC123"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}.to_json,
|
39
|
+
:headers => {'Content-Type' => 'application/json'}
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "wraps each item in the resource class" do
|
44
|
+
expect(get_list_response.records.map { |x| x.class }.uniq.first).to eq(GoCardlessPro::Resources::Payout)
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
expect(get_list_response.records.first.amount).to eq("amount-input")
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
expect(get_list_response.records.first.created_at).to eq("created_at-input")
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
expect(get_list_response.records.first.currency).to eq("currency-input")
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
expect(get_list_response.records.first.id).to eq("id-input")
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
expect(get_list_response.records.first.reference).to eq("reference-input")
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
expect(get_list_response.records.first.status).to eq("status-input")
|
71
|
+
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
it "exposes the cursors for before and after" do
|
76
|
+
expect(get_list_response.before).to eq(nil)
|
77
|
+
expect(get_list_response.after).to eq("ABC123")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#all" do
|
83
|
+
let!(:first_response_stub) do
|
84
|
+
stub_request(:get, /.*api.gocardless.com\/payouts$/).to_return(
|
85
|
+
body: {
|
86
|
+
payouts: [{
|
87
|
+
|
88
|
+
"amount" => "amount-input",
|
89
|
+
"created_at" => "created_at-input",
|
90
|
+
"currency" => "currency-input",
|
91
|
+
"id" => "id-input",
|
92
|
+
"links" => "links-input",
|
93
|
+
"reference" => "reference-input",
|
94
|
+
"status" => "status-input",
|
95
|
+
}],
|
96
|
+
meta: {
|
97
|
+
cursors: { after: 'AB345' },
|
98
|
+
limit: 1
|
99
|
+
}
|
100
|
+
}.to_json,
|
101
|
+
:headers => {'Content-Type' => 'application/json'}
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
let!(:second_response_stub) do
|
106
|
+
stub_request(:get, /.*api.gocardless.com\/payouts\?after=AB345/).to_return(
|
107
|
+
body: {
|
108
|
+
payouts: [{
|
109
|
+
|
110
|
+
"amount" => "amount-input",
|
111
|
+
"created_at" => "created_at-input",
|
112
|
+
"currency" => "currency-input",
|
113
|
+
"id" => "id-input",
|
114
|
+
"links" => "links-input",
|
115
|
+
"reference" => "reference-input",
|
116
|
+
"status" => "status-input",
|
117
|
+
}],
|
118
|
+
meta: {
|
119
|
+
limit: 2,
|
120
|
+
cursors: {}
|
121
|
+
}
|
122
|
+
}.to_json,
|
123
|
+
:headers => {'Content-Type' => 'application/json'}
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "automatically makes the extra requests" do
|
128
|
+
expect(client.payouts.all.to_a.length).to eq(2)
|
129
|
+
expect(first_response_stub).to have_been_requested
|
130
|
+
expect(second_response_stub).to have_been_requested
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
describe "#get" do
|
140
|
+
let(:id) { "ID123" }
|
141
|
+
|
142
|
+
subject(:get_response) { client.payouts.get(id) }
|
143
|
+
|
144
|
+
context "passing in a custom header" do
|
145
|
+
let!(:stub) do
|
146
|
+
stub_request(:get, /.*api.gocardless.com\/payouts\/ID123/)
|
147
|
+
.with(headers: { 'Foo' => 'Bar' })
|
148
|
+
.to_return(
|
149
|
+
body: {
|
150
|
+
payouts: {
|
151
|
+
|
152
|
+
"amount" => "amount-input",
|
153
|
+
"created_at" => "created_at-input",
|
154
|
+
"currency" => "currency-input",
|
155
|
+
"id" => "id-input",
|
156
|
+
"links" => "links-input",
|
157
|
+
"reference" => "reference-input",
|
158
|
+
"status" => "status-input",
|
159
|
+
}
|
160
|
+
}.to_json,
|
161
|
+
:headers => {'Content-Type' => 'application/json'}
|
162
|
+
)
|
163
|
+
end
|
164
|
+
|
165
|
+
subject(:get_response) do
|
166
|
+
client.payouts.get(id, headers: {
|
167
|
+
'Foo' => 'Bar'
|
168
|
+
})
|
169
|
+
end
|
170
|
+
|
171
|
+
it "includes the header" do
|
172
|
+
get_response
|
173
|
+
expect(stub).to have_been_requested
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context "when there is a payout to return" do
|
178
|
+
before do
|
179
|
+
stub_request(:get, /.*api.gocardless.com\/payouts\/ID123/).to_return(
|
180
|
+
body: {
|
181
|
+
payouts: {
|
182
|
+
|
183
|
+
"amount" => "amount-input",
|
184
|
+
"created_at" => "created_at-input",
|
185
|
+
"currency" => "currency-input",
|
186
|
+
"id" => "id-input",
|
187
|
+
"links" => "links-input",
|
188
|
+
"reference" => "reference-input",
|
189
|
+
"status" => "status-input",
|
190
|
+
}
|
191
|
+
}.to_json,
|
192
|
+
:headers => {'Content-Type' => 'application/json'}
|
193
|
+
)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "wraps the response in a resource" do
|
197
|
+
expect(get_response).to be_a(GoCardlessPro::Resources::Payout)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "when nothing is returned" do
|
202
|
+
before do
|
203
|
+
stub_request(:get, /.*api.gocardless.com\/payouts\/ID123/).to_return(
|
204
|
+
body: "",
|
205
|
+
headers: { 'Content-Type' => 'application/json' }
|
206
|
+
)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "returns nil" do
|
210
|
+
expect(get_response).to be_nil
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
end
|
@@ -0,0 +1,254 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GoCardlessPro::Services::RedirectFlowsService do
|
4
|
+
let(:client) do
|
5
|
+
GoCardlessPro::Client.new(
|
6
|
+
access_token: "SECRET_TOKEN"
|
7
|
+
)
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
describe "#create" do
|
16
|
+
subject(:post_create_response) { client.redirect_flows.create(params: new_resource) }
|
17
|
+
context "with a valid request" do
|
18
|
+
let(:new_resource) do
|
19
|
+
{
|
20
|
+
|
21
|
+
"created_at" => "created_at-input",
|
22
|
+
"description" => "description-input",
|
23
|
+
"id" => "id-input",
|
24
|
+
"links" => "links-input",
|
25
|
+
"redirect_url" => "redirect_url-input",
|
26
|
+
"scheme" => "scheme-input",
|
27
|
+
"session_token" => "session_token-input",
|
28
|
+
"success_redirect_url" => "success_redirect_url-input",
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
before do
|
33
|
+
stub_request(:post, /.*api.gocardless.com\/redirect_flows/).
|
34
|
+
with(
|
35
|
+
body: {
|
36
|
+
redirect_flows: {
|
37
|
+
|
38
|
+
"created_at" => "created_at-input",
|
39
|
+
"description" => "description-input",
|
40
|
+
"id" => "id-input",
|
41
|
+
"links" => "links-input",
|
42
|
+
"redirect_url" => "redirect_url-input",
|
43
|
+
"scheme" => "scheme-input",
|
44
|
+
"session_token" => "session_token-input",
|
45
|
+
"success_redirect_url" => "success_redirect_url-input",
|
46
|
+
}
|
47
|
+
}
|
48
|
+
).
|
49
|
+
to_return(
|
50
|
+
body: {
|
51
|
+
redirect_flows: {
|
52
|
+
|
53
|
+
"created_at" => "created_at-input",
|
54
|
+
"description" => "description-input",
|
55
|
+
"id" => "id-input",
|
56
|
+
"links" => "links-input",
|
57
|
+
"redirect_url" => "redirect_url-input",
|
58
|
+
"scheme" => "scheme-input",
|
59
|
+
"session_token" => "session_token-input",
|
60
|
+
"success_redirect_url" => "success_redirect_url-input",
|
61
|
+
}
|
62
|
+
}.to_json,
|
63
|
+
:headers => {'Content-Type' => 'application/json'}
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "creates and returns the resource" do
|
68
|
+
expect(post_create_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "with a request that returns a validation error" do
|
73
|
+
let(:new_resource) { {} }
|
74
|
+
|
75
|
+
before do
|
76
|
+
stub_request(:post, /.*api.gocardless.com\/redirect_flows/).to_return(
|
77
|
+
body: {
|
78
|
+
error: {
|
79
|
+
type: 'validation_failed',
|
80
|
+
code: 422,
|
81
|
+
errors: [
|
82
|
+
{ message: 'test error message', field: 'test_field' }
|
83
|
+
]
|
84
|
+
}
|
85
|
+
}.to_json,
|
86
|
+
headers: {'Content-Type' => 'application/json'},
|
87
|
+
status: 422
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "throws the correct error" do
|
92
|
+
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
describe "#get" do
|
102
|
+
let(:id) { "ID123" }
|
103
|
+
|
104
|
+
subject(:get_response) { client.redirect_flows.get(id) }
|
105
|
+
|
106
|
+
context "passing in a custom header" do
|
107
|
+
let!(:stub) do
|
108
|
+
stub_request(:get, /.*api.gocardless.com\/redirect_flows\/ID123/)
|
109
|
+
.with(headers: { 'Foo' => 'Bar' })
|
110
|
+
.to_return(
|
111
|
+
body: {
|
112
|
+
redirect_flows: {
|
113
|
+
|
114
|
+
"created_at" => "created_at-input",
|
115
|
+
"description" => "description-input",
|
116
|
+
"id" => "id-input",
|
117
|
+
"links" => "links-input",
|
118
|
+
"redirect_url" => "redirect_url-input",
|
119
|
+
"scheme" => "scheme-input",
|
120
|
+
"session_token" => "session_token-input",
|
121
|
+
"success_redirect_url" => "success_redirect_url-input",
|
122
|
+
}
|
123
|
+
}.to_json,
|
124
|
+
:headers => {'Content-Type' => 'application/json'}
|
125
|
+
)
|
126
|
+
end
|
127
|
+
|
128
|
+
subject(:get_response) do
|
129
|
+
client.redirect_flows.get(id, headers: {
|
130
|
+
'Foo' => 'Bar'
|
131
|
+
})
|
132
|
+
end
|
133
|
+
|
134
|
+
it "includes the header" do
|
135
|
+
get_response
|
136
|
+
expect(stub).to have_been_requested
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "when there is a redirect_flow to return" do
|
141
|
+
before do
|
142
|
+
stub_request(:get, /.*api.gocardless.com\/redirect_flows\/ID123/).to_return(
|
143
|
+
body: {
|
144
|
+
redirect_flows: {
|
145
|
+
|
146
|
+
"created_at" => "created_at-input",
|
147
|
+
"description" => "description-input",
|
148
|
+
"id" => "id-input",
|
149
|
+
"links" => "links-input",
|
150
|
+
"redirect_url" => "redirect_url-input",
|
151
|
+
"scheme" => "scheme-input",
|
152
|
+
"session_token" => "session_token-input",
|
153
|
+
"success_redirect_url" => "success_redirect_url-input",
|
154
|
+
}
|
155
|
+
}.to_json,
|
156
|
+
:headers => {'Content-Type' => 'application/json'}
|
157
|
+
)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "wraps the response in a resource" do
|
161
|
+
expect(get_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "when nothing is returned" do
|
166
|
+
before do
|
167
|
+
stub_request(:get, /.*api.gocardless.com\/redirect_flows\/ID123/).to_return(
|
168
|
+
body: "",
|
169
|
+
headers: { 'Content-Type' => 'application/json' }
|
170
|
+
)
|
171
|
+
end
|
172
|
+
|
173
|
+
it "returns nil" do
|
174
|
+
expect(get_response).to be_nil
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
describe "#complete" do
|
185
|
+
|
186
|
+
|
187
|
+
subject(:post_response) { client.redirect_flows.complete(resource_id) }
|
188
|
+
|
189
|
+
let(:resource_id) { "ABC123" }
|
190
|
+
|
191
|
+
let!(:stub) do
|
192
|
+
# /redirect_flows/%v/actions/complete
|
193
|
+
stub_url = "/redirect_flows/:identity/actions/complete".gsub(':identity', resource_id)
|
194
|
+
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
195
|
+
body: {
|
196
|
+
redirect_flows: {
|
197
|
+
|
198
|
+
"created_at" => "created_at-input",
|
199
|
+
"description" => "description-input",
|
200
|
+
"id" => "id-input",
|
201
|
+
"links" => "links-input",
|
202
|
+
"redirect_url" => "redirect_url-input",
|
203
|
+
"scheme" => "scheme-input",
|
204
|
+
"session_token" => "session_token-input",
|
205
|
+
"success_redirect_url" => "success_redirect_url-input",
|
206
|
+
}
|
207
|
+
}.to_json,
|
208
|
+
headers: {'Content-Type' => 'application/json'},
|
209
|
+
)
|
210
|
+
end
|
211
|
+
|
212
|
+
it "wraps the response and calls the right endpoint" do
|
213
|
+
expect(post_response).to be_a(GoCardlessPro::Resources::RedirectFlow)
|
214
|
+
|
215
|
+
expect(stub).to have_been_requested
|
216
|
+
end
|
217
|
+
|
218
|
+
context "when the request needs a body and custom header" do
|
219
|
+
|
220
|
+
let(:body) { { foo: 'bar' } }
|
221
|
+
let(:headers) { { 'Foo' => 'Bar' } }
|
222
|
+
subject(:post_response) { client.redirect_flows.complete(resource_id, body, headers) }
|
223
|
+
|
224
|
+
let(:resource_id) { "ABC123" }
|
225
|
+
|
226
|
+
let!(:stub) do
|
227
|
+
# /redirect_flows/%v/actions/complete
|
228
|
+
stub_url = "/redirect_flows/:identity/actions/complete".gsub(':identity', resource_id)
|
229
|
+
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
230
|
+
with(
|
231
|
+
body: { foo: 'bar' },
|
232
|
+
headers: { 'Foo' => 'Bar' }
|
233
|
+
).to_return(
|
234
|
+
body: {
|
235
|
+
redirect_flows: {
|
236
|
+
|
237
|
+
"created_at" => "created_at-input",
|
238
|
+
"description" => "description-input",
|
239
|
+
"id" => "id-input",
|
240
|
+
"links" => "links-input",
|
241
|
+
"redirect_url" => "redirect_url-input",
|
242
|
+
"scheme" => "scheme-input",
|
243
|
+
"session_token" => "session_token-input",
|
244
|
+
"success_redirect_url" => "success_redirect_url-input",
|
245
|
+
}
|
246
|
+
}.to_json,
|
247
|
+
headers: {'Content-Type' => 'application/json'},
|
248
|
+
)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
|
254
|
+
end
|