← Back to Pull requests

Feat/bunq provider #6103

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Dec 03, 2026 20:02 UTC
Author

Mostly LLM generated code, ruby is not my favourite language, open for feedback ;-)

Problem

bunq exposes a well-documented public API, but connecting it to Sure is not a
two-step OAuth dance: a personal API key authenticates in three steps
(installation, device registration, session), is bound to the IP address it was
installed from, and the setup endpoints allow as few as ten requests a day.
Getting any of that wrong strands a DeviceServer on the user's bunq account and
burns the quota that would have fixed it.

What this does

  • Keeps the API context instead of re-running the handshake. The RSA key

  • pair, installation id/token, device id and session token live on the
    connection, encrypted at rest. Only the session is rebuilt when bunq answers
    401; the installation is never repeated on purpose.
  • Imports monetary accounts and booked payments. Bank, savings and joint

  • accounts become accounts; payments become entries, deduplicated on the payment
    id, with counterparty, merchant reference and balance_after_mutation stored
    under the entry's bunq metadata. A foreign-currency payment keeps its own
    currency and records the pair. bunq signs a payment from the account's point of
    view, so the processor negates it to Sure's positive-is-expense convention.
  • Links self-transfers. A payment whose counterparty IBAN is one of the

  • connection's own accounts is linked to the matching leg, including the
    currency guard, and a removed leg is rejected rather than silently dropped.
  • Names entries the way a person reads them, with the merchant attributed and

  • the payee kept, matching how the other bank syncs name their rows.
  • Surfaces refusals instead of swallowing them. An IP refusal marks the

  • connection requires_update, a rotated API key resets the stale API context,
    and the provider card shows what happened.
  • Is a provider-kit provider, not a special case. The adapter declares its

  • connection (declares_connection), BunqItemsController builds on
    ProviderItemsController, the routes use the provider_items concern, and the
    panel/card/dialogs are the kit's components. Nothing is hardcoded in
    Settings::ProvidersController, SettingsHelper or Provider::Metadata; the
    settings panel, the accounts index, the provider picker and the logo all come
    from the declaration.

    Validation

    471 runs, 7402 assertions, 0 failures, 0 errors, 0 skips
    

    covering the bunq client, adapter, importer, syncer, self-transfer linker,
    processors and the wizard's controller routes, plus the provider-kit contract
    tests that pin every declared connection's list queries, the settings panel
    providers and the accounts-index providers (Provider::ConnectionDeclarationTest),
    and the provider-item component/card tests.

    The documented behaviour was verified against the bunq sandbox
    (installation → device → session → account → payment) as described in
    docs/providers/bunq.md, which also carries the runbook for a key that is
    refused.

    Notes for review

  • The branch is rebased onto current main (7e86933) in 26 linear commits and

  • touches no MoneyMoney import code, so it can be reviewed on its own.
  • docs/providers/bunq.md explains why OAuth was rejected (bunq asks for it from

  • public projects only, and a self-hosted app cannot offer the fixed redirect URI
    a registered client needs).
  • Adding a declared connection is not a provider-local change: the kit's contract

  • test enumerates the panel and accounts-index providers, so this branch updates
    that list too.

    Fixes from production use

    Two defects surfaced on a live connection running an earlier tag; both are
    fixed on this branch, each with a test that failed first.

  • Own-account pairs stayed pending. Sure's own matcher proposes a pair as a

  • pending transfer as soon as both legs exist — during the import, before this
    linker runs — so the linker found the leg already carrying a transfer and
    skipped it. The one component that can prove the pairing (the counterparty
    IBAN) declined to confirm what the heuristic had only guessed, leaving five
    savings moves for a person to confirm by hand after a single sync. The linker
    now confirms a pending proposal that joins exactly the two legs it would link,
    and still leaves a confirmed transfer alone.
  • A nameless move was called "Transaction". bunq sends an empty description

  • for a move between its own accounts and the payee is deliberately dropped
    there, so both halves were blank and the row fell back to the literal name
    "Transaction". The holder's name bunq reports is the fallback now.
  • The importer also stopped pruning an account whose import failed (it used to

  • look like a removal and detached the linked Sure account), honours the
    connection-level sync start date, and dropped two pieces of dead code.
  • security:backfill_encryption walks a manifest of models whose encrypted

  • columns it re-encrypts; BunqItem and BunqAccount were missing from it, so
    their ciphertext would never have been backfilled. Both are listed now, with
    the manifest version bumped and the digest its test pins.

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

    Summary by CodeRabbit

    New Features
    Added support for connecting Bunq with an API key and syncing account balances and transactions.
    Added account selection and setup flows, including production and sandbox options.
    Transactions between accounts on the same Bunq connection can be linked as transfers.
    Bunq connections and sync status now appear in the app.
    Bug Fixes
    Deleting a Bunq-linked transfer prevents it from being automatically recreated.
    Documentation
    * Added Bunq setup, sync, and transaction-import guidance.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jjmata Review duration: 2557m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    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
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #6103"
    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: 57% (MEDIUM) · Higher = larger blast radius
    57%
    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: 30.4% · Safe to merge
    30.4%