var-lab / lexoffice-bundle
A Symfony bundle to integrate the lexoffice api.
Installs: 1 720
Dependents: 0
Suggesters: 0
Security: 0
Type:symfony-bundle
pkg:composer/var-lab/lexoffice-bundle
Requires
- php: >=8.1
- ext-ctype: *
- ext-iconv: *
- ext-posix: *
- guzzlehttp/guzzle: ^7.8
- symfony/config: >=6.2
- symfony/dependency-injection: >=6.2
- symfony/filesystem: >=6.4
- symfony/http-client: >=6.4
- symfony/serializer: >=6.4
- symfony/validator: >=6.4
- thecodingmachine/safe: >=2.1 || ^3.3
Requires (Dev)
- ext-pcntl: *
- ergebnis/composer-normalize: ^2.15
- jangregor/phpstan-prophecy: ^1.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.4
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpstan/phpstan-strict-rules: ^1.1
- phpunit/php-code-coverage: ^9.2
- phpunit/phpunit: 9.5.16
- spatie/phpunit-snapshot-assertions: ^4.2
- squizlabs/php_codesniffer: *
- symfony/browser-kit: >=6.2.0
- symfony/framework-bundle: >=6.4
- symfony/http-kernel: >=6.2
- symfony/phpunit-bridge: >=6.2.0
- symfony/stopwatch: >=6.2.0
- symfony/var-exporter: >=6.2
- thecodingmachine/phpstan-safe-rule: >=1.2
- var-lab/coding-standard: ^2.0
Conflicts
README
Introduction
This bundle integrates the lexoffice public API into Symfony, utilizing Symfony's serializer to convert API responses into objects. Compatible with Symfony 6.4.
Installation
- Download the Bundle
Add the bundle to your composer.json:
composer require var-lab/lexoffice-bundle
2. Register the Bundle
(should be done automatically by composer)
return [
// ...
VarLabIT\LexofficeBundle\VarLabITLexofficeBundle::class => ['all' => true],
];
3. Add configuration
Create the config file config/packages/var_lab_it_lexoffice.yaml with following content:
var_lab_it_lexoffice:
api_key: '%env(LEXOFFICE_API_KEY)%'
add the api key to your .env:
# ...
LEXOFFICE_API_KEY=<your-api-key>
Usage
The following API functions are currently covered:
- Contacts
- [x] fetch contact
- [x] create contact
- [x] update contact
- Invoices
- [x] create invoice
- [x] update invoice
- [x] fetch invoice
- [x] download invoice pdf
The lexoffice bundle is currently undergoing further development. Your own pull requests are welcome.
Contacts
Create a new contact:
<?php
use VarLabIT\LexofficeBundle\Entity\Address;
use VarLabIT\LexofficeBundle\Entity\Company as LexofficeCompany;
use VarLabIT\LexofficeBundle\Entity\Contact;
use VarLabIT\LexofficeBundle\Entity\ContactRole;
use VarLabIT\LexofficeBundle\Entity\Enum\AddressType;
use VarLabIT\LexofficeBundle\Entity\Enum\RoleType;
use VarLabIT\LexofficeBundle\Entity\Person;
use VarLabIT\LexofficeBundle\LexofficeClient;
class CityPageController extends AbstractController {
public function __construct(
private readonly CompanyRepository $companyRepository,
private readonly LexofficeClient $lexofficeClient,
)
{
}
private function getContactObject(Company $company): Contact
{
$contact = new Contact();
$contact
->setVersion(0)
->addRole(RoleType::CUSTOMER, new ContactRole())
->setCompany(
(new LexofficeCompany())
->setName($company->getName())
->addContactPerson(
(new Person())
->setFirstName($company->getGivenName())
->setLastName($company->getFamilyName())
->setEmailAddress($company->getInvoiceEmail())
->setPrimary(true)
->setPhoneNumber($company->getContactPhone())
),
)
->addAddress(
AddressType::BILLING,
(new Address())
->setSupplement('Rechnungsadresse')
->setStreet($company->getAddress())
->setZip($company->getZipcode())
->setCity($company->getCity())
->setCountryCode($company->getCountry())
);
return $contact;
}
public function createContact(int $companyId): Response {
$company = $this->companyRepository->find($companyId);
$contact = $this->createContact($company);
$contact = $this->lexofficeClient->createContact($contact);
$company
->setVersion($contact->getVersion())
->setLexofficeId($contact->getId());
}
}
Update a contact:
public function createContact(int $companyId): Response {
$company = $this->companyRepository->find($companyId);
$contact = $this->createContact($company);
$contact = $this->lexofficeClient->updateContact($contact);
$company
->setVersion($contact->getVersion())
->setLexofficeId($contact->getId());
}
Maintainer
This bundle is maintained and created by var-lab IT GmbH and contributors.