Class: ISO8583::MKB::ISO8583Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/iso8583-mkb/iso8583_transaction.rb

Constant Summary collapse

@@trace_counter =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gateway) ⇒ ISO8583Transaction

Returns a new instance of ISO8583Transaction.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/iso8583-mkb/iso8583_transaction.rb', line 7

def initialize(gateway)
  @gateway = gateway

  now = Time.now
  @id = (now.year % 100) * 1_00_0000_0000 +
        (now.mday)       *    1_0000_0000 +
        now.hour         *       3600_000 +
        now.min          *         60_000 +
        now.sec          *          1_000 +
        now.usec         /          1_000

  @trace = @@trace_counter += 1
  @started_at = now

  Logging.logger.debug "Transaction #{id} started"
end

Instance Attribute Details

#gatewayObject (readonly)

Returns the value of attribute gateway.



3
4
5
# File 'lib/iso8583-mkb/iso8583_transaction.rb', line 3

def gateway
  @gateway
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/iso8583-mkb/iso8583_transaction.rb', line 3

def id
  @id
end

#traceObject (readonly)

Returns the value of attribute trace.



3
4
5
# File 'lib/iso8583-mkb/iso8583_transaction.rb', line 3

def trace
  @trace
end

Instance Method Details

#completeObject



37
38
39
40
41
# File 'lib/iso8583-mkb/iso8583_transaction.rb', line 37

def complete
  # TODO: track transactions

  Logging.logger.debug "Transaction #{@id} completed"
end

#request {|message| ... } ⇒ Object

Yields:

  • (message)


24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/iso8583-mkb/iso8583_transaction.rb', line 24

def request(&block)
  message = MKBMessage.new
  message["Transmission Date and Time"] = @started_at
  message["Systems Trace Audit Number"] = @trace
  message["Time, Local Transaction"] = @started_at
  message["Date, Local Transaction"] = @started_at
  message.reference = @id.to_s

  yield message

  ISO8583Request.new self, message
end