Package Data | |
---|---|
Maintainer Username: | Albin N |
Maintainer Contact: | andreasgoransson0@gmail.com (Andreas Göransson) |
Package Create Date: | 2017-02-24 |
Package Last Update: | 2017-02-27 |
Language: | PHP |
License: | Apache-2.0 |
Last Refreshed: | 2024-11-09 15:01:27 |
Package Statistics | |
---|---|
Total Downloads: | 268 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A simple Fortnox PHP package, including Laravel Service Provider for easy integration in Laravel.
Forked from wetcat-studios/fortie
The easiest way to install this package is through Composer.
composer require nivv/fortnox-laravel dev-master
Or add "nivv/fortnox-laravel": "dev-master"
to your composer.json
.
If you don't have Composer you should install it.
In Laravel you change use the published configuration file found at config/fortie.php
, it should look something like the following. Fill this in with the details provided by Fortnox when you signed up.
The Access Token is not provided when signing up, you need to get that seperately using your Auth Code and Client Secret. Read more about this process here.
<?php
return [
'default' => [
// Your specific access token
'access_token' => '<your access token>',
// Your specific client secret
'client_secret' => '<your client secret>',
// The type you're sending
'content_type' => 'application/json',
// The type you're accepting as response
'accepts' => 'application/json',
// The URL to the Fortnox API
'endpoint' => 'https://api.fortnox.se/3/',
],
];
Note that XML is not fully supported yet, the package can read and will attempt to translate the responses from Fortnox into XML structures, but when sending data to Fortnox it will always send in json.
In laravel the easiest way to use Fortie is to add the ServiceProvider, in config/app.php
add the following line to providers
array.
<?php
return [
...
'providers' => [
...
Nivv\Fortie\FortieServiceProvider::class,
],
...
];
When you've included the Service Provider you can then use dependency injection in your BaseController to make fortie available in all controllers.
abstract class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $fortie;
public function __construct(Fortie $fortie)
{
$this->fortie = $fortie;
}
}
Just call $this->fortie->...
to access Fortie.
class MyController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
dd($this->fortie->accounts()->listAllAccounts());
}
...
}
Of course you can also inject Fortie into any Laravel controller method to limit application wide access to Fortnox.
use Nivv\Fortie\Fortie as Fortie;
class MyController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Fortie $fortie)
{
dd($fortie->accounts()->listAllAccounts());
}
...
}
In Laravel the ServiceProvider takes care of setting up Fortie using the configuration file, if used outside of Laravel you need to instantiate Fortie using the configuration provided by Fortnox.
$fortie = new Fortie(
$endpoint,
$access_token,
$client_secret,
$content_type,
$accepts
);
To get an access token (for use with your integration) you need to request it using a authroization-code
.
In Laravel you can use the Artisan command to easily get the access token.
php artisan fortie:activate code=<your authorization code>
The package is set up with multiple providers, each provider is mapped towards a specific endpoint in the REST api. For example accounts are mapped to the accounts() method.
$arrayOfAccounts = $fortie->accounts()->all();
For details on the usage of all providers you should consult the Wiki.
This package is built with the following dependencies.
Copyright 2015 Andreas Göransson
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.