Class: Akatus::Payer

Inherits:
Object
  • Object
show all
Includes:
Transferrable
Defined in:
lib/akatus/payer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Transferrable

included, #initialize

Instance Attribute Details

#addressesObject

Returns the value of attribute addresses.



6
7
8
# File 'lib/akatus/payer.rb', line 6

def addresses
  @addresses
end

#phonesObject

Returns the value of attribute phones.



6
7
8
# File 'lib/akatus/payer.rb', line 6

def phones
  @phones
end

Instance Method Details

#addressObject



12
13
14
# File 'lib/akatus/payer.rb', line 12

def address
  addresses[0] if addresses
end

#address=(val) ⇒ Object



8
9
10
# File 'lib/akatus/payer.rb', line 8

def address=(val)
  addresses ? addresses.unshift(val) : (@addresses = [val])
end

#phoneObject



20
21
22
# File 'lib/akatus/payer.rb', line 20

def phone
  phones[0] if phones
end

#phone=(val) ⇒ Object



16
17
18
# File 'lib/akatus/payer.rb', line 16

def phone=(val)
  phones ? phones.unshift(val) : (@phones = [val])
end

#to_payload(include_root = true) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/akatus/payer.rb', line 24

def to_payload(include_root = true)
  payload = super(true)

  # Tweak Akatus' weird array format.
  payload['pagador']['enderecos'] = { 'endereco' => addresses.map { |a| a.to_payload(false) } }
  payload['pagador']['telefones'] = { 'telefone' => phones.map { |p| p.to_payload(false) } }

  include_root ? payload : payload.values.first
end