Enable Banking: support STET deferred-debit cards (OTHR purchases and negative ITAV balance)
DA
2d ago+481+481+012345678901234567890123456789-28-28-01234567890123456789
Fixes #6131
Summary
Support for French STET/BPCE deferred-debit credit cards (cartes à débit différé) via Enable Banking:
- Fetch
OTHRrows onCreditCardaccounts when pending sync is on (Importer#fetch_and_store_transactions). A400/422means "not supported": it is recorded as aninfoprovider_sync_errordebug log entry and leaves the pending set complete, since thePDNGrows were fetched. The rows go through the existing pending pipeline and settle through theirentry_referenceonce booked. - Cover a whole statement cycle. A purchase stays
OTHRuntil the monthly statement closes (up to 31 days), soEnableBankingEntry::Processor::DEFERRED_DEBIT_CYCLE_DAYS(45) sets:- the
OTHRrequest window, whatever the BOOK window: wider than a few-day incremental sync, and never as far back as an old sync start date, which could make the ASPSP reject thedate_fromwithout SCA (never before the user's sync start date either), with the post-fetch date filter applying the same bound toOTHRrows; - when such a purchase counts as stale: pending
OTHRentries are markedextra.enable_banking.deferred_debitandEnableBankingAccount::Processor#clean_up_pending_transactionsexcludes them after 45 days instead of 8. They are also left out of the amount-only duplicate reconciliation: a cycle doesn't follow the calendar month, so a purchase made just before a statement close can share its amount with an older purchase that close books, and they settle by their ownentry_referenceanyway. Other pending entries keep both rules (Entry.auto_exclude_stale_pendingandEntry.reconcile_pending_duplicatesgain an optionalentries:scope; default unchanged). For the same reason,Account::ProviderImportAdapter#find_pending_transactiondoesn't let a new booking of the same amount claim them: such a claim would also make the purchase's own BOOK row, which carries the same id, be skipped as already claimed.
- the
- Date unbooked
OTHRrows bytransaction_dateinstead of the cycle's shared futurevalue_date, through one helper (EnableBankingEntry::Processor.raw_date_value) now used bytransaction_date,compute_external_id,Importer#build_transaction_content_key,#newest_stored_transaction_dateand#row_date. Without it, identical purchases made on different days of a cycle collapse indeduplicate_api_transactions. - Keep identical same-day
OTHRpurchases apart:distinct_booked_reference?acceptsOTHRrows, whoseentry_referenceis stable until booking. - Let a negative
CLAV/ITAVreplace a stalePRCD/OPBD/CLBDon a credit card read as debt (Importer#fresher_balance). The sign comes fromsigned_balance_amount, so both"-120.50"and"120.50"+DBITcount. Non-negative ones stay excluded, including from the same-day tiebreak, keeping the #5886 / mBank PL guard.
Behaviour changes outside OTHR
transaction_date,newest_stored_transaction_dateand the post-fetch date filter now skip an empty-stringbooking_date/value_date(.presence, as the dedup key andcompute_external_idalready did) instead of raising onDate.parse("")or leaving the row unfiltered.
Tests
importer_balance_test.rb: negativeITAV(signed amount andDBIT) replaces a stalePRCD;ITAV = 0.00does not; a same-day positiveITAVstays out of the tiebreak. The existing "keeps a stale closing booked balance on a credit card over a newer available balance" test (positiveITAV) still covers the mBank guard.importer_pdng_test.rb:OTHRrows stored as pending and not collapsed (same day and across the cycle); dropped once booked with the sameentry_reference;422onOTHRtolerated without marking the pending set incomplete, with aninfodebug log entry; a whole cycle requested and kept on an incremental sync; only one cycle requested when a first fetch reaches further back; noOTHRrequest on a depository account; blankbooking_datein the date filter.enable_banking_entry/processor_test.rb:OTHRrow dated bytransaction_date;BOOK/PDNGunchanged; pendingOTHRmarkeddeferred_debit,PDNGnot; a purchase settles in place when its statement books it under the sameentry_reference; a booking of the same amount doesn't claim it.enable_banking_account/processor_test.rb: a deferred-debit purchase stays pending within the cycle and is excluded after it; it is not reconciled against an earlier cycle's booking of the same amount, while an ordinary pending still is.importer_pending_balance_test.rb: default emptyOTHRpage in the shared stub for the existing credit-card cases.
Validation
Run locally in the repo's devcontainer (Postgres 18, Redis):
bin/rails test test/models/enable_banking_item test/models/enable_banking_entry test/models/enable_banking_account test/models/enable_banking_account_test.rb test/models/entry_test.rb test/models/simplefin_item test/models/account/provider_import_adapter_test.rb: 784 runs, 0 failures, 0 errorsbin/rails test: 20314 runs, 0 failures, 0 errors, 9 skipsbin/rubocopon the changed files: no offensesbin/brakeman --no-pager: no warnings
No ERB, JavaScript or UI changes, so ERB lint, Biome and system tests don't apply.
Open questions
See #6131: pending-inclusive ITAV on a liability, and the date jump at statement close.
Summary by cubic
Fixes #6131 by adding Enable Banking support for French STET/BPCE deferred-debit credit cards, making their purchases visible as pending entries and letting a negative available balance update the account.
- Fetches
OTHRtransactions on credit card accounts during pending sync over a whole statement cycle (45 days), independent of the BOOK window and never before the user's sync start date, and tolerates400/422responses without marking the pending set incomplete. - Dates unbooked
OTHRrows bytransaction_daterather than the cycle's shared futurevalue_date, and keeps identical same-day purchases distinct viaentry_reference. - Marks pending
OTHRentries asdeferred_debitso they stay pending for a full cycle instead of 8 days; they are also left out of amount-only reconciliation and the pending claim heuristic, since a statement close can book an earlier cycle's purchase of the same amount and otherwise hide them. - Lets a negative
CLAV/ITAVreplace a stalePRCD/OPBD/CLBDbalance on a credit card read as debt, fromsigned_balance_amount; non-negative available balances stay excluded to preserve the mBank PL guard. transaction_date,newest_stored_transaction_date, and the post-fetch date filter now skip empty-stringbooking_date/value_dateinstead of raising onDate.parse("").
Summary by CodeRabbit
- New Features
- Credit-card imports now include eligible deferred-debit purchases as pending transactions, so card spending can appear before it is fully booked.
- Deferred-debit purchases remain pending for up to 45 days.
- Bug Fixes
- Pending card transactions use a more appropriate date when booking details are unavailable.
- Credit-card balances update more reliably: negative available balances can replace stale balances, while non-negative available credit does not incorrectly replace debt.
- Matching booked transactions replace corresponding pending purchases to avoid duplicates.
- Deferred-debit purchases are excluded from duplicate reconciliation with other pending transactions.