nivv / fortnox-laravel by Albin N
forked from wetcat-studios/fortie

Enable simple Fortnox integration
268
0
2
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

Build Status

Fortnox Laravel (fork of wetcat-studios/fortie)

A simple Fortnox PHP package, including Laravel Service Provider for easy integration in Laravel.

Forked from wetcat-studios/fortie

Installation

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.

Configuration

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.

Usage

Laravel

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());
    }

    ...

}

Non-laravel

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
);

Access tokens

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>

Providers

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.

Currently implemented providers

  • Accounts
  • Archive
  • Articles
  • Company Settings
  • Contracts
  • Currencies
  • Customers
  • Invoices
  • Offers
  • Orders
  • Price lists
  • Prices
  • Projects
  • Suppliers
  • Units
  • Vouchers

Not implemented yet

  • Article File Connections
  • Article URL Connections
  • Contract Accruals
  • Contract Templates
  • Cost Centres
  • Financial years
  • Inbox
  • Invoice accruals
  • Invoice payments
  • Locked period
  • Modes of payment
  • Print templates
  • Supplier Invoice Accruals
  • Supplier Invoice External URL connections
  • Supplier Invoice File Connections
  • Supplier Invoice Payments
  • Supplier Invoices
  • Tax reductions
  • Terms of Deliveries
  • Terms of payments
  • Voucher File Connections
  • Voucher Series
  • Way of Deliveries

Dependencies

This package is built with the following dependencies.

License

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.