class Centralpos::Account

Attributes

error[R]
gateway[R]
username[R]

Public Class Methods

new(username, password, mode = :sandbox) click to toggle source
# 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

Public Instance Methods

batch(id) click to toggle source
# File lib/centralpos/account.rb, line 73
def batch(id)
  Centralpos::Batch.new({id: id}.merge(account: self))
end
enabled_cards() click to toggle source
# File lib/centralpos/account.rb, line 55
def enabled_cards
  @enabled_cards ||= @gateway.call(:list_tarjetas_habilitadas)
end
live() click to toggle source
# File lib/centralpos/account.rb, line 40
def live
  @enabled_cards = nil
  @gateway.live
end
live?() click to toggle source
# File lib/centralpos/account.rb, line 45
def live?
  !sandbox?
end
open_batches() click to toggle source
# 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_batches() click to toggle source
# 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
sandbox() click to toggle source
# File lib/centralpos/account.rb, line 31
def sandbox
  @enabled_cards = nil
  @gateway.sandbox
end
sandbox?() click to toggle source
# File lib/centralpos/account.rb, line 36
def sandbox?
  @gateway.mode == :sandbox
end
valid?() click to toggle source
# File lib/centralpos/account.rb, line 49
def valid?
  response = enabled_cards
  @error = response[:error]
  @error.nil?
end

Private Instance Methods

attr_inspect() click to toggle source
# File lib/centralpos/account.rb, line 93
def attr_inspect
  [ :username ]
end