Repository navigation
v0.5.0
What's new
-
X402\Server\BotDetector— curated User-Agent matcher for bot-only-payment endpoints. Wires straight intoPaymentEnforcer'sshouldEnforcepredicate:use X402\Server\BotDetector; $detector = new BotDetector(extra: ['MyCustomCrawler']); $middleware = new PaymentEnforcer( // ... shouldEnforce: static fn ($request): bool => $detector->isBot($request->getHeaderLine('User-Agent')), );
Ships ~70 default patterns (Agents / Assistants / Scrapers / Search crawlers / Undocumented) sourced from https://knownagents.com. Override the list with
patterns:, extend it withextra:, or passpatterns: []to disable detection. Match is case-insensitive substring on the User-Agent. -
X402\Testing\FakeFacilitator— canonical test double, functional superset of the existingStubFacilitator(configurable outcomes) andRecordingFacilitator(call capture). One instance covers both:$fake = new FakeFacilitator(); // Tweak outcomes mid-test $fake->rejectVerify('insufficient-funds'); $fake->failSettle('on-chain-revert'); // Run the system under test, then assert $fake->assertVerified(); // any verify call $fake->assertSettled('https://example.test/premium'); // settle for a specific resource $fake->assertNothingSettled(); // no-settle paths
Records full signature + challenge payload per call (not just counts) — accessible via
verifyCalls()/settleCalls()for custom assertions. Theassert*()helpers usePHPUnit\Framework\Assert; php-x402 already pulls phpunit transitively viapestphp/pestin dev, so this is available wherever you run a Pest or PHPUnit suite.
Full Changelog: 0.4.1...0.5.0