validate method

  1. @override
void validate()
override

Validate the request data.

Performs comprehensive validation on the payment request including:

  • Amount validation (positive, within currency limits)
  • Email format validation
  • Reference format validation (if provided)
  • Callback URL validation (if provided)

Throws

Implementation

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

  // For bank transfers, account details are usually generated by Paystack
  // So we don't require them in the request, but if provided, validate them
  if (accountNumber != null) {
    if (accountNumber!.isEmpty) {
      throw ArgumentError('Account number cannot be empty if provided');
    }
    if (!RegExp(r'^\d{10}$').hasMatch(accountNumber!)) {
      throw ArgumentError('Account number must be exactly 10 digits');
    }
  }

  if (bankCode != null) {
    if (bankCode!.isEmpty) {
      throw ArgumentError('Bank code cannot be empty if provided');
    }
    if (!RegExp(r'^\d{3}$').hasMatch(bankCode!)) {
      throw ArgumentError('Bank code must be exactly 3 digits');
    }
  }

  if (bankName != null && bankName!.isEmpty) {
    throw ArgumentError('Bank name cannot be empty if provided');
  }
}