freema/heureka-kosik-api
Composer 安装命令:
composer require freema/heureka-kosik-api
包简介
Modern PHP client for Heureka Košík API
关键字:
README 文档
README
Modern PHP 8.1+ client for Heureka Košík API with full type safety and strict standards.
Requirements
- PHP 8.1 or higher
- ext-curl
- ext-json
Installation
Install via Composer:
composer require freema/heureka-kosik-api
Framework Integration
Nette Framework
The library provides seamless integration with Nette Framework through a DI Extension.
Installation
Register the extension in your config.neon:
extensions: heurekaKosikApi: Freema\HeurekaAPI\Bridges\HeurekaKosikApiExtension heurekaKosikApi: key: %env.HEUREKA_API_KEY% # Recommended: use environment variable debug: false # Set to true for test API endpoint autowired: true # Enable autowiring (default: true)
Usage in Nette
The API service is automatically registered in the DI container and can be autowired:
<?php declare(strict_types=1); namespace App\Presenters; use Freema\HeurekaAPI\Api; use Nette\Application\UI\Presenter; class OrderPresenter extends Presenter { public function __construct( private Api $heurekaApi, ) { } public function actionUpdateStatus(int $orderId): void { $response = $this->heurekaApi->putOrderStatus() ->setOrderId($orderId) ->setStatus(1) ->execute(); } }
Symfony Framework
The library includes a Symfony Bundle for easy integration with Symfony applications.
Installation
- Register the bundle in
config/bundles.php:
<?php return [ // ... other bundles Freema\HeurekaAPI\Bundle\HeurekaKosikApiBundle::class => ['all' => true], ];
- Create configuration file
config/packages/heureka_kosik_api.yaml:
heureka_kosik_api: api_key: '%env(HEUREKA_API_KEY)%' # Use environment variable debug: false # Set to true for test API endpoint
- Set your API key in
.envor.env.local:
HEUREKA_API_KEY=your_api_key_here
Usage in Symfony
The API service is automatically registered and can be autowired or accessed via the service container:
<?php declare(strict_types=1); namespace App\Controller; use Freema\HeurekaAPI\Api; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class OrderController extends AbstractController { public function __construct( private Api $heurekaApi, ) { } #[Route('/order/{id}/update-status', name: 'order_update_status')] public function updateStatus(int $id): Response { $response = $this->heurekaApi->putOrderStatus() ->setOrderId($id) ->setStatus(1) ->setTracnkingUrl('https://tracking.example.com/'. $id) ->execute(); // Handle response... return new Response('Status updated'); } }
You can also access the service directly from the container:
$api = $this->container->get('heureka_kosik_api'); // or $api = $this->container->get(\Freema\HeurekaAPI\Api::class);
Standalone Usage
The library can be used without any framework:
Quick Start
Initialization
<?php declare(strict_types=1); use Freema\HeurekaAPI\Api; $api = new Api('YOUR_API_KEY'); // For testing/debug mode: $api = new Api('YOUR_API_KEY', debug: true);
API Methods
GET payment/status
Get payment status for an order.
$response = $api->getPaymentStatus() ->setOrderId(22) ->execute(); $result = $response->toArray(); if ($api->getContainer()->hasError()) { $error = $api->getContainer()->getErrorMessage(); }
PUT order/status
Update order status on Heureka. It's important that every order change is transferred back to Heureka so customers can see the current status of their orders.
$response = $api->putOrderStatus() ->setOrderId(22) ->setStatus(1) ->setTracnkingUrl('https://www.example.com/?id=101010&transport') ->setNote('Objednávka je připravena k odeslání') ->setExpectDeliver('2025-01-15') ->execute();
PUT payment/status
Update payment status on Heureka. This method is used for cash on delivery or cash payment at a store branch.
use DateTime; $response = $api->putPaymentStatus() ->setOrderId(22) ->setStatus(1) ->setDate('2025-01-15') // Accepts string or DateTime object ->execute(); // Or with DateTime: $response = $api->putPaymentStatus() ->setOrderId(22) ->setStatus(1) ->setDate(new DateTime('2025-01-15')) ->execute();
GET order/status
Get information about order status and internal order number on Heureka.
$response = $api->getOrderStatus() ->setOrderId(22) ->execute();
GET stores
Get information about branches/pickup locations that the shop has stored on Heureka.
$response = $api->getStores()->execute();
GET shop/status
Get information about shop activation in Košík. Used to determine whether the shop is running in Košík or not. If Košík is disabled due to an API error or process error, it's described in the message parameter.
Note: Activation/deactivation information is cached for 30 minutes. If testing shop status via cron, use an interval of 30 minutes or more.
$response = $api->getShopStatus()->execute();
POST order/note
Send a note that the shop created during the order processing. These notes are displayed to the customer with their order in their profile.
$response = $api->postOrderNote() ->setOrderId(22) ->setNote('Zásilka bude doručena zítra dopoledne') ->execute();
POST order/invoice
Send an invoice (receipt) for an order. Shops that send invoices to customers electronically must also send them to Heureka so they can be resent or made available for download in the order overview.
- Maximum file size: 3 MB
- Format: PDF only
$response = $api->postOrderInvoice() ->setOrderId(22) ->setInvoiceFile('/path/to/invoice.pdf') ->execute();
Development
Code Quality Tools
# Run PHPStan (level 8 with strict rules) composer phpstan # Run PHP CS Fixer (check) composer cs-check # Run PHP CS Fixer (fix) composer cs-fix # Run tests composer test
Migration from v1.x
Breaking Changes
- PHP Version: Now requires PHP 8.1+
- Namespace Changes: Request classes moved to
Freema\HeurekaAPI\Request\namespace - Type Safety: All methods now have strict type hints and return types
- Removed: Manual loader.php (use Composer autoload)
Updated Code
Before (v1.x):
$container = new \Freema\HeurekaAPI\Api($apiKey); $response = $container->getOrderStatus()->setOrderId('22')->execute();
After (v2.x):
$api = new \Freema\HeurekaAPI\Api($apiKey); $response = $api->getOrderStatus()->setOrderId(22)->execute();
License
This library is licensed under BSD-3-Clause, GPL-2.0-or-later, and GPL-3.0-or-later.
freema/heureka-kosik-api 适用场景与选型建议
freema/heureka-kosik-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.14k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「e-commerce」 「heureka.cz」 「kosik」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 freema/heureka-kosik-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 freema/heureka-kosik-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 freema/heureka-kosik-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Knihovna pro snadný import recenzí e-shopu a produktů z Heuréka.cz
Implementation of the Omnibus Directive for Sylius application.
Livewire starter kit for Lunar e-commerce.
Admin Hub for GetCandy. A modern headless e-commerce solution for Laravel PHP framework.
A PSR-7 compatible library for making CRUD API endpoints
Automatically translate and review your content via Lokalise.
统计信息
- 总下载量: 2.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-01-25