Leftover from a version that could use accepted EUAs.
If this functionality is ever restored, the `$eua['accepted'] === null`
should become `!$eua['accepted'] || $expiresAt > new DateTime('now')`.`
If agreements are already available and no custom `access_days` is
passed, it will simply take the first match regardless of duration.
When a new agreement is needed, it defaults to the max supported.
Implements changes from #10410 but using `Arr::first()` rather than a
foreach loop to fix bugs returning invalid or expired agreements.
If an agreement exists with at least the requested `$txDays` then that
is used, otherwise a new one is created with the given parameters. If it
fails, we error out because `createRequisition()` would fail regardless.
Skips accepting EUAs: seems it's done automatically during requisition.
The end user agreement ID isn't stored with the bank integration, but it
*is* returned as part of the error for an expired account which works
perfectly for the case of renewing an expired requisition.
When `tx_days` isn't set in the request (i.e. it's a renewal) we instead
extract the EUA ID from the account error after getting the integration,
then once we have the EUA we're able to restore the old tx_days setting.
Since the BankIntegration query is used in both endpoints, this moves it
to a method with `firstOrFail()` rather than `first()` which also allows
for a cleanup of the integration saving code with try/catch/finally to
make it a little clearer which values apply to both new+existing cases.
If e.g. `&tx_days=365` is added to the URL, this will use it to set the
amount of history that's fetched from Nordigen on sync, with basic
safeguards to prevent it being set too low or above the bank's max.
While we set the days in the agreement, how many we fetch when
processing transactions depends on the `from_date` of the bank
integration. We could call `getInstitution($id)` on the API, but
consistency would dictate adding a wrapper in the Nordigen class and
it's already being called within `$nordigen->getAccount()` so it makes
more sense to extract the data in the account transformer instead.
App\Jobs\Bank\ProcessBankTransactionsNordigen also sets a from date, but
that's only used when not set on the bank integration so it can be left
at the Nordigen default of 90 days worth of transaction history.
In order to change the total days of transactions we can request, a
custom end user agreement is needed. There *are* methods to find
existing agreements, but assuming nothing else breaks it's probably
fairly safe to just go ahead and create one.
If it works, it only runs once... as far as I can tell.
Leftover from a version that could use accepted EUAs.
If this functionality is ever restored, the `$eua['accepted'] === null`
should become `!$eua['accepted'] || $expiresAt > new DateTime('now')`.`