Class: AN::AuthorizationResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/an.rb

Constant Summary collapse

FIELDS =
{
  1  => "responseCode",
  3  => "messageCode",
  4  => "messageDescription",
  5  => "authCode",
  6  => "avsResultCode",
  7  => "transId",
  38 => "transHash",
  39 => "cvvResultCode",
  40 => "cavvResultCode",
  51 => "accountNumber",
  52 => "accountType"
}

Instance Method Summary collapse

Constructor Details

#initialize(data, delimiter = ",") ⇒ AuthorizationResponse

Returns a new instance of AuthorizationResponse.



115
116
117
118
119
120
121
122
123
124
# File 'lib/an.rb', line 115

def initialize(data, delimiter = ",")
  @list = data.split(delimiter)
  @data = {}

  FIELDS.each do |index, field|
    # The FIELDS hash is using a 1-based index in order
    # to match the ordering number in the AIM documentation.
    @data[field] = @list[index - 1]
  end
end

Instance Method Details

#[](key) ⇒ Object



130
131
132
# File 'lib/an.rb', line 130

def [](key)
  @data[key]
end

#success?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/an.rb', line 134

def success?
  @data["responseCode"] == "1" && @data["messageCode"] == "1"
end

#to_hashObject



126
127
128
# File 'lib/an.rb', line 126

def to_hash
  @data
end

#transaction_idObject



138
139
140
# File 'lib/an.rb', line 138

def transaction_id
  @data["transId"]
end