Documentation
¶
Overview ¶
Package creditcard is a module that performs credit card validation.
Index ¶
Constants ¶
const ( // Unknown card type Unknown cardType = iota // AmericanExpress card type AmericanExpress // Aura card type Aura // Bankcard card type Bankcard // Cabal card type Cabal // ChinaUnionPay card type ChinaUnionPay // Dankort card type Dankort // DinersClubCarteBlanche card type DinersClubCarteBlanche // DinersClubEnroute card type DinersClubEnroute // DinersClubInternational card type DinersClubInternational // Discover card type Discover // Elo card type Elo // Hipercard card type Hipercard // InstaPayment card type InstaPayment // InterPayment card type InterPayment // JCB card type JCB // Maestro card type Maestro // Mastercard card type Mastercard // Visa card type Visa // VisaElectron card type VisaElectron )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Card ¶
type Card struct {
// Type is an optional string with one of the supported card types. If the type is supplied, it will be validated that the type matches the number
Type string
// Number is the credit card number
Number string
// ExpiryMonth is the credit card expiration month
ExpiryMonth int
// ExpiryYear is the credit card expiration year
ExpiryYear int
// CVV is the credit card CVV code
CVV string
}
Card is a struct that contains a credit card type. This holds generic information about the credit card
func (*Card) Validate ¶
func (c *Card) Validate() *Validation
Validate performs validation on the card. Apart from a copy of the card, it also returns - ValidCardNumber is a boolean that indicates if a credit card number is valid for a given credit card type if given and verifies that the credit card number passes the Luhn algorithm - ValidExpiryMonth is a boolean that indicates if a value is a valid credit card expiry month (the range is 1 to 12) - ValidExpiryYear is a boolean that indicates if a value is a valid credit card expiry year (the range is 1900 to 2200) - ValidCVV is a boolean that indicates if a CVV is valid for a given credit card type. For example, American Express requires a four digit CVV, while Visa and Mastercard require a three digit CVV - IsExpired is a boolean that indicates if a credit card's expiration date has been reached - Errors is an array of validation errors that might occur during validation
type Validation ¶
type Validation struct {
// A pointer to the struct that was passed in for validation
Card *Card
// ValidCardNumber is a boolean that indicates if a credit card number is valid for a given credit card type if given and verifies that the credit card number passes the Luhn algorithm
ValidCardNumber bool
// ValidExpiryMonth is a boolean that indicates if a value is a valid credit card expiry month (the range is 1 to 12)
ValidExpiryMonth bool
// ValidExpiryYear is a boolean that indicates if a value is a valid credit card expiry year (the range is 1900 to 2200)
ValidExpiryYear bool
// ValidCVV is a boolean that indicates if a CVV is valid for a given credit card type. For example, American Express requires a four digit CVV, while Visa and Mastercard require a three digit CVV
ValidCVV bool
// IsExpired is a boolean that indicates if a credit card's expiration date has been reached
IsExpired bool
// Errors is an array of validation errors that might occur during validation
Errors []string
}
Validation is the object returned by the validate method, which contains the validation result of the card