Module: ActiveMerchant::Billing::CreditCardMethods::ClassMethods
- Defined in:
- lib/active_merchant/billing/credit_card_methods.rb
Instance Method Summary collapse
-
#brand?(number) ⇒ Boolean
Returns a string containing the brand of card from the list of known information below.
-
#card_companies ⇒ Object
Regular expressions for the known card companies.
- #deprecated(message) ⇒ Object
- #first_digits(number) ⇒ Object
- #last_digits(number) ⇒ Object
- #mask(number) ⇒ Object
-
#matching_brand?(number, brand) ⇒ Boolean
Checks to see if the calculated brand matches the specified brand.
- #matching_type?(number, brand) ⇒ Boolean
- #type?(number) ⇒ Boolean
-
#valid_number?(number) ⇒ Boolean
Returns true if it validates.
Instance Method Details
#brand?(number) ⇒ Boolean
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 – TODO Refactor this method. We basically need to tighten up the Maestro Regexp.
Right now the Maestro regexp overlaps with the MasterCard regexp (IIRC). If we can tighten things up, we can boil this whole thing down to something like…
def brand?(number)
return 'visa' if valid_test_mode_card_number?(number)
card_companies.find([nil]) { |brand, regexp| number =~ regexp }.first.dup
end
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 75 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 ⇒ Object
Regular expressions for the known card companies.
References:
58 59 60 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 58 def card_companies CARD_COMPANIES end |
#deprecated(message) ⇒ Object
114 115 116 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 114 def deprecated() warn(Kernel.caller[1] + ) end |
#first_digits(number) ⇒ Object
92 93 94 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 92 def first_digits(number) number.to_s.slice(0,6) end |
#last_digits(number) ⇒ Object
96 97 98 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 96 def last_digits(number) number.to_s.length <= 4 ? number : number.to_s.slice(-4..-1) end |
#mask(number) ⇒ Object
100 101 102 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 100 def mask(number) "XXXX-XXXX-XXXX-#{last_digits(number)}" end |
#matching_brand?(number, brand) ⇒ Boolean
Checks to see if the calculated brand matches the specified brand
105 106 107 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 105 def matching_brand?(number, brand) brand?(number) == brand end |
#matching_type?(number, brand) ⇒ Boolean
109 110 111 112 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 109 def matching_type?(number, brand) 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) ⇒ Boolean
87 88 89 90 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 87 def type?(number) 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) ⇒ Boolean
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:
47 48 49 50 51 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 47 def valid_number?(number) valid_test_mode_card_number?(number) || valid_card_number_length?(number) && valid_checksum?(number) end |