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