Laravel bridge

  1. Installation
  2. Verify
  3. Validation rules
  4. Adding a registry
  5. Async
  6. Configuration
  7. Enabling AI

counterparty-laravel wires the toolkit into Laravel: an auto-discovered service provider, a facade, validation rules, a queued job and an event.

Installation

composer require gawrys/counterparty-laravel
php artisan vendor:publish --tag=counterparty-config

Zero-config HTTP. You do not call the factory or ::discover() yourself - the service provider does the wiring. It auto-discovers an installed PSR-18 client + PSR-17 factories, and on a stock Laravel app that is the bundled Guzzle (Guzzle 7 is a PSR-18 client and guzzlehttp/psr7 provides the factories), so there is nothing to install or bind.

To use a different client, bind it in your app and your binding wins:

// AppServiceProvider::register() - optional, only to override the default
$this->app->bind(\Psr\Http\Client\ClientInterface::class, fn () => new \Symfony\Component\HttpClient\Psr18Client());

Verify

use Gawrys\Counterparty\Laravel\Facades\Counterparty;
use Gawrys\Counterparty\Counterparty as Subject;

$outcome = Counterparty::verify(new Subject('Acme', 'PL', nip: '1234567890'));

Validation rules

$request->validate([
    'nip'  => ['required', new \Gawrys\Counterparty\Laravel\Rules\ActiveVatPayer()],
    'name' => ['required', new \Gawrys\Counterparty\Laravel\Rules\NotSanctioned()],
]);

Adding a registry

Counterparty::extendRegistry('de', fn ($cfg) => new GermanRegistryDriver($http));

Async

\Gawrys\Counterparty\Laravel\Jobs\VerifyCounterparty::dispatch($counterparty);

The queued job dispatches Events\CounterpartyFlagged when the outcome is adverse or needs review - listen for it to alert a compliance queue, etc.

Configuration

config/counterparty.php:

return [
    'strategy' => env('COUNTERPARTY_STRATEGY', 'rule_based'), // or 'ai'
    'review_threshold' => 0.5,
    'sanctions' => [
        'provider' => env('COUNTERPARTY_SANCTIONS', 'sanctions_network'),
        'threshold' => 0.7,
        'opensanctions' => [
            'api_key'  => env('OPENSANCTIONS_API_KEY'),
            'base_uri' => env('OPENSANCTIONS_BASE_URI', 'https://api.opensanctions.org'),
        ],
    ],
    'registries' => [
        'krs'   => ['enabled' => true],
        'ceidg' => ['enabled' => false, 'token' => env('CEIDG_TOKEN')],
        'regon' => ['enabled' => false, 'token' => env('REGON_TOKEN')],
        'crbr'  => ['enabled' => true],
    ],
    'ai' => ['review_threshold' => 0.6, 'cache_ttl' => 86400],
];

Enabling AI

Set COUNTERPARTY_STRATEGY=ai, install gawrys/counterparty-ai, and bind an AiResearchProvider (plus a PSR-16 CacheInterface):

$this->app->bind(\Gawrys\Counterparty\Ai\Research\AiResearchProvider::class, fn ($app) =>
    new \Gawrys\Counterparty\Ai\Research\AnthropicResearchProvider(
        $app->make(\Gawrys\Counterparty\Http\JsonHttpClient::class),
        config('services.anthropic.key'),
    ));
$this->app->bind(\Psr\SimpleCache\CacheInterface::class, fn ($app) => $app->make('cache.store'));

Wiring is conditional on the package being present, so there is no separate -ai-laravel package.


Counterparty Verification - a due-diligence aid, not a compliance product. MIT licensed.

This site uses Just the Docs, a documentation theme for Jekyll.