Files
sure/test
Pedro Santos 7c56c8e2e8 Enable Banking: progressive date_from fallback on WRONG_TRANSACTIONS_PERIOD (#2992)
* Enable Banking: progressive date_from fallback on WRONG_TRANSACTIONS_PERIOD

Some ASPSPs (e.g. Santander Totta and Activo Bank in PT) reject the
transactions window with 422 WRONG_TRANSACTIONS_PERIOD but do NOT return a
corrected date_from in the payload. The existing single-shot retry only fires
when the API supplies detail.date_from, so for these banks the retry was
skipped and the error surfaced as the generic "communication error";
transactions never synced even though the connection and session were valid.

This adds a bounded, progressive fallback: when the period is rejected and no
corrected date is available, retry with progressively shorter windows
(89 -> 60 -> 30 days). The ASPSP-suggested date is still preferred on the first
retry, so existing behaviour is preserved. The step-down only moves the window
forward, guaranteeing progress and avoiding an infinite loop.

Verified on a live instance: Activo Bank went from 0 to 82 transactions
imported once the fallback kicked in.

Refs #2989

Signed-off-by: Pedro Santos <pedro_santos@outlook.pt>

* Address review: forward-only progress across all fallback windows

- Accept the ASPSP-suggested corrected date only when it moves the window
  forward (current is nil or corrected > current), preserving the forward-only
  retry bound (CodeRabbit).
- Skip fallback windows that are not newer than the current date_from and pick
  the first that advances, instead of bailing out on a stale first candidate.
  Fixes the case where an initial/user lookback (e.g. 45d) is newer than the
  first window (89d) but the bank caps at 30d (Codex).

Signed-off-by: Pedro Santos <pedro_santos@outlook.pt>

* Add tests for progressive transactions date_from fallback

Covers the two cases the previous single-shot retry missed:
- WRONG_TRANSACTIONS_PERIOD without a corrected date_from -> falls back to the
  first shorter window (89 days).
- An initial lookback newer than the leading windows (45d) -> skips the 89/60
  windows and retries with the first that advances (30 days).

Signed-off-by: Pedro Santos <pedro_santos@outlook.pt>

---------

Signed-off-by: Pedro Santos <pedro_santos@outlook.pt>
2026-08-12 02:46:51 +02:00
..