Skip to content

feat(OUT-4005): payout reconciliation service + deposit lookup [2/4] - #274

Merged
SandipBajracharya merged 2 commits into
feature/payout-reconciliationfrom
OUT-4005-split-2
Aug 3, 2026
Merged

feat(OUT-4005): payout reconciliation service + deposit lookup [2/4]#274
SandipBajracharya merged 2 commits into
feature/payout-reconciliationfrom
OUT-4005-split-2

Conversation

@SandipBajracharya

Copy link
Copy Markdown
Collaborator

Stack 2/4 — base: OUT-4005-split-1

PayoutService.reconcile validates the payout, resolves its payments, and builds one batched QBO deposit. On resync it reuses an already-made deposit (stored id, then a txn-date query matching PrivateNote) so a retry can't create a duplicate. Adds getDepositsByTxnDate + schemas, error types, and unit/service tests.

Part of the OUT-4005 payout-reconciliation stack:

  1. schema + migration
  2. reconciliation service + deposit lookup ← this PR
  3. webhook + resync wiring
  4. typecheck tooling + chore

🤖 Generated with Claude Code

@linear-code

linear-code Bot commented Jul 31, 2026

Copy link
Copy Markdown

OUT-4005

@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
quickbooks-sync (dev) Ready Ready Preview Aug 3, 2026 8:34am
quickbooks-sync Building Building Aug 3, 2026 8:34am

Request Review

@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown

Greptile Summary

Adds the payout-reconciliation service and QuickBooks deposit lookup infrastructure.

  • Validates payout totals, line-item composition, and batching intent before creating a deposit.
  • Reuses stored or discoverable QuickBooks deposits during resync.
  • Adds paginated transaction-date deposit queries, payout-specific errors, DTO schemas, mocks, and tests.

Confidence Score: 5/5

The PR appears safe to merge with no concrete blocking or independently actionable non-blocking defects identified.

The reconciliation validation, payment resolution, deposit lookup pagination, retry behavior, and persistence paths are internally consistent with the established repository contracts examined.

Important Files Changed

Filename Overview
src/app/api/quickbooks/payout/payout.service.ts Introduces payout persistence, validation, payment resolution, deposit reconciliation, and resync idempotency behavior.
src/utils/intuitAPI.ts Adds a paginated QuickBooks deposit query by transaction date using the existing retry-wrapped custom-query path.
src/type/dto/intuitAPI.dto.ts Adds validation for the unwrapped QuickBooks deposit query response.
src/type/dto/webhook.dto.ts Extracts a reusable payout line-item schema without changing the enclosing webhook contract.
src/app/api/quickbooks/payout/payout.errors.ts Adds terminal and mixed-intent payout errors plus payout-specific retry classification.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant PayoutService
    participant SyncLogService
    participant IntuitAPI
    participant PaymentService
    participant Database

    Caller->>PayoutService: reconcile(payout, tokens, options)
    PayoutService->>PayoutService: Validate line items and totals
    alt Resync idempotency check
        PayoutService->>Database: Check stored qbDepositId
        PayoutService->>IntuitAPI: Query deposits by transaction date
        IntuitAPI-->>PayoutService: Matching deposits
        PayoutService->>Database: Persist discovered deposit ID
    else Deposit creation required
        PayoutService->>SyncLogService: Resolve successful payment IDs
        SyncLogService-->>PayoutService: Payment and batching metadata
        PayoutService->>PaymentService: Create batched bank deposit
        PaymentService->>IntuitAPI: Create QuickBooks deposit
        IntuitAPI-->>PaymentService: Deposit ID
        PayoutService->>Database: Persist deposit ID
    end
    PayoutService-->>Caller: depositId or null
Loading

Reviews (1): Last reviewed commit: "feat(OUT-4005): add payout reconciliatio..." | Re-trigger Greptile

import { validateAccessToken } from '@/utils/auth'

export class PayoutService extends BaseService {
private syncLogService = new SyncLogService(this.user)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? what would this be. Can you maybe move this to constructor instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it works, but the constructor should be good for this case.

Comment thread src/utils/intuitAPI.ts
deletePayment = this.wrapWithRetry(this._deletePayment)
deletePurchase = this.wrapWithRetry(this._deletePurchase)
createDeposit = this.wrapWithRetry(this._createDeposit)
getDepositsByTxnDate = this._getDepositsByTxnDate.bind(this)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the benifit of doing it this way?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDepositsByTxnDate is not wrapped with retry. In fact we do not wrap get functions with retry.

@priosshrsth priosshrsth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Base automatically changed from OUT-4005-split-1 to feature/payout-reconciliation August 3, 2026 08:32
SandipBajracharya and others added 2 commits August 3, 2026 14:17
PayoutService.reconcile validates the payout, resolves its payments, and
builds one batched deposit. On resync it reuses an already-made deposit
(stored id, then a txn-date query on PrivateNote) so a retry can't duplicate.
Adds getDepositsByTxnDate and its schemas.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@SandipBajracharya
SandipBajracharya merged commit 028757f into feature/payout-reconciliation Aug 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants