Module: ActiveMerchant::Billing::CreditCardMethods
- Included in:
- CreditCard
- Defined in:
- lib/active_merchant/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})?(\d{3})?$/, 'master' => /^(5[1-5]\d{4}|677189|222[1-9]\d{2}|22[3-9]\d{3}|2[3-6]\d{4}|27[01]\d{3}|2720\d{2})\d{10}$/, 'discover' => /^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/, 'american_express' => /^3[47]\d{13}$/, 'diners_club' => /^3(0[0-5]|[68]\d)\d{11}$/, 'jcb' => /^35(28|29|[3-8]\d)\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|6709|6771(?!89))\d{8}(\d{4}|\d{6,7})?$/, 'sodexo' => /^(606071|603389|606070|606069|606068|600818)\d{8}$/, 'vr' => /^(627416|637036)\d{8}$/ }
- ELECTRON_RANGES =
[ [400115], (400837..400839), (412921..412923), [417935], (419740..419741), (419773..419775), [424519], (424962..424963), [437860], [444000], [459472], (484406..484411), (484413..484414), (484418..484418), (484428..484455), (491730..491759), ]
Class Method Summary collapse
Instance Method Summary collapse
- #card_verification_value_length(brand) ⇒ Object
- #credit_card? ⇒ Boolean
-
#electron? ⇒ Boolean
Returns if the card matches known Electron BINs.
-
#valid_card_verification_value?(cvv, brand) ⇒ Boolean
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.
- #valid_expiry_year?(year) ⇒ Boolean
- #valid_issue_number?(number) ⇒ Boolean
- #valid_month?(month) ⇒ Boolean
- #valid_start_year?(year) ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
42 43 44 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 42 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#card_verification_value_length(brand) ⇒ Object
79 80 81 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 79 def card_verification_value_length(brand) brand == 'american_express' ? 4 : 3 end |
#credit_card? ⇒ Boolean
50 51 52 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 50 def credit_card? true end |
#electron? ⇒ Boolean
Returns if the card matches known Electron BINs
88 89 90 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 88 def electron? self.class.electron?(number) end |
#valid_card_verification_value?(cvv, brand) ⇒ Boolean
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
75 76 77 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 75 def valid_card_verification_value?(cvv, brand) cvv.to_s =~ /^\d{#{card_verification_value_length(brand)}}$/ end |
#valid_expiry_year?(year) ⇒ Boolean
54 55 56 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 54 def valid_expiry_year?(year) (Time.now.year..Time.now.year + 20).include?(year.to_i) end |
#valid_issue_number?(number) ⇒ Boolean
83 84 85 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 83 def valid_issue_number?(number) (number.to_s =~ /^\d{1,2}$/) end |
#valid_month?(month) ⇒ Boolean
46 47 48 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 46 def valid_month?(month) (1..12).include?(month.to_i) end |
#valid_start_year?(year) ⇒ Boolean
58 59 60 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 58 def valid_start_year?(year) ((year.to_s =~ /^\d{4}$/) && (year.to_i > 1987)) end |