Skip to content

dsparling/go-business-creditcard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-business-creditcard

Validate/generate credit card checksums/names.

The go-business-creditcard package is a simple port based on the Business::CreditCard Perl module by Ivan Kohler.

Installation

Simply install the package to your $GOPATH with the go tool from shell:

$ go get github.com/dsparling/go-business-creditcard

Make sure Git is installed on your machine and in your system's PATH.

go get installs the latest tagged release

Examples

Example.go is a sort of hello world for go-business-creditcard and should get you started for the barebones necessities of using the package.

cd examples
go run example.go

Validate

// true
fmt.Println(creditcard.Validate("4111111111111111"))
fmt.Println(creditcard.Validate("4111 1111 1111 1111"))
fmt.Println(creditcard.Validate("4111-1111-1111-1111"))

// false
fmt.Println(creditcard.Validate("1111111111111111"))
fmt.Println(creditcard.Validate("1111 1111 1111 1111"))
fmt.Println(creditcard.Validate("1111-1111-1111-1111"))

Cardtype

// Visa
fmt.Println(creditcard.Cardtype("4111111111111111"))
// MasterCard
fmt.Println(creditcard.Cardtype("5555555555554444"))
// AmericanExpress
fmt.Println(creditcard.Cardtype("378282246310005"))
// DinersClub/Carteblanche
fmt.Println(creditcard.Cardtype("30569309025904"))
// Discover
fmt.Println(creditcard.Cardtype("6011111111111117"))
// EnRoute
fmt.Println(creditcard.Cardtype("201400000000009"))
// JCB
fmt.Println(creditcard.Cardtype("3530111333300000"))

GenerateLastDigit

// Returns '9' - 5276440065421319
fmt.Println(creditcard.GenerateLastDigit("5276 4400 6542 131"))

About

Validate/generate credit card checksums/names.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages