Class: AchClient::ICheckGateway::ResponseRecordProcessor

Inherits:
Abstract::ResponseRecordProcessor show all
Defined in:
lib/ach_client/providers/soap/i_check_gateway/response_record_processor.rb

Overview

Transforms ICheckGateway transaction report response records into AchClient::Response objects

Constant Summary collapse

STATUS_COLUMN =

The column index with the record status

1
AMOUNT_COLUMN =

The column index with the record amount ($)

15
DATE_COLUMN =

The column index with the record submission date

17
RETURN_CODE_INDEX =

The string index range within the record status with the return code

3..5

Class Method Summary collapse

Class Method Details

.process_response_record(record) ⇒ AchClient::AchResponse

Transforms ICheckGateway transaction report response records into AchClient::Response object Here is an example record: ICHECK|N||external_ach_id|abc||||||||BC|012345678|********1234|250.00|D|9/12/2016|05:03:04|C1234-1234||AutoCheck|||abcde|CCD|||rns

Parameters:

  • record (String)

    the | separated record string from ICheckGateway

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ach_client/providers/soap/i_check_gateway/response_record_processor.rb', line 22

def self.process_response_record(record)
  # The response record is a | separated list
  record = record.split('|')
  # The first letter in the second column determines the response type
  case record[STATUS_COLUMN].first
  when 'N'
    # N - no, it hasn't settled yet
    AchClient::ProcessingAchResponse.new(
      amount: record[AMOUNT_COLUMN],
      date: Helpers::Utils.icheck_date_format(record[DATE_COLUMN])
    )
  when 'Y'
    # Y - yes, it has settled
    AchClient::SettledAchResponse.new(
      amount: record[AMOUNT_COLUMN],
      date: Helpers::Utils.icheck_date_format(record[DATE_COLUMN])
    )
  else
    # If it starts with R, it is probably a return, in which case the
    # column looks like: R (R01)
    # As of now, it looks like there are no corrections from
    # ICheckGateway
    if record[1].start_with?('R')
      AchClient::ReturnedAchResponse.new(
        amount: record[AMOUNT_COLUMN],
        date: Helpers::Utils.icheck_date_format(record[DATE_COLUMN]),
        return_code: AchClient::ReturnCodes.find_by(
          code: record[STATUS_COLUMN][RETURN_CODE_INDEX]
        )
      )
    else
      # If it doesn't start with an R, something that is undocumented is
      # happening, so we raise an error since we need to know about it
      raise "Couldnt process ICheckGateway Response: #{record.join('|')}"
    end
  end
end