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,323 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GoCardlessPro::Services::RefundsService 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.refunds.create(params: new_resource) }
|
17
|
+
context "with a valid request" do
|
18
|
+
let(:new_resource) do
|
19
|
+
{
|
20
|
+
|
21
|
+
"amount" => "amount-input",
|
22
|
+
"created_at" => "created_at-input",
|
23
|
+
"currency" => "currency-input",
|
24
|
+
"id" => "id-input",
|
25
|
+
"links" => "links-input",
|
26
|
+
"metadata" => "metadata-input",
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
before do
|
31
|
+
stub_request(:post, /.*api.gocardless.com\/refunds/).
|
32
|
+
with(
|
33
|
+
body: {
|
34
|
+
refunds: {
|
35
|
+
|
36
|
+
"amount" => "amount-input",
|
37
|
+
"created_at" => "created_at-input",
|
38
|
+
"currency" => "currency-input",
|
39
|
+
"id" => "id-input",
|
40
|
+
"links" => "links-input",
|
41
|
+
"metadata" => "metadata-input",
|
42
|
+
}
|
43
|
+
}
|
44
|
+
).
|
45
|
+
to_return(
|
46
|
+
body: {
|
47
|
+
refunds: {
|
48
|
+
|
49
|
+
"amount" => "amount-input",
|
50
|
+
"created_at" => "created_at-input",
|
51
|
+
"currency" => "currency-input",
|
52
|
+
"id" => "id-input",
|
53
|
+
"links" => "links-input",
|
54
|
+
"metadata" => "metadata-input",
|
55
|
+
}
|
56
|
+
}.to_json,
|
57
|
+
:headers => {'Content-Type' => 'application/json'}
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "creates and returns the resource" do
|
62
|
+
expect(post_create_response).to be_a(GoCardlessPro::Resources::Refund)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "with a request that returns a validation error" do
|
67
|
+
let(:new_resource) { {} }
|
68
|
+
|
69
|
+
before do
|
70
|
+
stub_request(:post, /.*api.gocardless.com\/refunds/).to_return(
|
71
|
+
body: {
|
72
|
+
error: {
|
73
|
+
type: 'validation_failed',
|
74
|
+
code: 422,
|
75
|
+
errors: [
|
76
|
+
{ message: 'test error message', field: 'test_field' }
|
77
|
+
]
|
78
|
+
}
|
79
|
+
}.to_json,
|
80
|
+
headers: {'Content-Type' => 'application/json'},
|
81
|
+
status: 422
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "throws the correct error" do
|
86
|
+
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
describe "#list" do
|
96
|
+
describe "with no filters" do
|
97
|
+
subject(:get_list_response) { client.refunds.list }
|
98
|
+
|
99
|
+
before do
|
100
|
+
stub_request(:get, /.*api.gocardless.com\/refunds/).to_return(
|
101
|
+
body: {
|
102
|
+
refunds: [{
|
103
|
+
|
104
|
+
"amount" => "amount-input",
|
105
|
+
"created_at" => "created_at-input",
|
106
|
+
"currency" => "currency-input",
|
107
|
+
"id" => "id-input",
|
108
|
+
"links" => "links-input",
|
109
|
+
"metadata" => "metadata-input",
|
110
|
+
}],
|
111
|
+
meta: {
|
112
|
+
cursors: {
|
113
|
+
before: nil,
|
114
|
+
after: "ABC123"
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}.to_json,
|
118
|
+
:headers => {'Content-Type' => 'application/json'}
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "wraps each item in the resource class" do
|
123
|
+
expect(get_list_response.records.map { |x| x.class }.uniq.first).to eq(GoCardlessPro::Resources::Refund)
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
expect(get_list_response.records.first.amount).to eq("amount-input")
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
expect(get_list_response.records.first.created_at).to eq("created_at-input")
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
expect(get_list_response.records.first.currency).to eq("currency-input")
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
expect(get_list_response.records.first.id).to eq("id-input")
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
expect(get_list_response.records.first.metadata).to eq("metadata-input")
|
146
|
+
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
it "exposes the cursors for before and after" do
|
151
|
+
expect(get_list_response.before).to eq(nil)
|
152
|
+
expect(get_list_response.after).to eq("ABC123")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "#all" do
|
158
|
+
let!(:first_response_stub) do
|
159
|
+
stub_request(:get, /.*api.gocardless.com\/refunds$/).to_return(
|
160
|
+
body: {
|
161
|
+
refunds: [{
|
162
|
+
|
163
|
+
"amount" => "amount-input",
|
164
|
+
"created_at" => "created_at-input",
|
165
|
+
"currency" => "currency-input",
|
166
|
+
"id" => "id-input",
|
167
|
+
"links" => "links-input",
|
168
|
+
"metadata" => "metadata-input",
|
169
|
+
}],
|
170
|
+
meta: {
|
171
|
+
cursors: { after: 'AB345' },
|
172
|
+
limit: 1
|
173
|
+
}
|
174
|
+
}.to_json,
|
175
|
+
:headers => {'Content-Type' => 'application/json'}
|
176
|
+
)
|
177
|
+
end
|
178
|
+
|
179
|
+
let!(:second_response_stub) do
|
180
|
+
stub_request(:get, /.*api.gocardless.com\/refunds\?after=AB345/).to_return(
|
181
|
+
body: {
|
182
|
+
refunds: [{
|
183
|
+
|
184
|
+
"amount" => "amount-input",
|
185
|
+
"created_at" => "created_at-input",
|
186
|
+
"currency" => "currency-input",
|
187
|
+
"id" => "id-input",
|
188
|
+
"links" => "links-input",
|
189
|
+
"metadata" => "metadata-input",
|
190
|
+
}],
|
191
|
+
meta: {
|
192
|
+
limit: 2,
|
193
|
+
cursors: {}
|
194
|
+
}
|
195
|
+
}.to_json,
|
196
|
+
:headers => {'Content-Type' => 'application/json'}
|
197
|
+
)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "automatically makes the extra requests" do
|
201
|
+
expect(client.refunds.all.to_a.length).to eq(2)
|
202
|
+
expect(first_response_stub).to have_been_requested
|
203
|
+
expect(second_response_stub).to have_been_requested
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
describe "#get" do
|
213
|
+
let(:id) { "ID123" }
|
214
|
+
|
215
|
+
subject(:get_response) { client.refunds.get(id) }
|
216
|
+
|
217
|
+
context "passing in a custom header" do
|
218
|
+
let!(:stub) do
|
219
|
+
stub_request(:get, /.*api.gocardless.com\/refunds\/ID123/)
|
220
|
+
.with(headers: { 'Foo' => 'Bar' })
|
221
|
+
.to_return(
|
222
|
+
body: {
|
223
|
+
refunds: {
|
224
|
+
|
225
|
+
"amount" => "amount-input",
|
226
|
+
"created_at" => "created_at-input",
|
227
|
+
"currency" => "currency-input",
|
228
|
+
"id" => "id-input",
|
229
|
+
"links" => "links-input",
|
230
|
+
"metadata" => "metadata-input",
|
231
|
+
}
|
232
|
+
}.to_json,
|
233
|
+
:headers => {'Content-Type' => 'application/json'}
|
234
|
+
)
|
235
|
+
end
|
236
|
+
|
237
|
+
subject(:get_response) do
|
238
|
+
client.refunds.get(id, headers: {
|
239
|
+
'Foo' => 'Bar'
|
240
|
+
})
|
241
|
+
end
|
242
|
+
|
243
|
+
it "includes the header" do
|
244
|
+
get_response
|
245
|
+
expect(stub).to have_been_requested
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context "when there is a refund to return" do
|
250
|
+
before do
|
251
|
+
stub_request(:get, /.*api.gocardless.com\/refunds\/ID123/).to_return(
|
252
|
+
body: {
|
253
|
+
refunds: {
|
254
|
+
|
255
|
+
"amount" => "amount-input",
|
256
|
+
"created_at" => "created_at-input",
|
257
|
+
"currency" => "currency-input",
|
258
|
+
"id" => "id-input",
|
259
|
+
"links" => "links-input",
|
260
|
+
"metadata" => "metadata-input",
|
261
|
+
}
|
262
|
+
}.to_json,
|
263
|
+
:headers => {'Content-Type' => 'application/json'}
|
264
|
+
)
|
265
|
+
end
|
266
|
+
|
267
|
+
it "wraps the response in a resource" do
|
268
|
+
expect(get_response).to be_a(GoCardlessPro::Resources::Refund)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
context "when nothing is returned" do
|
273
|
+
before do
|
274
|
+
stub_request(:get, /.*api.gocardless.com\/refunds\/ID123/).to_return(
|
275
|
+
body: "",
|
276
|
+
headers: { 'Content-Type' => 'application/json' }
|
277
|
+
)
|
278
|
+
end
|
279
|
+
|
280
|
+
it "returns nil" do
|
281
|
+
expect(get_response).to be_nil
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
describe "#update" do
|
292
|
+
subject(:put_update_response) { client.refunds.update(id, params: update_params) }
|
293
|
+
let(:id) { "ABC123" }
|
294
|
+
|
295
|
+
context "with a valid request" do
|
296
|
+
let(:update_params) { { "hello" => "world" } }
|
297
|
+
|
298
|
+
let!(:stub) do
|
299
|
+
stub_request(:put, /.*api.gocardless.com\/refunds\/ABC123/).to_return(
|
300
|
+
body: {
|
301
|
+
refunds: {
|
302
|
+
|
303
|
+
"amount" => "amount-input",
|
304
|
+
"created_at" => "created_at-input",
|
305
|
+
"currency" => "currency-input",
|
306
|
+
"id" => "id-input",
|
307
|
+
"links" => "links-input",
|
308
|
+
"metadata" => "metadata-input",
|
309
|
+
}
|
310
|
+
}.to_json,
|
311
|
+
:headers => {'Content-Type' => 'application/json'}
|
312
|
+
)
|
313
|
+
end
|
314
|
+
|
315
|
+
it "updates and returns the resource" do
|
316
|
+
expect(put_update_response).to be_a(GoCardlessPro::Resources::Refund)
|
317
|
+
expect(stub).to have_been_requested
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
|
323
|
+
end
|
@@ -0,0 +1,557 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GoCardlessPro::Services::SubscriptionsService 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.subscriptions.create(params: new_resource) }
|
17
|
+
context "with a valid request" do
|
18
|
+
let(:new_resource) do
|
19
|
+
{
|
20
|
+
|
21
|
+
"amount" => "amount-input",
|
22
|
+
"count" => "count-input",
|
23
|
+
"created_at" => "created_at-input",
|
24
|
+
"currency" => "currency-input",
|
25
|
+
"day_of_month" => "day_of_month-input",
|
26
|
+
"end_at" => "end_at-input",
|
27
|
+
"id" => "id-input",
|
28
|
+
"interval" => "interval-input",
|
29
|
+
"interval_unit" => "interval_unit-input",
|
30
|
+
"links" => "links-input",
|
31
|
+
"metadata" => "metadata-input",
|
32
|
+
"month" => "month-input",
|
33
|
+
"name" => "name-input",
|
34
|
+
"payment_reference" => "payment_reference-input",
|
35
|
+
"start_at" => "start_at-input",
|
36
|
+
"status" => "status-input",
|
37
|
+
"upcoming_payments" => "upcoming_payments-input",
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
before do
|
42
|
+
stub_request(:post, /.*api.gocardless.com\/subscriptions/).
|
43
|
+
with(
|
44
|
+
body: {
|
45
|
+
subscriptions: {
|
46
|
+
|
47
|
+
"amount" => "amount-input",
|
48
|
+
"count" => "count-input",
|
49
|
+
"created_at" => "created_at-input",
|
50
|
+
"currency" => "currency-input",
|
51
|
+
"day_of_month" => "day_of_month-input",
|
52
|
+
"end_at" => "end_at-input",
|
53
|
+
"id" => "id-input",
|
54
|
+
"interval" => "interval-input",
|
55
|
+
"interval_unit" => "interval_unit-input",
|
56
|
+
"links" => "links-input",
|
57
|
+
"metadata" => "metadata-input",
|
58
|
+
"month" => "month-input",
|
59
|
+
"name" => "name-input",
|
60
|
+
"payment_reference" => "payment_reference-input",
|
61
|
+
"start_at" => "start_at-input",
|
62
|
+
"status" => "status-input",
|
63
|
+
"upcoming_payments" => "upcoming_payments-input",
|
64
|
+
}
|
65
|
+
}
|
66
|
+
).
|
67
|
+
to_return(
|
68
|
+
body: {
|
69
|
+
subscriptions: {
|
70
|
+
|
71
|
+
"amount" => "amount-input",
|
72
|
+
"count" => "count-input",
|
73
|
+
"created_at" => "created_at-input",
|
74
|
+
"currency" => "currency-input",
|
75
|
+
"day_of_month" => "day_of_month-input",
|
76
|
+
"end_at" => "end_at-input",
|
77
|
+
"id" => "id-input",
|
78
|
+
"interval" => "interval-input",
|
79
|
+
"interval_unit" => "interval_unit-input",
|
80
|
+
"links" => "links-input",
|
81
|
+
"metadata" => "metadata-input",
|
82
|
+
"month" => "month-input",
|
83
|
+
"name" => "name-input",
|
84
|
+
"payment_reference" => "payment_reference-input",
|
85
|
+
"start_at" => "start_at-input",
|
86
|
+
"status" => "status-input",
|
87
|
+
"upcoming_payments" => "upcoming_payments-input",
|
88
|
+
}
|
89
|
+
}.to_json,
|
90
|
+
:headers => {'Content-Type' => 'application/json'}
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "creates and returns the resource" do
|
95
|
+
expect(post_create_response).to be_a(GoCardlessPro::Resources::Subscription)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "with a request that returns a validation error" do
|
100
|
+
let(:new_resource) { {} }
|
101
|
+
|
102
|
+
before do
|
103
|
+
stub_request(:post, /.*api.gocardless.com\/subscriptions/).to_return(
|
104
|
+
body: {
|
105
|
+
error: {
|
106
|
+
type: 'validation_failed',
|
107
|
+
code: 422,
|
108
|
+
errors: [
|
109
|
+
{ message: 'test error message', field: 'test_field' }
|
110
|
+
]
|
111
|
+
}
|
112
|
+
}.to_json,
|
113
|
+
headers: {'Content-Type' => 'application/json'},
|
114
|
+
status: 422
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "throws the correct error" do
|
119
|
+
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
describe "#list" do
|
129
|
+
describe "with no filters" do
|
130
|
+
subject(:get_list_response) { client.subscriptions.list }
|
131
|
+
|
132
|
+
before do
|
133
|
+
stub_request(:get, /.*api.gocardless.com\/subscriptions/).to_return(
|
134
|
+
body: {
|
135
|
+
subscriptions: [{
|
136
|
+
|
137
|
+
"amount" => "amount-input",
|
138
|
+
"count" => "count-input",
|
139
|
+
"created_at" => "created_at-input",
|
140
|
+
"currency" => "currency-input",
|
141
|
+
"day_of_month" => "day_of_month-input",
|
142
|
+
"end_at" => "end_at-input",
|
143
|
+
"id" => "id-input",
|
144
|
+
"interval" => "interval-input",
|
145
|
+
"interval_unit" => "interval_unit-input",
|
146
|
+
"links" => "links-input",
|
147
|
+
"metadata" => "metadata-input",
|
148
|
+
"month" => "month-input",
|
149
|
+
"name" => "name-input",
|
150
|
+
"payment_reference" => "payment_reference-input",
|
151
|
+
"start_at" => "start_at-input",
|
152
|
+
"status" => "status-input",
|
153
|
+
"upcoming_payments" => "upcoming_payments-input",
|
154
|
+
}],
|
155
|
+
meta: {
|
156
|
+
cursors: {
|
157
|
+
before: nil,
|
158
|
+
after: "ABC123"
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}.to_json,
|
162
|
+
:headers => {'Content-Type' => 'application/json'}
|
163
|
+
)
|
164
|
+
end
|
165
|
+
|
166
|
+
it "wraps each item in the resource class" do
|
167
|
+
expect(get_list_response.records.map { |x| x.class }.uniq.first).to eq(GoCardlessPro::Resources::Subscription)
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
expect(get_list_response.records.first.amount).to eq("amount-input")
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
expect(get_list_response.records.first.count).to eq("count-input")
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
expect(get_list_response.records.first.created_at).to eq("created_at-input")
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
expect(get_list_response.records.first.currency).to eq("currency-input")
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
expect(get_list_response.records.first.day_of_month).to eq("day_of_month-input")
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
expect(get_list_response.records.first.end_at).to eq("end_at-input")
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
expect(get_list_response.records.first.id).to eq("id-input")
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
expect(get_list_response.records.first.interval).to eq("interval-input")
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
expect(get_list_response.records.first.interval_unit).to eq("interval_unit-input")
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
expect(get_list_response.records.first.metadata).to eq("metadata-input")
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
expect(get_list_response.records.first.month).to eq("month-input")
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
expect(get_list_response.records.first.name).to eq("name-input")
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
expect(get_list_response.records.first.payment_reference).to eq("payment_reference-input")
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
expect(get_list_response.records.first.start_at).to eq("start_at-input")
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
expect(get_list_response.records.first.status).to eq("status-input")
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
expect(get_list_response.records.first.upcoming_payments).to eq("upcoming_payments-input")
|
234
|
+
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
it "exposes the cursors for before and after" do
|
239
|
+
expect(get_list_response.before).to eq(nil)
|
240
|
+
expect(get_list_response.after).to eq("ABC123")
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "#all" do
|
246
|
+
let!(:first_response_stub) do
|
247
|
+
stub_request(:get, /.*api.gocardless.com\/subscriptions$/).to_return(
|
248
|
+
body: {
|
249
|
+
subscriptions: [{
|
250
|
+
|
251
|
+
"amount" => "amount-input",
|
252
|
+
"count" => "count-input",
|
253
|
+
"created_at" => "created_at-input",
|
254
|
+
"currency" => "currency-input",
|
255
|
+
"day_of_month" => "day_of_month-input",
|
256
|
+
"end_at" => "end_at-input",
|
257
|
+
"id" => "id-input",
|
258
|
+
"interval" => "interval-input",
|
259
|
+
"interval_unit" => "interval_unit-input",
|
260
|
+
"links" => "links-input",
|
261
|
+
"metadata" => "metadata-input",
|
262
|
+
"month" => "month-input",
|
263
|
+
"name" => "name-input",
|
264
|
+
"payment_reference" => "payment_reference-input",
|
265
|
+
"start_at" => "start_at-input",
|
266
|
+
"status" => "status-input",
|
267
|
+
"upcoming_payments" => "upcoming_payments-input",
|
268
|
+
}],
|
269
|
+
meta: {
|
270
|
+
cursors: { after: 'AB345' },
|
271
|
+
limit: 1
|
272
|
+
}
|
273
|
+
}.to_json,
|
274
|
+
:headers => {'Content-Type' => 'application/json'}
|
275
|
+
)
|
276
|
+
end
|
277
|
+
|
278
|
+
let!(:second_response_stub) do
|
279
|
+
stub_request(:get, /.*api.gocardless.com\/subscriptions\?after=AB345/).to_return(
|
280
|
+
body: {
|
281
|
+
subscriptions: [{
|
282
|
+
|
283
|
+
"amount" => "amount-input",
|
284
|
+
"count" => "count-input",
|
285
|
+
"created_at" => "created_at-input",
|
286
|
+
"currency" => "currency-input",
|
287
|
+
"day_of_month" => "day_of_month-input",
|
288
|
+
"end_at" => "end_at-input",
|
289
|
+
"id" => "id-input",
|
290
|
+
"interval" => "interval-input",
|
291
|
+
"interval_unit" => "interval_unit-input",
|
292
|
+
"links" => "links-input",
|
293
|
+
"metadata" => "metadata-input",
|
294
|
+
"month" => "month-input",
|
295
|
+
"name" => "name-input",
|
296
|
+
"payment_reference" => "payment_reference-input",
|
297
|
+
"start_at" => "start_at-input",
|
298
|
+
"status" => "status-input",
|
299
|
+
"upcoming_payments" => "upcoming_payments-input",
|
300
|
+
}],
|
301
|
+
meta: {
|
302
|
+
limit: 2,
|
303
|
+
cursors: {}
|
304
|
+
}
|
305
|
+
}.to_json,
|
306
|
+
:headers => {'Content-Type' => 'application/json'}
|
307
|
+
)
|
308
|
+
end
|
309
|
+
|
310
|
+
it "automatically makes the extra requests" do
|
311
|
+
expect(client.subscriptions.all.to_a.length).to eq(2)
|
312
|
+
expect(first_response_stub).to have_been_requested
|
313
|
+
expect(second_response_stub).to have_been_requested
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
describe "#get" do
|
323
|
+
let(:id) { "ID123" }
|
324
|
+
|
325
|
+
subject(:get_response) { client.subscriptions.get(id) }
|
326
|
+
|
327
|
+
context "passing in a custom header" do
|
328
|
+
let!(:stub) do
|
329
|
+
stub_request(:get, /.*api.gocardless.com\/subscriptions\/ID123/)
|
330
|
+
.with(headers: { 'Foo' => 'Bar' })
|
331
|
+
.to_return(
|
332
|
+
body: {
|
333
|
+
subscriptions: {
|
334
|
+
|
335
|
+
"amount" => "amount-input",
|
336
|
+
"count" => "count-input",
|
337
|
+
"created_at" => "created_at-input",
|
338
|
+
"currency" => "currency-input",
|
339
|
+
"day_of_month" => "day_of_month-input",
|
340
|
+
"end_at" => "end_at-input",
|
341
|
+
"id" => "id-input",
|
342
|
+
"interval" => "interval-input",
|
343
|
+
"interval_unit" => "interval_unit-input",
|
344
|
+
"links" => "links-input",
|
345
|
+
"metadata" => "metadata-input",
|
346
|
+
"month" => "month-input",
|
347
|
+
"name" => "name-input",
|
348
|
+
"payment_reference" => "payment_reference-input",
|
349
|
+
"start_at" => "start_at-input",
|
350
|
+
"status" => "status-input",
|
351
|
+
"upcoming_payments" => "upcoming_payments-input",
|
352
|
+
}
|
353
|
+
}.to_json,
|
354
|
+
:headers => {'Content-Type' => 'application/json'}
|
355
|
+
)
|
356
|
+
end
|
357
|
+
|
358
|
+
subject(:get_response) do
|
359
|
+
client.subscriptions.get(id, headers: {
|
360
|
+
'Foo' => 'Bar'
|
361
|
+
})
|
362
|
+
end
|
363
|
+
|
364
|
+
it "includes the header" do
|
365
|
+
get_response
|
366
|
+
expect(stub).to have_been_requested
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
context "when there is a subscription to return" do
|
371
|
+
before do
|
372
|
+
stub_request(:get, /.*api.gocardless.com\/subscriptions\/ID123/).to_return(
|
373
|
+
body: {
|
374
|
+
subscriptions: {
|
375
|
+
|
376
|
+
"amount" => "amount-input",
|
377
|
+
"count" => "count-input",
|
378
|
+
"created_at" => "created_at-input",
|
379
|
+
"currency" => "currency-input",
|
380
|
+
"day_of_month" => "day_of_month-input",
|
381
|
+
"end_at" => "end_at-input",
|
382
|
+
"id" => "id-input",
|
383
|
+
"interval" => "interval-input",
|
384
|
+
"interval_unit" => "interval_unit-input",
|
385
|
+
"links" => "links-input",
|
386
|
+
"metadata" => "metadata-input",
|
387
|
+
"month" => "month-input",
|
388
|
+
"name" => "name-input",
|
389
|
+
"payment_reference" => "payment_reference-input",
|
390
|
+
"start_at" => "start_at-input",
|
391
|
+
"status" => "status-input",
|
392
|
+
"upcoming_payments" => "upcoming_payments-input",
|
393
|
+
}
|
394
|
+
}.to_json,
|
395
|
+
:headers => {'Content-Type' => 'application/json'}
|
396
|
+
)
|
397
|
+
end
|
398
|
+
|
399
|
+
it "wraps the response in a resource" do
|
400
|
+
expect(get_response).to be_a(GoCardlessPro::Resources::Subscription)
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
context "when nothing is returned" do
|
405
|
+
before do
|
406
|
+
stub_request(:get, /.*api.gocardless.com\/subscriptions\/ID123/).to_return(
|
407
|
+
body: "",
|
408
|
+
headers: { 'Content-Type' => 'application/json' }
|
409
|
+
)
|
410
|
+
end
|
411
|
+
|
412
|
+
it "returns nil" do
|
413
|
+
expect(get_response).to be_nil
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
describe "#update" do
|
424
|
+
subject(:put_update_response) { client.subscriptions.update(id, params: update_params) }
|
425
|
+
let(:id) { "ABC123" }
|
426
|
+
|
427
|
+
context "with a valid request" do
|
428
|
+
let(:update_params) { { "hello" => "world" } }
|
429
|
+
|
430
|
+
let!(:stub) do
|
431
|
+
stub_request(:put, /.*api.gocardless.com\/subscriptions\/ABC123/).to_return(
|
432
|
+
body: {
|
433
|
+
subscriptions: {
|
434
|
+
|
435
|
+
"amount" => "amount-input",
|
436
|
+
"count" => "count-input",
|
437
|
+
"created_at" => "created_at-input",
|
438
|
+
"currency" => "currency-input",
|
439
|
+
"day_of_month" => "day_of_month-input",
|
440
|
+
"end_at" => "end_at-input",
|
441
|
+
"id" => "id-input",
|
442
|
+
"interval" => "interval-input",
|
443
|
+
"interval_unit" => "interval_unit-input",
|
444
|
+
"links" => "links-input",
|
445
|
+
"metadata" => "metadata-input",
|
446
|
+
"month" => "month-input",
|
447
|
+
"name" => "name-input",
|
448
|
+
"payment_reference" => "payment_reference-input",
|
449
|
+
"start_at" => "start_at-input",
|
450
|
+
"status" => "status-input",
|
451
|
+
"upcoming_payments" => "upcoming_payments-input",
|
452
|
+
}
|
453
|
+
}.to_json,
|
454
|
+
:headers => {'Content-Type' => 'application/json'}
|
455
|
+
)
|
456
|
+
end
|
457
|
+
|
458
|
+
it "updates and returns the resource" do
|
459
|
+
expect(put_update_response).to be_a(GoCardlessPro::Resources::Subscription)
|
460
|
+
expect(stub).to have_been_requested
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
describe "#cancel" do
|
470
|
+
|
471
|
+
|
472
|
+
subject(:post_response) { client.subscriptions.cancel(resource_id) }
|
473
|
+
|
474
|
+
let(:resource_id) { "ABC123" }
|
475
|
+
|
476
|
+
let!(:stub) do
|
477
|
+
# /subscriptions/%v/actions/cancel
|
478
|
+
stub_url = "/subscriptions/:identity/actions/cancel".gsub(':identity', resource_id)
|
479
|
+
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
480
|
+
body: {
|
481
|
+
subscriptions: {
|
482
|
+
|
483
|
+
"amount" => "amount-input",
|
484
|
+
"count" => "count-input",
|
485
|
+
"created_at" => "created_at-input",
|
486
|
+
"currency" => "currency-input",
|
487
|
+
"day_of_month" => "day_of_month-input",
|
488
|
+
"end_at" => "end_at-input",
|
489
|
+
"id" => "id-input",
|
490
|
+
"interval" => "interval-input",
|
491
|
+
"interval_unit" => "interval_unit-input",
|
492
|
+
"links" => "links-input",
|
493
|
+
"metadata" => "metadata-input",
|
494
|
+
"month" => "month-input",
|
495
|
+
"name" => "name-input",
|
496
|
+
"payment_reference" => "payment_reference-input",
|
497
|
+
"start_at" => "start_at-input",
|
498
|
+
"status" => "status-input",
|
499
|
+
"upcoming_payments" => "upcoming_payments-input",
|
500
|
+
}
|
501
|
+
}.to_json,
|
502
|
+
headers: {'Content-Type' => 'application/json'},
|
503
|
+
)
|
504
|
+
end
|
505
|
+
|
506
|
+
it "wraps the response and calls the right endpoint" do
|
507
|
+
expect(post_response).to be_a(GoCardlessPro::Resources::Subscription)
|
508
|
+
|
509
|
+
expect(stub).to have_been_requested
|
510
|
+
end
|
511
|
+
|
512
|
+
context "when the request needs a body and custom header" do
|
513
|
+
|
514
|
+
let(:body) { { foo: 'bar' } }
|
515
|
+
let(:headers) { { 'Foo' => 'Bar' } }
|
516
|
+
subject(:post_response) { client.subscriptions.cancel(resource_id, body, headers) }
|
517
|
+
|
518
|
+
let(:resource_id) { "ABC123" }
|
519
|
+
|
520
|
+
let!(:stub) do
|
521
|
+
# /subscriptions/%v/actions/cancel
|
522
|
+
stub_url = "/subscriptions/:identity/actions/cancel".gsub(':identity', resource_id)
|
523
|
+
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
524
|
+
with(
|
525
|
+
body: { foo: 'bar' },
|
526
|
+
headers: { 'Foo' => 'Bar' }
|
527
|
+
).to_return(
|
528
|
+
body: {
|
529
|
+
subscriptions: {
|
530
|
+
|
531
|
+
"amount" => "amount-input",
|
532
|
+
"count" => "count-input",
|
533
|
+
"created_at" => "created_at-input",
|
534
|
+
"currency" => "currency-input",
|
535
|
+
"day_of_month" => "day_of_month-input",
|
536
|
+
"end_at" => "end_at-input",
|
537
|
+
"id" => "id-input",
|
538
|
+
"interval" => "interval-input",
|
539
|
+
"interval_unit" => "interval_unit-input",
|
540
|
+
"links" => "links-input",
|
541
|
+
"metadata" => "metadata-input",
|
542
|
+
"month" => "month-input",
|
543
|
+
"name" => "name-input",
|
544
|
+
"payment_reference" => "payment_reference-input",
|
545
|
+
"start_at" => "start_at-input",
|
546
|
+
"status" => "status-input",
|
547
|
+
"upcoming_payments" => "upcoming_payments-input",
|
548
|
+
}
|
549
|
+
}.to_json,
|
550
|
+
headers: {'Content-Type' => 'application/json'},
|
551
|
+
)
|
552
|
+
end
|
553
|
+
end
|
554
|
+
end
|
555
|
+
|
556
|
+
|
557
|
+
end
|