Class: AchClient::Sftp::AchBatch

Inherits:
Abstract::AchBatch show all
Defined in:
lib/ach_client/providers/sftp/ach_batch.rb

Overview

NACHA representation of an AchBatch

Instance Method Summary collapse

Methods inherited from Abstract::AchBatch

#send_batch

Constructor Details

#initialize(ach_transactions: [], batch_number: nil) ⇒ AchBatch

Returns a new instance of AchBatch.



7
8
9
10
# File 'lib/ach_client/providers/sftp/ach_batch.rb', line 7

def initialize(ach_transactions: [], batch_number: nil)
  super(ach_transactions: ach_transactions)
  @batch_number = batch_number
end

Instance Method Details

#batch_file_nameString

The filename used for the batch

Returns:

  • (String)

    filename to use



14
15
16
# File 'lib/ach_client/providers/sftp/ach_batch.rb', line 14

def batch_file_name
  self.class.module_parent.file_naming_strategy.(@batch_number)
end

#cook_some_nachasACH::ACHFile

Converts this AchBatch into the NACHA object representation provided by the ACH gem.

Returns:

  • (ACH::ACHFile)

    Yo NACHA



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ach_client/providers/sftp/ach_batch.rb', line 34

def cook_some_nachas
  nacha = ACH::ACHFile.new
  nacha.instance_variable_set(:@header, nacha_file_header)

  # The NACHA can have multiple batches.
  # Transactions in the same batch must have the same originator and
  # sec_code, so we group by sec_code and originator when building batches
  @ach_transactions.group_by(&:sec_code).map do |sec_code, transactions|
    transactions.group_by(&:originator_name)
                .map do |originator_name, batch_transactions|
      batch_transactions.group_by(&:effective_entry_date)
                      .map do |, batched_transactions|
        nacha.batches << nacha_batch(
          sec_code,
          originator_name,
          ,
          batched_transactions
        )
      end
    end
  end
  nacha
end

#do_send_batchArray<String>

Sends the batch to SFTP provider

Returns:

  • (Array<String>)


20
21
22
23
24
25
26
27
28
29
# File 'lib/ach_client/providers/sftp/ach_batch.rb', line 20

def do_send_batch
  self.class.module_parent.write_remote_file(
    file_path: File.join(
      self.class.module_parent.outgoing_path,
      batch_file_name
    ),
    file_body: cook_some_nachas.to_s
  )
  @ach_transactions.map(&:external_ach_id)
end