bernskioldmedia / laravel-fortnox
A Laravel package to consume the Fortnox API.
Requires
- php: ^8.2|^8.3
- guzzlehttp/guzzle: ^7.8
- illuminate/contracts: ^9.0|^10.0|^11.0|^12.0
- laravel/socialite: ^5.0
- neam/php-sie: 3.3.3.1
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^8.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0|^8.0|^9.0|^10.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- roave/security-advisories: dev-latest
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2025-05-31 20:31:13 UTC
README
A Laravel package to consume the Fortnox API.
Installation
You can install the package via composer:
composer require bernskioldmedia/laravel-fortnox
Publishing the config file is optional. You can publish the config file with:
php artisan vendor:publish --provider="Bernskiold\LaravelFortnox\LaravelFortnoxServiceProvider" --tag="config"
You need to set your Fortnox app credentials in your .env
file. You can obtain these credentials by creating an
application in the Fortnox Developer Portal.
You also need to set which scopes you want to request access to. The scopes you can request are listed in the Fortnox API documentation.
FORTNOX_CLIENT_ID=your-client-id FORTNOX_CLIENT_SECRET=your-client-secret FORTNOX_SCOPES=scope1,scope2,scope3
Finally, you should register the command that refreshes access tokens automatically.
In Laravel 12 and later, you register the command in your routes/console.php
file:
use Bernskiold\LaravelFortnox\Commands\RefreshAccessToken; use Illuminate\Support\Facades\Schedule; // Refresh the Fortnox access token if expired. Schedule::call(RefreshAccessToken::class)->everyMinute()->withoutOverlapping();
In Laravel 11 and earlier, you can register the command in your app/Console/Kernel.php
file:
use Bernskiold\LaravelFortnox\Commands\RefreshAccessToken; protected function schedule(Schedule $schedule) { // Refresh the Fortnox access token if expired. $schedule->call(RefreshAccessToken::class)->everyMinute()->withoutOverlapping(); }
Usage
Basic Usage
You can use the provided Fortnox
facade to access the support endpoints. For example, to get a list of invoices:
use Bernskiold\LaravelFortnox\Facades\Fortnox; // This will return a collection of invoices. $invoices = Fortnox::invoices()->all()->get();
Changing the token storage
By default the package will store the access token in the Laravel cache. However, you can change this storage provider, either to one of the built-in providers or to a custom one.
To create a custom token storage provider, you need to implement the Bernskiold\LaravelFortnox\Contracts\TokenStorage
interface. You can then register your custom provider in the fortnox.php
config file under the storage_provider
key.
The build-in storage providers are:
Bernskiold\LaravelFortnox\StorageProviders\CacheTokenStorage
: Uses Laravel's cache to store the token.Bernskiold\LaravelFortnox\StorageProviders\LaravelSettingsStorage
: Uses Spatie's Laravel Settings package to store the token.
Both of these providers offer configuration settings in the fortnox.php
config file.
Acting as user or application
The package supports both accessing the API as a Fortnox user or as a system application (via a service account).
By default the package will act as a service account, but you may change this by changing the use_service_account
option in the config file to false
.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.