Module: AbtainBilling::Billing::CreditCardMethods::ClassMethods

Defined in:
lib/abtain_billing/billing/credit_card_methods.rb

Instance Method Summary collapse

Instance Method Details

#card_companiesObject



60
61
62
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 60

def card_companies
  CARD_COMPANIES
end

#is_test_number?(number) ⇒ Boolean

Returns true if the credit card matches one of our known test numbers

Returns:

  • (Boolean)


70
71
72
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 70

def is_test_number?(number)
  test_numbers.include?(number)
end

#last_digits(number) ⇒ Object



99
100
101
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 99

def last_digits(number)     
  number.to_s.length <= 4 ? number : number.to_s.slice(-4..-1) 
end

#mask(number) ⇒ Object



103
104
105
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 103

def mask(number)
  "XXXX-XXXX-XXXX-#{last_digits(number)}"
end

#matching_type?(number, type) ⇒ Boolean

Checks to see if the calculated type matches the specified type

Returns:

  • (Boolean)


108
109
110
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 108

def matching_type?(number, type)
  type?(number) == type
end

#test_numbersObject

List of credit card numbers used for testing



65
66
67
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 65

def test_numbers
  TEST_NUMBERS
end

#type?(number) ⇒ Boolean

Returns a string containing the type 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 type?(number)
  return 'visa' if valid_test_mode_card_number?(number)
  card_companies.find([nil]) { |type, regexp| number =~ regexp }.first.dup
end

Returns:

  • (Boolean)


87
88
89
90
91
92
93
94
95
96
97
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 87

def type?(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

#valid_number?(number) ⇒ Boolean

Returns true if it validates. Optionally, you can pass a card type as an argument and make sure it is of the correct type.

References:

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 49

def valid_number?(number)
  valid_test_mode_card_number?(number) || 
    valid_card_number_length?(number) && 
    valid_checksum?(number)
end