Sha256: 91a6da84ae21919e72d61354c5c308d56b9de5936128711b5dd69f8a08f24e86

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

module AchClient
  # Represents an Ach Return code. Consult NACHA documentation for a full list
  # See config/return_codes.yml for our list.
  class ReturnCode

    # The first character in a correction code
    CORRECTION_START_CHARACTER = 'C'

    # The first character in an internal return code
    INTERNAL_START_CHARACTER = 'X'

    # Returns that are both internal and corrections start with this string
    INTERNAL_CORRECTION_STRING = 'XZ'

    attr_accessor :code,
                  :description,
                  :reason

    # Constructs a Ach return code
    # @param code [String] the 3 char code identifier (ie 'R01')
    # @param description [String] full explanation of the return
    # @param reason [String] shorter explanation of the return
    def initialize(code:, description:, reason: nil)
      @code = code
      @description = description
      @reason = reason
    end

    # @return Whether or not this return is a correction/notice of change
    def correction?
      @code.start_with?(CORRECTION_START_CHARACTER) || @code.start_with?(INTERNAL_CORRECTION_STRING)
    end

    # @return Whether or not the return is internal
    # An "internal" return means that the ACH provider knew that the ACH
    #   would fail and didn't bother to send it to their upstream provider
    def internal?
      @code.start_with?(INTERNAL_START_CHARACTER)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ach_client-5.0.0 lib/ach_client/objects/return_code.rb
ach_client-4.0.0 lib/ach_client/objects/return_code.rb
ach_client-3.1.0 lib/ach_client/objects/return_code.rb
ach_client-3.0.0 lib/ach_client/objects/return_code.rb
ach_client-2.1.0 lib/ach_client/objects/return_code.rb
ach_client-2.0.0 lib/ach_client/objects/return_code.rb