PHP code example of davix / customs-domain

1. Go to this page and download the library: Download davix/customs-domain 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/ */

    

davix / customs-domain example snippets


use Davix\Customs\Validation\CodeNormaliser;

$normaliser = new CodeNormaliser();

$result = $normaliser->normalise('6201.40.10.19');

$result->isSuccess();                            // true
$result->code();                                 // '6201401019'
$result->wasModified();                          // true
$normaliser->formatForDisplay($result->code());  // '6201.40.10.19'

$result = $normaliser->normalise('6.20140102E+09');

$result->isFailure(); // true

use Davix\Customs\Tariff\CommodityResolver;
use Davix\Customs\Tariff\MeasuredProperty;

$resolver = new CommodityResolver($repository);

$resolution = $resolver->resolve('620140', [
    MeasuredProperty::NET_WEIGHT => 1.5,
]);

$resolution->outcome;
$resolution->commodity;
$resolution->candidates;
$resolution->narrowedByMeasurement;
$resolution->candidatesBeforeNarrowing;

use Davix\Customs\Provider\Hmrc\HmrcClientOptions;
use Davix\Customs\Tariff\Jurisdiction;

$options = HmrcClientOptions::for(
    Jurisdiction::NorthernIreland
);

if ($repository->jurisdiction() !== $provider->jurisdiction()) {
    throw new RuntimeException(
        'Tariff repository and provider use different jurisdictions.'
    );
}

use Davix\Customs\Rule\DefaultRuleSet;
use Davix\Customs\Rule\EvaluationContext;

$pool = DefaultRuleSet::pool();

// Includes rules that need tariff measures/provider data:
// $pool = DefaultRuleSet::fullPool();

$evaluation = $pool->evaluate(
    $productData,
    new EvaluationContext(
        evaluatedAt: new DateTimeImmutable(),
        settings: $settings,
        resolution: $resolution,
        historic: $historicRecord,
        detail: $commodityDetail,
        certificates: $certificateIndex,
        quotas: $quotaSet,
    ),
);

$evaluation->issueCodes();
$evaluation->highestSeverity();
$evaluation->hasBlocking();

public function prerequisites(): array
{
    return [
        InvalidCodeFormat::CODE,
    ];
}

use Davix\Customs\Scan\ProductScanner;
use Davix\Customs\Scan\ScanOptions;

$scanner = new ProductScanner(
    rules: DefaultRuleSet::fullPool(),
    resolver: $resolver,
    provider: $provider,
    settings: $settings,
    options: new ScanOptions(),
);

foreach ($scanner->scan($products) as $result) {
    // Persist, display or otherwise process the result.
}

$summary = $scanner->summary();

$options = new ScanOptions(
    fetchMeasures: true,
    fetchQuotas: true,
    resolveWithdrawnCodes: true,
);

$options = ScanOptions::offline();

use Davix\Customs\Provider\Hmrc\HmrcClient;
use Davix\Customs\Provider\Hmrc\HmrcClientOptions;

$provider = new HmrcClient(
    httpClient: $httpClient,
    requestFactory: $requestFactory,
    options: new HmrcClientOptions(),
    cache: $cache,
    logger: $logger,
);

$issue->messageKey();
$issue->context;