Class: Centralpos::Account

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/centralpos/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#ensure_array, #in_time_zone, #inspect

Constructor Details

#initialize(username, password, mode = :sandbox) ⇒ Account

Returns a new instance of Account.



25
26
27
28
29
# File 'lib/centralpos/account.rb', line 25

def initialize(username, password, mode = :sandbox)
  @username = username
  @gateway = Centralpos::Core::Gateway.new(username, password, mode)
  self
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



23
24
25
# File 'lib/centralpos/account.rb', line 23

def error
  @error
end

#gatewayObject (readonly)

Returns the value of attribute gateway.



23
24
25
# File 'lib/centralpos/account.rb', line 23

def gateway
  @gateway
end

#usernameObject (readonly)

Returns the value of attribute username.



23
24
25
# File 'lib/centralpos/account.rb', line 23

def username
  @username
end

Instance Method Details

#batch(id) ⇒ Object



73
74
75
# File 'lib/centralpos/account.rb', line 73

def batch(id)
  Centralpos::Batch.new({id: id}.merge(account: self))
end

#enabled_cardsObject



55
56
57
# File 'lib/centralpos/account.rb', line 55

def enabled_cards
  @enabled_cards ||= @gateway.call(:list_tarjetas_habilitadas)
end

#liveObject



40
41
42
43
# File 'lib/centralpos/account.rb', line 40

def live
  @enabled_cards = nil
  @gateway.live
end

#live?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/centralpos/account.rb', line 45

def live?
  !sandbox?
end

#open_batchesObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/centralpos/account.rb', line 59

def open_batches
  response = @gateway.call(:get_presentaciones_abiertas)
  if response[:success] && response[:error].nil?
    return [] unless response[:result][:lista_presentaciones]

    batches = ensure_array(response[:result][:lista_presentaciones][:presentacion])
    batches.map do |batch_data|
      Centralpos::Batch.new(batch_data.merge(account: self))
    end
  else
    response
  end
end

#past_batchesObject



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/centralpos/account.rb', line 77

def past_batches
  response = @gateway.call(:get_estado_presentaciones)
  if response[:success] && response[:error].nil?
    return [] unless response[:result][:lista_presentaciones]

    batches = ensure_array(response[:result][:lista_presentaciones][:presentacion_procesada])
    batches.map do |batch_data|
      Centralpos::Batch.new(batch_data.merge(account: self))
    end
  else
    response
  end
end

#sandboxObject



31
32
33
34
# File 'lib/centralpos/account.rb', line 31

def sandbox
  @enabled_cards = nil
  @gateway.sandbox
end

#sandbox?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/centralpos/account.rb', line 36

def sandbox?
  @gateway.mode == :sandbox
end

#valid?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/centralpos/account.rb', line 49

def valid?
  response = enabled_cards
  @error = response[:error]
  @error.nil?
end