class Bambora::BatchUpload::MakeArray

Attributes

array[RW]
txn_type[RW]

Public Class Methods

new(txn_type) click to toggle source
# File lib/bambora/batch_upload.rb, line 58
def initialize(txn_type)
  @txn_type = txn_type
  @array    = []
end

Public Instance Methods

push_into_file(params) click to toggle source
# File lib/bambora/batch_upload.rb, line 62
def push_into_file(params)
  validate_args params
  array << OpenStruct.new(txn_type:               @txn_type,
                          payment_type:           params[:payment_type].to_s,
                          institution_number:     params[:institution_number].to_s,
                          transit_number:         params[:transit_number], 
                          transit_routing_number: params[:transit_routing_number].to_s,
                          account_number:         params[:account_number].to_s,
                          account_code:           params[:account_code].to_s,
                          amount:                 params[:amount],
                          ref:                    (params[:reference] || 0 ).to_s,
                          recipient:              params[:recipient].to_s,
                          customer_code:          params[:customer_code].to_s,
                          descriptor:             params[:dynamic_descriptor].to_s,
                          standard_entry_code:    params[:standard_entry_code].to_s,
                          entry_detail_addenda:   params[:entry_detail_addenda_record].to_s
                         )
end

Private Instance Methods

validate_args(params) click to toggle source
# File lib/bambora/batch_upload.rb, line 81
def validate_args params
  unless @txn_type == "E" || @txn_type == "A"
    raise ArgumentError, "Must specify transaction type: E (EFT) or A (ACH)" 
  end
  unless params[:payment_type] == "D" || params[:payment_type] == "C"
    raise ArgumentError, "Must provide payment type: C (credit) or D (debit)" 
  end
  if params[:amount].nil?
    raise ArgumentError, "Must provide amount"       
  end
  #banking info
  if @txn_type == "E"
    if params[:customer_code].nil? && (params[:transit_number].nil? || 
                                       params[:institution_number].nil? ||
                                       params[:account_number].nil?)
      raise ArgumentError, "Must either provide customer code or transit, institution, and account #s"
    end
  else
    if params[:customer_code].nil? && (params[:transit_routing_number].nil? || 
                                       params[:account_code].nil? ||
                                       params[:account_number].nil?)
      raise ArgumentError, "Must either provide customer code or transit routing, account #s, and accounting code"
    end
  end
end