← Back to Pull requests

Enable Banking: support STET deferred-debit cards (OTHR purchases and negative ITAV balance) #6132

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Dec 04, 2026 11:47 UTC
Author

Fixes #6131

Summary


Support for French STET/BPCE deferred-debit credit cards (cartes à débit différé) via Enable Banking:

1. Fetch OTHR rows on CreditCard accounts when pending sync is on (Importer#fetch_and_store_transactions). A 400/422 means "not supported": it is recorded as an info provider_sync_error debug log entry and leaves the pending set complete, since the PDNG rows were fetched. The rows go through the existing pending pipeline and settle through their entry_reference once booked.
2. Cover a whole statement cycle. A purchase stays OTHR until the monthly statement closes (up to 31 days), so EnableBankingEntry::Processor::DEFERRED_DEBIT_CYCLE_DAYS (45) sets:
- the OTHR request 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 the date_from without SCA (never before the user's sync start date either), with the post-fetch date filter applying the same bound to OTHR rows;
- when such a purchase counts as stale: pending OTHR entries are marked extra.enable_banking.deferred_debit and EnableBankingAccount::Processor#clean_up_pending_transactions excludes 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 own entry_reference anyway. Other pending entries keep both rules (Entry.auto_exclude_stale_pending and Entry.reconcile_pending_duplicates gain an optional entries: scope; default unchanged). For the same reason, Account::ProviderImportAdapter#find_pending_transaction doesn'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.
3. Date unbooked OTHR rows by transaction_date instead of the cycle's shared future value_date, through one helper (EnableBankingEntry::Processor.raw_date_value) now used by transaction_date, compute_external_id, Importer#build_transaction_content_key, #newest_stored_transaction_date and #row_date. Without it, identical purchases made on different days of a cycle collapse in deduplicate_api_transactions.
4. Keep identical same-day OTHR purchases apart: distinct_booked_reference? accepts OTHR rows, whose entry_reference is stable until booking.
5. Let a negative CLAV/ITAV replace a stale PRCD/OPBD/CLBD on a credit card read as debt (Importer#fresher_balance). The sign comes from signed_balance_amount, so both "-120.50" and "120.50" + DBIT count. 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_date and the post-fetch date filter now skip an empty-string booking_date/value_date (.presence, as the dedup key and compute_external_id already did) instead of raising on Date.parse("") or leaving the row unfiltered.
  • Tests


  • importer_balance_test.rb: negative ITAV (signed amount and DBIT) replaces a stale PRCD; ITAV = 0.00 does not; a same-day positive ITAV stays out of the tiebreak. The existing "keeps a stale closing booked balance on a credit card over a newer available balance" test (positive ITAV) still covers the mBank guard.

  • importer_pdng_test.rb: OTHR rows stored as pending and not collapsed (same day and across the cycle); dropped once booked with the same entry_reference; 422 on OTHR tolerated without marking the pending set incomplete, with an info debug log entry; a whole cycle requested and kept on an incremental sync; only one cycle requested when a first fetch reaches further back; no OTHR request on a depository account; blank booking_date in the date filter.

  • enable_banking_entry/processor_test.rb: OTHR row dated by transaction_date; BOOK/PDNG unchanged; pending OTHR marked deferred_debit, PDNG not; a purchase settles in place when its statement books it under the same entry_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 empty OTHR page 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 errors

  • bin/rails test: 20314 runs, 0 failures, 0 errors, 9 skips

  • bin/rubocop on the changed files: no offenses

  • bin/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.

    <!-- This is an auto-generated description by cubic. -->
    ---

    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 OTHR transactions 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 tolerates 400/422 responses without marking the pending set incomplete.

  • Dates unbooked OTHR rows by transaction_date rather than the cycle's shared future value_date, and keeps identical same-day purchases distinct via entry_reference.

  • Marks pending OTHR entries as deferred_debit so 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/ITAV replace a stale PRCD/OPBD/CLBD balance on a credit card read as debt, from signed_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-string booking_date/value_date instead of raising on Date.parse("").
  • <sup>Written for commit 49e83dcc7a6a660c9ffff0e840e87d95c6460faf. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/we-promise/sure/pull/6132?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    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.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jjmata Review duration: 1611m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #6132"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%