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