x402 icon indicating copy to clipboard operation
x402 copied to clipboard

feat: initial php server support

Open lucasacoutinho opened this issue 1 month ago • 2 comments

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

lucasacoutinho avatar Nov 27 '25 11:11 lucasacoutinho

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

cb-heimdall avatar Nov 27 '25 11:11 cb-heimdall

@lucasacoutinho is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Nov 27 '25 11:11 vercel[bot]