Skip to content

Commit 02b059c

Browse files
committed
Merge branch 'release/0.7.0'
2 parents 10a4d0c + 402dbb4 commit 02b059c

18 files changed

Lines changed: 499 additions & 358 deletions

File tree

app/Exceptions/Handler.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
namespace App\Exceptions;
2626

27+
use Throwable;
2728
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
2829

2930
/**
@@ -40,6 +41,7 @@ class Handler extends ExceptionHandler
4041
//
4142
];
4243

44+
4345
/**
4446
* A list of the inputs that are never flashed for validation exceptions.
4547
*
@@ -49,4 +51,19 @@ class Handler extends ExceptionHandler
4951
'password',
5052
'password_confirmation',
5153
];
54+
55+
/**
56+
* @param \Illuminate\Http\Request $request
57+
* @param Throwable $e
58+
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response
59+
* @throws \Throwable
60+
*/
61+
public function render($request, Throwable $e)
62+
{
63+
if($e instanceof ImporterErrorException || $e instanceof ImporterHttpException) {
64+
$isDebug = config('app.debug');
65+
return response()->view('errors.exception', ['exception' => $e, 'debug' => $isDebug], 500);
66+
}
67+
return parent::render($request, $e);
68+
}
5269
}

app/Http/Controllers/Import/ConfigurationController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function index(Request $request)
120120
// get list of asset accounts:
121121
$url = SecretManager::getBaseUrl();
122122
$token = SecretManager::getAccessToken();
123-
123+
$fireflyAccounts = 0;
124124

125125
$request = new GetAccountsRequest($url, $token);
126126
$request->setType(GetAccountsRequest::ASSET);
@@ -131,6 +131,7 @@ public function index(Request $request)
131131
/** @var Account $account */
132132
foreach ($response as $account) {
133133
$accounts[self::ASSET_ACCOUNTS][$account->id] = $account;
134+
$fireflyAccounts++;
134135
}
135136

136137
// also get liabilities
@@ -144,6 +145,7 @@ public function index(Request $request)
144145
/** @var Account $account */
145146
foreach ($response as $account) {
146147
$accounts[self::LIABILITIES][$account->id] = $account;
148+
$fireflyAccounts++;
147149
}
148150

149151
// possibilities for duplicate detection (unique columns)
@@ -175,7 +177,7 @@ public function index(Request $request)
175177

176178
return view(
177179
'import.004-configure.index',
178-
compact('mainTitle', 'subTitle', 'accounts', 'configuration', 'flow', 'importerAccounts', 'uniqueColumns')
180+
compact('mainTitle', 'subTitle', 'fireflyAccounts','accounts', 'configuration', 'flow', 'importerAccounts', 'uniqueColumns')
179181
);
180182
}
181183

