ProductPromotion
Logo

Ruby

made by https://0x3d.site

GitHub - didww/credit_card_validations: :credit_card: ruby gem for validating credit card numbers, generating valid numbers, luhn checks
:credit_card: ruby gem for validating credit card numbers, generating valid numbers, luhn checks - didww/credit_card_validations
Visit Site

GitHub - didww/credit_card_validations: :credit_card: ruby gem for validating credit card numbers, generating valid numbers, luhn checks

GitHub - didww/credit_card_validations: :credit_card: ruby gem for validating credit card numbers, generating valid numbers, luhn checks

CreditCardValidations

Gem Version License

Gem adds validator to check whether or not a given number actually falls within the ranges of possible numbers prior to performing such verification, and, as such, CreditCardValidations simply verifies that the credit card number provided is well-formed.

More info about card BIN numbers http://en.wikipedia.org/wiki/Bank_card_number

Installation

Add this line to your application's Gemfile:

$ gem 'credit_card_validations'

And then execute:

$ bundle

Or install it yourself as:

$ gem install credit_card_validations

Usage

The following issuing institutes are accepted:

Name Key
American Express :amex
China UnionPay :unionpay
Dankort :dankort
Diners Club :diners
Elo :elo
Discover :discover
Hipercard :hipercard
JCB :jcb
Maestro :maestro
MasterCard :mastercard
MIR :mir
Rupay :rupay
Solo :solo
Switch :switch
Visa :visa

The following are supported with plugins

Name Key
Diners Club US :diners_us
EnRoute :en_route
Laser :laser

Examples using string monkey patch

require 'credit_card_validations/string'
'5274 5763 9425 9961'.credit_card_brand   #=> :mastercard
'5274 5763 9425 9961'.credit_card_brand_name   #=> "MasterCard"
'5274 5763 9425 9961'.valid_credit_card_brand?(:mastercard, :visa) #=> true
'5274 5763 9425 9961'.valid_credit_card_brand?(:amex) #=> false
'5274 5763 9425 9961'.valid_credit_card_brand?('MasterCard') #=> true

ActiveModel support

only for certain brands

class CreditCardModel
  attr_accessor :number
  include ActiveModel::Validations
  validates :number, credit_card_number: {brands: [:amex, :maestro]}
end

for all known brands

validates :number, presence: true, credit_card_number: true

Examples using CreditCardValidations::Detector class

number = "4111111111111111"
detector = CreditCardValidations::Detector.new(number)
detector.brand #:visa
detector.visa? #true
detector.valid?(:mastercard,:maestro) #false
detector.valid?(:visa, :mastercard) #true
detector.issuer_category  #"Banking and financial"

Also You can add your own brand rules to detect other credit card brands/types

passing name,length(integer/array of integers) and prefix(string/array of strings) Example

CreditCardValidations.add_brand(:voyager, {length: 15, prefixes: '86'})
voyager_test_card_number = '869926275400212'
CreditCardValidations::Detector.new(voyager_test_card_number).brand #:voyager
CreditCardValidations::Detector.new(voyager_test_card_number).voyager? #true

Remove brands also supported

CreditCardValidations::Detector.delete_brand(:maestro)

Check luhn

CreditCardValidations::Detector.new(@credit_card_number).valid_luhn?
#or
CreditCardValidations::Luhn.valid?(@credit_card_number)

Generate credit card numbers that pass validation

CreditCardValidations::Factory.random(:amex)
# => "348051773827666"
CreditCardValidations::Factory.random(:maestro)
# => "6010430241237266856"

Plugins

require 'credit_card_validations/plugins/en_route'
require 'credit_card_validations/plugins/laser'
require 'credit_card_validations/plugins/diners_us'

Configuration

In order to override default data source you can copy original one , change it and configure during rails initializer

 CreditCardValidations.configure do |config|
      config.source = '/path/to/my_brands.yml'
 end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory