gocardless_pro 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -29
- data/lib/gocardless_pro.rb +7 -3
- data/lib/gocardless_pro/api_response.rb +14 -0
- data/lib/gocardless_pro/client.rb +24 -12
- data/lib/gocardless_pro/list_response.rb +7 -3
- data/lib/gocardless_pro/request.rb +3 -11
- data/lib/gocardless_pro/resources/{helper.rb → bank_details_lookup.rb} +15 -4
- data/lib/gocardless_pro/resources/creditor.rb +14 -13
- data/lib/gocardless_pro/resources/creditor_bank_account.rb +14 -10
- data/lib/gocardless_pro/resources/customer.rb +8 -4
- data/lib/gocardless_pro/resources/customer_bank_account.rb +15 -13
- data/lib/gocardless_pro/resources/event.rb +6 -1
- data/lib/gocardless_pro/resources/mandate.rb +10 -7
- data/lib/gocardless_pro/resources/mandate_pdf.rb +42 -0
- data/lib/gocardless_pro/resources/payment.rb +12 -11
- data/lib/gocardless_pro/resources/payout.rb +9 -6
- data/lib/gocardless_pro/resources/redirect_flow.rb +24 -30
- data/lib/gocardless_pro/resources/refund.rb +15 -15
- data/lib/gocardless_pro/resources/subscription.rb +26 -22
- data/lib/gocardless_pro/response.rb +5 -0
- data/lib/gocardless_pro/services/bank_details_lookups_service.rb +55 -0
- data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +8 -9
- data/lib/gocardless_pro/services/creditors_service.rb +6 -7
- data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +15 -18
- data/lib/gocardless_pro/services/customers_service.rb +6 -7
- data/lib/gocardless_pro/services/events_service.rb +4 -6
- data/lib/gocardless_pro/services/mandate_pdfs_service.rb +63 -0
- data/lib/gocardless_pro/services/mandates_service.rb +12 -24
- data/lib/gocardless_pro/services/payments_service.rb +15 -16
- data/lib/gocardless_pro/services/payouts_service.rb +5 -6
- data/lib/gocardless_pro/services/redirect_flows_service.rb +13 -17
- data/lib/gocardless_pro/services/refunds_service.rb +16 -19
- data/lib/gocardless_pro/services/subscriptions_service.rb +10 -11
- data/lib/gocardless_pro/version.rb +1 -1
- data/spec/api_response_spec.rb +28 -0
- data/spec/resources/bank_details_lookup_spec.rb +39 -0
- data/spec/resources/creditor_spec.rb +0 -4
- data/spec/resources/{helper_spec.rb → mandate_pdf_spec.rb} +17 -1
- data/spec/resources/subscription_spec.rb +4 -4
- data/spec/services/bank_details_lookups_service_spec.rb +80 -0
- data/spec/services/creditor_bank_accounts_service_spec.rb +2 -0
- data/spec/services/creditors_service_spec.rb +2 -0
- data/spec/services/customer_bank_accounts_service_spec.rb +2 -0
- data/spec/services/customers_service_spec.rb +2 -0
- data/spec/services/events_service_spec.rb +2 -0
- data/spec/services/mandate_pdfs_service_spec.rb +80 -0
- data/spec/services/mandates_service_spec.rb +2 -0
- data/spec/services/payments_service_spec.rb +2 -0
- data/spec/services/payouts_service_spec.rb +2 -0
- data/spec/services/refunds_service_spec.rb +2 -0
- data/spec/services/subscriptions_service_spec.rb +26 -24
- metadata +17 -8
- data/lib/gocardless_pro/services/helpers_service.rb +0 -99
- data/spec/services/helpers_service_spec.rb +0 -122
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0679426d50fd7a646344adfbe02b150edec3f19a
|
4
|
+
data.tar.gz: 326eb4aba24167005218f2cc4b3cdc787afaef11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 107065812a3eb12360a3dc8e10b3920f04886277fb9671079b224d70489a7373773691170ce46401660679b2b2b43c04cc59279e59ee1d4665684d30c58b365d
|
7
|
+
data.tar.gz: 03ead3f29fe550c6b33883f53bbeb2d6dcdc0d8ec6795462c4d6d7aa3aafc7019c13159c430ac4904672b93e107dbbb23628f4317fc2da2d01a0566c09f92cea
|
data/README.md
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
# Ruby Client for GoCardless Pro API
|
2
2
|
|
3
|
-
- [YARD Docs](http://gocardless.github.io/pro-client-ruby/)
|
4
3
|
- [GoCardless Pro API Docs](https://developer.gocardless.com/pro/)
|
5
4
|
- [RubyGems](https://rubygems.org/gems/gocardless_pro)
|
6
5
|
|
7
|
-
This client is still in beta and is subject to change. Until a stable major version is released you should expect breaking changes.
|
8
|
-
|
9
6
|
Add this line to your application's Gemfile:
|
10
7
|
|
11
8
|
```ruby
|
@@ -21,17 +18,17 @@ require 'gocardless_pro'
|
|
21
18
|
## Usage Examples
|
22
19
|
|
23
20
|
- In the case of a single response, the client will return you an instance of the resource
|
24
|
-
- In the case of list responses, the client will return an instance of `ListResponse
|
21
|
+
- In the case of list responses, the client will return an instance of `ListResponse`.
|
25
22
|
- You can also call `#all` to get a lazily paginated list of resource that will deal with making extra API requests to paginate through all the data
|
26
23
|
|
27
24
|
### Initialising the client
|
28
25
|
|
29
26
|
The client is initialised with an Access Token.
|
30
|
-
You can also pass in `environment` as `:sandbox` to make requests to the sandbox environment rather than
|
27
|
+
You can also pass in `environment` as `:sandbox` to make requests to the sandbox environment rather than production.
|
31
28
|
|
32
29
|
```rb
|
33
30
|
@client = GoCardlessPro::Client.new(
|
34
|
-
|
31
|
+
access_token: ENV["GOCARDLESS_TOKEN"]
|
35
32
|
)
|
36
33
|
```
|
37
34
|
|
@@ -71,6 +68,12 @@ As with list, the last argument can be an options hash, with any URL parameters
|
|
71
68
|
@client.customers.get(customers_id, params: { limit: 200 })
|
72
69
|
```
|
73
70
|
|
71
|
+
Both individual resource and `ListResponse` instances provide an `api_response` method, which lets you access the following properties of the request:
|
72
|
+
|
73
|
+
- `status`
|
74
|
+
- `headers`
|
75
|
+
- `body`
|
76
|
+
|
74
77
|
### POST/PUT Requests
|
75
78
|
|
76
79
|
For POST and PUT requests you need to pass in the body in under the `params` key:
|
@@ -91,32 +94,14 @@ As with GET requests, if any parameters are required they come first:
|
|
91
94
|
@client.customers.update(customer_id, {...})
|
92
95
|
```
|
93
96
|
|
94
|
-
### Custom Headers
|
95
|
-
|
96
|
-
If you need to pass in a custom header to an endpoint, you can pass in a `headers` object to the options hash:
|
97
|
-
|
98
|
-
```rb
|
99
|
-
@client.helpers.mandate({
|
100
|
-
params: {
|
101
|
-
account_number: 200000,
|
102
|
-
...
|
103
|
-
},
|
104
|
-
headers: {
|
105
|
-
'Accept': 'application/pdf'
|
106
|
-
}
|
107
|
-
})
|
108
|
-
```
|
109
|
-
|
110
|
-
There are very few endpoints in the API that require custom headers. Currently, the only ones that do are [helpers](https://developer.gocardless.com/pro/#api-endpoints-helpers).
|
111
|
-
|
112
97
|
### Handling failures
|
113
98
|
|
114
|
-
When an API returns an error, the client __will raise__ an error that corresponds to the type of error. All errors subclass `
|
99
|
+
When an API returns an error, the client __will raise__ an error that corresponds to the type of error. All errors subclass `GoCardlessPro::Error`. There are four errors that could be thrown:
|
115
100
|
|
116
|
-
- `
|
117
|
-
- `
|
118
|
-
- `
|
119
|
-
- `
|
101
|
+
- `GoCardlessPro::GoCardlessError`
|
102
|
+
- `GoCardlessPro::InvalidApiUsageError`
|
103
|
+
- `GoCardlessPro::InvalidStateError`
|
104
|
+
- `GoCardlessPro::ValidationError`
|
120
105
|
|
121
106
|
These errors are fully documented in the [API documentation](https://developer.gocardless.com/pro/#overview-errors).
|
122
107
|
|
data/lib/gocardless_pro.rb
CHANGED
@@ -33,6 +33,10 @@ require_relative 'gocardless_pro/error/invalid_state_error'
|
|
33
33
|
require_relative 'gocardless_pro/paginator'
|
34
34
|
require_relative 'gocardless_pro/request'
|
35
35
|
require_relative 'gocardless_pro/response'
|
36
|
+
require_relative 'gocardless_pro/api_response'
|
37
|
+
|
38
|
+
require_relative 'gocardless_pro/resources/bank_details_lookup'
|
39
|
+
require_relative 'gocardless_pro/services/bank_details_lookups_service'
|
36
40
|
|
37
41
|
require_relative 'gocardless_pro/resources/creditor'
|
38
42
|
require_relative 'gocardless_pro/services/creditors_service'
|
@@ -49,12 +53,12 @@ require_relative 'gocardless_pro/services/customer_bank_accounts_service'
|
|
49
53
|
require_relative 'gocardless_pro/resources/event'
|
50
54
|
require_relative 'gocardless_pro/services/events_service'
|
51
55
|
|
52
|
-
require_relative 'gocardless_pro/resources/helper'
|
53
|
-
require_relative 'gocardless_pro/services/helpers_service'
|
54
|
-
|
55
56
|
require_relative 'gocardless_pro/resources/mandate'
|
56
57
|
require_relative 'gocardless_pro/services/mandates_service'
|
57
58
|
|
59
|
+
require_relative 'gocardless_pro/resources/mandate_pdf'
|
60
|
+
require_relative 'gocardless_pro/services/mandate_pdfs_service'
|
61
|
+
|
58
62
|
require_relative 'gocardless_pro/resources/payment'
|
59
63
|
require_relative 'gocardless_pro/services/payments_service'
|
60
64
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module GoCardlessPro
|
2
|
+
# wraps a faraday response object with some accessors
|
3
|
+
class ApiResponse
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@response = response
|
8
|
+
end
|
9
|
+
|
10
|
+
def_delegator :@response, :headers
|
11
|
+
def_delegator :@response, :body
|
12
|
+
def_delegator :@response, :status_code
|
13
|
+
end
|
14
|
+
end
|
@@ -3,6 +3,11 @@ module GoCardlessPro
|
|
3
3
|
class Client
|
4
4
|
extend Forwardable
|
5
5
|
|
6
|
+
# Access to the service for bank_details_lookup to make API calls
|
7
|
+
def bank_details_lookups
|
8
|
+
@bank_details_lookups ||= Services::BankDetailsLookupsService.new(@api_service)
|
9
|
+
end
|
10
|
+
|
6
11
|
# Access to the service for creditor to make API calls
|
7
12
|
def creditors
|
8
13
|
@creditors ||= Services::CreditorsService.new(@api_service)
|
@@ -28,16 +33,16 @@ module GoCardlessPro
|
|
28
33
|
@events ||= Services::EventsService.new(@api_service)
|
29
34
|
end
|
30
35
|
|
31
|
-
# Access to the service for helper to make API calls
|
32
|
-
def helpers
|
33
|
-
@helpers ||= Services::HelpersService.new(@api_service)
|
34
|
-
end
|
35
|
-
|
36
36
|
# Access to the service for mandate to make API calls
|
37
37
|
def mandates
|
38
38
|
@mandates ||= Services::MandatesService.new(@api_service)
|
39
39
|
end
|
40
40
|
|
41
|
+
# Access to the service for mandate_pdf to make API calls
|
42
|
+
def mandate_pdfs
|
43
|
+
@mandate_pdfs ||= Services::MandatePdfsService.new(@api_service)
|
44
|
+
end
|
45
|
+
|
41
46
|
# Access to the service for payment to make API calls
|
42
47
|
def payments
|
43
48
|
@payments ||= Services::PaymentsService.new(@api_service)
|
@@ -108,7 +113,7 @@ module GoCardlessPro
|
|
108
113
|
def default_options
|
109
114
|
{
|
110
115
|
default_headers: {
|
111
|
-
'GoCardless-Version' => '2015-
|
116
|
+
'GoCardless-Version' => '2015-07-06',
|
112
117
|
'User-Agent' => "#{user_agent}",
|
113
118
|
'Content-Type' => 'application/json'
|
114
119
|
}
|
@@ -121,14 +126,21 @@ module GoCardlessPro
|
|
121
126
|
gem_name = 'gocardless_pro'
|
122
127
|
gem_info = "#{gem_name}"
|
123
128
|
gem_info += "/v#{ GoCardlessPro::VERSION}" if defined?(GoCardlessPro::VERSION)
|
129
|
+
|
124
130
|
ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
|
131
|
+
|
125
132
|
ruby_version = RUBY_VERSION
|
126
|
-
ruby_version += "
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
comment
|
131
|
-
|
133
|
+
ruby_version += "p#{RUBY_PATCHLEVEL}" if defined?(RUBY_PATCHLEVEL)
|
134
|
+
|
135
|
+
interpreter_version = defined?(JRUBY_VERSION) ? JRUBY_VERSION : RUBY_VERSION
|
136
|
+
|
137
|
+
comment = [
|
138
|
+
"#{ruby_engine}/#{ruby_version}",
|
139
|
+
"#{RUBY_ENGINE}/#{interpreter_version}",
|
140
|
+
"#{RUBY_PLATFORM}"
|
141
|
+
]
|
142
|
+
comment << "faraday/#{Faraday::VERSION}"
|
143
|
+
"#{gem_info} #{comment.join(' ')}"
|
132
144
|
end
|
133
145
|
end
|
134
146
|
end
|
@@ -9,21 +9,25 @@ module GoCardlessPro
|
|
9
9
|
# @option option :resource_class the class for the resource returned by the API
|
10
10
|
# @option option :unenveloped_body the parsed response from the API
|
11
11
|
def initialize(options = {})
|
12
|
-
@
|
12
|
+
@response = options.fetch(:response)
|
13
13
|
@resource_class = options.fetch(:resource_class)
|
14
14
|
@unenveloped_body = options.fetch(:unenveloped_body)
|
15
15
|
|
16
16
|
@records = @unenveloped_body.map { |item| @resource_class.new(item) }
|
17
17
|
end
|
18
18
|
|
19
|
+
def api_response
|
20
|
+
@api_response ||= ApiResponse.new(@response)
|
21
|
+
end
|
22
|
+
|
19
23
|
# return the before cursor for paginating
|
20
24
|
def before
|
21
|
-
@
|
25
|
+
@response.body['meta']['cursors']['before']
|
22
26
|
end
|
23
27
|
|
24
28
|
# return the after cursor for paginating
|
25
29
|
def after
|
26
|
-
@
|
30
|
+
@response.body['meta']['cursors']['after']
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
@@ -42,10 +42,10 @@ module GoCardlessPro
|
|
42
42
|
def request_body
|
43
43
|
if @method == :get
|
44
44
|
nil
|
45
|
-
elsif
|
45
|
+
elsif [:post, :put, :delete].include?(@method)
|
46
46
|
@given_options.fetch(:params, {})
|
47
47
|
else
|
48
|
-
fail "
|
48
|
+
fail "Unknown request method #{@method}"
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -53,17 +53,9 @@ module GoCardlessPro
|
|
53
53
|
def request_query
|
54
54
|
if @method == :get
|
55
55
|
@given_options.fetch(:params, {})
|
56
|
-
elsif @method == :post || @method == :put
|
57
|
-
{}
|
58
56
|
else
|
59
|
-
|
57
|
+
{}
|
60
58
|
end
|
61
59
|
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def options
|
66
|
-
{ headers: @headers, body: @body, query: @query }
|
67
|
-
end
|
68
60
|
end
|
69
61
|
end
|
@@ -11,13 +11,24 @@ require 'uri'
|
|
11
11
|
module GoCardlessPro
|
12
12
|
# A module containing classes for each of the resources in the GC Api
|
13
13
|
module Resources
|
14
|
-
#
|
15
|
-
# Represents an instance of a
|
16
|
-
class
|
14
|
+
# Look up the name and reachability of a bank.
|
15
|
+
# Represents an instance of a bank_details_lookup resource returned from the API
|
16
|
+
class BankDetailsLookup
|
17
|
+
attr_reader :available_debit_schemes
|
18
|
+
|
19
|
+
attr_reader :bank_name
|
17
20
|
# initialize a resource instance
|
18
21
|
# @param object [Hash] an object returned from the API
|
19
|
-
def initialize(object)
|
22
|
+
def initialize(object, response = nil)
|
20
23
|
@object = object
|
24
|
+
|
25
|
+
@available_debit_schemes = object['available_debit_schemes']
|
26
|
+
@bank_name = object['bank_name']
|
27
|
+
@response = response
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_response
|
31
|
+
ApiResponse.new(@response)
|
21
32
|
end
|
22
33
|
|
23
34
|
# Provides the resource as a hash of all it's readable attributes
|
@@ -11,16 +11,14 @@ require 'uri'
|
|
11
11
|
module GoCardlessPro
|
12
12
|
# A module containing classes for each of the resources in the GC Api
|
13
13
|
module Resources
|
14
|
-
# Each
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# the API also supports collecting payments on behalf of others.
|
14
|
+
# Each [payment](#core-endpoints-payments) taken through the API is linked to
|
15
|
+
# a "creditor", to whom the payment is then paid out. In most cases your
|
16
|
+
# organisation will have a single "creditor", but the API also supports
|
17
|
+
# collecting payments on behalf of others.
|
19
18
|
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# your organisation.
|
19
|
+
# Please get in touch if you
|
20
|
+
# wish to use this endpoint. Currently, for Anti Money Laundering reasons, any
|
21
|
+
# creditors you add must be directly related to your organisation.
|
24
22
|
# Represents an instance of a creditor resource returned from the API
|
25
23
|
class Creditor
|
26
24
|
attr_reader :address_line1
|
@@ -44,7 +42,7 @@ module GoCardlessPro
|
|
44
42
|
attr_reader :region
|
45
43
|
# initialize a resource instance
|
46
44
|
# @param object [Hash] an object returned from the API
|
47
|
-
def initialize(object)
|
45
|
+
def initialize(object, response = nil)
|
48
46
|
@object = object
|
49
47
|
|
50
48
|
@address_line1 = object['address_line1']
|
@@ -58,6 +56,11 @@ module GoCardlessPro
|
|
58
56
|
@name = object['name']
|
59
57
|
@postal_code = object['postal_code']
|
60
58
|
@region = object['region']
|
59
|
+
@response = response
|
60
|
+
end
|
61
|
+
|
62
|
+
def api_response
|
63
|
+
ApiResponse.new(@response)
|
61
64
|
end
|
62
65
|
|
63
66
|
# return the links that the resource has
|
@@ -67,9 +70,7 @@ module GoCardlessPro
|
|
67
70
|
|
68
71
|
default_eur_payout_account: '',
|
69
72
|
|
70
|
-
default_gbp_payout_account: ''
|
71
|
-
|
72
|
-
logo: ''
|
73
|
+
default_gbp_payout_account: ''
|
73
74
|
|
74
75
|
}.keys.sort
|
75
76
|
).new(*@links.sort.map(&:last))
|
@@ -12,16 +12,15 @@ module GoCardlessPro
|
|
12
12
|
# A module containing classes for each of the resources in the GC Api
|
13
13
|
module Resources
|
14
14
|
# Creditor Bank Accounts hold the bank details of a
|
15
|
-
# [creditor](
|
16
|
-
#
|
17
|
-
# [payouts](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-payouts)
|
18
|
-
# will be sent to.
|
15
|
+
# [creditor](#core-endpoints-creditor). These are the bank accounts which your
|
16
|
+
# [payouts](#core-endpoints-payouts) will be sent to.
|
19
17
|
#
|
20
|
-
# Note that
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# existing record instead, the ID
|
24
|
-
# `links[creditor_bank_account]` in the error
|
18
|
+
# Note that
|
19
|
+
# creditor bank accounts must be unique, and so you will encounter a
|
20
|
+
# `bank_account_exists` error if you try to create a duplicate bank account.
|
21
|
+
# You may wish to handle this by updating the existing record instead, the ID
|
22
|
+
# of which will be provided as `links[creditor_bank_account]` in the error
|
23
|
+
# response.
|
25
24
|
# Represents an instance of a creditor_bank_account resource returned from the API
|
26
25
|
class CreditorBankAccount
|
27
26
|
attr_reader :account_holder_name
|
@@ -43,7 +42,7 @@ module GoCardlessPro
|
|
43
42
|
attr_reader :metadata
|
44
43
|
# initialize a resource instance
|
45
44
|
# @param object [Hash] an object returned from the API
|
46
|
-
def initialize(object)
|
45
|
+
def initialize(object, response = nil)
|
47
46
|
@object = object
|
48
47
|
|
49
48
|
@account_holder_name = object['account_holder_name']
|
@@ -56,6 +55,11 @@ module GoCardlessPro
|
|
56
55
|
@id = object['id']
|
57
56
|
@links = object['links']
|
58
57
|
@metadata = object['metadata']
|
58
|
+
@response = response
|
59
|
+
end
|
60
|
+
|
61
|
+
def api_response
|
62
|
+
ApiResponse.new(@response)
|
59
63
|
end
|
60
64
|
|
61
65
|
# return the links that the resource has
|
@@ -13,9 +13,8 @@ module GoCardlessPro
|
|
13
13
|
module Resources
|
14
14
|
# Customer objects hold the contact details for a customer. A customer can
|
15
15
|
# have several [customer bank
|
16
|
-
# accounts](
|
17
|
-
#
|
18
|
-
# [mandates](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-mandates).
|
16
|
+
# accounts](#core-endpoints-customer-bank-accounts), which in turn can have
|
17
|
+
# several Direct Debit [mandates](#core-endpoints-mandates).
|
19
18
|
# Represents an instance of a customer resource returned from the API
|
20
19
|
class Customer
|
21
20
|
attr_reader :address_line1
|
@@ -47,7 +46,7 @@ module GoCardlessPro
|
|
47
46
|
attr_reader :region
|
48
47
|
# initialize a resource instance
|
49
48
|
# @param object [Hash] an object returned from the API
|
50
|
-
def initialize(object)
|
49
|
+
def initialize(object, response = nil)
|
51
50
|
@object = object
|
52
51
|
|
53
52
|
@address_line1 = object['address_line1']
|
@@ -64,6 +63,11 @@ module GoCardlessPro
|
|
64
63
|
@metadata = object['metadata']
|
65
64
|
@postal_code = object['postal_code']
|
66
65
|
@region = object['region']
|
66
|
+
@response = response
|
67
|
+
end
|
68
|
+
|
69
|
+
def api_response
|
70
|
+
ApiResponse.new(@response)
|
67
71
|
end
|
68
72
|
|
69
73
|
# Provides the resource as a hash of all it's readable attributes
|
@@ -12,18 +12,15 @@ module GoCardlessPro
|
|
12
12
|
# A module containing classes for each of the resources in the GC Api
|
13
13
|
module Resources
|
14
14
|
# Customer Bank Accounts hold the bank details of a
|
15
|
-
# [customer](
|
16
|
-
#
|
17
|
-
# [
|
18
|
-
#
|
19
|
-
#
|
20
|
-
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# bank account. You may wish to handle this by updating the existing record
|
25
|
-
# instead, the ID of which will be provided as links[customer_bank_account] in
|
26
|
-
# the error response.
|
15
|
+
# [customer](#core-endpoints-customers). They always belong to a
|
16
|
+
# [customer](#core-endpoints-customers), and may be linked to several Direct
|
17
|
+
# Debit [mandates](#core-endpoints-mandates).
|
18
|
+
#
|
19
|
+
# Note that customer bank
|
20
|
+
# accounts must be unique, and so you will encounter a `bank_account_exists`
|
21
|
+
# error if you try to create a duplicate bank account. You may wish to handle
|
22
|
+
# this by updating the existing record instead, the ID of which will be
|
23
|
+
# provided as links[customer_bank_account] in the error response.
|
27
24
|
# Represents an instance of a customer_bank_account resource returned from the API
|
28
25
|
class CustomerBankAccount
|
29
26
|
attr_reader :account_holder_name
|
@@ -45,7 +42,7 @@ module GoCardlessPro
|
|
45
42
|
attr_reader :metadata
|
46
43
|
# initialize a resource instance
|
47
44
|
# @param object [Hash] an object returned from the API
|
48
|
-
def initialize(object)
|
45
|
+
def initialize(object, response = nil)
|
49
46
|
@object = object
|
50
47
|
|
51
48
|
@account_holder_name = object['account_holder_name']
|
@@ -58,6 +55,11 @@ module GoCardlessPro
|
|
58
55
|
@id = object['id']
|
59
56
|
@links = object['links']
|
60
57
|
@metadata = object['metadata']
|
58
|
+
@response = response
|
59
|
+
end
|
60
|
+
|
61
|
+
def api_response
|
62
|
+
ApiResponse.new(@response)
|
61
63
|
end
|
62
64
|
|
63
65
|
# return the links that the resource has
|