chrisjohnleah / sage-business-cloud-accounting-api-laravel
Laravel bridge for the Sage Business Cloud Accounting API SDK — service provider, facade, Eloquent token store, artisan commands, and Blade components.
Package info
github.com/chrisjohnleah/sage-business-cloud-accounting-api-laravel
pkg:composer/chrisjohnleah/sage-business-cloud-accounting-api-laravel
Requires
- php: ^8.3
- chrisjohnleah/sage-business-cloud-accounting-api: ^0.1
- illuminate/console: ^11.0 || ^12.0 || ^13.0
- illuminate/contracts: ^11.0 || ^12.0 || ^13.0
- illuminate/database: ^11.0 || ^12.0 || ^13.0
- illuminate/support: ^11.0 || ^12.0 || ^13.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- orchestra/testbench: ^9.0 || ^10.0 || ^11.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
README
The Laravel bridge for chrisjohnleah/sage-business-cloud-accounting-api. Adds a service provider, a Sage facade, an Eloquent token store, artisan commands, and a Blade connect button — so a Laravel app can talk to Sage with zero wiring.
Requirements
- PHP 8.3+
- Laravel 11, 12, or 13
Installation
composer require chrisjohnleah/sage-business-cloud-accounting-api-laravel php artisan migrate # creates the sage_tokens table php artisan vendor:publish --tag=sage-config # optional
Set your Sage Developer app credentials in .env:
SAGE_CLIENT_ID=... SAGE_CLIENT_SECRET=... SAGE_REDIRECT_URI=https://your-app.test/oauth/sage/callback SAGE_SCOPES=readonly # or full_access
Connecting
Render the connect button in a Blade view:
<x-sage::connect-button label="Connect to Sage" class="btn btn-primary" />
…or print the URL from the console:
php artisan sage:connect
php artisan sage:status # check the connection
In your OAuth callback route, complete the handshake:
use ChrisJohnLeah\SageAccounting\Laravel\Facades\Sage; Route::get('/oauth/sage/callback', function (Request $request) { Sage::exchangeCode($request->query('code'), $request->query('state'), session('sage_state')); Sage::resolveBusiness(); return redirect('/dashboard')->with('status', 'Connected to Sage'); });
Using it
Everything from the core SDK is available through the Sage facade — token refresh and pagination are automatic:
use ChrisJohnLeah\SageAccounting\Laravel\Facades\Sage; foreach (Sage::purchaseInvoices()->list(['updated_or_created_since' => $since]) as $invoice) { SupplierBill::updateOrCreate( ['sage_invoice_id' => $invoice->id], [ 'supplier' => $invoice->contactName, 'outstanding' => $invoice->outstandingAmount, 'due_date' => $invoice->dueDate, 'status' => $invoice->status?->displayedAs, ], ); }
You can also resolve the client directly: app(\ChrisJohnLeah\SageAccounting\Sage::class).
Configuration
Publish config/sage.php to customise endpoints, scopes, the token table name, and the refresh buffer.
Testing
composer check # Pint + Larastan (max) + Pest
Licence
MIT © Chris John Leah. See LICENSE.
Not affiliated with or endorsed by The Sage Group plc.