@@ -187,7 +189,7 @@ public function index(Request $request)
187189
*/
188190
private function getNordigenAccounts(string $identifier): array
189191
{
190-
if (Cache::has($identifier)) {
192+
if (Cache::has($identifier) && config('importer.use_cache')) {
191193
$result = Cache::get($identifier);
192194
$return = [];
193195
foreach ($result as $arr) {

app/Http/Controllers/NavController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public function toRoles()
5555
return redirect(route('005-roles.index'));
5656
}
5757

58+
/**
59+
* @return Application|RedirectResponse|Redirector
60+
*/
61+
public function toConversion()
62+
{
63+
app('log')->debug(__METHOD__);
64+
session()->forget(Constants::CONVERSION_COMPLETE_INDICATOR);
65+
return redirect(route('005-roles.index'));
66+
}
67+
5868
/**
5969
* Return back to index. Needs no session updates.
6070
*/

app/Http/Controllers/TokenController.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
use GuzzleHttp\Client;
3232
use GuzzleHttp\Exception\ClientException;
3333
use GuzzleHttp\Exception\GuzzleException;
34+
use GuzzleHttp\Exception\RequestException;
3435
use Illuminate\Contracts\Foundation\Application;
3536
use Illuminate\Contracts\View\Factory;
3637
use Illuminate\Http\JsonResponse;
3738
use Illuminate\Http\RedirectResponse;
3839
use Illuminate\Http\Request;
3940
use Illuminate\Routing\Redirector;
4041
use Illuminate\View\View;
41-
use InvalidArgumentException;
4242
use JsonException;
4343
use Str;
4444
use Throwable;
@@ -61,17 +61,18 @@ class TokenController extends Controller
6161
public function callback(Request $request)
6262
{
6363
app('log')->debug(sprintf('Now at %s', __METHOD__));
64-
$state = (string) $request->session()->pull('state');
64+
$state = (string) session()->pull('state');
6565
$codeVerifier = (string) $request->session()->pull('code_verifier');
6666
$clientId = (int) $request->session()->pull('form_client_id');
6767
$baseURL = (string) $request->session()->pull('form_base_url');
6868
$vanityURL = (string) $request->session()->pull('form_vanity_url');
6969
$code = $request->get('code');
7070

71-
throw_unless(
72-
strlen($state) > 0 && $state === $request->state,
73-
InvalidArgumentException::class
74-
);
71+
if (0 === strlen($state) || $state !== $request->state) {
72+
app('log')->error(sprintf('State according to session: "%s"', $state));
73+
app('log')->error(sprintf('State returned in request : "%s"', $request->state));
74+
throw new ImporterErrorException('The "state" returned from your server doesn\'t match the state that was sent.');
75+
}
7576
// always POST to the base URL, never the vanity URL.
7677
$finalURL = sprintf('%s/oauth/token', $baseURL);
7778
$params = [
@@ -93,11 +94,14 @@ public function callback(Request $request)
9394
];
9495
try {
9596
$response = (new Client($opts))->post($finalURL, $params);
96-
} catch (ClientException $e) {
97-
$body = (string) $e->getResponse()->getBody();
98-
app('log')->error(sprintf('Client exception when decoding response: %s', $e->getMessage()));
99-
app('log')->error(sprintf('Response from server: "%s"', $body));
100-
app('log')->error($e->getTraceAsString());
97+
} catch (ClientException | RequestException $e) {
98+
$body = $e->getMessage();
99+
if ($e->hasResponse()) {
100+
$body = (string) $e->getResponse()->getBody();
101+
app('log')->error(sprintf('Client exception when decoding response: %s', $e->getMessage()));
102+
app('log')->error(sprintf('Response from server: "%s"', $body));
103+
app('log')->error($e->getTraceAsString());
104+
}
101105

102106
return view('error')->with('message', $e->getMessage())->with('body', $body);
103107
}

app/Services/Nordigen/Conversion/Routine/GenerateTransactions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ private function generateTransaction(string $accountId, Transaction $entry): arr
224224
'tags' => [],
225225
'category_name' => null,
226226
'category_id' => null,
227+
'notes' => $entry->getNotes(),
227228
'external_id' => $entry->transactionId,
228229
'internal_reference' => $entry->accountIdentifier,
229230
];

app/Services/Nordigen/Model/Transaction.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,21 @@ public function getSourceIban(): ?string
355355
return null;
356356
}
357357

358+
/**
359+
* Returns notes based on info in the transaction.
360+
* @return string
361+
*/
362+
public function getNotes(): string
363+
{
364+
$notes = '';
365+
if ('' !== $this->additionalInformation) {
366+
$notes = $this->additionalInformation;
367+
}
368+
// room for other fields
369+
370+
return $notes;
371+
}
372+
358373
/**
359374
* Return account number of the source account.
360375
*

app/Services/Nordigen/Request/ListAccountsRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function setIdentifier(string $identifier): void
6666
public function get(): Response
6767
{
6868
$json = $this->authenticatedGet();
69+
6970
return new ListAccountsResponse($json);
7071
}
7172

app/Services/Nordigen/Response/ListAccountsResponse.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ public function __construct(array $data)
4747
{
4848
$this->accounts = [];
4949

50+
app('log')->debug('ListAccountsResponse:', $data ?? []);
51+
5052
/** @var string $account */
5153
foreach ($data['accounts'] as $account) {
54+
app('log')->debug(sprintf('ListAccountsResponse includes account "%s"', $account));
5255
$this->accounts[] = Account::createFromIdentifier($account);
5356
}
5457
$this->collection = new Collection($this->accounts);

app/Services/Nordigen/Services/AccountInformationCollector.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ public static function collectInformation(Account $account): Account
7474
$balanceAccount->setStatus('no-balance');
7575
}
7676
}
77-
// overrule settings to test layout:
78-
// $balanceAccount->setIban('');
79-
// $balanceAccount->setName('');
80-
// $balanceAccount->setDisplayName('');
81-
// $balanceAccount->setOwnerName('');
82-
// $balanceAccount->setStatus('no-info');
83-
8477
return $balanceAccount;
8578
}
8679

changelog.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 0.7.0 - 2022-01-22
6+
7+
- ⚠️ Using Nordigen? This release WILL create duplicate transactions. Don't import large batches.
8+
9+
A special thanks to the excellent folks over at @nordigen for some quick debugging and fixing.
10+
11+
### Added
12+
- A special 500 page so you can see what's happening.
13+
- Nordigen will now import transaction details in notes.
14+
- If you have no Firefly III accounts, the importer will warn you.
15+
- Extra account details debug information.
16+
17+
### Fixed
18+
- A missing method broke navigation.
19+
- Sometimes session details would get lost in translation.
20+
521
## 0.6.5 - 2022-01-15
622

723
### Fixed

0 commit comments

Comments
 (0)