Class: Besepa::BankAccount

Inherits:
Resource show all
Includes:
ApiCalls::Create, ApiCalls::Destroy, ApiCalls::List, ApiCalls::Search, ApiCalls::Update
Defined in:
lib/besepa/bank_account.rb

Constant Summary collapse

FIELDS =
[:id, :iban, :bic, :bank_name, :status, :created_at, :customer_id]

Constants inherited from Resource

Resource::ALLOWED_NILS

Constants included from Utils::Request

Utils::Request::END_POINT_URL_PREFIX

Instance Attribute Summary collapse

Attributes inherited from Resource

#activities

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiCalls::Destroy

#destroy

Methods included from ApiCalls::Update

#save

Methods included from ApiCalls::Create

included

Methods included from ApiCalls::Search

included

Methods included from ApiCalls::List

included

Methods inherited from Resource

#allowed_nils, #as_json, handle_errors, #initialize, #klass_name, #serializable_hash

Methods included from Utils::Request

#delete, #get, #post, #put

Methods included from Utils::Connection

#connection

Constructor Details

This class inherits a constructor from Besepa::Resource

Instance Attribute Details

#customerObject

Returns the value of attribute customer.



16
17
18
# File 'lib/besepa/bank_account.rb', line 16

def customer
  @customer
end

#mandateObject

Returns the value of attribute mandate.



16
17
18
# File 'lib/besepa/bank_account.rb', line 16

def mandate
  @mandate
end

Class Method Details

.klass_nameObject



18
19
20
# File 'lib/besepa/bank_account.rb', line 18

def self.klass_name
  "bank_account"
end

Instance Method Details

#generate_signature_requestObject



47
48
49
50
51
# File 'lib/besepa/bank_account.rb', line 47

def generate_signature_request
  response = put "/#{api_path({customer_id: customer_id})}/generate_signature_request"
  process_attributes(response['response'])
  self
end

#replace(iban, bic, bank_name = nil, signature_type = nil, phone_number = nil, redirect_after_signature = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/besepa/bank_account.rb', line 28

def replace(iban, bic, bank_name=nil, signature_type=nil, phone_number=nil, redirect_after_signature=nil)
  payload = {}
  payload[self.class.klass_name] = {
    iban: iban,
    bic: bic,
    bank_name: bank_name,
  }
  if !signature_type.nil?
    payload[self.class.klass_name][:mandate] = {
      signature_type: signature_type,
      phone_number: phone_number,
      redirect_after_signature: redirect_after_signature,
    }
  end
  response = post "/#{api_path({customer_id: customer_id})}/replace", payload
  process_attributes(response['response'])
  self
end

#set_as_defaultObject



22
23
24
25
26
# File 'lib/besepa/bank_account.rb', line 22

def set_as_default
  response = put "/#{api_path({customer_id: customer_id})}/set_as_default"
  process_attributes(response['response'])
  self
end

#statsObject



63
64
65
66
# File 'lib/besepa/bank_account.rb', line 63

def stats
  response = get "#{api_path}/stats"
  response['response']
end

#to_hashObject



53
54
55
56
57
58
59
60
61
# File 'lib/besepa/bank_account.rb', line 53

def to_hash
  values = {}
  self.class::FIELDS.each do |key|
    values[key] = self.send("#{key.to_s}")
  end
  values[:mandate] = mandate.to_hash if mandate
  values[:customer] = customer.to_hash if customer
  values
end