From dc73db2a07f9c2cf014b21b0220aa4a97ad47168 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 1 Oct 2018 19:24:24 +0200 Subject: [PATCH 01/14] Added FinTS import --- .../FinTSJobConfiguration.php | 137 ++++++++++++++++ app/Import/Routine/FinTSRoutine.php | 84 ++++++++++ app/Support/FinTS/FinTS.php | 92 +++++++++++ .../FinTS/ChooseAccountHandler.php | 120 ++++++++++++++ .../FinTS/FinTSConfigurationInterface.php | 50 ++++++ .../FinTS/NewFinTSJobHandler.php | 106 +++++++++++++ .../Routine/FinTS/StageImportDataHandler.php | 147 ++++++++++++++++++ composer.json | 1 + config/import.php | 10 ++ public/images/logos/fints.png | Bin 0 -> 2399 bytes resources/lang/en_US/form.php | 10 ++ resources/lang/en_US/import.php | 9 +- .../views/import/fints/choose_account.twig | 44 ++++++ resources/views/import/fints/new.twig | 39 +++++ 14 files changed, 848 insertions(+), 1 deletion(-) create mode 100644 app/Import/JobConfiguration/FinTSJobConfiguration.php create mode 100644 app/Import/Routine/FinTSRoutine.php create mode 100644 app/Support/FinTS/FinTS.php create mode 100644 app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php create mode 100644 app/Support/Import/JobConfiguration/FinTS/FinTSConfigurationInterface.php create mode 100644 app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php create mode 100644 app/Support/Import/Routine/FinTS/StageImportDataHandler.php create mode 100644 public/images/logos/fints.png create mode 100644 resources/views/import/fints/choose_account.twig create mode 100644 resources/views/import/fints/new.twig diff --git a/app/Import/JobConfiguration/FinTSJobConfiguration.php b/app/Import/JobConfiguration/FinTSJobConfiguration.php new file mode 100644 index 0000000000..a3dc24b709 --- /dev/null +++ b/app/Import/JobConfiguration/FinTSJobConfiguration.php @@ -0,0 +1,137 @@ +. + */ +declare(strict_types=1); + +namespace FireflyIII\Import\JobConfiguration; + +use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Models\ImportJob; +use FireflyIII\Support\Import\JobConfiguration\FinTS\ChooseAccountHandler; +use FireflyIII\Support\Import\JobConfiguration\FinTS\FinTSConfigurationInterface; +use FireflyIII\Support\Import\JobConfiguration\FinTS\NewFinTSJobHandler; +use Illuminate\Support\MessageBag; + +abstract class FinTSConfigurationSteps +{ + const NEW = 'new'; + const CHOOSE_ACCOUNT = 'choose_account'; + const GO_FOR_IMPORT = 'go-for-import'; +} + +class FinTSJobConfiguration implements JobConfigurationInterface +{ + /** @var ImportJob */ + private $importJob; + + /** + * Returns true when the initial configuration for this job is complete. + * + * @return bool + */ + public function configurationComplete(): bool + { + return $this->importJob->stage == FinTSConfigurationSteps::GO_FOR_IMPORT; + } + + /** + * Store any data from the $data array into the job. Anything in the message bag will be flashed + * as an error to the user, regardless of its content. + * + * @param array $data + * + * @return MessageBag + * @throws FireflyException + */ + public function configureJob(array $data): MessageBag + { + return $this->getConfigurationObject()->configureJob($data); + } + + /** + * Return the data required for the next step in the job configuration. + * + * @return array + * @throws FireflyException + */ + public function getNextData(): array + { + return $this->getConfigurationObject()->getNextData(); + } + + /** + * Returns the view of the next step in the job configuration. + * + * @return string + * @throws FireflyException + */ + public function getNextView(): string + { + switch ($this->importJob->stage) { + case FinTSConfigurationSteps::NEW: + case FinTSConfigurationSteps::CHOOSE_ACCOUNT: + return 'import.fints.' . $this->importJob->stage; + break; + default: + // @codeCoverageIgnoreStart + throw new FireflyException( + sprintf('FinTSJobConfiguration::getNextView() cannot handle stage "%s"', $this->importJob->stage) + ); + // @codeCoverageIgnoreEnd + } + } + + /** + * @param ImportJob $importJob + */ + public function setImportJob(ImportJob $importJob): void + { + $this->importJob = $importJob; + } + + /** + * Get the configuration handler for this specific stage. + * + * @return FinTSConfigurationInterface + * @throws FireflyException + */ + private function getConfigurationObject(): FinTSConfigurationInterface + { + $class = 'DoNotExist'; + switch ($this->importJob->stage) { + case FinTSConfigurationSteps::NEW: + $class = NewFinTSJobHandler::class; + break; + case FinTSConfigurationSteps::CHOOSE_ACCOUNT: + $class = ChooseAccountHandler::class; + break; + } + if (!class_exists($class)) { + throw new FireflyException(sprintf('Class %s does not exist in getConfigurationClass().', $class)); // @codeCoverageIgnore + } + + $configurator = app($class); + $configurator->setImportJob($this->importJob); + + return $configurator; + } + + +} \ No newline at end of file diff --git a/app/Import/Routine/FinTSRoutine.php b/app/Import/Routine/FinTSRoutine.php new file mode 100644 index 0000000000..7effeecfc5 --- /dev/null +++ b/app/Import/Routine/FinTSRoutine.php @@ -0,0 +1,84 @@ +. + */ +declare(strict_types=1); + +namespace FireflyIII\Import\Routine; + + +use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Import\JobConfiguration\FinTSConfigurationSteps; +use FireflyIII\Models\ImportJob; +use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; +use FireflyIII\Support\Import\Routine\FinTS\StageImportDataHandler; +use Illuminate\Support\Facades\Log; + +class FinTSRoutine implements RoutineInterface +{ + /** @var ImportJob */ + private $importJob; + /** @var ImportJobRepositoryInterface */ + private $repository; + + /** + * At the end of each run(), the import routine must set the job to the expected status. + * + * The final status of the routine must be "provider_finished". + * + * @throws FireflyException + */ + public function run(): void + { + Log::debug(sprintf('Now in FinTSRoutine::run() with status "%s" and stage "%s".', $this->importJob->status, $this->importJob->stage)); + $valid = ['ready_to_run']; // should be only ready_to_run + if (\in_array($this->importJob->status, $valid, true)) { + switch ($this->importJob->stage) { + default: + throw new FireflyException(sprintf('FinTSRoutine cannot handle stage "%s".', $this->importJob->stage)); // @codeCoverageIgnore + case FinTSConfigurationSteps::GO_FOR_IMPORT: + $this->repository->setStatus($this->importJob, 'running'); + /** @var StageImportDataHandler $handler */ + $handler = app(StageImportDataHandler::class); + $handler->setImportJob($this->importJob); + $handler->run(); + $transactions = $handler->getTransactions(); + + $this->repository->setTransactions($this->importJob, $transactions); + $this->repository->setStatus($this->importJob, 'provider_finished'); + $this->repository->setStage($this->importJob, 'final'); + + return; + } + } + } + + /** + * @param ImportJob $importJob + * + * @return void + */ + public function setImportJob(ImportJob $importJob): void + { + $this->importJob = $importJob; + $this->repository = app(ImportJobRepositoryInterface::class); + $this->repository->setUser($importJob->user); + } + +} \ No newline at end of file diff --git a/app/Support/FinTS/FinTS.php b/app/Support/FinTS/FinTS.php new file mode 100644 index 0000000000..c2bff5b290 --- /dev/null +++ b/app/Support/FinTS/FinTS.php @@ -0,0 +1,92 @@ +finTS = new \Fhp\FinTs( + $config['fints_url'], + $config['fints_port'], + $config['fints_bank_code'], + $config['fints_username'], + $config['fints_password'] + ); + } + + public function checkConnection() + { + try { + $this->finTS->getSEPAAccounts(); + return true; + } catch (\Exception $exception) { + return $exception->getMessage(); + } + } + + /** + * @return \Fhp\Model\SEPAAccount[] + * @throws FireflyException + */ + public function getAccounts() + { + try { + return $this->finTS->getSEPAAccounts(); + } catch (\Exception $exception) { + throw new FireflyException($exception->getMessage()); + } + } + + /** + * @param string $accountNumber + * @return \Fhp\Model\SEPAAccount + * @throws FireflyException + */ + public function getAccount($accountNumber) + { + $accounts = $this->getAccounts(); + $filteredAccounts = array_filter($accounts, function ($account) use ($accountNumber) { + return $account->getAccountNumber() == $accountNumber; + }); + if (count($filteredAccounts) != 1) { + throw new FireflyException("Cannot find account with number " . $accountNumber); + } + return $filteredAccounts[0]; + } + + /** + * @param \Fhp\Model\SEPAAccount $account + * @param \DateTime $from + * @param \DateTIme $to + * @return \Fhp\Model\StatementOfAccount\StatementOfAccount|null + * @throws FireflyException + */ + public function getStatementOfAccount(\Fhp\Model\SEPAAccount $account, \DateTime $from, \DateTIme $to) + { + try { + return $this->finTS->getStatementOfAccount($account, $from, $to); + } catch (\Exception $exception) { + throw new FireflyException($exception->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php new file mode 100644 index 0000000000..b17749b437 --- /dev/null +++ b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php @@ -0,0 +1,120 @@ +. + */ +declare(strict_types=1); + +namespace FireflyIII\Support\Import\JobConfiguration\FinTS; + + +use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Import\JobConfiguration\FinTSConfigurationSteps; +use FireflyIII\Models\AccountType; +use FireflyIII\Models\ImportJob; +use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; +use FireflyIII\Support\FinTS\FinTS; +use Illuminate\Support\MessageBag; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; + +class ChooseAccountHandler implements FinTSConfigurationInterface +{ + /** @var ImportJob */ + private $importJob; + /** @var ImportJobRepositoryInterface */ + private $repository; + /** @var AccountRepositoryInterface */ + private $accountRepository; + + /** + * Store data associated with current stage. + * + * @param array $data + * + * @return MessageBag + */ + public function configureJob(array $data): MessageBag + { + $config = $this->importJob->configuration; + $config['fints_account'] = (string)($data['fints_account'] ?? ''); + $config['local_account'] = (string)($data['local_account'] ?? ''); + $config['local_account'] = (string)($data['local_account'] ?? ''); + $config['from_date'] = (string)($data['from_date'] ?? ''); + $config['to_date'] = (string)($data['to_date'] ?? ''); + $this->repository->setConfiguration($this->importJob, $config); + + try { + $finTS = new FinTS($this->importJob->configuration); + $finTS->getAccount($config['fints_account']); + } catch (FireflyException $e) { + return new MessageBag($e->getMessage()); + } + + $this->repository->setStage($this->importJob, FinTSConfigurationSteps::GO_FOR_IMPORT); + + return new MessageBag(); + } + + /** + * Get the data necessary to show the configuration screen. + * + * @return array + * @throws \FireflyIII\Exceptions\FireflyException + */ + public function getNextData(): array + { + $finTS = new FinTS($this->importJob->configuration); + $finTSAccounts = $finTS->getAccounts(); + $finTSAccountsData = []; + foreach ($finTSAccounts as $account) { + $finTSAccountsData[$account->getAccountNumber()] = $account->getIban(); + } + + $localAccounts = []; + foreach ($this->accountRepository->getAccountsByType([AccountType::ASSET]) as $localAccount) { + $display_name = $localAccount->name; + if ($localAccount->iban) { + $display_name .= " - $localAccount->iban"; + } + $localAccounts[$localAccount->id] = $display_name; + } + + $data = [ + 'fints_accounts' => $finTSAccountsData, + 'fints_account' => $this->importJob->configuration['fints_account'] ?? null, + 'local_accounts' => $localAccounts, + 'local_account' => $this->importJob->configuration['local_account'] ?? null, + 'from_date' => $this->importJob->configuration['from_date'] ?? (new \DateTime('now - 1 month'))->format('Y-m-d'), + 'to_date' => $this->importJob->configuration['to_date'] ?? (new \DateTime('now'))->format('Y-m-d') + ]; + return $data; + } + + /** + * @param ImportJob $importJob + */ + public function setImportJob(ImportJob $importJob): void + { + $this->importJob = $importJob; + $this->repository = app(ImportJobRepositoryInterface::class); + $this->accountRepository = app(AccountRepositoryInterface::class); + $this->repository->setUser($importJob->user); + } + + +} \ No newline at end of file diff --git a/app/Support/Import/JobConfiguration/FinTS/FinTSConfigurationInterface.php b/app/Support/Import/JobConfiguration/FinTS/FinTSConfigurationInterface.php new file mode 100644 index 0000000000..47bcedad33 --- /dev/null +++ b/app/Support/Import/JobConfiguration/FinTS/FinTSConfigurationInterface.php @@ -0,0 +1,50 @@ +. + */ +declare(strict_types=1); + +namespace FireflyIII\Support\Import\JobConfiguration\FinTS; + +use FireflyIII\Models\ImportJob; +use Illuminate\Support\MessageBag; + +interface FinTSConfigurationInterface +{ + /** + * Store data associated with current stage. + * + * @param array $data + * + * @return MessageBag + */ + public function configureJob(array $data): MessageBag; + + /** + * Get the data necessary to show the configuration screen. + * + * @return array + */ + public function getNextData(): array; + + /** + * @param ImportJob $importJob + */ + public function setImportJob(ImportJob $importJob): void; +} \ No newline at end of file diff --git a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php new file mode 100644 index 0000000000..848543da0d --- /dev/null +++ b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php @@ -0,0 +1,106 @@ +. + */ +declare(strict_types=1); + + +namespace FireflyIII\Support\Import\JobConfiguration\FinTS; + + +use FireflyIII\Import\JobConfiguration\FinTSConfigurationSteps; +use FireflyIII\Models\ImportJob; +use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; +use FireflyIII\Support\FinTS\FinTS; +use Illuminate\Support\MessageBag; + +class NewFinTSJobHandler implements FinTSConfigurationInterface +{ + /** @var ImportJob */ + private $importJob; + /** @var ImportJobRepositoryInterface */ + private $repository; + + /** + * Store data associated with current stage. + * + * @param array $data + * + * @return MessageBag + * @throws \FireflyIII\Exceptions\FireflyException + */ + public function configureJob(array $data): MessageBag + { + $config = []; + + $config['fints_url'] = trim($data['fints_url'] ?? ''); + $config['fints_port'] = (int)($data['fints_port'] ?? ''); + $config['fints_bank_code'] = (string)($data['fints_bank_code'] ?? ''); + $config['fints_username'] = (string)($data['fints_username'] ?? ''); + $config['fints_password'] = (string)($data['fints_password'] ?? ''); + + $this->repository->setConfiguration($this->importJob, $config); + + $incomplete = false; + foreach ($config as $value) { + $incomplete = $value == '' or $incomplete; + } + if ($incomplete) { + return new MessageBag([trans('import.incomplete_fints_form')]); + } + + $finTS = new FinTS($this->importJob->configuration); + if (($checkConnection = $finTS->checkConnection()) !== true) { + return new MessageBag([trans('import.fints_connection_failed', ['originalError' => $checkConnection])]); + } + + $this->repository->setStage($this->importJob, FinTSConfigurationSteps::CHOOSE_ACCOUNT); + + return new MessageBag(); + } + + /** + * Get the data necessary to show the configuration screen. + * + * @return array + */ + public function getNextData(): array + { + $config = $this->importJob->configuration; + var_dump($config); + return [ + 'fints_url' => $config['fints_url'] ?? "", + 'fints_port' => $config['fints_port'] ?? "443", + 'fints_bank_code' => $config['fints_bank_code'] ?? "", + 'fints_username' => $config['fints_username'] ?? "", + 'fints_password' => $config['fints_password'] ?? "", + ]; + } + + /** + * @param ImportJob $importJob + */ + public function setImportJob(ImportJob $importJob): void + { + $this->importJob = $importJob; + $this->repository = app(ImportJobRepositoryInterface::class); + $this->repository->setUser($importJob->user); + } + +} \ No newline at end of file diff --git a/app/Support/Import/Routine/FinTS/StageImportDataHandler.php b/app/Support/Import/Routine/FinTS/StageImportDataHandler.php new file mode 100644 index 0000000000..1f120c5600 --- /dev/null +++ b/app/Support/Import/Routine/FinTS/StageImportDataHandler.php @@ -0,0 +1,147 @@ +transactions = []; + $this->importJob = $importJob; + $this->repository = app(ImportJobRepositoryInterface::class); + $this->accountRepository = app(AccountRepositoryInterface::class); + $this->mapper = app(OpposingAccountMapper::class); + $this->mapper->setUser($importJob->user); + $this->repository->setUser($importJob->user); + $this->accountRepository->setUser($importJob->user); + } + + /** + * @throws \FireflyIII\Exceptions\FireflyException + */ + public function run() + { + Log::debug('Now in StageImportDataHandler::run()'); + + $localAccount = $this->accountRepository->find($this->importJob->configuration['local_account']); + $finTS = new FinTS($this->importJob->configuration); + $fintTSAccount = $finTS->getAccount($this->importJob->configuration['fints_account']); + $statementOfAccount = $finTS->getStatementOfAccount($fintTSAccount, new \DateTime($this->importJob->configuration['from_date']), new \DateTime($this->importJob->configuration['to_date'])); + $collection = []; + foreach ($statementOfAccount->getStatements() as $statement) { + foreach ($statement->getTransactions() as $transaction) { + $collection[] = $this->convertTransaction($transaction, $localAccount); + } + } + + $this->transactions = $collection; + } + + private function convertTransaction(FinTSTransaction $transaction, LocalAccount $source): array + { + Log::debug(sprintf('Start converting transaction %s', $transaction->getDescription1())); + + $amount = $transaction->getAmount(); + $debitOrCredit = $transaction->getCreditDebit(); + + Log::debug(sprintf('Amount is %s', $amount)); + if ($debitOrCredit == Transaction::CD_CREDIT) { + $type = TransactionType::DEPOSIT; + } else { + $type = TransactionType::WITHDRAWAL; + $amount = -$amount; + } + + $destination = $this->mapper->map( + null, + $amount, + ['iban' => $transaction->getAccountNumber(), 'name' => $transaction->getName()] + ); + if ($debitOrCredit == Transaction::CD_CREDIT) { + [$source, $destination] = [$destination, $source]; + } + + if ($source->accountType->type === AccountType::ASSET && $destination->accountType->type === AccountType::ASSET) { + $type = TransactionType::TRANSFER; + Log::debug('Both are assets, will make transfer.'); + } + + $storeData = [ + 'user' => $this->importJob->user_id, + 'type' => $type, + 'date' => $transaction->getValutaDate()->format('Y-m-d'), + 'description' => $transaction->getDescription1(), + 'piggy_bank_id' => null, + 'piggy_bank_name' => null, + 'bill_id' => null, + 'bill_name' => null, + 'tags' => [], + 'internal_reference' => null, + 'external_id' => null, + 'notes' => null, + 'bunq_payment_id' => null, + 'transactions' => [ + // single transaction: + [ + 'description' => null, + 'amount' => $amount, + 'currency_id' => null, + 'currency_code' => 'EUR', + 'foreign_amount' => null, + 'foreign_currency_id' => null, + 'foreign_currency_code' => null, + 'budget_id' => null, + 'budget_name' => null, + 'category_id' => null, + 'category_name' => null, + 'source_id' => $source->id, + 'source_name' => null, + 'destination_id' => $destination->id, + 'destination_name' => null, + 'reconciled' => false, + 'identifier' => 0, + ], + ], + ]; + + return $storeData; + } + + /** + * @return array + */ + public function getTransactions(): array + { + return $this->transactions; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index 3a22067015..66d610c88b 100644 --- a/composer.json +++ b/composer.json @@ -64,6 +64,7 @@ "league/commonmark": "0.*", "league/csv": "9.*", "league/fractal": "^0.17.0", + "mschindler83/fints-hbci-php": "^1.0", "pragmarx/google2fa": "3.*", "pragmarx/google2fa-laravel": "0.*", "rcrowe/twigbridge": "0.9.*", diff --git a/config/import.php b/config/import.php index 5f6a724700..ff93e167ae 100644 --- a/config/import.php +++ b/config/import.php @@ -25,6 +25,7 @@ declare(strict_types=1); use FireflyIII\Import\JobConfiguration\BunqJobConfiguration; use FireflyIII\Import\JobConfiguration\FakeJobConfiguration; use FireflyIII\Import\JobConfiguration\FileJobConfiguration; +use FireflyIII\Import\JobConfiguration\FinTSJobConfiguration; use FireflyIII\Import\JobConfiguration\SpectreJobConfiguration; use FireflyIII\Import\JobConfiguration\YnabJobConfiguration; use FireflyIII\Import\Prerequisites\BunqPrerequisites; @@ -34,6 +35,7 @@ use FireflyIII\Import\Prerequisites\YnabPrerequisites; use FireflyIII\Import\Routine\BunqRoutine; use FireflyIII\Import\Routine\FakeRoutine; use FireflyIII\Import\Routine\FileRoutine; +use FireflyIII\Import\Routine\FinTSRoutine; use FireflyIII\Import\Routine\SpectreRoutine; use FireflyIII\Import\Routine\YnabRoutine; use FireflyIII\Support\Import\Routine\File\CSVProcessor; @@ -49,6 +51,7 @@ return [ 'plaid' => false, 'quovo' => false, 'yodlee' => false, + 'fints' => true, 'bad' => false, // always disabled ], // demo user can use these import providers (when enabled): @@ -61,6 +64,7 @@ return [ 'plaid' => false, 'quovo' => false, 'yodlee' => false, + 'fints' => false, ], // a normal user user can use these import providers (when enabled): 'allowed_for_user' => [ @@ -72,6 +76,7 @@ return [ 'plaid' => true, 'quovo' => true, 'yodlee' => true, + 'fints' => true, ], // some providers have pre-requisites. 'has_prereq' => [ @@ -83,6 +88,7 @@ return [ 'plaid' => true, 'quovo' => true, 'yodlee' => true, + 'fints' => false, ], // if so, there must be a class to handle them. 'prerequisites' => [ @@ -94,6 +100,7 @@ return [ 'plaid' => false, 'quovo' => false, 'yodlee' => false, + 'fints' => false, ], // some providers may need extra configuration per job 'has_job_config' => [ @@ -105,6 +112,7 @@ return [ 'plaid' => false, 'quovo' => false, 'yodlee' => false, + 'fints' => true, ], // if so, this is the class that handles it. 'configuration' => [ @@ -116,6 +124,7 @@ return [ 'plaid' => false, 'quovo' => false, 'yodlee' => false, + 'fints' => FinTSJobConfiguration::class, ], // this is the routine that runs the actual import. 'routine' => [ @@ -127,6 +136,7 @@ return [ 'plaid' => false, 'quovo' => false, 'yodlee' => false, + 'fints' => FinTSRoutine::class, ], 'options' => [ diff --git a/public/images/logos/fints.png b/public/images/logos/fints.png new file mode 100644 index 0000000000000000000000000000000000000000..0024f8af419524303cfc8ff70c14412df89883a1 GIT binary patch literal 2399 zcmZ`*3se)=77c%d2vuHHguZ4WAo?_u1PmdB2m}QbkU$Cv_$mPg2@n#K0b&)9pyolX zA3lowl~2?@F{lNBWk67mU$_wXQBsUhthHzqB>sf8u->55B4Jy__8pB~Oh<;K>@U3xkh9#HGkD6{C}4 zIs&0?%A(OBy1N@Oh{HxRgE@g9TEOPQY`kft`thL4?P07%)L8 zC{Vba3EkZjMd9#3)Go9Y8e>A%L7`A2UT_G}%W3bj9G=;kghCLP2mmoLG3XdeG>3N> zz}nc@02myA!|j9_JNZW=A*NtwB!A1&B7d#p1oDG;EH1?2M55&DG6OkLke!K%JkiJB zQk@VhAwI0b zu9^<+?MLC?iWD%pOUV>XT=GVeS5EW-`J9L-c?-UYWI<#cNnvOu{HY^LDhh|q<$-)Y zEFE7^)PjL)S}3MdJKgNXd7z%VcfQra(g z*A!2`H+Te4f=R%tY!dt|5ZyV!tdOHlOb8_7Fj#9M7DvS5Q5eO*8s6#^9Hk265eg4v zLL45A!-*g(T(IR+lqK4FNvRxPmXZMZIZ`@TONUm0!l#z311tY}1CVt*q5(hnebMIX zGk>VfTQsv?s zZ{w<}x(_wpo(ILP15;8p-)UpqE|z_5E)3yKyPsT)W{-<2N()44A{Ei|uSPn_Q~nI>9ZBVE z5cA+rsfxM1@FHWHZL?UO4MW-^Jn{7Hv0I)Z89WA*XZ4?O^f-axUb9a z+uX0rT1(X@9Kvfh9jpFva}3`4Qi#y8VMFIBpH8iij>>UTAy-xLS@Gq&X$EAh&MMA!AslV}&Ue z)XV{=qE;<)ndE@ydb8PnFk|k9M*O34b*lO=gOV<3rs^LZ0`xm-5uWlk#=HVzrP;T> z+0bfr?`?8LP5b>iFJBJjyziz0!t|jJkCIO!Q}>e=4hDz|FJy=ZYwxbZ%rx;W{+XKU zj0yBFtf9?5cv9UD*bk|97@i@m4`|p{Y*9n|a%Y}?WTv^aQFbDwF(K{oOV|3T4^uR; zjvIB{UQ@UD7SZ?ToVrNhsfx{o2Sw86`&@&N?g=2R9IKu)Uj3tsx#F+a+?cESU%AL-!B1vx+!3BDZTM;Xu-~1HE(gLf4i*6o z>N#$s>2-0}8P5ne>gwj=g*KAR+!!_mJ?KSQG@*DX1b()tx7ASZBIK-keAM*mc?7vjMJHohGou%ae|^}LFL3KNFvKGXw(D-y z8V=1iY1I4IzkOfbQhPaGSn$~Q_sfS 'Public key', 'country_code' => 'Country code', 'provider_code' => 'Bank or data-provider', + 'fints_url' => 'FinTS API URL', + 'fints_port' => 'Port', + 'fints_bank_code' => 'Bank code', + 'fints_username' => 'Username', + 'fints_password' => 'PIN / Password', + 'fints_account' => 'FinTS account', + 'local_account' => 'Firefly III account', + 'from_date' => 'Date from', + 'to_date' => 'Date to', + 'due_date' => 'Due date', 'payment_date' => 'Payment date', diff --git a/resources/lang/en_US/import.php b/resources/lang/en_US/import.php index 16f0e84c73..783b8f0a7f 100644 --- a/resources/lang/en_US/import.php +++ b/resources/lang/en_US/import.php @@ -199,7 +199,14 @@ return [ 'spectre_extra_key_units' => 'Units', 'spectre_extra_key_unit_price' => 'Unit price', 'spectre_extra_key_transactions_count' => 'Transaction count', - + //job configuration for finTS + 'fints_connection_failed' => 'An error occurred while trying to connecting to your bank. Please mak sure that all the data you entered is correct. Original error message: :originalError', + 'button_fints' => 'FinTS', + 'job_config_fints_url_help' => 'E.g. https://banking-dkb.s-fints-pt-dkb.de/fints30', + 'job_config_fints_username_help' => 'For many banks this is your account number.', + 'job_config_fints_port_help' => 'The default port is 443.', + 'job_config_fints_account_help' => 'Choose the bank account for which you want to import transactions.', + 'job_config_local_account_help' => 'Choose the Firefly III account corresponding to your bank account chosen above.', // specifics: 'specific_ing_name' => 'ING NL', 'specific_ing_descr' => 'Create better descriptions in ING exports', diff --git a/resources/views/import/fints/choose_account.twig b/resources/views/import/fints/choose_account.twig new file mode 100644 index 0000000000..8b0509dac7 --- /dev/null +++ b/resources/views/import/fints/choose_account.twig @@ -0,0 +1,44 @@ +{% extends "./layout/default" %} + +{% block breadcrumbs %} + {{ Breadcrumbs.render }} +{% endblock %} +{% block content %} +
+ + +
+
+
+
+

{{ trans('import.job_config_input') }}

+
+
+ {{ ExpandedForm.select('fints_account', data.fints_accounts, data.fints_account, {helpText: trans('import.job_config_fints_account_help'), required: true}) }} +
+
+ {{ ExpandedForm.select('local_account', data.local_accounts, data.local_account, {helpText: trans('import.job_config_local_account_help'), required: true}) }} +
+
+ {{ ExpandedForm.date('from_date', data.from_date, {required: true}) }} +
+
+ {{ ExpandedForm.date('to_date', data.to_date, {required: true}) }} +
+
+
+
+
+
+
+
+ +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/resources/views/import/fints/new.twig b/resources/views/import/fints/new.twig new file mode 100644 index 0000000000..70e67b057a --- /dev/null +++ b/resources/views/import/fints/new.twig @@ -0,0 +1,39 @@ +{% extends "./layout/default" %} + +{% block breadcrumbs %} + {{ Breadcrumbs.render }} +{% endblock %} +{% block content %} +
+ + +
+
+
+
+

{{ trans('import.job_config_input') }}

+
+
+ {{ ExpandedForm.text('fints_url', data.fints_url, {helpText: trans('import.job_config_fints_url_help'), required: true}) }} + {{ ExpandedForm.text('fints_port', data.fints_port, {helpText: trans('import.job_config_fints_port_help'), required: true}) }} + {{ ExpandedForm.text('fints_bank_code', data.fints_bank_code, {required: true}) }} + {{ ExpandedForm.text('fints_username', data.fints_username, {helpText: trans('import.job_config_fints_username_help'), required: true}) }} + {{ ExpandedForm.password('fints_password', {required: true}) }} +
+
+
+
+
+
+
+
+ +
+
+
+
+
+{% endblock %} \ No newline at end of file From c32e9fabd9bd5b491ab947c7bfb73218fcda4f3e Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 3 Oct 2018 13:46:18 +0200 Subject: [PATCH 02/14] Bugfix --- .../Import/JobConfiguration/FinTS/ChooseAccountHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php index b17749b437..0be29ffbe0 100644 --- a/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php +++ b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php @@ -53,7 +53,6 @@ class ChooseAccountHandler implements FinTSConfigurationInterface $config = $this->importJob->configuration; $config['fints_account'] = (string)($data['fints_account'] ?? ''); $config['local_account'] = (string)($data['local_account'] ?? ''); - $config['local_account'] = (string)($data['local_account'] ?? ''); $config['from_date'] = (string)($data['from_date'] ?? ''); $config['to_date'] = (string)($data['to_date'] ?? ''); $this->repository->setConfiguration($this->importJob, $config); From 91e0e33a0466e5907dab17e4874625b869136316 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 3 Oct 2018 13:47:38 +0200 Subject: [PATCH 03/14] Remove debug --- app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php index 848543da0d..d18f8c50d8 100644 --- a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php +++ b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php @@ -83,7 +83,6 @@ class NewFinTSJobHandler implements FinTSConfigurationInterface public function getNextData(): array { $config = $this->importJob->configuration; - var_dump($config); return [ 'fints_url' => $config['fints_url'] ?? "", 'fints_port' => $config['fints_port'] ?? "443", From ce917298ed1acaf2c5fbbbd73903a6ea2589a2ef Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 3 Oct 2018 13:56:53 +0200 Subject: [PATCH 04/14] Store password encrypted --- app/Support/FinTS/FinTS.php | 3 ++- .../Import/JobConfiguration/FinTS/NewFinTSJobHandler.php | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Support/FinTS/FinTS.php b/app/Support/FinTS/FinTS.php index c2bff5b290..5da743aa43 100644 --- a/app/Support/FinTS/FinTS.php +++ b/app/Support/FinTS/FinTS.php @@ -4,6 +4,7 @@ namespace FireflyIII\Support\FinTS; use FireflyIII\Exceptions\FireflyException; +use Illuminate\Support\Facades\Crypt; class FinTS { @@ -30,7 +31,7 @@ class FinTS $config['fints_port'], $config['fints_bank_code'], $config['fints_username'], - $config['fints_password'] + Crypt::decrypt($config['fints_password']) ); } diff --git a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php index d18f8c50d8..d03f773813 100644 --- a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php +++ b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php @@ -28,6 +28,7 @@ use FireflyIII\Import\JobConfiguration\FinTSConfigurationSteps; use FireflyIII\Models\ImportJob; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use FireflyIII\Support\FinTS\FinTS; +use Illuminate\Support\Facades\Crypt; use Illuminate\Support\MessageBag; class NewFinTSJobHandler implements FinTSConfigurationInterface @@ -53,7 +54,7 @@ class NewFinTSJobHandler implements FinTSConfigurationInterface $config['fints_port'] = (int)($data['fints_port'] ?? ''); $config['fints_bank_code'] = (string)($data['fints_bank_code'] ?? ''); $config['fints_username'] = (string)($data['fints_username'] ?? ''); - $config['fints_password'] = (string)($data['fints_password'] ?? ''); + $config['fints_password'] = (string)(Crypt::encrypt($data['fints_password']) ?? ''); $this->repository->setConfiguration($this->importJob, $config); @@ -87,8 +88,7 @@ class NewFinTSJobHandler implements FinTSConfigurationInterface 'fints_url' => $config['fints_url'] ?? "", 'fints_port' => $config['fints_port'] ?? "443", 'fints_bank_code' => $config['fints_bank_code'] ?? "", - 'fints_username' => $config['fints_username'] ?? "", - 'fints_password' => $config['fints_password'] ?? "", + 'fints_username' => $config['fints_username'] ?? "" ]; } From 3ba41d712f38dd4f2af0f59f0499ccad31293e7a Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 3 Oct 2018 13:57:17 +0200 Subject: [PATCH 05/14] Added import and type hinting --- app/Support/FinTS/FinTS.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Support/FinTS/FinTS.php b/app/Support/FinTS/FinTS.php index 5da743aa43..47931fb77c 100644 --- a/app/Support/FinTS/FinTS.php +++ b/app/Support/FinTS/FinTS.php @@ -3,6 +3,7 @@ namespace FireflyIII\Support\FinTS; +use Fhp\Model\SEPAAccount; use FireflyIII\Exceptions\FireflyException; use Illuminate\Support\Facades\Crypt; @@ -46,7 +47,7 @@ class FinTS } /** - * @return \Fhp\Model\SEPAAccount[] + * @return SEPAAccount[] * @throws FireflyException */ public function getAccounts() @@ -60,13 +61,13 @@ class FinTS /** * @param string $accountNumber - * @return \Fhp\Model\SEPAAccount + * @return SEPAAccount * @throws FireflyException */ - public function getAccount($accountNumber) + public function getAccount(string $accountNumber) { $accounts = $this->getAccounts(); - $filteredAccounts = array_filter($accounts, function ($account) use ($accountNumber) { + $filteredAccounts = array_filter($accounts, function (SEPAAccount $account) use ($accountNumber) { return $account->getAccountNumber() == $accountNumber; }); if (count($filteredAccounts) != 1) { @@ -76,13 +77,13 @@ class FinTS } /** - * @param \Fhp\Model\SEPAAccount $account + * @param SEPAAccount $account * @param \DateTime $from * @param \DateTIme $to * @return \Fhp\Model\StatementOfAccount\StatementOfAccount|null * @throws FireflyException */ - public function getStatementOfAccount(\Fhp\Model\SEPAAccount $account, \DateTime $from, \DateTIme $to) + public function getStatementOfAccount(SEPAAccount $account, \DateTime $from, \DateTIme $to) { try { return $this->finTS->getStatementOfAccount($account, $from, $to); From d7ca7e4cd8ccc8ad44fc73abc5baf2319bc3dab0 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 3 Oct 2018 13:58:57 +0200 Subject: [PATCH 06/14] MessageBag needs messages as array --- .../Import/JobConfiguration/FinTS/ChooseAccountHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php index 0be29ffbe0..7bc9ba665e 100644 --- a/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php +++ b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php @@ -61,7 +61,7 @@ class ChooseAccountHandler implements FinTSConfigurationInterface $finTS = new FinTS($this->importJob->configuration); $finTS->getAccount($config['fints_account']); } catch (FireflyException $e) { - return new MessageBag($e->getMessage()); + return new MessageBag([$e->getMessage()]); } $this->repository->setStage($this->importJob, FinTSConfigurationSteps::GO_FOR_IMPORT); From 84d0e44a08f258d6de41bb13b82096f0af70c8df Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 3 Oct 2018 13:59:48 +0200 Subject: [PATCH 07/14] Strict comparison --- .../Import/JobConfiguration/FinTS/NewFinTSJobHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php index d03f773813..a2063f4780 100644 --- a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php +++ b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php @@ -60,7 +60,7 @@ class NewFinTSJobHandler implements FinTSConfigurationInterface $incomplete = false; foreach ($config as $value) { - $incomplete = $value == '' or $incomplete; + $incomplete = $value === '' or $incomplete; } if ($incomplete) { return new MessageBag([trans('import.incomplete_fints_form')]); From 7de3c7f80a52cf2c3c2238f4558f3530997c26ee Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 3 Oct 2018 14:02:06 +0200 Subject: [PATCH 08/14] Code style --- .../Import/JobConfiguration/FinTS/NewFinTSJobHandler.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php index a2063f4780..ccc4b7b67a 100644 --- a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php +++ b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php @@ -85,10 +85,10 @@ class NewFinTSJobHandler implements FinTSConfigurationInterface { $config = $this->importJob->configuration; return [ - 'fints_url' => $config['fints_url'] ?? "", - 'fints_port' => $config['fints_port'] ?? "443", - 'fints_bank_code' => $config['fints_bank_code'] ?? "", - 'fints_username' => $config['fints_username'] ?? "" + 'fints_url' => $config['fints_url'] ?? '', + 'fints_port' => $config['fints_port'] ?? '443', + 'fints_bank_code' => $config['fints_bank_code'] ?? '', + 'fints_username' => $config['fints_username'] ?? '' ]; } From 4bb4ffbac4ce534b6576198881e46638edd24b93 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 3 Oct 2018 14:05:07 +0200 Subject: [PATCH 09/14] Use Carbon instead of DateTime --- .../Import/JobConfiguration/FinTS/ChooseAccountHandler.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php index 7bc9ba665e..0bc1c40f7e 100644 --- a/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php +++ b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Support\Import\JobConfiguration\FinTS; +use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Import\JobConfiguration\FinTSConfigurationSteps; use FireflyIII\Models\AccountType; @@ -98,8 +99,8 @@ class ChooseAccountHandler implements FinTSConfigurationInterface 'fints_account' => $this->importJob->configuration['fints_account'] ?? null, 'local_accounts' => $localAccounts, 'local_account' => $this->importJob->configuration['local_account'] ?? null, - 'from_date' => $this->importJob->configuration['from_date'] ?? (new \DateTime('now - 1 month'))->format('Y-m-d'), - 'to_date' => $this->importJob->configuration['to_date'] ?? (new \DateTime('now'))->format('Y-m-d') + 'from_date' => $this->importJob->configuration['from_date'] ?? (new Carbon('now - 1 month'))->format('Y-m-d'), + 'to_date' => $this->importJob->configuration['to_date'] ?? (new Carbon('now'))->format('Y-m-d') ]; return $data; } From 7e590fb6b3421ce777018dca85e15df08d40d277 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 3 Oct 2018 14:10:53 +0200 Subject: [PATCH 10/14] Use arbitrary precision math --- app/Support/Import/Routine/FinTS/StageImportDataHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Support/Import/Routine/FinTS/StageImportDataHandler.php b/app/Support/Import/Routine/FinTS/StageImportDataHandler.php index 1f120c5600..e22927ffce 100644 --- a/app/Support/Import/Routine/FinTS/StageImportDataHandler.php +++ b/app/Support/Import/Routine/FinTS/StageImportDataHandler.php @@ -71,7 +71,7 @@ class StageImportDataHandler { Log::debug(sprintf('Start converting transaction %s', $transaction->getDescription1())); - $amount = $transaction->getAmount(); + $amount = (string) $transaction->getAmount(); $debitOrCredit = $transaction->getCreditDebit(); Log::debug(sprintf('Amount is %s', $amount)); @@ -79,7 +79,7 @@ class StageImportDataHandler $type = TransactionType::DEPOSIT; } else { $type = TransactionType::WITHDRAWAL; - $amount = -$amount; + $amount = bcmul($amount, '-1'); } $destination = $this->mapper->map( From 88083c5b38f2dec0027c641087d6afb73f92d7dd Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 3 Oct 2018 14:13:46 +0200 Subject: [PATCH 11/14] Added 'original-source'-field to imported transactions --- app/Support/Import/Routine/FinTS/StageImportDataHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Support/Import/Routine/FinTS/StageImportDataHandler.php b/app/Support/Import/Routine/FinTS/StageImportDataHandler.php index e22927ffce..daac971462 100644 --- a/app/Support/Import/Routine/FinTS/StageImportDataHandler.php +++ b/app/Support/Import/Routine/FinTS/StageImportDataHandler.php @@ -110,6 +110,7 @@ class StageImportDataHandler 'external_id' => null, 'notes' => null, 'bunq_payment_id' => null, + 'original-source' => sprintf('fints-v%s', config('firefly.version')), 'transactions' => [ // single transaction: [ From 306e1081e3b13f4cf5ee5de9e7f079e543d56439 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 5 Oct 2018 16:19:48 +0200 Subject: [PATCH 12/14] Bugfix: array_filter preserves keys, so $filteredAccounts[0] might not exist --- app/Support/FinTS/FinTS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Support/FinTS/FinTS.php b/app/Support/FinTS/FinTS.php index 47931fb77c..d5dba345ee 100644 --- a/app/Support/FinTS/FinTS.php +++ b/app/Support/FinTS/FinTS.php @@ -73,7 +73,7 @@ class FinTS if (count($filteredAccounts) != 1) { throw new FireflyException("Cannot find account with number " . $accountNumber); } - return $filteredAccounts[0]; + return reset($filteredAccounts); } /** From aaff40c4ad8faf2d5490309b85806f3456a1062b Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 5 Oct 2018 16:30:05 +0200 Subject: [PATCH 13/14] Construct FinTS via service container so it can be mocked --- .../Import/JobConfiguration/FinTS/ChooseAccountHandler.php | 4 ++-- .../Import/JobConfiguration/FinTS/NewFinTSJobHandler.php | 2 +- app/Support/Import/Routine/FinTS/StageImportDataHandler.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php index 0bc1c40f7e..d08575288a 100644 --- a/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php +++ b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php @@ -59,7 +59,7 @@ class ChooseAccountHandler implements FinTSConfigurationInterface $this->repository->setConfiguration($this->importJob, $config); try { - $finTS = new FinTS($this->importJob->configuration); + $finTS = app(FinTS::class, ['config' => $this->importJob->configuration]); $finTS->getAccount($config['fints_account']); } catch (FireflyException $e) { return new MessageBag([$e->getMessage()]); @@ -78,7 +78,7 @@ class ChooseAccountHandler implements FinTSConfigurationInterface */ public function getNextData(): array { - $finTS = new FinTS($this->importJob->configuration); + $finTS = app(FinTS::class, ['config' => $this->importJob->configuration]); $finTSAccounts = $finTS->getAccounts(); $finTSAccountsData = []; foreach ($finTSAccounts as $account) { diff --git a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php index ccc4b7b67a..619177ff6d 100644 --- a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php +++ b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php @@ -66,7 +66,7 @@ class NewFinTSJobHandler implements FinTSConfigurationInterface return new MessageBag([trans('import.incomplete_fints_form')]); } - $finTS = new FinTS($this->importJob->configuration); + $finTS = app(FinTS::class, ['config' => $this->importJob->configuration]); if (($checkConnection = $finTS->checkConnection()) !== true) { return new MessageBag([trans('import.fints_connection_failed', ['originalError' => $checkConnection])]); } diff --git a/app/Support/Import/Routine/FinTS/StageImportDataHandler.php b/app/Support/Import/Routine/FinTS/StageImportDataHandler.php index daac971462..443502ef6b 100644 --- a/app/Support/Import/Routine/FinTS/StageImportDataHandler.php +++ b/app/Support/Import/Routine/FinTS/StageImportDataHandler.php @@ -54,7 +54,7 @@ class StageImportDataHandler Log::debug('Now in StageImportDataHandler::run()'); $localAccount = $this->accountRepository->find($this->importJob->configuration['local_account']); - $finTS = new FinTS($this->importJob->configuration); + $finTS = app(FinTS::class, ['config' => $this->importJob->configuration]); $fintTSAccount = $finTS->getAccount($this->importJob->configuration['fints_account']); $statementOfAccount = $finTS->getStatementOfAccount($fintTSAccount, new \DateTime($this->importJob->configuration['from_date']), new \DateTime($this->importJob->configuration['to_date'])); $collection = []; From 0cda098b4f86c446c89f0a9b529a87abaecc5db5 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 5 Oct 2018 16:32:29 +0200 Subject: [PATCH 14/14] Don't use deprecated method accountRepository->find --- .../Import/Routine/FinTS/StageImportDataHandler.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Support/Import/Routine/FinTS/StageImportDataHandler.php b/app/Support/Import/Routine/FinTS/StageImportDataHandler.php index 443502ef6b..2162b1d754 100644 --- a/app/Support/Import/Routine/FinTS/StageImportDataHandler.php +++ b/app/Support/Import/Routine/FinTS/StageImportDataHandler.php @@ -6,6 +6,7 @@ namespace FireflyIII\Support\Import\Routine\FinTS; use Fhp\Model\StatementOfAccount\Transaction as FinTSTransaction; use Fhp\Model\StatementOfAccount\Transaction; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\AccountType; use FireflyIII\Models\ImportJob; use FireflyIII\Models\TransactionType; @@ -47,13 +48,16 @@ class StageImportDataHandler } /** - * @throws \FireflyIII\Exceptions\FireflyException + * @throws FireflyException */ public function run() { Log::debug('Now in StageImportDataHandler::run()'); - $localAccount = $this->accountRepository->find($this->importJob->configuration['local_account']); + $localAccount = $this->accountRepository->findNull($this->importJob->configuration['local_account']); + if ($localAccount === null) { + throw new FireflyException('Cannot find Firefly account with id ' . $this->importJob->configuration['local_account']); + } $finTS = app(FinTS::class, ['config' => $this->importJob->configuration]); $fintTSAccount = $finTS->getAccount($this->importJob->configuration['fints_account']); $statementOfAccount = $finTS->getStatementOfAccount($fintTSAccount, new \DateTime($this->importJob->configuration['from_date']), new \DateTime($this->importJob->configuration['to_date']));