gocardless_pro 2.21.0 → 2.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +25 -43
- data/Gemfile +7 -0
- data/gocardless_pro.gemspec +2 -2
- data/lib/gocardless_pro.rb +6 -0
- data/lib/gocardless_pro/api_service.rb +1 -1
- data/lib/gocardless_pro/client.rb +11 -1
- data/lib/gocardless_pro/resources/event.rb +12 -0
- data/lib/gocardless_pro/resources/payer_authorisation.rb +119 -0
- data/lib/gocardless_pro/resources/payout.rb +2 -0
- data/lib/gocardless_pro/resources/payout_item.rb +6 -0
- data/lib/gocardless_pro/resources/tax_rate.rb +51 -0
- data/lib/gocardless_pro/services/bank_details_lookups_service.rb +0 -10
- data/lib/gocardless_pro/services/base_service.rb +11 -0
- data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +0 -10
- data/lib/gocardless_pro/services/creditors_service.rb +0 -10
- data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +0 -10
- data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +0 -10
- data/lib/gocardless_pro/services/customer_notifications_service.rb +0 -10
- data/lib/gocardless_pro/services/customers_service.rb +0 -10
- data/lib/gocardless_pro/services/events_service.rb +0 -10
- data/lib/gocardless_pro/services/instalment_schedules_service.rb +0 -10
- data/lib/gocardless_pro/services/mandate_import_entries_service.rb +0 -10
- data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -10
- data/lib/gocardless_pro/services/mandate_pdfs_service.rb +0 -10
- data/lib/gocardless_pro/services/mandates_service.rb +0 -10
- data/lib/gocardless_pro/services/payer_authorisations_service.rb +208 -0
- data/lib/gocardless_pro/services/payments_service.rb +0 -10
- data/lib/gocardless_pro/services/payout_items_service.rb +0 -10
- data/lib/gocardless_pro/services/payouts_service.rb +0 -10
- data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -10
- data/lib/gocardless_pro/services/refunds_service.rb +6 -11
- data/lib/gocardless_pro/services/subscriptions_service.rb +1 -11
- data/lib/gocardless_pro/services/tax_rates_service.rb +74 -0
- data/lib/gocardless_pro/version.rb +1 -1
- data/spec/resources/payer_authorisation_spec.rb +418 -0
- data/spec/resources/payout_item_spec.rb +5 -0
- data/spec/resources/payout_spec.rb +8 -0
- data/spec/resources/tax_rate_spec.rb +198 -0
- data/spec/services/creditor_bank_accounts_service_spec.rb +1 -1
- data/spec/services/customer_bank_accounts_service_spec.rb +1 -1
- data/spec/services/customer_notifications_service_spec.rb +1 -1
- data/spec/services/customers_service_spec.rb +1 -1
- data/spec/services/instalment_schedules_service_spec.rb +1 -1
- data/spec/services/mandate_imports_service_spec.rb +2 -2
- data/spec/services/mandates_service_spec.rb +2 -2
- data/spec/services/payer_authorisations_service_spec.rb +572 -0
- data/spec/services/payments_service_spec.rb +2 -2
- data/spec/services/payout_items_service_spec.rb +9 -0
- data/spec/services/payouts_service_spec.rb +12 -0
- data/spec/services/redirect_flows_service_spec.rb +1 -1
- data/spec/services/subscriptions_service_spec.rb +3 -3
- data/spec/services/tax_rates_service_spec.rb +381 -0
- metadata +19 -7
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative './base_service'
|
2
|
-
require 'uri'
|
3
2
|
|
4
3
|
# encoding: utf-8
|
5
4
|
#
|
@@ -225,15 +224,6 @@ module GoCardlessPro
|
|
225
224
|
def envelope_key
|
226
225
|
'payments'
|
227
226
|
end
|
228
|
-
|
229
|
-
# take a URL with placeholder params and substitute them out for the actual value
|
230
|
-
# @param url [String] the URL with placeholders in
|
231
|
-
# @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
|
232
|
-
def sub_url(url, param_map)
|
233
|
-
param_map.reduce(url) do |new_url, (param, value)|
|
234
|
-
new_url.gsub(":#{param}", URI.escape(value))
|
235
|
-
end
|
236
|
-
end
|
237
227
|
end
|
238
228
|
end
|
239
229
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative './base_service'
|
2
|
-
require 'uri'
|
3
2
|
|
4
3
|
# encoding: utf-8
|
5
4
|
#
|
@@ -54,15 +53,6 @@ module GoCardlessPro
|
|
54
53
|
def envelope_key
|
55
54
|
'payout_items'
|
56
55
|
end
|
57
|
-
|
58
|
-
# take a URL with placeholder params and substitute them out for the actual value
|
59
|
-
# @param url [String] the URL with placeholders in
|
60
|
-
# @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
|
61
|
-
def sub_url(url, param_map)
|
62
|
-
param_map.reduce(url) do |new_url, (param, value)|
|
63
|
-
new_url.gsub(":#{param}", URI.escape(value))
|
64
|
-
end
|
65
|
-
end
|
66
56
|
end
|
67
57
|
end
|
68
58
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative './base_service'
|
2
|
-
require 'uri'
|
3
2
|
|
4
3
|
# encoding: utf-8
|
5
4
|
#
|
@@ -93,15 +92,6 @@ module GoCardlessPro
|
|
93
92
|
def envelope_key
|
94
93
|
'payouts'
|
95
94
|
end
|
96
|
-
|
97
|
-
# take a URL with placeholder params and substitute them out for the actual value
|
98
|
-
# @param url [String] the URL with placeholders in
|
99
|
-
# @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
|
100
|
-
def sub_url(url, param_map)
|
101
|
-
param_map.reduce(url) do |new_url, (param, value)|
|
102
|
-
new_url.gsub(":#{param}", URI.escape(value))
|
103
|
-
end
|
104
|
-
end
|
105
95
|
end
|
106
96
|
end
|
107
97
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative './base_service'
|
2
|
-
require 'uri'
|
3
2
|
|
4
3
|
# encoding: utf-8
|
5
4
|
#
|
@@ -127,15 +126,6 @@ module GoCardlessPro
|
|
127
126
|
def envelope_key
|
128
127
|
'redirect_flows'
|
129
128
|
end
|
130
|
-
|
131
|
-
# take a URL with placeholder params and substitute them out for the actual value
|
132
|
-
# @param url [String] the URL with placeholders in
|
133
|
-
# @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
|
134
|
-
def sub_url(url, param_map)
|
135
|
-
param_map.reduce(url) do |new_url, (param, value)|
|
136
|
-
new_url.gsub(":#{param}", URI.escape(value))
|
137
|
-
end
|
138
|
-
end
|
139
129
|
end
|
140
130
|
end
|
141
131
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative './base_service'
|
2
|
-
require 'uri'
|
3
2
|
|
4
3
|
# encoding: utf-8
|
5
4
|
#
|
@@ -14,7 +13,8 @@ module GoCardlessPro
|
|
14
13
|
# Creates a new refund object.
|
15
14
|
#
|
16
15
|
# This fails with:<a name="total_amount_confirmation_invalid"></a><a
|
17
|
-
# name="number_of_refunds_exceeded"></a
|
16
|
+
# name="number_of_refunds_exceeded"></a><a
|
17
|
+
# name="available_refund_amount_insufficient"></a>
|
18
18
|
#
|
19
19
|
# - `total_amount_confirmation_invalid` if the confirmation amount doesn't match
|
20
20
|
# the total amount refunded for the payment. This safeguard is there to prevent
|
@@ -23,6 +23,10 @@ module GoCardlessPro
|
|
23
23
|
# - `number_of_refunds_exceeded` if five or more refunds have already been
|
24
24
|
# created against the payment.
|
25
25
|
#
|
26
|
+
# - `available_refund_amount_insufficient` if the creditor does not have
|
27
|
+
# sufficient balance for refunds available to cover the cost of the requested
|
28
|
+
# refund.
|
29
|
+
#
|
26
30
|
# Example URL: /refunds
|
27
31
|
# @param options [Hash] parameters as a hash, under a params key.
|
28
32
|
def create(options = {})
|
@@ -139,15 +143,6 @@ module GoCardlessPro
|
|
139
143
|
def envelope_key
|
140
144
|
'refunds'
|
141
145
|
end
|
142
|
-
|
143
|
-
# take a URL with placeholder params and substitute them out for the actual value
|
144
|
-
# @param url [String] the URL with placeholders in
|
145
|
-
# @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
|
146
|
-
def sub_url(url, param_map)
|
147
|
-
param_map.reduce(url) do |new_url, (param, value)|
|
148
|
-
new_url.gsub(":#{param}", URI.escape(value))
|
149
|
-
end
|
150
|
-
end
|
151
146
|
end
|
152
147
|
end
|
153
148
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative './base_service'
|
2
|
-
require 'uri'
|
3
2
|
|
4
3
|
# encoding: utf-8
|
5
4
|
#
|
@@ -148,7 +147,7 @@ module GoCardlessPro
|
|
148
147
|
# When `pause_cycles` is omitted the subscription is paused until the [resume
|
149
148
|
# endpoint](#subscriptions-resume-a-subscription) is called.
|
150
149
|
# If the subscription is collecting a fixed number of payments, `end_date` will
|
151
|
-
# be set to `
|
150
|
+
# be set to `null`.
|
152
151
|
# When paused indefinitely, `upcoming_payments` will be empty.
|
153
152
|
#
|
154
153
|
# When `pause_cycles` is provided the subscription will be paused for the number
|
@@ -324,15 +323,6 @@ module GoCardlessPro
|
|
324
323
|
def envelope_key
|
325
324
|
'subscriptions'
|
326
325
|
end
|
327
|
-
|
328
|
-
# take a URL with placeholder params and substitute them out for the actual value
|
329
|
-
# @param url [String] the URL with placeholders in
|
330
|
-
# @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
|
331
|
-
def sub_url(url, param_map)
|
332
|
-
param_map.reduce(url) do |new_url, (param, value)|
|
333
|
-
new_url.gsub(":#{param}", URI.escape(value))
|
334
|
-
end
|
335
|
-
end
|
336
326
|
end
|
337
327
|
end
|
338
328
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative './base_service'
|
2
|
+
|
3
|
+
# encoding: utf-8
|
4
|
+
#
|
5
|
+
# This client is automatically generated from a template and JSON schema definition.
|
6
|
+
# See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
|
7
|
+
#
|
8
|
+
|
9
|
+
module GoCardlessPro
|
10
|
+
module Services
|
11
|
+
# Service for making requests to the TaxRate endpoints
|
12
|
+
class TaxRatesService < BaseService
|
13
|
+
# Returns a [cursor-paginated](#api-usage-cursor-pagination) list of all tax
|
14
|
+
# rates.
|
15
|
+
# Example URL: /tax_rates
|
16
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
17
|
+
def list(options = {})
|
18
|
+
path = '/tax_rates'
|
19
|
+
|
20
|
+
options[:retry_failures] = true
|
21
|
+
|
22
|
+
response = make_request(:get, path, options)
|
23
|
+
|
24
|
+
ListResponse.new(
|
25
|
+
response: response,
|
26
|
+
unenveloped_body: unenvelope_body(response.body),
|
27
|
+
resource_class: Resources::TaxRate
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
|
32
|
+
#
|
33
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
34
|
+
# Otherwise they will be the body of the request.
|
35
|
+
def all(options = {})
|
36
|
+
Paginator.new(
|
37
|
+
service: self,
|
38
|
+
options: options
|
39
|
+
).enumerator
|
40
|
+
end
|
41
|
+
|
42
|
+
# Retrieves the details of a tax rate.
|
43
|
+
# Example URL: /tax_rates/:identity
|
44
|
+
#
|
45
|
+
# @param identity # The unique identifier created by the jurisdiction, tax type and version
|
46
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
47
|
+
def get(identity, options = {})
|
48
|
+
path = sub_url('/tax_rates/:identity', 'identity' => identity)
|
49
|
+
|
50
|
+
options[:retry_failures] = true
|
51
|
+
|
52
|
+
response = make_request(:get, path, options)
|
53
|
+
|
54
|
+
return if response.body.nil?
|
55
|
+
|
56
|
+
Resources::TaxRate.new(unenvelope_body(response.body), response)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Unenvelope the response of the body using the service's `envelope_key`
|
62
|
+
#
|
63
|
+
# @param body [Hash]
|
64
|
+
def unenvelope_body(body)
|
65
|
+
body[envelope_key] || body['data']
|
66
|
+
end
|
67
|
+
|
68
|
+
# return the key which API responses will envelope data under
|
69
|
+
def envelope_key
|
70
|
+
'tax_rates'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,418 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GoCardlessPro::Resources::PayerAuthorisation do
|
4
|
+
let(:client) do
|
5
|
+
GoCardlessPro::Client.new(
|
6
|
+
access_token: 'SECRET_TOKEN'
|
7
|
+
)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:response_headers) { { 'Content-Type' => 'application/json' } }
|
11
|
+
|
12
|
+
describe '#get' do
|
13
|
+
let(:id) { 'ID123' }
|
14
|
+
|
15
|
+
subject(:get_response) { client.payer_authorisations.get(id) }
|
16
|
+
|
17
|
+
context 'passing in a custom header' do
|
18
|
+
let!(:stub) do
|
19
|
+
stub_url = '/payer_authorisations/:identity'.gsub(':identity', id)
|
20
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
21
|
+
with(headers: { 'Foo' => 'Bar' }).
|
22
|
+
to_return(
|
23
|
+
body: {
|
24
|
+
'payer_authorisations' => {
|
25
|
+
|
26
|
+
'bank_account' => 'bank_account-input',
|
27
|
+
'created_at' => 'created_at-input',
|
28
|
+
'customer' => 'customer-input',
|
29
|
+
'id' => 'id-input',
|
30
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
31
|
+
'links' => 'links-input',
|
32
|
+
'mandate' => 'mandate-input',
|
33
|
+
'status' => 'status-input',
|
34
|
+
},
|
35
|
+
}.to_json,
|
36
|
+
headers: response_headers
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
subject(:get_response) do
|
41
|
+
client.payer_authorisations.get(id, headers: {
|
42
|
+
'Foo' => 'Bar',
|
43
|
+
})
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'includes the header' do
|
47
|
+
get_response
|
48
|
+
expect(stub).to have_been_requested
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when there is a payer_authorisation to return' do
|
53
|
+
before do
|
54
|
+
stub_url = '/payer_authorisations/:identity'.gsub(':identity', id)
|
55
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
56
|
+
body: {
|
57
|
+
'payer_authorisations' => {
|
58
|
+
|
59
|
+
'bank_account' => 'bank_account-input',
|
60
|
+
'created_at' => 'created_at-input',
|
61
|
+
'customer' => 'customer-input',
|
62
|
+
'id' => 'id-input',
|
63
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
64
|
+
'links' => 'links-input',
|
65
|
+
'mandate' => 'mandate-input',
|
66
|
+
'status' => 'status-input',
|
67
|
+
},
|
68
|
+
}.to_json,
|
69
|
+
headers: response_headers
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'wraps the response in a resource' do
|
74
|
+
expect(get_response).to be_a(GoCardlessPro::Resources::PayerAuthorisation)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when nothing is returned' do
|
79
|
+
before do
|
80
|
+
stub_url = '/payer_authorisations/:identity'.gsub(':identity', id)
|
81
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
|
82
|
+
body: '',
|
83
|
+
headers: response_headers
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns nil' do
|
88
|
+
expect(get_response).to be_nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "when an ID is specified which can't be included in a valid URI" do
|
93
|
+
let(:id) { '`' }
|
94
|
+
|
95
|
+
it "doesn't raise an error" do
|
96
|
+
expect { get_response }.to_not raise_error(/bad URI/)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#create' do
|
102
|
+
subject(:post_create_response) { client.payer_authorisations.create(params: new_resource) }
|
103
|
+
context 'with a valid request' do
|
104
|
+
let(:new_resource) do
|
105
|
+
{
|
106
|
+
|
107
|
+
'bank_account' => 'bank_account-input',
|
108
|
+
'created_at' => 'created_at-input',
|
109
|
+
'customer' => 'customer-input',
|
110
|
+
'id' => 'id-input',
|
111
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
112
|
+
'links' => 'links-input',
|
113
|
+
'mandate' => 'mandate-input',
|
114
|
+
'status' => 'status-input',
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
before do
|
119
|
+
stub_request(:post, %r{.*api.gocardless.com/payer_authorisations}).
|
120
|
+
with(
|
121
|
+
body: {
|
122
|
+
'payer_authorisations' => {
|
123
|
+
|
124
|
+
'bank_account' => 'bank_account-input',
|
125
|
+
'created_at' => 'created_at-input',
|
126
|
+
'customer' => 'customer-input',
|
127
|
+
'id' => 'id-input',
|
128
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
129
|
+
'links' => 'links-input',
|
130
|
+
'mandate' => 'mandate-input',
|
131
|
+
'status' => 'status-input',
|
132
|
+
},
|
133
|
+
}
|
134
|
+
).
|
135
|
+
to_return(
|
136
|
+
body: {
|
137
|
+
'payer_authorisations' =>
|
138
|
+
|
139
|
+
{
|
140
|
+
|
141
|
+
'bank_account' => 'bank_account-input',
|
142
|
+
'created_at' => 'created_at-input',
|
143
|
+
'customer' => 'customer-input',
|
144
|
+
'id' => 'id-input',
|
145
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
146
|
+
'links' => 'links-input',
|
147
|
+
'mandate' => 'mandate-input',
|
148
|
+
'status' => 'status-input',
|
149
|
+
},
|
150
|
+
|
151
|
+
}.to_json,
|
152
|
+
headers: response_headers
|
153
|
+
)
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'creates and returns the resource' do
|
157
|
+
expect(post_create_response).to be_a(GoCardlessPro::Resources::PayerAuthorisation)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'with a request that returns a validation error' do
|
162
|
+
let(:new_resource) { {} }
|
163
|
+
|
164
|
+
before do
|
165
|
+
stub_request(:post, %r{.*api.gocardless.com/payer_authorisations}).to_return(
|
166
|
+
body: {
|
167
|
+
error: {
|
168
|
+
type: 'validation_failed',
|
169
|
+
code: 422,
|
170
|
+
errors: [
|
171
|
+
{ message: 'test error message', field: 'test_field' },
|
172
|
+
],
|
173
|
+
},
|
174
|
+
}.to_json,
|
175
|
+
headers: response_headers,
|
176
|
+
status: 422
|
177
|
+
)
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'throws the correct error' do
|
181
|
+
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'with a request that returns an idempotent creation conflict error' do
|
186
|
+
let(:id) { 'ID123' }
|
187
|
+
|
188
|
+
let(:new_resource) do
|
189
|
+
{
|
190
|
+
|
191
|
+
'bank_account' => 'bank_account-input',
|
192
|
+
'created_at' => 'created_at-input',
|
193
|
+
'customer' => 'customer-input',
|
194
|
+
'id' => 'id-input',
|
195
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
196
|
+
'links' => 'links-input',
|
197
|
+
'mandate' => 'mandate-input',
|
198
|
+
'status' => 'status-input',
|
199
|
+
}
|
200
|
+
end
|
201
|
+
|
202
|
+
let!(:post_stub) do
|
203
|
+
stub_request(:post, %r{.*api.gocardless.com/payer_authorisations}).to_return(
|
204
|
+
body: {
|
205
|
+
error: {
|
206
|
+
type: 'invalid_state',
|
207
|
+
code: 409,
|
208
|
+
errors: [
|
209
|
+
{
|
210
|
+
message: 'A resource has already been created with this idempotency key',
|
211
|
+
reason: 'idempotent_creation_conflict',
|
212
|
+
links: {
|
213
|
+
conflicting_resource_id: id,
|
214
|
+
},
|
215
|
+
},
|
216
|
+
],
|
217
|
+
},
|
218
|
+
}.to_json,
|
219
|
+
headers: response_headers,
|
220
|
+
status: 409
|
221
|
+
)
|
222
|
+
end
|
223
|
+
|
224
|
+
let!(:get_stub) do
|
225
|
+
stub_url = "/payer_authorisations/#{id}"
|
226
|
+
stub_request(:get, /.*api.gocardless.com#{stub_url}/).
|
227
|
+
to_return(
|
228
|
+
body: {
|
229
|
+
'payer_authorisations' => {
|
230
|
+
|
231
|
+
'bank_account' => 'bank_account-input',
|
232
|
+
'created_at' => 'created_at-input',
|
233
|
+
'customer' => 'customer-input',
|
234
|
+
'id' => 'id-input',
|
235
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
236
|
+
'links' => 'links-input',
|
237
|
+
'mandate' => 'mandate-input',
|
238
|
+
'status' => 'status-input',
|
239
|
+
},
|
240
|
+
}.to_json,
|
241
|
+
headers: response_headers
|
242
|
+
)
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'fetches the already-created resource' do
|
246
|
+
post_create_response
|
247
|
+
expect(post_stub).to have_been_requested
|
248
|
+
expect(get_stub).to have_been_requested
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
describe '#update' do
|
254
|
+
subject(:put_update_response) { client.payer_authorisations.update(id, params: update_params) }
|
255
|
+
let(:id) { 'ABC123' }
|
256
|
+
|
257
|
+
context 'with a valid request' do
|
258
|
+
let(:update_params) { { 'hello' => 'world' } }
|
259
|
+
|
260
|
+
let!(:stub) do
|
261
|
+
stub_url = '/payer_authorisations/:identity'.gsub(':identity', id)
|
262
|
+
stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
|
263
|
+
body: {
|
264
|
+
'payer_authorisations' => {
|
265
|
+
|
266
|
+
'bank_account' => 'bank_account-input',
|
267
|
+
'created_at' => 'created_at-input',
|
268
|
+
'customer' => 'customer-input',
|
269
|
+
'id' => 'id-input',
|
270
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
271
|
+
'links' => 'links-input',
|
272
|
+
'mandate' => 'mandate-input',
|
273
|
+
'status' => 'status-input',
|
274
|
+
},
|
275
|
+
}.to_json,
|
276
|
+
headers: response_headers
|
277
|
+
)
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'updates and returns the resource' do
|
281
|
+
expect(put_update_response).to be_a(GoCardlessPro::Resources::PayerAuthorisation)
|
282
|
+
expect(stub).to have_been_requested
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
describe '#submit' do
|
288
|
+
subject(:post_response) { client.payer_authorisations.submit(resource_id) }
|
289
|
+
|
290
|
+
let(:resource_id) { 'ABC123' }
|
291
|
+
|
292
|
+
let!(:stub) do
|
293
|
+
# /payer_authorisations/%v/actions/submit
|
294
|
+
stub_url = '/payer_authorisations/:identity/actions/submit'.gsub(':identity', resource_id)
|
295
|
+
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
296
|
+
body: {
|
297
|
+
'payer_authorisations' => {
|
298
|
+
|
299
|
+
'bank_account' => 'bank_account-input',
|
300
|
+
'created_at' => 'created_at-input',
|
301
|
+
'customer' => 'customer-input',
|
302
|
+
'id' => 'id-input',
|
303
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
304
|
+
'links' => 'links-input',
|
305
|
+
'mandate' => 'mandate-input',
|
306
|
+
'status' => 'status-input',
|
307
|
+
},
|
308
|
+
}.to_json,
|
309
|
+
headers: response_headers
|
310
|
+
)
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'wraps the response and calls the right endpoint' do
|
314
|
+
expect(post_response).to be_a(GoCardlessPro::Resources::PayerAuthorisation)
|
315
|
+
|
316
|
+
expect(stub).to have_been_requested
|
317
|
+
end
|
318
|
+
|
319
|
+
context 'when the request needs a body and custom header' do
|
320
|
+
let(:body) { { foo: 'bar' } }
|
321
|
+
let(:headers) { { 'Foo' => 'Bar' } }
|
322
|
+
subject(:post_response) { client.payer_authorisations.submit(resource_id, body, headers) }
|
323
|
+
|
324
|
+
let(:resource_id) { 'ABC123' }
|
325
|
+
|
326
|
+
let!(:stub) do
|
327
|
+
# /payer_authorisations/%v/actions/submit
|
328
|
+
stub_url = '/payer_authorisations/:identity/actions/submit'.gsub(':identity', resource_id)
|
329
|
+
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
330
|
+
with(
|
331
|
+
body: { foo: 'bar' },
|
332
|
+
headers: { 'Foo' => 'Bar' }
|
333
|
+
).to_return(
|
334
|
+
body: {
|
335
|
+
'payer_authorisations' => {
|
336
|
+
|
337
|
+
'bank_account' => 'bank_account-input',
|
338
|
+
'created_at' => 'created_at-input',
|
339
|
+
'customer' => 'customer-input',
|
340
|
+
'id' => 'id-input',
|
341
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
342
|
+
'links' => 'links-input',
|
343
|
+
'mandate' => 'mandate-input',
|
344
|
+
'status' => 'status-input',
|
345
|
+
},
|
346
|
+
}.to_json,
|
347
|
+
headers: response_headers
|
348
|
+
)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
describe '#confirm' do
|
354
|
+
subject(:post_response) { client.payer_authorisations.confirm(resource_id) }
|
355
|
+
|
356
|
+
let(:resource_id) { 'ABC123' }
|
357
|
+
|
358
|
+
let!(:stub) do
|
359
|
+
# /payer_authorisations/%v/actions/confirm
|
360
|
+
stub_url = '/payer_authorisations/:identity/actions/confirm'.gsub(':identity', resource_id)
|
361
|
+
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
|
362
|
+
body: {
|
363
|
+
'payer_authorisations' => {
|
364
|
+
|
365
|
+
'bank_account' => 'bank_account-input',
|
366
|
+
'created_at' => 'created_at-input',
|
367
|
+
'customer' => 'customer-input',
|
368
|
+
'id' => 'id-input',
|
369
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
370
|
+
'links' => 'links-input',
|
371
|
+
'mandate' => 'mandate-input',
|
372
|
+
'status' => 'status-input',
|
373
|
+
},
|
374
|
+
}.to_json,
|
375
|
+
headers: response_headers
|
376
|
+
)
|
377
|
+
end
|
378
|
+
|
379
|
+
it 'wraps the response and calls the right endpoint' do
|
380
|
+
expect(post_response).to be_a(GoCardlessPro::Resources::PayerAuthorisation)
|
381
|
+
|
382
|
+
expect(stub).to have_been_requested
|
383
|
+
end
|
384
|
+
|
385
|
+
context 'when the request needs a body and custom header' do
|
386
|
+
let(:body) { { foo: 'bar' } }
|
387
|
+
let(:headers) { { 'Foo' => 'Bar' } }
|
388
|
+
subject(:post_response) { client.payer_authorisations.confirm(resource_id, body, headers) }
|
389
|
+
|
390
|
+
let(:resource_id) { 'ABC123' }
|
391
|
+
|
392
|
+
let!(:stub) do
|
393
|
+
# /payer_authorisations/%v/actions/confirm
|
394
|
+
stub_url = '/payer_authorisations/:identity/actions/confirm'.gsub(':identity', resource_id)
|
395
|
+
stub_request(:post, /.*api.gocardless.com#{stub_url}/).
|
396
|
+
with(
|
397
|
+
body: { foo: 'bar' },
|
398
|
+
headers: { 'Foo' => 'Bar' }
|
399
|
+
).to_return(
|
400
|
+
body: {
|
401
|
+
'payer_authorisations' => {
|
402
|
+
|
403
|
+
'bank_account' => 'bank_account-input',
|
404
|
+
'created_at' => 'created_at-input',
|
405
|
+
'customer' => 'customer-input',
|
406
|
+
'id' => 'id-input',
|
407
|
+
'incomplete_fields' => 'incomplete_fields-input',
|
408
|
+
'links' => 'links-input',
|
409
|
+
'mandate' => 'mandate-input',
|
410
|
+
'status' => 'status-input',
|
411
|
+
},
|
412
|
+
}.to_json,
|
413
|
+
headers: response_headers
|
414
|
+
)
|
415
|
+
end
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|