• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    Go
  • License
    Other
  • Created about 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Credit card validation with the Luhn algorithm for golang

go-credit-card Build Status Coverage Status GoDoc

Basic credit card validation using the Luhn algorithm

Currently identifies the following credit card companies:

  • American Express
  • Aura
  • Bankcard
  • Cabal
  • China Unionpay
  • Dankort
  • Diners Club Carte Blanche
  • Diners Club enRoute
  • Diners Club International
  • Discover
  • Elo
  • Hipercard
  • InterPayment
  • InstaPayment
  • JCB
  • Maestro
  • MasterCard
  • Naranja
  • Visa
  • Visa Electron

Installation

go get github.com/durango/go-credit-card

Quick Start

// Initialize a new card:
card := creditcard.Card{Number: "4242424242424242", Cvv: "11111", Month: "02", Year: "2016"}

// Retrieve the card's method (which credit card company this card belongs to)
err := card.Method() // card.Company({Short: "visa", Long: "Visa"})

// Display last four digits
lastFour, err := card.LastFour() // 4242

// Validate the card's number (without capturing)
err := card.Validate() // will return an error due to not allowing test cards

err := card.Validate(true) // this will work though