PeBankAccountForm class

A secure form widget for entering a customer's bank account information.

PeBankAccountForm provides a UI component for securely collecting bank account details. It does not store data locally and instead tokenizes the information using PayEngine.

Features:

  • Securely collects bank account details.
  • Supports additional customizable fields.
  • Provides methods to show/hide the keyboard.
  • Allows tokenizing the entered data for safe storage.

Usage Example:

class BankAccountScreen extends StatefulWidget {
  const BankAccountScreen({Key? key}) : super(key: key);

  @override
  State<BankAccountScreen> createState() => _BankAccountViewState();
}

class _BankAccountViewState extends State<BankAccountScreen> {
  late PeBankAccountForm bankAccountForm;
  Map<String, dynamic> result = {};

  @override
  void initState() {
    super.initState();

    // Define additional fields if required
    var additionalFields = [
      PayEngineField('address_zip', 'text', 'Zip Code', true,
          keyboardType: PayEngineKeyboardType.number,
          pattern: r"^(?:\d{5}(?:-\d{4})?|[A-Z]\d[A-Z] ?\d[A-Z]\d)$"),
    ];

    bankAccountForm = PeBankAccountForm(additionalFields: additionalFields);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Bank Account')),
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              /// The bank account form
              bankAccountForm,
              const SizedBox(height: 20),

              /// Show keyboard
              ElevatedButton(
                onPressed: () => bankAccountForm.showKeyboard(),
                child: const Text('Show Keyboard'),
              ),

              /// Hide keyboard
              ElevatedButton(
                onPressed: () => bankAccountForm.hideKeyboard(),
                child: const Text('Hide Keyboard'),
              ),

              /// Tokenize bank account data
              ElevatedButton(
                onPressed: () async {
                  try {
                    final response = await bankAccountForm.tokenize();
                    setState(() {
                      result = response.toJson();
                    });
                  } catch (e) {
                    setState(() {
                      result = {'error': e.toString()};
                    });
                  }
                },
                child: const Text('Tokenize Bank Account'),
              ),

              /// Display the tokenization result
              const SizedBox(height: 20),
              Container(
                padding: const EdgeInsets.all(10),
                decoration: BoxDecoration(
                  color: Colors.yellow[100],
                  borderRadius: BorderRadius.circular(8),
                ),
                child: Text("Tokenized Data: \n${result.toString()}"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

How It Works:

  1. Create an instance of PeBankAccountForm, optionally passing additional fields.
  2. Display the form inside your widget tree.
  3. Use showKeyboard and hideKeyboard to manage input focus.
  4. Call tokenize to securely send the bank account data and receive a token.
Inheritance
Implemented types

Constructors

PeBankAccountForm({Key? key, List<PayEngineField>? additionalFields})
Creates a new instance of PeBankAccountForm.

Properties

additionalFields List<PayEngineField>?
Optional additional fields that can be added to the form.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<PeBankAccountForm>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
hideKeyboard() → void
Hides the keyboard for input fields.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
showKeyboard() → void
Shows the keyboard for input fields.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
tokenize([String? merchantId, Map<String, String>? additionalData]) Future<PEBankAccount>
Tokenizes the bank account details entered in the form.
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited