lacodix/sevdesk-saloon

A PHP package for consuming the SevDesk API based on Saloon

v0.12.1 2024-09-16 10:32 UTC

This package is auto-updated.

Last update: 2024-12-16 10:56:05 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Documentation

** WORK IN PROGRESS _ DOCUMENTATION NOT READY **

You can find the entire documentation for this package on our documentation site.

This package helps you to consume the Sevdesk API with your PHP projects. The package is based on Saloon https://api.sevdesk.de/

Installation

composer require lacodix/sevdesk-saloon

Quickstart

Create an API Connector first. You have to provide some configuration data, to get the sevdesk api working. There are several settings that you'd have to set in all requests otherwise, like default tax rates and your api user id.

use Lacodix\SevdeskSaloon\SevdeskSaloon;

$sevdeskSaloon = new SevdeskSaloon(
    $api_token, // Your API Token - get it in your Sevdesk account
    [
        'sevUserId'   => 12345678,     // the Sevdesk Uer ID - needed to create invoices
        'taxRate'     => 19,
        'taxText'     => 'MwSt 19%',   // only in version 1.0
        'taxType'     => 'default',    // only in version 1.0
        'taxRule'     => 1,            // only in version 2.0
        'currency'    => 'EUR',
        'invoiceType' => 'RE',
    ]
);

Get Your API User Id

Unfortunately Sevdesk doesn't show up the user ids on the UI. So you have to consume the API without configuration for the first time. You can just run the following code (you need a valid token).

    $sevdeskSaloon = new SevdeskSaloon($api_token);
    $sevdeskSaloon->sevUsers->get();

this will return an array of all sevUsers in your account. Take the ID and save it in your configuration.

[
    [
      "id" => "1234567",
      "objectName" => "SevUser",
      "additionalInformation" => null,
      "create" => ...,
      ...
    ]
]

Consuming the Api

With the connector you can just consume all existing API resources

    $sevdeskSaloon->contact()->get();
    $sevdeskSaloon->contact()->create($contactType, $contactData);
    
    $sevdeskSaloon->invoice()->get();
    $sevdeskSaloon->invoice()->create($sevContactId, $items, $data);
    $sevdeskSaloon->invoice()->sendViaEmail($invoiceId, $data);

Mock API Calls in your tests

Since this package is based on Saloon, you can just use the MockClient to mock all requests in your tests.

See Saloon Documentation for more information.

Contributing

Please run the following commands and solve potential problems before committing and think about adding tests for new functionality.

composer rector:test
composer insights
composer csfixer:test
composer phpstan:test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

With the first usage of Sevdesk API we used the package laravel-sevdesk-api created by Martin. Nevertheless we had some issues, for example when downloading invoices as PDF, which Martin solved via a direkt print out of the pdf, while we wanted to save the PDF on our side. Finally the testability with mocking the default Guzzle Client is a impertinence, why we decided to make our own package based on Saloon and with no dependency on Laravel, so you can also use it in other composer based PHP Projects. Some few parts are still based on Martins package like the Countries-Enum.

License

The MIT License (MIT). Please see License File for more information.