From d2848cf569387dfbd25b1ca14ae3a61b21b56384 Mon Sep 17 00:00:00 2001 From: Paul Sohier Date: Wed, 25 Apr 2018 19:11:32 +0200 Subject: [PATCH] getIban might return null from the bunq API. Fixes #1378 as it gets imported now :) --- app/Import/Routine/BunqRoutine.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/Import/Routine/BunqRoutine.php b/app/Import/Routine/BunqRoutine.php index ffc7f09df4..9ae6e42871 100644 --- a/app/Import/Routine/BunqRoutine.php +++ b/app/Import/Routine/BunqRoutine.php @@ -320,23 +320,27 @@ class BunqRoutine implements RoutineInterface private function convertToAccount(LabelMonetaryAccount $party, string $expectedType): Account { Log::debug('in convertToAccount()'); - // find opposing party by IBAN first. - $result = $this->accountRepository->findByIbanNull($party->getIban(), [$expectedType]); - if (null !== $result) { - Log::debug(sprintf('Search for %s resulted in account %s (#%d)', $party->getIban(), $result->name, $result->id)); - return $result; - } - - // try to find asset account just in case: - if ($expectedType !== AccountType::ASSET) { - $result = $this->accountRepository->findByIbanNull($party->getIban(), [AccountType::ASSET]); + if ($party->getIban() !== null) { + // find opposing party by IBAN first. + $result = $this->accountRepository->findByIbanNull($party->getIban(), [$expectedType]); if (null !== $result) { - Log::debug(sprintf('Search for Asset "%s" resulted in account %s (#%d)', $party->getIban(), $result->name, $result->id)); + Log::debug(sprintf('Search for %s resulted in account %s (#%d)', $party->getIban(), $result->name, $result->id)); return $result; } + + // try to find asset account just in case: + if ($expectedType !== AccountType::ASSET) { + $result = $this->accountRepository->findByIbanNull($party->getIban(), [AccountType::ASSET]); + if (null !== $result) { + Log::debug(sprintf('Search for Asset "%s" resulted in account %s (#%d)', $party->getIban(), $result->name, $result->id)); + + return $result; + } + } } + // create new account: $data = [ 'user_id' => $this->job->user_id,