Class: FidorApi::Beneficiary::Base

Inherits:
Connectivity::Resource show all
Defined in:
lib/fidor_api/beneficiary/base.rb

Direct Known Subclasses

ACH, P2pAccountNumber, P2pPhone, P2pUsername, Swift, Unknown, Utility

Constant Summary collapse

ROUTING_INFO_ERROR_PREFIX =
"routing_info.".freeze

Instance Attribute Summary collapse

Attributes inherited from Connectivity::Resource

#error_keys

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Connectivity::Resource

all, find, #initialize, model_name, #persisted?, #reload, #update_attributes

Constructor Details

This class inherits a constructor from FidorApi::Connectivity::Resource

Instance Attribute Details

#confirmable_actionObject

Returns the value of attribute confirmable_action.



8
9
10
# File 'lib/fidor_api/beneficiary/base.rb', line 8

def confirmable_action
  @confirmable_action
end

Class Method Details

.delete(id) ⇒ Object



19
20
21
22
# File 'lib/fidor_api/beneficiary/base.rb', line 19

def delete(id)
  endpoint.for(new(id: id)).delete
  true
end

.new(hash = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/fidor_api/beneficiary/base.rb', line 11

def new(hash={})
  if self == Base
    class_for_response_hash(hash).new hash
  else
    super
  end
end

Instance Method Details

#as_jsonObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fidor_api/beneficiary/base.rb', line 58

def as_json
  {
    account_id:  ,
    unique_name: unique_name,
    contact: {
      name:           contact_name,
      address_line_1: contact_address_line_1,
      address_line_2: contact_address_line_2,
      city:           contact_city,
      country:        contact_country
    }.compact,
    bank: {
      name:           bank_name,
      address_line_1: bank_address_line_1,
      address_line_2: bank_address_line_2,
      city:           bank_city,
      country:        bank_country
    }.compact,
    routing_type: as_json_routing_type,
    routing_info: as_json_routing_info
  }.compact
end

#saveObject



53
54
55
56
# File 'lib/fidor_api/beneficiary/base.rb', line 53

def save
  fail InvalidRecordError unless valid?
  super
end

#set_attributes(attrs = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fidor_api/beneficiary/base.rb', line 37

def set_attributes(attrs = {})
  self.contact_name           = attrs.fetch("contact", {})["name"]
  self.contact_address_line_1 = attrs.fetch("contact", {})["address_line_1"]
  self.contact_address_line_2 = attrs.fetch("contact", {})["address_line_2"]
  self.contact_city           = attrs.fetch("contact", {})["city"]
  self.contact_country        = attrs.fetch("contact", {})["country"]

  self.bank_name              = attrs.fetch("bank",    {})["name"]
  self.bank_address_line_1    = attrs.fetch("bank",    {})["address_line_1"]
  self.bank_address_line_2    = attrs.fetch("bank",    {})["address_line_2"]
  self.bank_city              = attrs.fetch("bank",    {})["city"]
  self.bank_country           = attrs.fetch("bank",    {})["country"]

  super(attrs.except("contact", "bank", "routing_type", "routing_info"))
end