validatePayment function
Validates a Payment - currency code, dates, bank accounts, and beneficiary name (required since v1.2.0).
Implementation
void validatePayment(Payment payment, String path,
{int version = Version.v120}) {
for (var i = 0; i < payment.bankAccounts.length; i++) {
validateBankAccount(payment.bankAccounts[i], '$path.bankAccounts[$i]');
}
if (!_isValidCurrencyCode(payment.currencyCode)) {
throw BysquareValidationError(
'Invalid currency code. Make sure ISO 4217 format is used.',
'$path.currencyCode',
);
}
if (payment.paymentDueDate != null &&
!_isValidYyyymmdd(payment.paymentDueDate!)) {
throw BysquareValidationError(
'Invalid date. Make sure YYYYMMDD format is used.',
'$path.paymentDueDate',
);
}
if (payment is StandingOrder &&
payment.lastDate != null &&
!_isValidYyyymmdd(payment.lastDate!)) {
throw BysquareValidationError(
'Invalid date. Make sure YYYYMMDD format is used.',
'$path.lastDate',
);
}
if (payment is DirectDebit &&
payment.validTillDate != null &&
!_isValidYyyymmdd(payment.validTillDate!)) {
throw BysquareValidationError(
'Invalid date. Make sure YYYYMMDD format is used.',
'$path.validTillDate',
);
}
if (version >= Version.v120 && payment.beneficiary.name.isEmpty) {
throw BysquareValidationError(
'Beneficiary name is required.',
'$path.beneficiary.name',
);
}
}