Recipe: asynchronous verification
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.