# Getting started (laravel-go-credit-card)

> Install the package and configure validation and session exclusions for a Laravel for Go checkout form.

- Package: laravel-go-credit-card (Laravel for Go, alpha), go modules: `github.com/bowerbird-si/laravel-go-credit-card`
- Maintenance: active; Latest release: 0.1.0 (2026-12-04); Framework: go.laravel.com v0.2.0 or later; Go: Go 1.27 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-go-credit-card), [pkg.go.dev](https://pkg.go.dev/github.com/bowerbird-si/laravel-go-credit-card@v0.1.0), [Changelog](https://oss.bowerbird.si/go-credit-card/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-go-credit-card/blob/516b06ae7d4962972d8cf865beb39b4cfa10a77b/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-go-credit-card/blob/516b06ae7d4962972d8cf865beb39b4cfa10a77b/SECURITY.md)
- Based on: [laravel-validation-rules/credit-card](https://github.com/laravel-validation-rules/credit-card): The card validation package this independent Go implementation follows, pinned to version 1.12.3.
- PHP parity: full (30 covered, 12 diverged, 0 planned of 42 abilities; 830 fixtures; follows laravel-validation-rules/credit-card 1.12.3; verified 2026-12-04)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/go-credit-card/docs/getting-started/
- Source: https://github.com/bowerbird-si/laravel-go-credit-card/blob/516b06ae7d4962972d8cf865beb39b4cfa10a77b/docs/getting-started.md

Install the package and configure validation and session exclusions for a Laravel for Go checkout form.

```shellscript
go get github.com/bowerbird-si/laravel-go-credit-card
```

`creditcard.Parse("4111 0000 0000 0008")` validates the number and returns a card containing its
brand and digit count. Use `card.Brand().Funding()` for debit or credit. `creditcard.Detect` checks
brand recognition alone. To require a particular brand, look it up with `creditcard.BrandNamed("visa")`
and call its `Parse` method. The checks run locally and validate format and checksum. The payment
provider verifies the account and authorizes payments.

## Validate a form

Keep numbers and security codes in string fields to preserve leading zeroes. This example uses the
standard sibling name `card_number`. Use `CVCFrom("number")` when the field has a different name.

```go
type Payment struct {
    CardNumber string `json:"card_number"`
    CVC        string `json:"cvc"`
    Expiry     string `json:"expiry"`
}

func (f *Payment) Rules() validation.Rules {
    return validation.For(f,
        rule.Field(&f.CardNumber, rule.Required, creditcard.Number()),
        rule.Field(&f.CVC, rule.Required, creditcard.CVC()),
        rule.Field(&f.Expiry, rule.Required, creditcard.ExpirationDate("m/y")),
    )
}
```

Import `go.laravel.com/validation` and `go.laravel.com/validation/rule` for the form. Add
`rule.Required` to mandatory fields. Laravel skips these card rules for missing, null and blank
values.

### Keep card fields out of old input

Laravel flashes form input to the session on a validation redirect. Set `DontFlash` on your
application's `laravel.Options` before accepting a card form.

```go
laravel.Options{
    Errors: web.Errors{
        DontFlash: []string{"card_number", "cvc"},
    },
}
```

Import `go.laravel.com` and `go.laravel.com/web` for this configuration. Use the submitted field paths,
such as `card.number` and `cards.*.cvc` for nested forms. The application uses the same exclusions
with `web.Back().WithInput()`.

## Expiration checks

`ExpirationDate("m/y")` expects PHP format tokens. For separate fields, use `ExpirationYear()`
and `ExpirationMonth()` with the default sibling paths `expiration_year` and
`expiration_month`. The `From` constructors select other field paths. All three rules use the
Laravel application clock. For direct checks, pass a reference time to `ValidExpiration` or
`ValidExpirationDate`.

The card stays valid through its expiration month. A two-digit year in a split field uses the
current century. A formatted date uses the PHP pivot, where `69` means 2069 and `70` means 1970.

## Messages

Rules use English by default. Call `Message("Check the entered value.")` to override a rule, or
`MessageFor(creditcard.KeyLengthInvalid, "Check the number of digits.")` to replace one failure
message. A template can use Laravel's `:attribute` placeholder.
