Download the PHP package zynqa/filament-freeagent without Composer
On this page you can find all versions of the php package zynqa/filament-freeagent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zynqa/filament-freeagent
More information about zynqa/filament-freeagent
Files in zynqa/filament-freeagent
Package filament-freeagent
Short Description FreeAgent integration for FilamentPHP
License MIT
Informations about the package filament-freeagent
FreeAgent Integration for FilamentPHP
A comprehensive Laravel/FilamentPHP package that integrates FreeAgent accounting software into Filament applications. View and download FreeAgent invoices directly from your Filament admin panel with system-wide OAuth authentication and contact-based scoping.
Features
- System-Wide OAuth 2.0: Single admin-managed OAuth connection for the entire application
- Invoice Management: View all invoices with comprehensive filtering and search
- Project Integration: Display invoices with linked FreeAgent projects
- PDF Downloads: Download invoice PDFs directly from Filament with proper validation
- Auto-sync: Automatic cache refresh when data becomes stale (30 min TTL)
- Contact-Based Scoping: Admin sees all invoices, users see only their contact's invoices
- Settings Integration: Integrated into app's General Settings (not standalone)
- Date Format Support: Uses application's configured date format
- Comprehensive Caching: Intelligent caching with automatic token refresh
- Filament-First Design: Native Filament Resources, Actions, Notifications
- Policy-Based Authorization: Granular permission control via Laravel Policies
- Full Pagination: Fetches all invoices from FreeAgent API (not limited to 25)
Requirements
- PHP 8.2+
- Laravel 11+
- FilamentPHP 3.2+
- FreeAgent account (Production or Sandbox)
- Spatie Laravel Settings (for app-wide settings)
Installation
1. Install via Composer
2. Publish and Run Migrations
This will publish and run:
add_freeagent_contact_id_to_users_table- Adds FreeAgent contact linkage to userscreate_freeagent_oauth_tokens_table- OAuth token storagecreate_freeagent_contacts_table- FreeAgent contacts cachecreate_freeagent_invoices_table- FreeAgent invoices cachecreate_freeagent_projects_table- FreeAgent projects cacheadd_project_fields_to_freeagent_invoices_table- Links invoices to projects
3. Publish Configuration (Optional)
4. Add Trait to User Model
Add the HasFreeAgentContact trait to your User model:
5. Add FreeAgent Settings to GeneralSettings
Add FreeAgent fields to your app's GeneralSettings class:
6. Create Settings Migration
Then run: php artisan migrate
7. Add FreeAgent Section to General Settings Page
In your ManageGeneralSettings page, add the FreeAgent section to the Integrations tab:
Configuration
Option 1: UI Configuration (Recommended)
- Navigate to Settings → General Settings → Integrations
- Expand FreeAgent Integration section
- Enter your OAuth credentials and API URLs
- Click Save
Settings are stored in database and override .env values.
Option 2: Environment Variables
Add these to your .env file (used as fallback if UI not configured):
Configuration Priority:
- Database Settings (UI configured) ← Highest
- Environment Variables (
.env) - Default Values ← Lowest
FreeAgent OAuth App Setup
- Log into your FreeAgent account
- Go to Settings → Developer Dashboard
- Create a new OAuth application:
- Name: Your Application Name
- Redirect URI:
https://yourapp.com/freeagent/callback
- Copy the Client ID and Client Secret
Usage
For Administrators
1. Configure OAuth Credentials
Settings → General Settings → Integrations → FreeAgent Integration
- Enter Client ID and Client Secret
- Configure API URLs (or use defaults)
- Save settings
2. Connect FreeAgent (Admin-Only)
Settings → General Settings → Integrations → FreeAgent Integration
- Click "Connect FreeAgent" button
- Authorize access in FreeAgent OAuth flow
- You'll be redirected back
- Status changes to "Connected" ✅
Important: This creates a system-wide connection that all users share. Only admins can connect/disconnect.
3. Assign FreeAgent Contacts to Users
Users → Edit User → FreeAgent Tab
- Select the FreeAgent Contact from dropdown
- Save
- User will now see invoices for that contact only
Contact Assignment:
- Required for regular users to see invoices
- Not required for super_admins (they see all invoices)
- Users without contact linkage see empty state
4. Disconnect FreeAgent (Admin-Only)
Settings → General Settings → Integrations → FreeAgent Integration
- Click "Disconnect FreeAgent" button
- Confirm in modal
- All users lose access to FreeAgent invoices
For Regular Users
View Invoices
- Navigate to Invoices in sidebar
- See invoices for your assigned contact only
- Use filters to find specific invoices
- Click "View" to see invoice details
- Click "Download PDF" to download invoice
Sync Invoices
- Click "Sync Invoices" button
- Confirm sync
- Latest invoices fetched from FreeAgent
Note: If not connected to a contact, you'll see:
"No Invoices Available - Your account is not yet linked to a FreeAgent contact. Please contact your administrator to set up access."
Authorization & Multi-Tenancy
Admin Access (super_admin role)
- ✅ See ALL invoices regardless of contact
- ✅ Configure OAuth credentials
- ✅ Connect/disconnect FreeAgent
- ✅ Assign contacts to users
- ✅ Access FreeAgent settings
User Access (regular users)
- ✅ See invoices only for their assigned contact
- ✅ Must have
freeagent_contact_idset by admin - ✅ Can sync invoices (uses system-wide connection)
- ✅ Can download PDFs for their invoices
- ❌ Cannot see other contacts' invoices
- ❌ Cannot connect/disconnect FreeAgent
- ❌ Cannot change their contact assignment
Contact-Based Scoping
The package implements secure contact-based scoping:
Policy Implementation
Features in Detail
Invoice List
Columns:
- Reference - Invoice number (searchable, sortable, copyable)
- Client & Project - Shows "Contact : Project" format
- Status - Color-coded badge (Paid=green, Sent/Open=yellow, Overdue=red, Draft=gray)
- Invoice Date - Uses app's configured date format
- Due Date - Color-coded (red if overdue)
- Total - Amount with currency
- Overdue - Boolean indicator (toggleable)
Filters:
- Status (multiple selection)
- Contact (searchable dropdown)
- Overdue Only
- Unpaid Only
- Date Range (from/to)
Actions:
- View - See invoice details
- Download PDF - Download invoice PDF
- Sync Invoices - Fetch latest from FreeAgent
- FreeAgent Settings - Go to settings (admin only)
Invoice Detail View
Sections:
- Invoice Details: Reference, Status, Project, Dates
- Contact Information: Name, Email, Phone
- Financial Details: Net, VAT/Tax, Total, Currency
- Sync Information: Last synced timestamp
Project Integration
Invoices automatically link to FreeAgent projects:
- Projects synced from FreeAgent API
- Displayed as "Contact : Project" in list
- Shown in detail view
- Searchable by project name
Date Format Integration
All dates use the app's configured format:
- Configure: Settings → General Settings → General → Date Format
- Supported: DD/MM/YYYY, MM/DD/YYYY, YYYY-MM-DD, and more
- Applied to: Table columns, filters, detail view, datetime fields
PDF Downloads
Secure PDF download with validation:
- Downloads invoice PDF from FreeAgent API
- Validates PDF magic bytes (
%PDF) - Proper content headers
- Authorization check before download
- Base64 decoding handled automatically
Caching & Sync Strategy
System-Wide Connection
The package uses a single OAuth connection (user_id = 1) shared by all users:
- Admin connects once in General Settings
- All users benefit from the connection
- No per-user OAuth required
- Simplified token management
Automatic On-Access Sync
When a user visits the invoices page:
- Check if cache is stale (>30 minutes old)
- If stale, automatically sync in background
- Display fresh data to user
- No user interaction needed
Manual Sync
Users can click "Sync Invoices" to force a refresh:
- Fetches latest invoices from FreeAgent
- Syncs contacts and projects
- Updates local database
- Shows sync statistics (created/updated counts)
Pagination
All API calls use full pagination:
- Fetches 100 records per page (FreeAgent max)
- Continues until all records fetched
- No 25-record limit
- Safety limit: 1000 pages
API Services
FreeAgentService
Core service for FreeAgent API interactions:
FreeAgentOAuthService
System-wide OAuth token management:
Note: All methods now use system-wide token (user_id = 1) instead of per-user tokens.
FreeAgentCacheService
Sync and cache management:
Database Structure
Tables
freeagent_oauth_tokens
- Stores system-wide OAuth token (user_id = 1)
- Auto-refreshes when expired
- Single token for entire app
freeagent_contacts
- Cached contact data from FreeAgent
- Links to users table via
freeagent_contact_id - Includes organization name, email, phone
freeagent_invoices
- Cached invoice data from FreeAgent
- Linked to contacts and projects
- Includes status, dates, amounts
freeagent_projects
- Cached project data from FreeAgent
- Linked to contacts
- Includes name, status, dates, budget
users (modified)
- Added
freeagent_contact_idcolumn - Links user to FreeAgent contact
Relationships
Error Handling
OAuth Errors
- Token expired: Automatically refreshes token
- No token: Shows "Not Connected" in settings
- Refresh failed: Deletes token, requires reconnection
- User notifications: Friendly error messages with action buttons
API Errors
- Rate limit exceeded: Returns 429 error with notification
- Network errors: Retries with exponential backoff (3 attempts)
- Authentication failed: Prompts OAuth reconnection
- PDF errors: Validates content and shows clear error messages
Logging
All errors are logged with context:
Security
- ✅ OAuth tokens encrypted in database
- ✅ CSRF protection on OAuth flow via state parameter
- ✅ Policy-based authorization on all actions
- ✅ Rate limiting on API requests (120/min per user)
- ✅ Hidden sensitive fields in model serialization
- ✅ Admin-only connection management
- ✅ Contact-based data isolation
- ✅ PDF content validation (magic bytes check)
- ✅ Settings stored securely with Spatie Laravel Settings
Testing
Changelog
Recent Improvements
- ✅ System-wide OAuth connection (admin-managed)
- ✅ Project integration with invoices
- ✅ Full pagination support (no 25-record limit)
- ✅ PDF download with base64 decoding
- ✅ Date format integration with app settings
- ✅ Contact-based scoping improvements
- ✅ Settings integration into app's GeneralSettings
- ✅ Empty state for unlinked users
- ✅ Status color coding (Paid/Sent/Overdue)
- ✅ Migration organization (package stubs)
Roadmap
- [ ] Webhook support for real-time updates
- [ ] Support for expenses and timesheets
- [ ] Bulk invoice actions
- [ ] Advanced reporting and analytics
- [ ] Export to CSV/Excel
- [ ] Multi-currency enhancements
- [ ] Invoice templates customization
Troubleshooting
"Cannot assign Closure to property" Error
Solution: Clear cache after settings updates:
"No Invoices Available" Message
Causes:
- Admin hasn't connected FreeAgent
- User not linked to a FreeAgent contact
- No invoices for user's contact
Solution: Contact admin to link your account to a FreeAgent contact.
PDF Download Corrupted
This has been fixed! PDFs now properly decode from base64 and validate magic bytes.
Invoices Not Syncing
Check:
- FreeAgent connected in Settings
- OAuth token not expired (auto-refreshes)
- Check
storage/logs/laravel.logfor errors
Support
For issues, feature requests, or questions:
- GitHub Issues: https://github.com/zynqa/filament-freeagent/issues
- Email: [email protected]
- Documentation: See package
.mdfiles
License
MIT License - see LICENSE file for details
Credits
- Built by Zynqa
- Powered by FilamentPHP
- Integrates with FreeAgent
- Uses Spatie Laravel Settings
All versions of filament-freeagent with dependencies
filament/filament Version ^3.2 || ^4.0 || ^5.0
spatie/laravel-settings Version ^3.0
spatie/laravel-package-tools Version ^1.16
illuminate/support Version ^11.28 || ^12.0 || ^13.0
guzzlehttp/guzzle Version ^7.8