Card Validator API - Ruby Gem

Card Validator checks whether a card number is valid, identifies the card brand, and flags risk. It runs the Luhn checksum, detects the scheme (Visa, Mastercard, Amex and more), returns the PCI-safe BIN and last 4 digits, flags known processor test cards, and returns a composite risk score.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_cardvalidator'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_cardvalidator

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_cardvalidator'

# Initialize the client
client = APIVerve::Cardvalidator::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({ number: "4900264223817524" })

# Print the response
puts response

Error Handling

begin
  response = client.execute({ number: "4900264223817524" })
  puts response["data"]
rescue APIVerve::Cardvalidator::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Cardvalidator::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Cardvalidator::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "card": {
      "niceType": "Visa",
      "type": "visa",
      "patterns": [
        4
      ],
      "gaps": [
        4,
        8,
        12
      ],
      "lengths": [
        16,
        18,
        19
      ],
      "code": {
        "name": "CVV",
        "size": 3
      },
      "matchStrength": 1
    },
    "brand": "Visa",
    "cardNumber": "4900264223817524",
    "bin": "490026",
    "last4": "7524",
    "isValid": true,
    "isPotentiallyValid": true,
    "isTestCard": false,
    "riskScore": 0,
    "riskLevel": "low"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.