Skip to main content
CreditCardField ← Back to Table of Contents

Summary

Payment input that combines four fields (number, name, expiry, CVV) into one cohesive component. Includes an interactive 3D-style card preview that flips when focusing the CVV field and validates numbers using the Luhn algorithm.
ClassBjanczak\FilamentFlexFields\Filament\Forms\Components\CreditCardField
State typearray{number, name, expiry, cvv}
Model cast'payment_method' => 'array'
FieldTypecredit-card
Playgroundcredit-card slug in Flex Fields playground
Default variantmidnight

Basic usage

Standard payment form

use Bjanczak\FilamentFlexFields\Filament\Forms\Components\CreditCardField;

CreditCardField::make('card_details')
    ->label('Payment Method')
    ->required();

Custom labels and variant

CreditCardField::make('card_details')
    ->variant('ocean')
    ->numberLabel('Numer karty')
    ->nameLabel('Imię i nazwisko')
    ->expiryLabel('Data ważności')
    ->cvvLabel('Kod CVV');

State & validation

Stored value

The field stores an array of card details. Note that for security, you should usually only store the number (masked), name, and expiry in your database, while sending the full details to your payment processor.
// Dehydrated state for storage
[
    'number' => '4111111111111111',
    'name' => 'John Doe',
    'expiry' => '12/28',
]

Built-in Validation

CreditCardField performs several automatic checks:
  • Luhn Check: Validates the card number checksum.
  • Expiry Date: Ensures the card is not expired and the format is MM/YY.
  • CVV Format: Validates 3 or 4 digit numeric codes.
  • Required Fields: If required(), all four sub-fields must be filled.

Visual Customization

Variants

Choose from four built-in card themes:
VariantColors
midnightDeep dark / black (default)
oceanBlue gradient
sunsetOrange / red gradient
slateNeutral gray
CreditCardField::make('card')->variant('sunset');

Input Variants

Change the style of the text inputs below the card:
  • primary: Standard bordered inputs.
  • secondary: Subtle background-only inputs.
  • flat: Minimalist underline style.
CreditCardField::make('card')->inputVariant('flat');

Configuration API

All methods accept Closure unless noted.
MethodTypeDefaultDescription
variant(string|Closure $variant)Setup'midnight'Card theme: midnight, ocean, sunset, slate
inputVariant(string|Closure $var)Setup'primary'Input style: primary, secondary, flat
flipOnCvvFocus(bool|Closure $cond)SetuptrueFlip card to back when CVV is focused
numberLabel(string|Closure $label)Setup(trans)Card number field label
nameLabel(string|Closure $label)Setup(trans)Cardholder name field label
expiryLabel(string|Closure $label)Setup(trans)Expiry date field label
cvvLabel(string|Closure $label)Setup(trans)CVV field label
mark(string|Closure $mark)Setup'CARD'Text shown on the card preview
size(string|Closure $size)Setup'md'sm, md, lg
rounding(string|Closure $round)SetupconfigBorder radius token
focusOutline(bool|Closure $cond)SetuptrueShow focus rings on inputs

Real-world examples

Checkout Page Section

Section::make('Payment Information')
    ->description('We support Visa, Mastercard, and American Express.')
    ->schema([
        CreditCardField::make('payment_details')
            ->variant('midnight')
            ->inputVariant('primary')
            ->required(),
            
        Placeholder::make('security_note')
            ->content('Your payment information is encrypted and never stored on our servers.'),
    ]);

Playground

/admin/flex-fields-playground/credit-card See Playground for setup.
ComponentWhen to use instead
FlexTextInputSingle masked input for card number only
SelectFieldSelecting from saved payment methods
AddressAutocompleteBilling address collection

CSS classes (reference)

ClassRole
fff-credit-card-fieldRoot wrapper
fff-credit-card-field__previewThe 3D card container
fff-credit-card-field__card-frontFront side of card
fff-credit-card-field__card-backBack side of card
fff-credit-card-field__inputsGrid of text inputs
fff-credit-card-field--{variant}Theme variant class
fff-credit-card-field--input-{variant}Input style variant class