heureka/overenozakazniky
PHP client for Heureka “Ověřeno zákazníky” (ShopCertification). Set customer email, numeric order ID, and ordered product ITEM_IDs, then log orders via the API. Supports CZ and SK services; includes examples and docs.
composer require heureka/overeno-zakazniky
$certification = new \Heureka\ShopCertification('your_api_key_here');
For SK shops, specify the service:
$certification = new \Heureka\ShopCertification('your_api_key_here', [
'service' => \Heureka\ShopCertification::HEUREKA_SK
]);
// Set customer email (required)
$certification->setEmail('customer@example.com');
// Set order ID (optional but recommended)
$certification->setOrderId(12345);
// Add product ITEM_IDs (optional but recommended for tracking)
$certification->addProductItemId('PROD123');
$certification->addProductItemId('PROD456');
// Execute the request
$response = $certification->logOrder();
Key files to reference:
examples/ folder for ready-to-use examples.src/Heureka/ShopCertification.php for core logic.src/Heureka/Exceptions/ for error handling.Typical Laravel integration (e.g., in an OrderService or OrderObserver):
use Heureka\ShopCertification;
use Illuminate\Support\Facades\Log;
class OrderService {
protected $certification;
public function __construct() {
$this->certification = new ShopCertification(config('heureka.api_key'), [
'service' => config('heureka.service', ShopCertification::HEUREKA_CZ)
]);
}
public function logOrderToHeureka($order) {
$this->certification->setEmail($order->email);
$this->certification->setOrderId($order->id);
foreach ($order->products as $product) {
$this->certification->addProductItemId($product->heureka_item_id);
}
try {
$response = $this->certification->logOrder();
Log::info('Heureka certification logged', ['response' => $response]);
} catch (\Heureka\Exceptions\RequesterException $e) {
Log::error('Heureka certification failed', ['error' => $e->getMessage()]);
// Optionally: Retry or notify admin
}
}
}
Trigger logging after an order.placed event:
// In EventServiceProvider
protected $listen = [
'order.placed' => [
'App\Listeners\LogOrderToHeureka',
],
];
For bulk orders (e.g., via queue jobs):
class HeurekaBatchLogger {
public function logBatch($orderIds) {
$certification = new ShopCertification(config('heureka.api_key'));
foreach ($orderIds as $orderId) {
$order = Order::find($orderId);
$certification->setEmail($order->email);
$certification->setOrderId($orderId);
// Reset product IDs for each order
$certification->resetProductItemIds();
foreach ($order->products as $product) {
$certification->addProductItemId($product->heureka_item_id);
}
$certification->logOrder();
}
}
}
Store API keys and settings in .env:
HEUREKA_API_KEY=your_api_key_here
HEUREKA_SERVICE=cz # or 'sk'
Load via Laravel config:
// config/heureka.php
return [
'api_key' => env('HEUREKA_API_KEY'),
'service' => env('HEUREKA_SERVICE', \Heureka\ShopCertification::HEUREKA_CZ),
];
Mock the client in unit tests:
$mock = Mockery::mock('\Heureka\ShopCertification[logOrder]');
$mock->shouldReceive('logOrder')->once()->andReturn(['code' => 200]);
Wrong API Key for Region
401 Unauthorized with "Unknown API key".service parameter.
$certification = new ShopCertification('cz_key', ['service' => ShopCertification::HEUREKA_CZ]);
Invalid JSON Payload
400 Bad Request.$data = [
'apiKey' => $certification->getApiKey(),
'email' => $certification->getEmail(),
'orderId' => $certification->getOrderId(),
'productItemIds' => $certification->getProductItemIds(),
];
json_encode($data); // Test if valid
Missing Content-Type Header
415 Unsupported Media Type.VerifyCsrfToken) interferes.Duplicate Product IDs
DuplicateProductItemIdException.addProductItemId() only once per product or reset IDs between orders:
$certification->resetProductItemIds();
Order ID as String vs. Integer
$certification->setOrderId((string) $order->id);
Timeouts
$certification = new ShopCertification('key', [
'service' => ShopCertification::HEUREKA_CZ,
'timeout' => 10, // seconds
]);
Enable Guzzle Debugging
Add this to your ShopCertification constructor to log requests:
$client = new \GuzzleHttp\Client([
'debug' => fopen('heureka_debug.log', 'w'),
]);
Validate Heureka Item IDs
Ensure ITEM_ID matches your Heureka XML feed (case-sensitive, no spaces).
Check Email Format
Invalid emails (e.g., missing @) may cause silent failures. Validate with:
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new \InvalidArgumentException("Invalid email: $email");
}
Handle Exceptions Gracefully Catch specific exceptions:
try {
$certification->logOrder();
} catch (\Heureka\Exceptions\RequesterException $e) {
// Log or retry
} catch (\Heureka\Exceptions\DuplicateProductItemIdException $e) {
// Handle duplicates
}
Custom Request Handler Override the HTTP client for logging/retries:
$certification = new ShopCertification('key', [
'handler' => \GuzzleHttp\HandlerStack::create(),
]);
Add Metadata Extend the payload with custom fields (if Heureka supports them):
$certification->setAdditionalData(['custom_field' => 'value']);
Queue Failed Orders Use Laravel Queues to retry failed requests:
try {
$certification->logOrder();
} catch (\Exception $e) {
LogOrderToHeurekaJob::dispatch($order)->delay(now()->addMinute());
}
Local Testing Mock the API endpoint for development:
// In phpunit.xml
<env name="HEUREKA_API_URL" value="http://localhost:8000/mock-heureka"/>
composer require php:^7.3 if needed.\Heureka\ShopCertification::HEUREKA_CZ // Default
\Heureka\ShopCertification::HEUREKA_SK
How can I help you explore Laravel packages today?