Class: DCAS::Response

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

Direct Known Subclasses

AchResponse, AchReturn

Constant Summary collapse

CC_RET_CODES =
{
  '0' => 'D',
  '1' => 'G',
  '2' => 'I', # I think, we should never get this status. (Haven't yet...)
  '99' => 'E' # These are always server errors
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Response

Returns a new instance of Response.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/dcas/response.rb', line 80

def initialize(attrs={})
  new_attrs = {}
  nattrs = attrs.dup
  if nattrs.is_a?(Hash) # Is xml-hash
    nattrs.stringify_keys!
    # status, order_number, transacted_at, transaction_id, description
    new_attrs = nattrs
  elsif nattrs.respond_to?('[]') # Is csv row
    # GotoBilling: MerchantID,FirstName,LastName,CustomerID,Amount,SentDate,SettleDate,TransactionID,TransactionType,Status,Description
    # DCAS:        CC,AccountNumber,ReturnCode,ReasonDescription,ConfirmationNumber
    # ret could be 0 (denied), 1 (approved), 2 (call for authorization), or 99 (error)
    new_attrs = {
      :status => (nattrs[2].to_s == 'I' ? 'R' : CC_RET_CODES[nattrs[2].to_s]),
      :description => nattrs[3],
      :account_number => nattrs[1],
      :client_id    => nattrs[4][4..-1]
    }
    # This is the case where Malibu must call DCAS for authorization. We haven't come across that need yet, but a note should be made.
    # I'll make it an informational and 'Received' record -- but we have no answer other than this. The transaction won't go through without attention.
    new_attrs[:information] = "MUST CALL FOR Credit Card payment authorization! If you have any questions ask your Manager or the tech guy." if nattrs[2].to_s == 'I'
  end
  self.attributes = new_attrs
end

Instance Attribute Details

#account_numberObject

Returns the value of attribute account_number.



51
52
53
# File 'lib/dcas/response.rb', line 51

def 
  @account_number
end

#ach_submittedObject

Returns the value of attribute ach_submitted.



51
52
53
# File 'lib/dcas/response.rb', line 51

def 
  
end

#check_numberObject

Returns the value of attribute check_number.



51
52
53
# File 'lib/dcas/response.rb', line 51

def check_number
  @check_number
end

#client_idObject

Returns the value of attribute client_id.



51
52
53
# File 'lib/dcas/response.rb', line 51

def client_id
  @client_id
end

#descriptionObject

Returns the value of attribute description.



51
52
53
# File 'lib/dcas/response.rb', line 51

def description
  @description
end

#informationObject

Returns the value of attribute information.



51
52
53
# File 'lib/dcas/response.rb', line 51

def information
  @information
end

#statusObject

Returns the value of attribute status.



51
52
53
# File 'lib/dcas/response.rb', line 51

def status
  @status
end

Class Method Details

.each_response_in(filename_or_content) ⇒ Object

Runs the given block for each response in the given response file.

Raises:

  • (ArgumentError)


43
44
45
46
47
48
# File 'lib/dcas/response.rb', line 43

def each_response_in(filename_or_content)
  raise ArgumentError, "must include a block!" unless block_given?
  responses_in(filename_or_content).each do |response|
    yield response
  end
end

.responses_in(filename_or_content) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dcas/response.rb', line 21

def responses_in(filename_or_content)
  responses = []

  if filename_or_content !~ /\n/ && File.exists?(filename_or_content)
    filename_or_content = File.open(filename_or_content, 'rb').map {|l| l.gsub(/[\n\r]+/, "\n")}.join
  end

  CSV::Reader.parse(filecontents) do |ccrow|
    # Could be simply '9999' -- error!
    begin
      next if ccrow == ['9999']
      # Otherwise, it is in this format:
      # CC,AccountNumber,ReturnCode,ReasonDescription,CustTraceCode
      responses << new(ccrow)
    rescue # Rescue errors caused by the data in the csv.
    end
  end

  responses
end

Instance Method Details

#attributesObject



52
53
54
55
56
57
58
59
# File 'lib/dcas/response.rb', line 52

def attributes
  at = {}
  instance_variables.each do |iv|
    iv.gsub!('@', '')
    at[iv] = instance_variable_get("@#{iv}")
  end
  at
end

#attributes=(new_attributes) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/dcas/response.rb', line 60

def attributes=(new_attributes)
  return if new_attributes.nil?
  with(new_attributes.dup) do |a|
    a.stringify_keys!
    a.each {|k,v| send(k + "=", a.delete(k)) if respond_to?("#{k}=")}
  end
end

#invalid?Boolean

Tells if the payment was invalid. By default it’s just false, but child classes can redefine this.

Returns:

  • (Boolean)


69
70
71
# File 'lib/dcas/response.rb', line 69

def invalid?
  false
end