Skip to content
Create account or Sign in
The Stripe Docs logo
/
Ask AI
Create accountSign in
Get started
Payments
Revenue
Platforms and marketplaces
Money management
Developer resources
APIs & SDKsHelp
OverviewAccept a paymentUpgrade your integration
Online payments
OverviewFind your use case
Use Payment Links
Use a prebuilt checkout page
Build a custom integration with Elements
Build an in-app integration
Use Managed Payments
Recurring payments
In-person payments
Terminal
Payment methods
Add payment methods
Manage payment methods
Faster checkout with Link
Payment operations
Analytics
Balances and settlement time
Compliance and security
Currencies
Declines
Disputes
Fraud prevention
Radar fraud protection
Payouts
ReceiptsRefunds and cancellations
Advanced integrations
Custom payment flows
Flexible acquiring
Off-Session Payments
Multiprocessor orchestration
Beyond payments
Incorporate your company
Crypto
Agentic commerce
Machine payments
    Overview
    Quickstart
    x402
Financial Connections
Climate
Verify identities
United States
English (United States)
HomePaymentsMachine payments

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 authorization. Stripe handles deposit addresses and automatically captures the PaymentIntent when funds settle on-chain.

GitHub

You can find the app’s complete source code on GitHub.

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.

Node.js
Python
No results
import { paymentMiddleware } from "@x402/hono"; import { x402ResourceServer, HTTPFacilitatorClient } from "@x402/core/server"; import { ExactEvmScheme } from "@x402/evm/exact/server"; app.use( paymentMiddleware( { "GET /paid": { accepts: [ { scheme: "exact", price: "$0.01", network: "eip155:84532", payTo: createPayToAddress, } ], description: "Data retrieval endpoint", mimeType: "application/json", } }, new x402ResourceServer(facilitatorClient).register( "eip155:84532", new ExactEvmScheme() ) ) )

Create a PaymentIntent

To process payments, create a PaymentIntent that accepts the crypto payment method. Use the payTo method from earlier.

Node.js
Python
No results
async function createPayToAddress(context) { // If a payment header exists, extract the destination address from it if (context.paymentHeader) { const decoded = JSON.parse( Buffer.from(context.paymentHeader, "base64").toString() ); const toAddress = decoded.payload?.authorization?.to; if (toAddress && typeof toAddress === "string") { return toAddress; } } // Create a new PaymentIntent to get a fresh crypto deposit address const decimals = 6; // USDC has 6 decimals const amountInCents = Number(10000) / Math.pow(10, decimals - 2); const paymentIntent = await stripe.paymentIntents.create({ amount: amountInCents, currency: "usd", payment_method_types: ["crypto"], payment_method_data: { type: "crypto", }, payment_method_options: { crypto: { mode: "custom", }, }, confirm: true, }); const depositDetails = paymentIntent.next_action.crypto_collect_deposit_details; const payToAddress = depositDetails.deposit_addresses["base"].address; return payToAddress; }

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.

Command Line
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.

Command Line
purl http://localhost:3000/paid

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.

Was this page helpful?
YesNo
  • Need help? Contact Support.
  • Check out our changelog.
  • Questions? Contact Sales.
  • LLM? Read llms.txt.
  • Powered by Markdoc