PHPackages                             mjaschen/collmex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. mjaschen/collmex

ActiveLibrary[API Development](/categories/api)

mjaschen/collmex
================

Collmex PHP SDK

3.9.0(2mo ago)2080.7k↓37.7%25[4 PRs](https://github.com/mjaschen/collmex/pulls)MITPHPPHP ^8.1CI passing

Since Feb 26Pushed 2mo ago8 watchersCompare

[ Source](https://github.com/mjaschen/collmex)[ Packagist](https://packagist.org/packages/mjaschen/collmex)[ Fund](https://www.paypal.com/paypalme/mjaschen)[ GitHub Sponsors](https://github.com/mjaschen)[ RSS](/packages/mjaschen-collmex/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (28)Versions (135)Used By (0)

Collmex API PHP SDK
===================

[](#collmex-api-php-sdk)

[![Latest Stable Version](https://camo.githubusercontent.com/9cdb15692a197d6dc6543bfcaf060bf28d4f14e2299fb13b2fd10137e3c683d8/68747470733a2f2f706f7365722e707567782e6f72672f6d6a61736368656e2f636f6c6c6d65782f76)](https://packagist.org/packages/mjaschen/collmex)[![Total Downloads](https://camo.githubusercontent.com/1246c96cbd6fd3bc333d6ebef8982d797eaf54e4d5bb017381410d0eb8b5a36b/68747470733a2f2f706f7365722e707567782e6f72672f6d6a61736368656e2f636f6c6c6d65782f646f776e6c6f616473)](https://packagist.org/packages/mjaschen/collmex)[![CI Status](https://github.com/mjaschen/collmex/workflows/Collmex%20PHP%20SDK%20Tests/badge.svg)](https://github.com/mjaschen/collmex/actions)[![License](https://camo.githubusercontent.com/5f5e1e617480afdf541e2dcbf323e171ad6a576059c1ea8be3c26e8f4ede1197/68747470733a2f2f706f7365722e707567782e6f72672f6d6a61736368656e2f636f6c6c6d65782f6c6963656e7365)](https://packagist.org/packages/mjaschen/collmex)

This library provides a wrapper for the Collmex API. It's not complete yet, some record types (and maybe some features) are missing.

Please create a pull request if you have implemented a new type/feature or create issues for bugs/feature requests.

There is (or least should be…) a *Type* class for every Collmex record type ("Satzart"). Currently, only the base types (`MESSAGE`, `LOGIN`, `NEW_OBJECT_ID`) and a few normal record types are implemented:

- `ABO_GET`
- `ACC_BAL`
- `ACCBAL_GET`
- `ACCDOC`
- `ACCDOC_GET`
- ... [full list »](#list-of-supported-types)

Compatibility
-------------

[](#compatibility)

The Collmex PHP SDK requires PHP &gt;= 8.1. It's possible to install an older version of the Collmex PHP SDK if you're still using an unsupported PHP version:

- for PHP 7.3, 7.4 and 8.0 compatibility: use the 2.x tags (`composer require mjaschen/collmex:^2.0`); this version will receive security updates until version 4.0 is released.
- for PHP 7.2 compatibility: use the 1.x tags (`composer require mjaschen/collmex:^1.0`); this version won't receive any updates.
- for PHP 7.0 compatibility: use the 0.12.x tags (`composer require mjaschen/collmex:^0.12`); this version won't receive any updates.
- for PHP 5.6 compatibility: use the 0.11.x tags (`composer require mjaschen/collmex:^0.11`); this version won't receive any updates.

New features will only go into the main branch and won't be backported.

PHP VersionCollmex PHP SDK VersionSupport Status8.53.x✅ active8.43.x✅ active8.33.x✅ active8.23.x✅ active8.13.x✅ active8.02.x⚠️ security only7.42.x⚠️ security only7.32.x⚠️ security only7.21.x❌ end of life7.11.x❌ end of life7.01.x❌ end of life5.60.11.x❌ end of lifeInstallation
------------

[](#installation)

Using Composer, just add it to your `composer.json` by running:

```
composer require mjaschen/collmex
```

If you want to use the included Laravel service provider `CollmexServiceProvider`, add it to the `config/app.php` providers array:

```
return [

    // ...

    'providers' => [
        // ...
        \MarcusJaschen\Collmex\CollmexServiceProvider::class,
    ],

    // ...
];
```

Upgrading
---------

[](#upgrading)

### Version 2.x to 3.x

[](#version-2x-to-3x)

1. Read the [change log](https://github.com/mjaschen/collmex/blob/main/CHANGELOG.md). You will see the list of everything changed between versions 2 and 3.
2. Ensure your codebase is compatible with all requirements in `composer.json`.
3. Update your `composer.json` to require version 3.x of the Collmex PHP SDK:

```
{
  "require": {
    "mjaschen/collmex": "^3.0"
  }
}
```

### Version 1.x to 2.x

[](#version-1x-to-2x)

1. Read the [change log](https://github.com/mjaschen/collmex/blob/main/CHANGELOG.md). You will see the list of everything changed between versions 1 and 2.
2. Ensure your codebase is compatible with all requirements in `composer.json`.
3. Rename attributes which are used in your codebase. Some attributes in the type classes have been renamed. If you use these attributes, you have to adjust your code as well. A simple search-and-replace is sufficient for this. Below you will find the complete list of renamed attributes:

ClassOld NameNew Name`Stock``charge_number``batch_number``Stock``charge_description``batch_description``StockChange``destination_charge``destination_batch``StockChange``destination_charge_labeling``destination_batch_labeling``StockChange``source_charge``source_batch``AccountDocumentGet``only_changed``changed_only``CustomerGet``only_changed``changed_only``MemberGet``only_changed``changed_only``SalesOrderGet``only_changed``changed_only``StockGet``only_changed``changed_only``VoucherGet``only_changed``changed_only``Customer``forename``firstname``CustomerOrder``forename``firstname``Invoice``forename``firstname``Member``forename``firstname``Customer``firm``company``DifferentShippingAddress``firm``company``Member``firm``company``CustomerOrder``customer_firm``customer_company``Invoice``customer_firm``customer_company``CustomerOrder``delivery_firm``delivery_company``Invoice``delivery_firm``delivery_company`Usage/Examples
--------------

[](#usageexamples)

### Fetch from Collmex API

[](#fetch-from-collmex-api)

#### Load a Collmex *Customer* record:

[](#load-a-collmex-customer-record)

```
use MarcusJaschen\Collmex\Client\Curl as CurlClient;
use MarcusJaschen\Collmex\Request;
use MarcusJaschen\Collmex\Type\CustomerGet;

// initialize HTTP client
$collmexClient = new CurlClient('USER', 'PASSWORD', 'CUSTOMER_ID');

// create request object
$collmexRequest = new Request($collmexClient);

// create a record type; we're querying the API for customer with ID=12345
$getCustomerType = new CustomerGet(array('customer_id' => '12345'));

// send HTTP request and get response object
$collmexResponse = $collmexRequest->send($getCustomerType->getCsv());

if ($collmexResponse->isError()) {
    echo 'Collmex error: ' . $collmexResponse->getErrorMessage() . '; Code=' . $collmexResponse->getErrorCode() . PHP_EOL;

    return;
}

$records = $collmexResponse->getRecords();

foreach ($records as $record) {
    // contains one Customer object and the Message object(s)
    var_dump($record->getData());
}

// show unparsed response contents:
var_dump($collmexResponse->getResponseRaw());
```

#### Fetch a PDF Invoice from Collmex

[](#fetch-a-pdf-invoice-from-collmex)

```
use MarcusJaschen\Collmex\Client\Curl as CurlClient;
use MarcusJaschen\Collmex\Request;
use MarcusJaschen\Collmex\Type\InvoiceGet;

$collmexRequest = new Request(new CurlClient('USER', 'PASSWORD', 'CUSTOMER_ID'));
$getInvoice = new InvoiceGet(['invoice_id' => '1', 'format' => InvoiceGet::FORMAT_ZIP]);

try {
    $collmexResponse = $collmexRequest->send($getInvoice->getCsv());
} catch (\Exception) {
    // Error Handling ...
}

/** @var \Symfony\Component\Finder\Finder $files */
$files = $collmexResponse->getFilesByType(type: 'pdf');

/** @var SplFileInfo $file */
foreach ($files as $file) {
    $pdfContent = file_get_contents($file->getPathname());
    // save, mail, display, etc.
    break;
}
```

### Send Data to Collmex

[](#send-data-to-collmex)

Create a new Collmex *Customer* record and get the Collmex customer ID from the response data:

```
use MarcusJaschen\Collmex\Client\Curl as CurlClient;
use MarcusJaschen\Collmex\Request;
use MarcusJaschen\Collmex\Type\Customer;

// initialize HTTP client
$collmexClient = new CurlClient('USER', 'PASSWORD', 'CUSTOMER_ID');

// create request object
$collmexRequest = new Request($collmexClient);

// create a record type; we create a customer with some basic fields
$customer = new Customer(
    [
        'client_id' => '1',
        'salutation' => 'Herr',
        'firstname' => 'Charly',
        'lastname' => 'Cash',
        'street' => 'Hauptstraße 12',
        'zipcode' => '12222',
        'city' => 'Berlin',
        'inactive' => Customer::STATUS_ACTIVE,
        'country' => 'DE',
        'phone' => '+49300000000',
        'email' => 'cash@example.org',
        'output_medium' => Customer::OUTPUT_MEDIUM_EMAIL,
    ]
);

// send HTTP request and get response object
$collmexResponse = $collmexRequest->send($customer->getCsv());

if ($collmexResponse->isError()) {
    echo 'Collmex error: ' . $collmexResponse->getErrorMessage() . '; Code=' . $collmexResponse->getErrorCode() . PHP_EOL;

    return;
}

  $newObject = $collmexResponse->getFirstRecord();
  echo 'New Collmex customer ID=' . $newObject->new_id . PHP_EOL;

  $records = $collmexResponse->getRecords();

  foreach ($records as $record) {
      // contains one NewObject object and the Message object(s)
      var_dump($record->getData());
  }
```

### Send Multiple Records at Once

[](#send-multiple-records-at-once)

The Collmex API accepts requests containing multiple records.

For example, a customer order with three line-items is sent as three CSV records/lines within a single request.

The `MultiRequest` class provides a simple way to send multiple records to Collmex at once. Any valid `Type` (or an array of valid `Type` instances) can be added to a queue and eventually sent to the Collmex API.

```
use MarcusJaschen\Collmex\Client\Curl as CurlClient;
use MarcusJaschen\Collmex\MultiRequest;
use MarcusJaschen\Collmex\Type\CustomerOrder;

// initialize HTTP client
$collmexClient = new CurlClient('USER', 'PASSWORD', 'CUSTOMER_ID');

// create request object
$collmexMultiRequest = new MultiRequest($collmexClient);

// create a record type; we create a CustomerOrder with some basic fields
$customerOrderData = [
    'client_id' => '1',
    'customer_salutation' => 'Herr',
    'customer_firstname' => 'Charly',
    'customer_lastname' => 'Cash',
    'customer_street' => 'Hauptstraße 12',
    'customer_zipcode' => '12222',
    'customer_city' => 'Berlin',
    'customer_country' => 'DE',
    'customer_phone' => '+49300000000',
    'customer_email' => 'cash@example.org',
    'order_date' => '01.01.1970',
    'status' => CustomerOrder::STATUS_CONFIRMED,
];

// set several item positions
$customerOrderItem = new CustomerOrder(
    array_merge(
        $customerOrderData,
        [
            'product_description' => 'erster Artikel',
            'quantity' => '1',
            'price' => '10,50',
            'tax_rate' => CustomerOrder::TAX_RATE_FULL,
        ]
    )
);
$collmexMultiRequest->add($customerOrderItem);

$customerOrderItem = new CustomerOrder(
    array_merge(
        $customerOrderData,
        [
            'product_description' => 'zweiter Artikel',
            'quantity' => '10',
            'price' => '37,99',
            'tax_rate' => CustomerOrder::TAX_RATE_REDUCED,
        ]
    )
);
$collmexMultiRequest->add($customerOrderItem);

$customerOrderItem = new CustomerOrder(
    array_merge(
        $customerOrderData,
        [
            'product_description' => 'Artikel Nummer drei',
            'quantity' => '3',
            'price' => '1250,00',
            'tax_rate' => CustomerOrder::TAX_RATE_FULL,
        ]
    )
);
$collmexMultiRequest->add($customerOrderItem);

// send HTTP request and get response object
$collmexResponse = $collmexMultiRequest->send();

if ($collmexResponse->isError()) {
    echo 'Collmex error: ' . $collmexResponse->getErrorMessage() . '; Code=' . $collmexResponse->getErrorCode() . PHP_EOL;

    return;
}

$newObject = $collmexResponse->getFirstRecord();
echo 'New Collmex order ID=' . $newObject->new_id . PHP_EOL;

$records = $collmexResponse->getRecords();

foreach ($records as $record) {
    // contains one NewObject object and the Message object(s)
    var_dump($record->getData());
}
```

Notes
-----

[](#notes)

Collmex expects all strings encoded in code page 1252 (Windows) while the Collmex PHP SDK expects all inputs as UTF-8 and outputs everything as UTF-8. The conversion of string encodings is done transparently by using the Symfony String Component and PHP's `mb_convert_encoding()` function before sending a request to the Collmex API and after receiving the response from the API.

### Numeric / money values

[](#numeric--money-values)

This SDK does not convert numeric values to the string format required by the Collmex API by default.

For more information on format requirements, see the [offical API documentation](https://www.collmex.de/c.cmx?1005,1,help,daten_importieren_datentypen_felder).

The library provides helpers for simple conversion from several types to the Collmex money format:

typeexample valuecallresult (string)*float*`19.99``Money::fromFloat(19.99)``19,99`*integer* (cents)`1999``Money::fromCents(1999)``19,99`[Money for PHP](https://www.moneyphp.org/en/stable/)`$money = \Money\Money::EUR(1999)``Money::fromMoney($money)``19,99`Fully qualified class name for the helper: `\MarcusJaschen\Collmex\CollmexField\Money`.

See the unit tests for [more examples](tests/Unit/CollmexField/MoneyTest.php).

### Date Values

[](#date-values)

Collmex unterstands two different formats for dates:

- ISO style: `YYYYMMDD`
- German style: `DD.MM.YYYY`

The library provides a helper to convert `DateTime` (which covers *Carbon*instances as well) from and to the Collmex date format:

```
use MarcusJaschen\Collmex\CollmexField\Date;

echo Date::toDateTime('20220921')->format('Y-m-d')
echo Date::toDateTime('12.08.2022')->format('Y-m-d')
```

This will output

```
2022-09-21
2022-08-12

```

To convert a `DateTime` instance to Collmex format (ISO style):

```
use MarcusJaschen\Collmex\CollmexField\Date;

echo Date::fromDateTime(new \DateTime('2022-09-21T00:00:00', new \DateTimeZone('Europe/Berlin')))
```

This will output

```
20220921

```

List of Supported Types
-----------------------

[](#list-of-supported-types)

- `ABO_GET`
- `ACC_BAL`
- `ACCBAL_GET`
- `ACCDOC`
- `ACCDOC_GET`
- `ADDRESS_GROUPS_GET`
- `API_NOTIFICATION`
- `CMXADR`
- `ADRGRP`
- `BANK_STATEMENT_GET_FROM_BANK`
- `BATCH_GET`
- `BILL_OF_MATERIAL_GET`
- `CMXABO`
- `CMXADR`
- `CMXBOM`
- `CMXBTC`
- `CMXDLV`
- `CMXEPF`
- `CMXINV`
- `CMXKND`
- `CMXLIF`
- `CMXLRN`
- `CMXMGD`
- `CMXORD-2`
- `CMXPOD`
- `CMXPRD`
- `CMXPRI`
- `CMXPRI_CHANGE`
- `CMXQTN`
- `CMXSBI`
- `CMXSTK`
- `CMXUMS`
- `CMXVAG`
- `CREATE_DUE_INVOICES`
- `CUSTOMER_GET`
- `DELIVERY_GET`
- `EMPLOYEE`
- `EMPLOYEE_GET`
- `INVOICE_GET`
- `INVOICE_PAYMENT`
- `INVOICE_PAYMENT_GET`
- `INVOICE_OUTPUT`
- `INVOICE_OUTPUT_SET`
- `MEMBER_GET`
- `OPEN_ITEM`
- `OPEN_ITEMS_GET`
- `PAYMENT_CONFIRMATION`
- `PRICE_GROUP`
- `PRICE_GROUPS_GET`
- `PRDGRP`
- `PRODUCT_GET`
- `PRODUCT_GROUPS_GET`
- `PRODUCT_PRICE_GET`
- `PRODUCTION_ORDER`
- `PRODUCTION_ORDER_GET`
- `PROJECT_STAFF`
- `PROJECT_STAFF_GET`
- `PURCHASE_ORDER_GET`
- `SALES_ORDER_GET`
- `SHIPMENT_CONFIRM`
- `SHIPMENT_NOTIFICATION_SEND`
- `SHIPMENT_ORDERS_GET`
- `STOCK_AVAILABLE`
- `STOCK_AVAILABLE_GET`
- `STOCK_CHANGE`
- `STOCK_CHANGE_GET`
- `STOCK_GET`
- `TRACKING_NUMBER`
- `VENDOR_GET`
- `VOUCHER`
- `VOUCHER_GET`

Development
-----------

[](#development)

### Run code checks

[](#run-code-checks)

To run checks and tests, it's the easiest to use the provided Composer scripts:

- lint PHP files for syntax errors: `composer ci:lint`
- run static analysis with [phpstan](https://phpstan.org) and report errors: `composer ci:phpstan`
- run unit tests with PHPUnit: `composer ci:tests`
- check the code style with [PHP\_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer): `composer ci:sniff`

To run all checks and tests at once, just use `composer ci`.

Of course, it's possible to use the test runners directly, e.g. for PHPUnit:

```
./vendor/bin/phpunit
```

phpstan:

```
./vendor/bin/phpstan
```

### Autoformat the code

[](#autoformat-the-code)

You can use a Composer script to autoformat the code:

```
composer fix:php-cs
```

Collmex API Documentation
-------------------------

[](#collmex-api-documentation)

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance85

Actively maintained with recent releases

Popularity43

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 65.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~35 days

Total

125

Last Release

75d ago

Major Versions

0.12.0 → 1.0.02019-10-26

1.6.3 → 2.0.02021-12-08

2.12.0 → 3.0.02023-11-29

1.6.4 → 3.5.12025-10-02

PHP version history (13 changes)0.1.2PHP &gt;=5.3.0

0.4.0PHP &gt;=5.4.0

0.5.2PHP &gt;=5.5.9

0.7.0PHP &gt;=5.6

0.7.1PHP ^5.6.0 || ~7.0.0 || ~7.1.0 || ~7.2.0

0.10.0PHP ^5.6.0 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0

0.12.0PHP ~7.0 || ~7.1 || ~7.2 || ~7.3

1.0.0PHP ~7.1 || ~7.2 || ~7.3

1.3.0PHP ~7.1 || ~7.2 || ~7.3 || ~7.4

1.3.2PHP ^7.2

1.4.0PHP &gt;=7.2

2.0.0PHP ^7.3 || ^8.0

3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/bc523e51187f3e61b07b112fe26f3845e3261cf3aff2b488a986c48105b1623f?d=identicon)[marcusj](/maintainers/marcusj)

---

Top Contributors

[![mjaschen](https://avatars.githubusercontent.com/u/328130?v=4)](https://github.com/mjaschen "mjaschen (490 commits)")[![oliverklee](https://avatars.githubusercontent.com/u/765746?v=4)](https://github.com/oliverklee "oliverklee (109 commits)")[![codebear-linee](https://avatars.githubusercontent.com/u/4145216?v=4)](https://github.com/codebear-linee "codebear-linee (49 commits)")[![Johnny99211](https://avatars.githubusercontent.com/u/43766368?v=4)](https://github.com/Johnny99211 "Johnny99211 (43 commits)")[![Naoray](https://avatars.githubusercontent.com/u/10154100?v=4)](https://github.com/Naoray "Naoray (15 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 commits)")[![timopaul](https://avatars.githubusercontent.com/u/16575322?v=4)](https://github.com/timopaul "timopaul (7 commits)")[![lakdev](https://avatars.githubusercontent.com/u/48860258?v=4)](https://github.com/lakdev "lakdev (5 commits)")[![sreimers](https://avatars.githubusercontent.com/u/296762?v=4)](https://github.com/sreimers "sreimers (4 commits)")[![flowdee](https://avatars.githubusercontent.com/u/2278756?v=4)](https://github.com/flowdee "flowdee (2 commits)")[![mkurzeja](https://avatars.githubusercontent.com/u/1044032?v=4)](https://github.com/mkurzeja "mkurzeja (2 commits)")[![lukaspluemper](https://avatars.githubusercontent.com/u/9088407?v=4)](https://github.com/lukaspluemper "lukaspluemper (2 commits)")[![karameloso](https://avatars.githubusercontent.com/u/530785?v=4)](https://github.com/karameloso "karameloso (1 commits)")[![florianliebig](https://avatars.githubusercontent.com/u/10775702?v=4)](https://github.com/florianliebig "florianliebig (1 commits)")[![juyal-ahmed](https://avatars.githubusercontent.com/u/905868?v=4)](https://github.com/juyal-ahmed "juyal-ahmed (1 commits)")[![janakan22](https://avatars.githubusercontent.com/u/45364621?v=4)](https://github.com/janakan22 "janakan22 (1 commits)")[![strausmann](https://avatars.githubusercontent.com/u/4519228?v=4)](https://github.com/strausmann "strausmann (1 commits)")[![thomas-udalrik](https://avatars.githubusercontent.com/u/13256547?v=4)](https://github.com/thomas-udalrik "thomas-udalrik (1 commits)")

---

Tags

collmexapicollmex

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mjaschen-collmex/health.svg)

```
[![Health](https://phpackages.com/badges/mjaschen-collmex/health.svg)](https://phpackages.com/packages/mjaschen-collmex)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6939.5M343](/packages/drupal-core-recommended)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
