Module: ActiveMerchant::Billing::CreditCardMethods::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#brand?(number) ⇒ Boolean

Returns a string containing the brand of card from the list of known information below.

Returns:

  • (Boolean)

283
284
285
286
287
288
289
290
291
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 283

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_companiesObject


278
279
280
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 278

def card_companies
  CARD_COMPANY_DETECTORS.keys
end

#electron?(number) ⇒ Boolean

Returns:

  • (Boolean)

293
294
295
296
297
298
299
300
301
302
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 293

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


309
310
311
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 309

def first_digits(number)
  number&.slice(0, 6) || ''
end

#last_digits(number) ⇒ Object


313
314
315
316
317
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 313

def last_digits(number)
  return '' if number.nil?

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

#mask(number) ⇒ Object


319
320
321
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 319

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

Returns:

  • (Boolean)

324
325
326
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 324

def matching_brand?(number, brand)
  brand?(number) == brand
end

#matching_type?(number, brand) ⇒ Boolean

Returns:

  • (Boolean)

328
329
330
331
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 328

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

Returns:

  • (Boolean)

304
305
306
307
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 304

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:

Returns:

  • (Boolean)

271
272
273
274
275
276
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 271

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