module ActiveMerchant::Billing::CreditCardMethods::ClassMethods
Constants
- BYTES_TO_DIGITS
- BYTES_TO_DIGITS_DOUBLED
Public Instance Methods
brand?(number)
click to toggle source
Returns a string containing the brand of card from the list of known information below.
# File lib/active_merchant/billing/credit_card_methods.rb, line 390 def brand?(number) return 'bogus' if valid_test_mode_card_number?(number) CARD_COMPANY_DETECTORS.each do |company, func| return company.dup if func.call(number) end return nil end
card_companies()
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 385 def card_companies CARD_COMPANY_DETECTORS.keys end
electron?(number)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 400 def electron?(number) return false unless [16, 19].include?(number&.length) # don't recalculate for each range bank_identification_number = first_digits(number).to_i ELECTRON_RANGES.any? do |range| range.include?(bank_identification_number) end end
first_digits(number)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 416 def first_digits(number) number&.slice(0, 6) || '' end
last_digits(number)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 420 def last_digits(number) return '' if number.nil? number.length <= 4 ? number : number.slice(-4..-1) end
mask(number)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 426 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 431 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 435 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 411 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 378 def valid_number?(number) valid_test_mode_card_number?(number) || valid_card_number_length?(number) && valid_card_number_characters?(brand?(number), number) && valid_by_algorithm?(brand?(number), number) end
Private Instance Methods
sodexo_no_luhn?(numbers)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 460 def sodexo_no_luhn?(numbers) SODEXO_NO_LUHN.call(numbers) end
valid_luhn_non_zero_check_digit?(numbers)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 541 def valid_luhn_non_zero_check_digit?(numbers) return valid_luhn?(numbers.delete(' ')) if numbers[5] == ' ' check_digit = numbers[-1] luhn_payload = numbers.delete(' ').chop valid_luhn_with_check_digit?(luhn_payload, check_digit) end
valid_luhn_with_check_digit?(numbers, check_digit)
click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 528 def valid_luhn_with_check_digit?(numbers, check_digit) sum = 0 doubler = true numbers.reverse.bytes.each do |bytes| doubler ? sum += BYTES_TO_DIGITS_DOUBLED[bytes] : sum += BYTES_TO_DIGITS[bytes] doubler = !doubler end (10 - (sum % 10)) % 10 == check_digit.to_i end