x402 paymentsPrivate preview
Use x402 for machine-to-machine payments.
x402 is a protocol for internet payments. When a client requests a paid resource, your server returns an HTTP 402 response with payment details. The client pays, then retries the request with an authorisation. Stripe handles deposit addresses and automatically captures the PaymentIntent when funds settle on-chain.
Before you begin
- A Stripe account
- Crypto payins enabled on your account
Payment lifecycle
In this guide, you build the server. Your server indicates that payment is required and returns the content after successful payment. You interact with Stripe and a facilitator to complete the payment.
Create your endpoint
Add payment middleware to your endpoint to require payment.
This example requires 0.01 USD, paid in USDC, per request to /paid.
Create a PaymentIntent
To process payments, create a PaymentIntent that accepts the crypto payment method. Use the payTo method from earlier.
This function returns a crypto deposit address that the client receives and uses for payment.
Test your endpoint
Make a request to your server without an eligible client to confirm it returns a 402 status code.
curl http://localhost:3000/paid
You see a 402 status code.
Next, make a request with an eligible client. Use Stripe’s purl to test in the command line.
If you connected a wallet, the server returns the content and you can confirm payment. In the Stripe Dashboard, go to Payments to see the transaction.