validateFields method

void validateFields(
  1. String id,
  2. String secret,
  3. String subject,
  4. String amount,
  5. String currency,
  6. String? email,
)

Implementation

void validateFields(
  String id,
  String secret,
  String subject,
  String amount,
  String currency,
  String? email,
) {
  if (id.isEmpty) {
    throw ArgumentError.value(id, 'id cannot be empty or null');
  }

  if (secret.isEmpty) {
    throw ArgumentError.value(secret, 'secret cannot be empty or null');
  }

  if (subject.isEmpty) {
    throw ArgumentError.value(subject, 'subject cannot be empty or null');
  }

  var amountInt = int.parse(amount);
  if (amount.isEmpty) {
    throw ArgumentError.value(amount, 'amount cannot be empty or null');
  } else if (amountInt is int && amountInt <= 0) {
    throw ArgumentError.value(
        amount, 'amount must be an int and greater than 0');
  }

  if (currency.isEmpty) {
    throw ArgumentError.value(currency, 'currency cannot be empty or null');
  }

  if (email != null && email.isNotEmpty && !validateEmail(email)) {
    throw ArgumentError.value(email, 'wrong email format');
  }
}