Module: AbtainBilling::Billing::CreditCardMethods

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

Overview

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

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

CARD_COMPANIES =
{ 
  'visa'               => /^4\d{12}(\d{3})?$/,
  'master'             => /^(5[1-5]\d{4}|677189)\d{10}$/,
  'discover'           => /^(6011|65\d{2})\d{12}$/,
  'american_express'   => /^3[47]\d{13}$/,
  'diners_club'        => /^3(0[0-5]|[68]\d)\d{11}$/,
  'jcb'                => /^3528\d{12}$/,
  'switch'             => /^6759\d{12}(\d{2,3})?$/,  
  'solo'               => /^6767\d{12}(\d{2,3})?$/,
  'dankort'            => /^5019\d{12}$/,
  'maestro'            => /^(5[06-8]|6\d)\d{10,17}$/,
  'forbrugsforeningen' => /^600722\d{10}$/,
  'laser'              => /^(6304|6706|6771|6709)\d{8}(\d{4}|\d{6,7})?$/
}
TEST_NUMBERS =
%w[378282246310005 371449635398431 378734493671000 30569309025904 38520000023237 6011111111111117 6011000990]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



22
23
24
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 22

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#valid_expiry_year?(year) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 30

def valid_expiry_year?(year)
  (Time.now.year..Time.now.year + 20).include?(year)
end

#valid_issue_number?(number) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 38

def valid_issue_number?(number)
  number.to_s =~ /^\d{1,2}$/
end

#valid_month?(month) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 26

def valid_month?(month)
  (1..12).include?(month)
end

#valid_start_year?(year) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/abtain_billing/billing/credit_card_methods.rb', line 34

def valid_start_year?(year)
  year.to_s =~ /^\d{4}$/ && year.to_i > 1987
end