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)


191
192
193
194
195
196
197
198
199
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 191

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



186
187
188
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 186

def card_companies
  CARD_COMPANY_DETECTORS.keys
end

#electron?(number) ⇒ Boolean

Returns:

  • (Boolean)


201
202
203
204
205
206
207
208
209
210
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 201

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



217
218
219
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 217

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

#last_digits(number) ⇒ Object



221
222
223
224
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 221

def last_digits(number)
  return '' if number.nil?
  number.length <= 4 ? number : number.slice(-4..-1)
end

#mask(number) ⇒ Object



226
227
228
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 226

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)


231
232
233
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 231

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

#matching_type?(number, brand) ⇒ Boolean

Returns:

  • (Boolean)


235
236
237
238
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 235

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)


212
213
214
215
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 212

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)


179
180
181
182
183
184
# File 'lib/active_merchant/billing/credit_card_methods.rb', line 179

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