lib/active_merchant/billing/check.rb in activemerchant-1.3.2 vs lib/active_merchant/billing/check.rb in activemerchant-1.4.0
- old
+ new
@@ -7,22 +7,29 @@
# You may use Check in place of CreditCard with any gateway that supports it. Currently, only
# +BrainTreeGateway+ supports the Check object.
class Check
include Validateable
- attr_accessor :name, :routing_number, :account_number, :account_holder_type, :account_type
+ attr_accessor :first_name, :last_name, :routing_number, :account_number, :account_holder_type, :account_type, :number
- def initialize(args={})
- args = args.with_indifferent_access
- self.name = args[:name]
- self.routing_number = args[:routing_number]
- self.account_number = args[:account_number]
- self.account_holder_type = args[:account_holder_type]
- self.account_type = args[:account_type]
+ # Used for Canadian bank accounts
+ attr_accessor :institution_number, :transit_number
+
+ def name
+ @name ||= "#{@first_name} #{@last_name}".strip
end
+ def name=(value)
+ return if value.blank?
+
+ @name = value
+ segments = value.split(' ')
+ @last_name = segments.pop
+ @first_name = segments.join(' ')
+ end
+
def validate
- for attr in [:name, :routing_number, :account_number]
+ [: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?