Class: ISO8583::MKB::Request

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

Direct Known Subclasses

Authorization, Reversal

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transaction) ⇒ Request

Returns a new instance of Request.



22
23
24
25
26
27
28
29
# File 'lib/iso8583-mkb/request.rb', line 22

def initialize(transaction)
  @retries = 4
  @timeout = 60
  @retry_with = nil
  @complete = nil
  @request = nil
  @transaction = transaction
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



17
18
19
# File 'lib/iso8583-mkb/request.rb', line 17

def request
  @request
end

#retriesObject

Returns the value of attribute retries.



19
20
21
# File 'lib/iso8583-mkb/request.rb', line 19

def retries
  @retries
end

#statusObject (readonly)

Returns the value of attribute status.



17
18
19
# File 'lib/iso8583-mkb/request.rb', line 17

def status
  @status
end

#timeoutObject

Returns the value of attribute timeout.



20
21
22
# File 'lib/iso8583-mkb/request.rb', line 20

def timeout
  @timeout
end

Class Method Details

.build_classObject



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/iso8583-mkb/request.rb', line 4

def build_class
  [ const_get(:MANDATORY), const_get(:OPTIONAL) ].each do |hash|
    hash.each do |key, iso8583_name|
      attr_accessor key.intern
    end
  end

  const_get(:RESPONSE).each do |iso8583_name, key|
    attr_reader key.intern
  end
end

Instance Method Details

#status_descriptionObject



35
36
37
# File 'lib/iso8583-mkb/request.rb', line 35

def status_description
  Errors.error @status
end

#submit(&complete) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/iso8583-mkb/request.rb', line 39

def submit(&complete)
  translated_fields = {}

  self.class.const_get(:MANDATORY).each do |key, iso8583_name|
    value = instance_variable_get :"@#{key}"
    if value.nil?
      raise "required attribute #{key} (#{iso8583_name}) is not specified"
    end

    translated_fields[iso8583_name] = value
  end


  self.class.const_get(:OPTIONAL).each do |key, iso8583_name|
    value = instance_variable_get :"@#{key}"
    unless value.nil?
      translated_fields[iso8583_name] = value
    end
  end

  @request = @transaction.request do |message|
    message.mti = self.class.const_get(:MTI)

    translated_fields.each do |key, value|
      message[key] = value
    end

    message.to_b # to validate encoding of the fields
  end

  @retry_with = [
    self.class.const_get(:REPEAT_MTI),
    translated_fields
  ]

  @complete = complete
  @request.start @timeout, &method(:request_completed)
end

#success?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/iso8583-mkb/request.rb', line 31

def success?
  Errors.success? @status
end