Use these Go functions and Laravel for Go rules when moving a form from laravel-validation-rules/credit-card.
| PHP | Go |
|---|---|
Factory::makeFromNumber($number) | creditcard.Parse(number) |
new Visa($number) | Look up creditcard.BrandNamed("visa"), then call brand.Parse(number) |
CardNumber | creditcard.Number() |
CardCvc | creditcard.CVC() or creditcard.CVCFrom("number") |
CardExpirationYear | creditcard.ExpirationYear() |
CardExpirationMonth | creditcard.ExpirationMonth() |
CardExpirationDate('m/y') | creditcard.ExpirationDate("m/y") |
ExpirationDateValidator::validate | creditcard.ValidExpiration(year, month, now) |
MSG_* | creditcard.Key* constants |
To pass a companion value directly, use CVCFor(number), ExpirationYearFor(month) or
ExpirationMonthFor(year).
Add rule.Required to mandatory fields. Laravel for Go skips these rules on missing, null and blank
fields. Configure DontFlash for every card
number and CVC field before accepting checkout form submissions.
The Go rule messages default to English. Use Message or MessageFor with an exported Key*
constant if your application expects translation keys. Parsing strips ASCII whitespace before
brand recognition. Validation failures expose a fixed category or message without submitted values.