Search by

PHP client to consume docs-dispatcher.io API services

v1.8.0 2026-08-08 20:45 UTC

README

pipeline status coverage report

DocsDispatcher PHP Client

Versions

SDK versionPHP versionBranch
v0.1.x7.2+php-7x
v0.2.x8.1+develop

Installation

$ composer require docs-dispatcher.io/sdk

Getting started

Concepts

This library relays on the following concepts in order to be able to use it with a minimal knowledge of the API itself.

Authentication

Two authentication methods are supported:

  • Basic Auth (username/password)
  • Bearer Token (JWT token) - recommended for API v3.6+

Service(s)

A service is an API endpoint having its own parameters. For a detailed list of them, please read the API documentation, also available as Swagger format.

ServiceMediator

A single class that will be in charge to temporary store your defined services and their corresponding configurations in order to build the request to be sent to the API.

Client

The class that actually triggers calls to API. It decorates a GuzzleHttp\Client instance.

Usage

A realistic usage can be found in the attached sample file exemple.php. For more details about configuring each services, please refer to the API documentation.

Authentication Examples

Using Bearer Token (JWT) - Recommended:

use DocsDispatcherIo\Sdk\Authentication\BearerTokenAuthentication;
use DocsDispatcherIo\Sdk\Client;

$authentication = new BearerTokenAuthentication('your-jwt-token-here');
$client = new Client($authentication);

Using Basic Auth:

use DocsDispatcherIo\Sdk\Authentication\BasicAuthAuthentication;
use DocsDispatcherIo\Sdk\Client;

$authentication = new BasicAuthAuthentication('username', 'password');
$client = new Client($authentication);

Available Services

The SDK supports the following services:

  • EmailService: Send emails with attachments
  • FileService: Generate documents from templates
  • SmsService: Send SMS messages
  • PostalService: Send postal mail
  • ESignService: Handle electronic signatures
  • UploadService: Upload files to external services
  • InvoicingService: Create invoices, quotes, or credit notes — classic flow (IpaidThat, Qonto, Pennylane) or electronic flow (ESALINK, SuperPDP, JeFacture)

Invoicing Service Example

use DocsDispatcherIo\Sdk\Argument\Address;
use DocsDispatcherIo\Sdk\Argument\Enums\CustomerTypes;
use DocsDispatcherIo\Sdk\Argument\Enums\DiscountTypes;
use DocsDispatcherIo\Sdk\Argument\Enums\InvoiceDocumentTypes;
use DocsDispatcherIo\Sdk\Argument\InvoiceCustomer;
use DocsDispatcherIo\Sdk\Argument\InvoiceItem;
use DocsDispatcherIo\Sdk\Service\InvoicingService;
use DocsDispatcherIo\Sdk\ServiceMediator;

// Create customer billing address
$billingAddress = new Address(
    'Acme Corp',           // Name
    '123 Main Street',     // Address
    'Paris',               // City
    '75001',               // Postal code
    'FR'                   // Country code
);

// Create a company customer
$customer = new InvoiceCustomer(
    CustomerTypes::COMPANY,
    'billing@acme.com',
    $billingAddress
);
$customer
    ->setName('Acme Corporation')
    ->setVatNumber('FR12345678901')
    ->setRegistrationNumber('123456789')
    ->setPhone('+33123456789');

// Create invoice items
$item1 = new InvoiceItem('Consulting Services', 150.00);
$item1
    ->setQuantity(10.0)
    ->setTaxPercent(20.0)
    ->setAdditionalInfo('Monthly retainer');

$item2 = new InvoiceItem('Development Services', 200.00);
$item2
    ->setQuantity(5.0)
    ->setTaxPercent(20.0)
    ->setDiscount(DiscountTypes::PERCENTAGE, 10.0, 'Volume discount');

// Create the invoicing service
$invoicingService = new InvoicingService(
    $customer,
    [$item1, $item2],
    InvoiceDocumentTypes::INVOICE,
    '2025-11-20'  // Issue date
);

$invoicingService
    ->setProvider('ipaidthat')  // or 'qonto', 'pennylane' (classic flow)
    ->setTitle('Monthly Services Invoice')
    ->setExternalId('INV-2025-001')
    ->setCurrency('EUR')
    ->setLocale('fr_FR')
    ->setDueDate('2025-12-31')
    ->setShipping(25.50)
    ->setDiscount(DiscountTypes::PERCENTAGE, 5.0, 'Early payment discount')
    ->setSendByEmail(true)
    ->addRecipientEmail('finance@acme.com')
    ->setSendCopy(true);

$serviceMediator = new ServiceMediator([$invoicingService]);
$response = $client->executeRequest($serviceMediator, 'application/json');

Customer Types:

  • CustomerTypes::COMPANY - For businesses (requires name, registrationNumber, vatNumber)
  • CustomerTypes::INDIVIDUAL - For consumers (requires firstname, lastname)
  • CustomerTypes::FREELANCE - For freelancers (requires firstname, lastname, optional businessName, registrationNumber, vatNumber)

Document Types:

  • InvoiceDocumentTypes::INVOICE - Standard invoice
  • InvoiceDocumentTypes::QUOTE - Quotation/estimate (classic flow only)
  • InvoiceDocumentTypes::CREDIT - Credit note

Electronic Invoicing (PDP/Peppol):

By default, InvoicingService uses the classic flow (invoice/quote/credit note emitted by a provider that owns the document lifecycle: IpaidThat, Qonto, Pennylane). Call setElectronicFlow(true) to route the invoice/credit note through a PDP under the French e-invoicing reform (AFNOR XP Z12-013) or Peppol network instead (ESALINK, SuperPDP, JeFacture). QUOTE and the email delivery fields (sendByEmail, sendCopy, recipientsEmail) are not applicable to the electronic flow.

use DocsDispatcherIo\Sdk\Argument\Enums\FlowProfile;
use DocsDispatcherIo\Sdk\Argument\Enums\FlowSyntax;
use DocsDispatcherIo\Sdk\Argument\Enums\ProcessingRule;

$invoicingService
    ->setProvider('esalink')
    ->setElectronicFlow(true)
    ->setFlowSyntax(FlowSyntax::UBL)
    ->setFlowProfile(FlowProfile::EXTENDED_CTC_FR)
    ->setProcessingRule(ProcessingRule::B2B)
    ->setSenderCompanyNumber('853322915')
    ->setSenderCompanyNumberScheme('fr_siren');

Development

PHP always runs via Docker in this repo, never on the host. To run the test suite or the formatter locally, build ci/Dockerfile and run composer install / phpunit / php-cs-fixer inside it — see .gitlab-ci.yml for the exact commands CI runs.

A git pre-commit hook auto-fixes staged files with php-cs-fixer fix (not just --dry-run) before each commit, so formatting never reaches CI already broken. Enable it once per clone:

git config core.hooksPath .githooks