2883: Fix unidentified card holds
Merged
OT
2mo ago+1188+1188+0123456789012345678901234567890123456789-52-52-01234567890123456789
Fixes #2883
Problem
Certain European ASPSPs under Open Banking / PSD2 return unfinalized card authorization holds with:
- Missing
transaction_id,entry_reference, and counterparty information. - Inverted direction / sign: card purchase holds are reported as credits (
CRDTindicator or positive amounts) instead of debits. - Remittance containing only a masked card PAN (e.g.
474836xxxxxx6879 003015315475).
In Sure, this caused holds to import as settled income (+€14.97). When the settled purchase arrived (-€14.97), pending-to-posted reconciliation failed due to the mismatched sign, stranding duplicate phantom income in user ledgers and creating garbageProviderMerchantrecords.
Resulting Behavior
- Masked PAN Pattern: Added
MASKED_CARD_DESCRIPTOR = /\A\d{4,6}[xX*]{4,8}\d{4}(?:\s+\d+)?\z/to detect raw card authorization holds without matching legitimate merchant names. - Sign Normalization: Inverted credit holds are normalized to positive outflows (expenses in Sure's sign convention) across both Enable Banking and Lunchflow. Legitimate credits without card descriptors remain inflows.
- Clean Naming & Merchant Suppression: Holds are named
"Card Authorization Hold", merchant creation is suppressed (merchant: nil), and raw PAN strings are preserved innotes. - Pending Lifecycle & Reconciliation:
- Both providers flag holds as pending (
extra[provider]["pending"] = true) and respect their respectiveinclude_pendingsettings. - Matching amounts allow
Account::ProviderImportAdapterto claim the pending hold upon settlement. Lunchflow'sfind_existing_posted_versionbypasses strict name matching for holds so out-of-order settlement reconciles cleanly.
- Both providers flag holds as pending (
Validation
test/models/enable_banking_entry/processor_test.rb: verified masked descriptor detection, amount normalization, non-inversion of legitimate credits, and end-to-end settlement claiming.test/models/lunchflow_entry/processor_test.rb: verified hold detection, amount normalization, and posted reconciliation without name constraint.
Summary by CodeRabbit
- New Features
- Masked card authorization holds are recognized as pending transactions, even when a provider omits pending status or a transaction identifier.
- Holds appear as “Card Authorization Hold,” with positive amounts and no assigned merchant.
- Pending transaction settings apply to these holds across supported bank connections, including removing stored holds when pending transactions are excluded.
- Bug Fixes
- When a hold later appears as a posted transaction, it can be matched to the existing entry instead of duplicated.
- Empty transaction responses now correctly update stored transactions when pending transactions are excluded.