class GoCardlessPro::Services::BankAuthorisationsService
Service for making requests to the BankAuthorisation endpoints
Public Instance Methods
create(options = {})
click to toggle source
Create a Bank Authorisation. Example URL: /bank_authorisations @param options [Hash] parameters as a hash, under a params key.
# File lib/gocardless_pro/services/bank_authorisations_service.rb, line 33 def create(options = {}) path = '/bank_authorisations' params = options.delete(:params) || {} options[:params] = {} options[:params][envelope_key] = params options[:retry_failures] = true begin response = make_request(:post, path, options) # Response doesn't raise any errors until #body is called response.tap(&:body) rescue InvalidStateError => e if e.idempotent_creation_conflict? case @api_service.on_idempotency_conflict when :raise raise IdempotencyConflict, e.error when :fetch return get(e.conflicting_resource_id) end end raise e end return if response.body.nil? Resources::BankAuthorisation.new(unenvelope_body(response.body), response) end
get(identity, options = {})
click to toggle source
Fetches a bank authorisation Example URL: /bank_authorisations/:identity
@param identity # Unique identifier, beginning with “BAU”. @param options [Hash] parameters as a hash, under a params key.
# File lib/gocardless_pro/services/bank_authorisations_service.rb, line 18 def get(identity, options = {}) path = sub_url('/bank_authorisations/:identity', 'identity' => identity) options[:retry_failures] = true response = make_request(:get, path, options) return if response.body.nil? Resources::BankAuthorisation.new(unenvelope_body(response.body), response) end
Private Instance Methods
envelope_key()
click to toggle source
return the key which API responses will envelope data under
# File lib/gocardless_pro/services/bank_authorisations_service.rb, line 75 def envelope_key 'bank_authorisations' end
unenvelope_body(body)
click to toggle source
Unenvelope the response of the body using the service's `envelope_key`
@param body [Hash]
# File lib/gocardless_pro/services/bank_authorisations_service.rb, line 70 def unenvelope_body(body) body[envelope_key] || body['data'] end