CardFields

@MainActor
public struct CardFields : View

A SwiftUI view that renders a complete card entry form, including fields for card number, expiration date, and CVV. It handles input validation, card brand detection, and focus advancement between fields automatically.

Initializer

  • Creates a CardFields form.

    Declaration

    Swift

    @MainActor
    public init(
        authorization: String,
        card: BTCard,
        completion: @escaping (BTCardNonce?, Error?) -> Void
    )

    Parameters

    authorization

    A valid tokenization key or client token.

    card

    A BTCard created using the CardFields convenience initializer, used to supply additional fields such as cardholder name or billing address. Card number, expiration date, and CVV are managed by the form — if set on the BTCard, they will be overwritten by the values entered in the form.

    completion

    Called with the resulting BTCardNonce on success, or an Error on failure.

View

Public Methods

  • Registers a handler that is called whenever the form’s overall validity changes.

    Use the isValid parameter to enable or disable your submit button. When the user taps submit, call the provided submit closure to tokenize the card. The merchant is responsible for providing and managing the submit button — CardFields does not include one.

    Declaration

    Swift

    @MainActor
    public func onValidityChange(_ handler: @escaping (Bool, @escaping () -> Void) -> Void) -> CardFields

    Parameters

    handler

    A closure receiving the current validity state and a submit closure the merchant should call when their submit button is tapped.

    Return Value

    A modified CardFields view.