Skip to content

[BE-41] Xero accounting integration #1228

Description

@yusuftomilola

Overview

Hub accountants use Xero for bookkeeping. Manually re-entering every invoice and payment into Xero is time-consuming and error-prone. Auto-syncing ManageHub invoices and payments to Xero eliminates this.

Context

  • InvoicesModule: backend/src/invoices/ — source of invoice data
  • PaymentsModule: backend/src/payments/ — source of payment data
  • Package: xero-node (Xero's official Node.js SDK)
  • @nestjs/schedule: for nightly reconciliation cron job

Tasks

  • Create XeroConnection entity: id, hubId (singleton — one per hub), accessToken (encrypted), refreshToken (encrypted), tenantId, connectedAt, expiresAt
  • GET /integrations/xero/connect — initiate Xero OAuth 2.0 PKCE flow (admin only)
  • GET /integrations/xero/callback — exchange code for tokens; store in XeroConnection
  • DELETE /integrations/xero — disconnect and delete XeroConnection (admin only)
  • GET /integrations/xero/status — returns connection status (admin only)
  • On invoice PAID event: create a matching Xero Invoice via Xero Accounting API
  • On payment SUCCESS event: create a Xero Payment record linked to the Xero Invoice
  • Nightly @Cron('0 4 * * *') reconciliation job: sync last 24 hours of invoices/payments; log discrepancies
  • Token refresh handled automatically before each API call

Files to Modify / Create

  • New: backend/src/integrations/xero/ (module, entity, controller, service)
  • backend/src/app.module.ts

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions