Extended IBAN validation

This commit is contained in:
Sander Dorigo 2023-06-23 10:57:26 +02:00
parent 5fdcf37d06
commit 0cab974048
3 changed files with 15 additions and 2 deletions

View File

@ -92,10 +92,11 @@ trait WithdrawalValidation
{
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
Log::debug('Now in validateWithdrawalDestination()', $array);
// source can be any of the following types.
$validTypes = $this->combinations[$this->transactionType][$this->source->accountType->type] ?? [];
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
if (null === $accountId && null === $accountName && null === $accountIban && false === $this->canCreateTypes($validTypes)) {
// if both values are NULL return false,
// because the destination of a withdrawal can never be created automatically.
$this->destError = (string)trans('validation.withdrawal_dest_need_data');
@ -117,6 +118,15 @@ trait WithdrawalValidation
return false;
}
}
// if there is an iban, it can only be in use by a revenue account or we will fail.
if(null !== $accountIban && '' !== $accountIban) {
app('log')->debug('Check if there is not already an account with this IBAN');
$existing = $this->findExistingAccount([AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], ['iban' => $accountIban]);
if(null !== $existing) {
$this->destError = (string)trans('validation.withdrawal_dest_iban_exists');
return false;
}
}
// if the account can be created anyway don't need to search.
return true === $this->canCreateTypes($validTypes);

View File

@ -107,7 +107,7 @@ return [
'webhooks' => true,
'handle_debts' => true,
],
'version' => '6.0.15',
'version' => '6.0.16',
'api_version' => '2.0.4',
'db_version' => 19,

View File

@ -208,6 +208,9 @@ return [
'withdrawal_dest_need_data' => '[a] Need to get a valid destination account ID and/or valid destination account name to continue.',
'withdrawal_dest_bad_data' => 'Could not find a valid destination account when searching for ID ":id" or name ":name".',
'withdrawal_dest_iban_exists' => 'This destination account IBAN is already in use by an asset account or a liability and cannot be used as a withdrawal destination.',
'deposit_src_iban_exists' => 'This source account IBAN is already in use by an asset account or a liability and cannot be used as a deposit source.',
'reconciliation_source_bad_data' => 'Could not find a valid reconciliation account when searching for ID ":id" or name ":name".',
'generic_source_bad_data' => '[e] Could not find a valid source account when searching for ID ":id" or name ":name".',