Module: ActiveMerchant::Billing::CreditCardMethods::ClassMethods
- Defined in:
- lib/active_merchant/billing/credit_card_methods.rb
Instance Method Summary collapse
-
#brand?(number) ⇒ Boolean
Returns a string containing the brand of card from the list of known information below.
- #card_companies ⇒ Object
- #electron?(number) ⇒ Boolean
- #first_digits(number) ⇒ Object
- #last_digits(number) ⇒ Object
- #mask(number) ⇒ Object
-
#matching_brand?(number, brand) ⇒ Boolean
Checks to see if the calculated brand matches the specified brand.
- #matching_type?(number, brand) ⇒ Boolean
- #type?(number) ⇒ Boolean
-
#valid_number?(number) ⇒ Boolean
Returns true if it validates.
Instance Method Details
#brand?(number) ⇒ Boolean
Returns a string containing the brand of card from the list of known information below.
227 228 229 230 231 232 233 234 235 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 227 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 ⇒ Object
222 223 224 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 222 def card_companies CARD_COMPANY_DETECTORS.keys end |
#electron?(number) ⇒ Boolean
237 238 239 240 241 242 243 244 245 246 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 237 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) ⇒ Object
253 254 255 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 253 def first_digits(number) number&.slice(0, 6) || '' end |
#last_digits(number) ⇒ Object
257 258 259 260 261 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 257 def last_digits(number) return '' if number.nil? number.length <= 4 ? number : number.slice(-4..-1) end |
#mask(number) ⇒ Object
263 264 265 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 263 def mask(number) "XXXX-XXXX-XXXX-#{last_digits(number)}" end |
#matching_brand?(number, brand) ⇒ Boolean
Checks to see if the calculated brand matches the specified brand
268 269 270 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 268 def matching_brand?(number, brand) brand?(number) == brand end |
#matching_type?(number, brand) ⇒ Boolean
272 273 274 275 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 272 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) ⇒ Boolean
248 249 250 251 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 248 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) ⇒ Boolean
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:
215 216 217 218 219 220 |
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 215 def valid_number?(number) valid_test_mode_card_number?(number) || valid_card_number_length?(number) && valid_card_number_characters?(number) && valid_by_algorithm?(brand?(number), number) end |