x402
x402 copied to clipboard
feat: initial php server support
Description
This PR adds initial PHP server support for the x402 protocol.
Tests
Core Library (php/x402)
cd php/x402 && composer test
24 tests passing covering:
- AmountTest - Currency conversions (decimal ↔ USDC base units)
- NetworkTest - Chain IDs, testnet detection, USDC addresses, custom network registration
- PaymentPayloadTest - Base64 encoding/decoding, validation, error handling
- PaymentRequirementsTest - Requirements creation and serialization
Laravel Package (php/x402-laravel)
cd php/x402-laravel && composer test
52 tests covering:
Unit tests:
- Exception classes and error messages
- PendingPayment fluent builder API
Feature tests:
- DiscoveryTest - Resource registration, pagination, metadata filtering, auto-discovery of paid routes, JSON endpoint responses
- EventsTest - PaymentVerified, PaymentSettled, PaymentFailed event dispatching
- MacrosTest - Route::paid() macro, $request->payer(), $request->requirements() macros
- RequirePaymentMiddlewareTest - 402 responses, header validation, payment verification, settlement flow
- RequirePaymentTest - Full middleware integration with mock facilitator
Manual Testing
Verified the Laravel example app runs successfully: cd examples/php/servers/laravel && docker compose up
Tested endpoints:
- GET /free - Returns 200 (no payment required)
- GET /weather - Returns 402 with payment requirements
- GET /discovery/resources - Returns discovery JSON
Checklist
- [x] I have formatted and linted my code
- [x] All new and existing tests pass
- [x] My commits are signed (required for merge) -- you may need to rebase if you initially pushed unsigned commits
🟡 Heimdall Review Status
| Requirement | Status | More Info | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Reviews |
🟡
0/1
|
Denominator calculation
|
@lucasacoutinho is attempting to deploy a commit to the Coinbase Team on Vercel.
A member of the Team first needs to authorize it.