class GoCardless::Services::CustomerBankAccountService
Service for making requests to the CustomerBankAccount endpoints
Public Instance Methods
Get a lazily enumerated list of all the items returned. This is simmilar to the ‘list` method but will paginate for you automatically.
@param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Otherwise they will be the body of the request.
# File lib/gocardless-pro/services/customer_bank_account_service.rb, line 65 def all(options = {}) Paginator.new( service: self, path: '/customer_bank_accounts', options: options ).enumerator end
Creates a new bank account object associated to a customer id.
There are three different ways to supply bank account details:
-
[Local
details](developer.gocardless.com/pro/#ui-compliance-local-bank-details)
-
IBAN
-
[Customer Bank Account
Tokens](developer.gocardless.com/pro/#js-flow-create-a-customer-bank-account-token)
For more information on the different fields required in each country, see [local bank details](developer.gocardless.com/pro/#ui-compliance-local-bank-details). Example URL: /customer_bank_accounts @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.
# File lib/gocardless-pro/services/customer_bank_account_service.rb, line 34 def create(options = {}, custom_headers = {}) path = '/customer_bank_accounts' new_options = {} new_options[envelope_key] = options options = new_options response = make_request(:post, path, options, custom_headers) Resources::CustomerBankAccount.new(unenvelope_body(response.body)) end
Immediately cancels all associated mandates and cancellable payments.
This will return a ‘disable_failed` error if the bank account has already been disabled.
A disabled bank account can be re-enabled by creating a new bank account resource with the same details. Example URL: /customer_bank_accounts/:identity/actions/disable
@param identity # Unique identifier, beginning with “BA” @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.
# File lib/gocardless-pro/services/customer_bank_account_service.rb, line 118 def disable(identity, options = {}, custom_headers = {}) path = sub_url('/customer_bank_accounts/:identity/actions/disable', 'identity' => identity) new_options = {} new_options['data'] = options options = new_options response = make_request(:post, path, options, custom_headers) Resources::CustomerBankAccount.new(unenvelope_body(response.body)) end
Retrieves the details of an existing bank account. Example URL: /customer_bank_accounts/:identity
@param identity # Unique identifier, beginning with “BA” @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.
# File lib/gocardless-pro/services/customer_bank_account_service.rb, line 79 def get(identity, options = {}, custom_headers = {}) path = sub_url('/customer_bank_accounts/:identity', 'identity' => identity) response = make_request(:get, path, options, custom_headers) Resources::CustomerBankAccount.new(unenvelope_body(response.body)) end
Returns a [cursor-paginated](developer.gocardless.com/pro/#overview-cursor-pagination) list of your bank accounts. Example URL: /customer_bank_accounts @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.
# File lib/gocardless-pro/services/customer_bank_account_service.rb, line 50 def list(options = {}, custom_headers = {}) path = '/customer_bank_accounts' response = make_request(:get, path, options, custom_headers) ListResponse.new( raw_response: response, unenveloped_body: unenvelope_body(response.body), resource_class: Resources::CustomerBankAccount ) end
Unenvelope the response of the body using the service’s ‘envelope_key`
@param body [Hash]
# File lib/gocardless-pro/services/customer_bank_account_service.rb, line 132 def unenvelope_body(body) body[envelope_key] || body['data'] end
Updates a customer bank account object. Only the metadata parameter is allowed. Example URL: /customer_bank_accounts/:identity
@param identity # Unique identifier, beginning with “BA” @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters. Else, they will be the body of the request.
# File lib/gocardless-pro/services/customer_bank_account_service.rb, line 94 def update(identity, options = {}, custom_headers = {}) path = sub_url('/customer_bank_accounts/:identity', 'identity' => identity) new_options = {} new_options[envelope_key] = options options = new_options response = make_request(:put, path, options, custom_headers) Resources::CustomerBankAccount.new(unenvelope_body(response.body)) end
Private Instance Methods
return the key which API responses will envelope data under
# File lib/gocardless-pro/services/customer_bank_account_service.rb, line 139 def envelope_key 'customer_bank_accounts' end
take a URL with placeholder params and substitute them out for the acutal value @param url [String] the URL with placeholders in @param param_map [Hash] a hash of placeholders and their actual values
# File lib/gocardless-pro/services/customer_bank_account_service.rb, line 146 def sub_url(url, param_map) param_map.reduce(url) do |new_url, (param, value)| new_url.gsub(":#{param}", value) end end