creditcard

package module
v0.0.0-...-a9e175b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2022 License: CC-BY-SA-4.0 Imports: 3 Imported by: 12

README

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

Documentation

Overview

Package creditcard provides methods for validating credit cards

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	Number, Cvv, Month, Year string
	Company                  Company
}

Card holds generic information about the credit card

func (*Card) LastFour

func (c *Card) LastFour() (string, error)

LastFour returns the last four digits of the credit card's number

func (*Card) LastFourDigits

func (c *Card) LastFourDigits() (string, error)

LastFourDigits as an alias for LastFour

func (*Card) Method

func (c *Card) Method() error

Method returns an error from MethodValidate() or returns the credit card with it's company / issuer attached to it

func (*Card) MethodValidate

func (c *Card) MethodValidate() (Company, error)

MethodValidate adds/checks/verifies the credit card's company / issuer

func (*Card) Validate

func (c *Card) Validate(allowTestNumbers ...bool) error

Validate returns nil or an error describing why the credit card didn't validate this method checks for expiration date, CCV/CVV and the credit card's numbers. For allowing test cards to go through, simply pass true (bool) as the first argument

func (*Card) ValidateCVV

func (c *Card) ValidateCVV() error

validates the length of the card's CVV value

func (*Card) ValidateExpiration

func (c *Card) ValidateExpiration() error

validates the credit card's expiration date

func (*Card) ValidateNumber

func (c *Card) ValidateNumber() bool

ValidateNumber will check the credit card's number against the Luhn algorithm

func (*Card) Wipe

func (c *Card) Wipe()

Wipe returns the credit card with false/nullified/generic information

type Company

type Company struct {
	Short, Long string
}

Company holds a short and long names of who has issued the credit card

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL