module ActiveMerchant::Billing::CreditCardMethods

Convenience methods that can be included into a custom Credit Card object, such as an ActiveRecord based Credit Card object.

Constants

ALELO_RANGES

Alelo provides BIN ranges by e-mailing them out periodically. The BINs beginning with the digit 4 overlap with Visa's range of valid card numbers. By placing the 'alelo' entry in CARD_COMPANY_DETECTORS below the 'visa' entry, we identify these cards as Visa. This works because transactions with such cards will run on Visa rails.

CABAL_RANGES
CARD_COMPANY_DETECTORS
CARNET_BINS
CARNET_RANGES
ELECTRON_RANGES

www.barclaycard.co.uk/business/files/bin_rules.pdf

ELO_RANGES

dev.elo.com.br/apis/tabela-de-bins, download csv from left sidebar

MAESTRO_RANGES

www.mastercard.us/content/dam/mccom/global/documents/mastercard-rules.pdf, page 73

MASTERCARD_RANGES

www.mastercard.us/content/dam/mccom/global/documents/mastercard-rules.pdf, page 73

NARANJA_RANGES

Public Class Methods

in_bin_range?(number, ranges) click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 130
def self.in_bin_range?(number, ranges)
  bin = number.to_i
  ranges.any? do |range|
    range.cover?(bin)
  end
end
included(base) click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 126
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

card_verification_value_length(brand) click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 170
def card_verification_value_length(brand)
  case brand
  when 'american_express'
    4
  when 'maestro'
    0
  else
    3
  end
end
credit_card?() click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 141
def credit_card?
  true
end
electron?() click to toggle source

Returns if the card matches known Electron BINs

# File lib/active_merchant/billing/credit_card_methods.rb, line 186
def electron?
  self.class.electron?(number)
end
valid_card_verification_value?(cvv, brand) click to toggle source

Credit card providers have 3 digit verification values This isn't standardised, these are called various names such as CVC, CVV, CID, CSC and more See: en.wikipedia.org/wiki/Card_security_code American Express is the exception with 4 digits

Below are links from the card providers with their requirements visa: usa.visa.com/personal/security/3-digit-security-code.jsp master: www.mastercard.com/ca/merchant/en/getstarted/Anatomy_MasterCard.html jcb: www.jcbcard.com/security/info.html diners_club: www.dinersclub.com/assets/DinersClub_card_ID_features.pdf discover: www.discover.com/credit-cards/help-center/glossary.html american_express: online.americanexpress.com/myca/fuidfyp/us/action?request_type=un_fuid&Face=en_US

# File lib/active_merchant/billing/credit_card_methods.rb, line 166
def valid_card_verification_value?(cvv, brand)
  cvv.to_s =~ /^\d{#{card_verification_value_length(brand)}}$/
end
valid_expiry_year?(year) click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 145
def valid_expiry_year?(year)
  (Time.now.year..Time.now.year + 20).cover?(year.to_i)
end
valid_issue_number?(number) click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 181
def valid_issue_number?(number)
  (number.to_s =~ /^\d{1,2}$/)
end
valid_month?(month) click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 137
def valid_month?(month)
  (1..12).cover?(month.to_i)
end
valid_start_year?(year) click to toggle source
# File lib/active_merchant/billing/credit_card_methods.rb, line 149
def valid_start_year?(year)
  ((year.to_s =~ /^\d{4}$/) && (year.to_i > 1987))
end