Download the PHP package koh/sylius-x402 without Composer
On this page you can find all versions of the php package koh/sylius-x402. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download koh/sylius-x402
More information about koh/sylius-x402
Files in koh/sylius-x402
Package sylius-x402
Short Description x402 payment middleware for Sylius API routes: HTTP 402 with payment requirements agents can fulfil.
License MIT
Homepage https://ole-hartwig.eu/open-source/sylius-x402
Informations about the package sylius-x402
koh/sylius-x402
x402 payment middleware for Sylius: selected API paths
answer 402 Payment Required with a machine-readable price that an agent can
pay and retry.
It is off by default. Installing the bundle must not start charging for anything, and even when switched on it ships no settlement: the bundled verifier advertises prices and refuses every payment until you plug in a real one. That makes a shop protocol-correct and discoverable long before anyone decides to accept stablecoins.
Install
koh/sylius-agent-contracts comes with it. There is no route to import — the
bundle works as request and response listeners.
Configure
enabled: truewithoutpay_tofails the container build. A price with no address to pay would deny access and collect nothing.- On an
eip155:network,enabled: truealso needsasset,asset_nameandasset_version. Theexactscheme signs an EIP-3009 authorisation against the token's EIP-712 domain, so a 402 withoutextra.nameandextra.versionasks for a payment no client can sign. networkmust be a CAIP-2 chain id and everyamountdigits only; anything else fails the container build.methodsis empty by default, which gates every method. GatingGETbut leavingHEADfree would reveal that a resource exists, and its size, without payment.- Gate API paths only — never the storefront or the checkout.
Settling payments
Alias PaymentVerifierInterface to your own implementation:
verify() checks the PAYMENT-SIGNATURE header (a base64-encoded x402 v2
PaymentPayload) against the requirement and throws
PaymentRequiredException when it is missing or invalid. settle() runs only
after the controller produced a 2xx response — a request that ends in an
error has delivered nothing and is not charged. A settlement failure at that
point is logged and does not change the response; the caller already has what
they paid for. A string returned from settle() — the base64-encoded
SettlementResponse — is sent as PAYMENT-RESPONSE.
Letting authenticated agents through
Implement PaymentBypassVoterInterface from koh/sylius-agent-contracts to
exempt callers, for example agents holding an MCP access token. The listener
runs at priority 5, after the Symfony firewall (8), so the security token
exists when voters are asked. Base the decision on that token, never on a
request header the caller controls.
Output
The bundle speaks x402 protocol version 2 over HTTP
(specs/x402-specification-v2.md,
specs/transports-v2/http.md).
A gated request without a valid payment gets the PaymentRequired object
base64-encoded in the PAYMENT-REQUIRED header, and the same object as the
JSON body:
A 402 is never cached: the requirement is per request, and a cached challenge would keep answering after payment.
The same price table feeds PayableOperationProviderInterface, under the rail
x402. That is not an MPP payment method, so koh/sylius-mpp does not declare
these operations as MPP x-payment-info offers; the 402 above is where an
x402 client learns the price. While enabled is false nothing is published at
all.
Decommission
Set enabled: false first if agents may be mid-payment, and settle anything
outstanding in your verifier. Then remove the composer require, the
config/bundles.php entry, config/packages/koh_x402.yaml and any verifier
alias. The bundle owns no database table and no cache pool.
Security
Report vulnerabilities privately — see SECURITY.md. Advisories are published as CSAF 2.0 at https://ole-hartwig.eu/.well-known/csaf/.
The family threat model, covering this package, is at https://github.com/ohartwig/sylius-agent-ready/blob/main/docs/threat-model.md.
Licence
MIT — see LICENSE.
All versions of sylius-x402 with dependencies
php Version ^8.3
psr/log Version ^2.0 || ^3.0
sylius/sylius Version ^2.2.9 || ^2.3.0
symfony/config Version ^7.4 || ^8.0
symfony/dependency-injection Version ^7.4 || ^8.0
symfony/event-dispatcher Version ^7.4 || ^8.0
symfony/http-foundation Version ^7.4 || ^8.0
symfony/http-kernel Version ^7.4 || ^8.0
symfony/routing Version ^7.4 || ^8.0