esyoil-gmbh / collmex
Collmex PHP SDK
Requires
- php: ~7.1 || ~7.2 || ~7.3
- ext-curl: *
- ext-json: *
- ext-zip: *
- neitanod/forceutf8: ^2.0
- symfony/finder: ^4.0 || ^5.0
- symfony/http-foundation: ^4.0 || ^5.0
Requires (Dev)
- friendsofphp/php-cs-fixer: 2.16.1
- laravel/framework: ^7.2
- mockery/mockery: ^1.2
- phpunit/phpunit: ^7.5
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.4
- vimeo/psalm: ^3.1
- dev-master
- v1.3.0
- 1.2.0
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- 0.12.0
- 0.11.1
- 0.11.0
- 0.10.1
- 0.10.0
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.12
- 0.8.11
- 0.8.10
- 0.8.9
- 0.8.8
- 0.8.7
- 0.8.6
- 0.8.5
- 0.8.4
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.7
- 0.7.6
- 0.7.5
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.21
- 0.6.20
- 0.6.19
- 0.6.18
- 0.6.16
- 0.6.15
- 0.6.14
- 0.6.13
- 0.6.12
- 0.6.11
- 0.6.10
- 0.6.9
- 0.6.8
- 0.6.7
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.4
- 0.1.3
- 0.1.2
- dev-task/add-php7.4-support
- dev-feat_exception_chaining
This package is auto-updated.
Last update: 2024-09-14 16:29:34 UTC
README
此库为 Collmex API 提供了一个包装器。它尚未完成,一些记录类型(以及可能的一些功能)尚不完整。
如果您实现了新的类型/功能,请创建一个 pull request,或者创建问题报告错误/功能请求。
对于每个 Collmex 记录类型("Satzart"),都有一个 类型 类。目前只实现了基本类型(MESSAGE
、LOGIN
、NEW_OBJECT_ID
)和一些常规记录类型。
ABO_GET
ACC_BAL
ACCBAL_GET
ACCDOC
ACCDOC_GET
BILL_OF_MATERIAL_GET
CMXABO
CMXBOM
CMXDLV
CMXEPF
CMXINV
CMXKND
CMXMGD
CMXORD-2
CMXPOD
CMXPRD
CMXPRI
CMXPRI_CHANGE
CMXSTK
CMXUMS
CUSTOMER_GET
DELIVERY_GET
INVOICE_GET
INVOICE_OUTPUT_SET
MEMBER_GET
OPEN_ITEM
OPEN_ITEMS_GET
PAYMENT_CONFIRMATION
PRICE_GROUP
PRICE_GROUPS_GET
PRODUCT_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
安装
使用 Composer,只需将其添加到您的 composer.json
中即可,运行
composer require mjaschen/collmex
如果您想使用包含的 Laravel 服务提供程序 CollmexServiceProvider
,请将其添加到 config/app.php
的 providers 数组中
<?php return [ // ... 'providers' => [ // ... \MarcusJaschen\Collmex\CollmexServiceProvider::class, ], // ... ];
兼容性
Collmex PHP SDK 需要 PHP >= 7.1。如果您仍在使用古老的 PHP 版本,您可以安装 Collmex PHP SDK 的旧版本
- 为 PHP 7.0 兼容性:使用 0.12.x 分支(
composer require mjaschen/collmex:~0.12
) - 为 PHP 5.6 兼容性:使用 0.11.x 分支(
composer require mjaschen/collmex:~0.11
) - 为 PHP 5.5 兼容性:使用 0.6.x 分支(
composer require mjaschen/collmex:~0.6
) - 为 PHP 5.4 兼容性:使用 0.4.x 分支(
composer require mjaschen/collmex:~0.4
) - 为 PHP 5.3 兼容性:使用 0.3.x 分支(
composer require mjaschen/collmex:~0.3
)
新功能将只添加到 master 分支。
使用/示例
从 Collmex API 请求信息
加载 Collmex Customer 记录
<?php 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; } else { $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());
创建新的 Collmex 客户记录
创建新的 Collmex Customer 记录并从响应数据中获取 Collmex 客户 ID
<?php 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', 'forename' => '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; } else { $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()); } }
注意
Collmex 预期所有字符串都使用代码页 1252(Windows)编码,而 Collmex PHP SDK 预期所有输入都为 UTF-8 编码,并将所有输出作为 UTF-8 编码。在发送请求到 Collmex API 和从 API 收到响应后,使用 forceutf8 库透明地转换字符串编码。
开发
运行代码检查
要运行检查和测试,最简单的方法是使用提供的 Composer 脚本
- 使用
composer ci:lint
检查 PHP 文件中的语法错误 - 使用 Psalm 运行静态分析并报告错误:
composer ci:psalm
- 使用 PHPUnit 运行单元测试:
composer ci:tests
- 使用 PHP_CodeSniffer 检查代码风格:
composer ci:sniff
要同时运行所有检查和测试,只需使用 composer ci
。
当然,可以直接使用测试运行器,例如用于PHPUnit
./vendor/bin/phpunit
Psalm
./vendor/bin/psalm
自动格式化代码
您可以使用Composer脚本来自动格式化代码
composer fix:php-cs