Skip to content
A Go module to perform basic credit card validation
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
README.md
creditcard.go
creditcard_test.go
go.mod
go.sum

README.md

creditcard

Go Report Card GitHub tag (latest by date) GitHub

A Go module to perform basic credit card validation.

Installation

go get github.com/retgits/creditcard

Usage

Create a creditcard.Card struct and use the Validate() method to perform validation

package main

import (
    "fmt"
    "github.com/retgits/creditcard"
)

func main() {
    card := creditcard.Card{
        Type:        "Something",
        Number:      "5019717010103742",
        ExpiryMonth: 11,
        ExpiryYear:  2019,
        CVV:         "1234",
    }
    validation := card.Validate()
    fmt.Printf("%+v\n", validation)
    fmt.Printf("%+v\n", validation.Card)
    // This prints
    // &{Card:0xc000092040 ValidCardNumber:false ValidExpiryMonth:true ValidExpiryYear:true ValidCVV:false IsExpired:false Errors:[given card type doesn't match determined card type]}
    // &{Type:Something Number:5019717010103742 ExpiryMonth:11 ExpiryYear:2019 CVV:1234}
}

The sample here shows that the card's supplied type "Something" doesn't match what the type actually should be.

Supported Credit Card Types

This module supports a variety of credit cards:

  • American Express
  • Aura
  • Bankcard
  • Cabal
  • China UnionPay
  • Dankort
  • Diners Club Carte Blanche
  • Diners Club Enroute
  • Diners Club International
  • Discover
  • Elo
  • Hipercard
  • InstaPayment
  • InterPayment
  • JCB
  • Maestro
  • Mastercard
  • Visa
  • Visa Electron

Test Card Numbers

A list of test credit cards is available from PayPal.

LICENSE

This module is provided under the MIT license

Acknowledgements

This lib is built as a Go equivalent to the Node.js credit-card library and the amazing work by HubCash

You can’t perform that action at this time.