Class: Centralpos::Transaction

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

Constant Summary collapse

MD5_DIGEST =
OpenSSL::Digest.new("md5").freeze
UPDATABLE_VALUES =
[ :cc_number, :amount, :optional_data_1, :optional_data_2 ].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#ensure_array, #in_time_zone, #inspect

Constructor Details

#initialize(owner_id:, cc_number:, amount:, optional_data_1: "", optional_data_2: "", **extras) ⇒ Transaction

Returns a new instance of Transaction.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/centralpos/transaction.rb', line 22

def initialize(owner_id:, cc_number:, amount:, optional_data_1: "", optional_data_2: "", **extras)
  @id = md5("#{owner_id}-#{cc_number}")
  @owner_id = owner_id.to_i
  @cc_number = cc_number
  @amount = amount.to_s
  @optional_data_1 = optional_data_1
  @optional_data_2 = optional_data_2
  @extras = extras
  @applied = @extras[:applied]
  @message = @extras[:message]
  @card_error_code = @extras[:card_error_code]
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



6
7
8
# File 'lib/centralpos/transaction.rb', line 6

def amount
  @amount
end

#appliedObject (readonly)

Returns the value of attribute applied.



6
7
8
# File 'lib/centralpos/transaction.rb', line 6

def applied
  @applied
end

#card_error_codeObject (readonly)

Returns the value of attribute card_error_code.



6
7
8
# File 'lib/centralpos/transaction.rb', line 6

def card_error_code
  @card_error_code
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/centralpos/transaction.rb', line 6

def id
  @id
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/centralpos/transaction.rb', line 6

def message
  @message
end

#optional_data_1Object (readonly)

Returns the value of attribute optional_data_1.



6
7
8
# File 'lib/centralpos/transaction.rb', line 6

def optional_data_1
  @optional_data_1
end

#optional_data_2Object (readonly)

Returns the value of attribute optional_data_2.



6
7
8
# File 'lib/centralpos/transaction.rb', line 6

def optional_data_2
  @optional_data_2
end

#owner_idObject (readonly)

Returns the value of attribute owner_id.



6
7
8
# File 'lib/centralpos/transaction.rb', line 6

def owner_id
  @owner_id
end

Class Method Details

.load_it(data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/centralpos/transaction.rb', line 8

def self.load_it(data)
  data.merge!({
    owner_id:data[:id_user],
    cc_number:data[:nro_tarjeta],
    amount: data[:importe],
    optional_data_1: data[:dato_opcional],
    optional_data_2: data[:dato_opcional2],
    applied: data[:aplicado],
    message: data[:observaciones],
    card_error_code: data[:cod_error_tarjeta]
  })
  new(data)
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/centralpos/transaction.rb', line 44

def invalid?
  @owner_id.empty? || @cc_number.empty? || !@amount || @amount <= 0.0
end

#to_add_paramsObject



59
60
61
62
63
64
65
66
67
# File 'lib/centralpos/transaction.rb', line 59

def to_add_params
  {
    "DatoOpcional1" => @optional_data_1,
    "DatoOpcional2" => @optional_data_2,
    "IdUser"        => @owner_id,
    "NroTarjeta"    => @cc_number,
    "Importe"       => @amount
  }
end

#to_hashObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/centralpos/transaction.rb', line 48

def to_hash
  {
    id: id,
    owner_id: owner_id,
    amount: @amount,
    optional_data_1: @optional_data_1,
    optional_data_2: @optional_data_2,
    applied: @applied
  }
end

#to_remove_paramsObject



69
70
71
72
73
# File 'lib/centralpos/transaction.rb', line 69

def to_remove_params
  {
    "IdUser" => owner_id
  }
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  !invalid?
end