PHP code example of infomedia / uskladjenost-cijena-php

1. Go to this page and download the library: Download infomedia/uskladjenost-cijena-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

infomedia / uskladjenost-cijena-php example snippets


use UskladjenostCijena\Client;

$api = new Client(getenv('PC_TOKEN'));

// 1. Artikl po vašoj šifri (catalog:write). Odgovor nosi offer_id.
$item = $api->items()->upsert('SKU-1', [
    'merchant_id' => $merchantId,
    'kind' => 'product',          // product | service | price_component
    'name' => 'Deterdžent 3 kg',
    'barcode' => '3859000000001',
    'fmcg_category' => 'cleaning', // sidro na 2. 5. 2025.
]);

// 2. Cijena po vašoj šifri, bez offer_id-a (prices:write). Iznosi u centima.
$api->prices()->recordByExternal('SKU-1', [
    'regular_price_minor' => 1250,
    'effective_price_minor' => 990,   // akcijska; nikad iznad redovne
], ['location_code' => 'PU-01'], idempotencyKey: 'order-42-line-1');

// 3. Što ispisati uz cijenu (compliance:read).
$decision = $api->compliance()->byExternal('SKU-1', ['location_code' => 'PU-01']);
echo $decision['data']['anchor_display']['label']; // "Cijena na dan 10. 9. 2026.: 12,50 €" ili null

use UskladjenostCijena\Webhooks\Signature;

$event = Signature::event($secret, getallheaders(), file_get_contents('php://input')); // baca InvalidArgumentException ako potpis ne drži
if ($event['event'] === 'publication.failed') { /* ... */ }
bash
composer