Parent

Included Modules

Class/Module Index [+]

Quicksearch

ActiveMerchant::Billing::Check

The Check object is a plain old Ruby object, similar to CreditCard. It supports validation of necessary attributes such as checkholder’s name, routing and account numbers, but it is not backed by any database.

You may use Check in place of CreditCard with any gateway that supports it. Currently, only BraintreeGateway supports the Check object.

Attributes

account_holder_type[RW]
account_number[RW]
account_type[RW]
first_name[RW]
institution_number[RW]

Used for Canadian bank accounts

last_name[RW]
number[RW]
routing_number[RW]
transit_number[RW]

Used for Canadian bank accounts

Public Instance Methods

name() click to toggle source
# File lib/active_merchant/billing/check.rb, line 17
def name
  @name ||= "#{@first_name} #{@last_name}".strip
end
name=(value) click to toggle source
# File lib/active_merchant/billing/check.rb, line 21
def name=(value)
  return if value.blank?

  @name = value
  segments = value.split(' ')
  @last_name = segments.pop
  @first_name = segments.join(' ')
end
type() click to toggle source
# File lib/active_merchant/billing/check.rb, line 44
def type
  'check'
end
valid_routing_number?() click to toggle source

Routing numbers may be validated by calculating a checksum and dividing it by 10. The formula is:

(3(d1 + d4 + d7) + 7(d2 + d5 + d8) + 1(d3 + d6 + d9))mod 10 = 0

See en.wikipedia.org/wiki/Routing_transit_number#Internal_checksums

# File lib/active_merchant/billing/check.rb, line 52
def valid_routing_number?
  d = routing_number.to_s.split('').map(&:to_i).select { |d| (0..9).include?(d) }
  case d.size
    when 9 then
      checksum = ((3 * (d[0] + d[3] + d[6])) +
                  (7 * (d[1] + d[4] + d[7])) +
                       (d[2] + d[5] + d[8])) % 10
      case checksum
        when 0 then true
        else        false
      end
    else false
  end
end
validate() click to toggle source
# File lib/active_merchant/billing/check.rb, line 30
def validate
  [:name, :routing_number, :account_number].each do |attr|
    errors.add(attr, "cannot be empty") if self.send(attr).blank?
  end
  
  errors.add(:routing_number, "is invalid") unless valid_routing_number?
  
  errors.add(:account_holder_type, "must be personal or business") if
      !account_holder_type.blank? && !]business personal].include?(account_holder_type.to_s)
  
  errors.add(:account_type, "must be checking or savings") if
      !account_type.blank? && !]checking savings].include?(account_type.to_s)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.