module ActiveMerchant::Billing::CreditCardMethods::ClassMethods
Public Instance Methods
brand?(number)
click to toggle source
Returns a string containing the brand of card from the list of known information below. Need to check the cards in a particular order, as there is some overlap of the allowable ranges
# File lib/active_merchant/billing/credit_card_methods.rb, line 96 def brand?(number) return 'bogus' if valid_test_mode_card_number?(number) card_companies.reject { |c,p| c == 'maestro' }.each do |company, pattern| return company.dup if number =~ pattern end return 'maestro' if number =~ card_companies['maestro'] return nil end
card_companies()
click to toggle source
Regular expressions for the known card companies.
References:
# File lib/active_merchant/billing/credit_card_methods.rb, line 79 def card_companies CARD_COMPANIES end
first_digits(number)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 113 def first_digits(number) number.to_s.slice(0,6) end
last_digits(number)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 117 def last_digits(number) number.to_s.length <= 4 ? number : number.to_s.slice(-4..-1) end
mask(number)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 121 def mask(number) "XXXX-XXXX-XXXX-#{last_digits(number)}" end
matching_brand?(number, brand)
click to toggle source
Checks to see if the calculated brand matches the specified brand
# File lib/active_merchant/billing/credit_card_methods.rb, line 126 def matching_brand?(number, brand) brand?(number) == brand end
matching_type?(number, brand)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 130 def matching_type?(number, brand) ActiveMerchant.deprecated "CreditCard#matching_type? is deprecated and will be removed from a future release of ActiveMerchant. Please use CreditCard#matching_brand? instead." matching_brand?(number, brand) end
type?(number)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 108 def type?(number) ActiveMerchant.deprecated "CreditCard#type? is deprecated and will be removed from a future release of ActiveMerchant. Please use CreditCard#brand? instead." brand?(number) end
valid_number?(number)
click to toggle source
Returns true if it validates. Optionally, you can pass a card brand as an argument and make sure it is of the correct brand.
References:
# File lib/active_merchant/billing/credit_card_methods.rb, line 68 def valid_number?(number) valid_test_mode_card_number?(number) || valid_card_number_length?(number) && valid_checksum?(number) end