Recipe: asynchronous verification

  1. Laravel (queued job + event)
  2. Symfony (Messenger)
  3. Caching note

Verification calls external APIs, so run it off the request cycle for anything user-facing.

Laravel (queued job + event)

use Gawrys\Counterparty\Laravel\Jobs\VerifyCounterparty;
use Gawrys\Counterparty\Counterparty;

VerifyCounterparty::dispatch(new Counterparty('Acme', 'PL', nip: '1234567890'));

The job runs the verification and dispatches CounterpartyFlagged when the outcome is adverse or needs review. Listen for it:

use Gawrys\Counterparty\Laravel\Events\CounterpartyFlagged;

Event::listen(function (CounterpartyFlagged $event) {
    $outcome = $event->outcome;
    // notify compliance, persist a case, block onboarding, ...
});

Symfony (Messenger)

use Gawrys\Counterparty\Symfony\Messenger\VerifyCounterpartyMessage;
use Gawrys\Counterparty\Counterparty;

$bus->dispatch(new VerifyCounterpartyMessage(new Counterparty('Acme', 'PL', nip: '1234567890')));

Route it to an async transport:

# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async: '%env(MESSENGER_TRANSPORT_DSN)%'
        routing:
            'Gawrys\Counterparty\Symfony\Messenger\VerifyCounterpartyMessage': async

VerifyCounterpartyHandler returns the VerificationOutcome; capture it from the handled stamp, or have the handler dispatch your own domain event/notification.

Caching note

When using the AI strategy, results are PSR-16 cached by counterparty + report + prompt version, so re-running a job for an unchanged counterparty does not re-bill the LLM.


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

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