Skip to content

Stripe Rail

Overview

The Stripe rail supports three payment modes:

  1. Invoice payment — recipient is a Stripe invoice ID (in_xxx) → calls POST /v1/invoices/{id}/pay
  2. PaymentIntent confirmation — recipient is a PaymentIntent ID (pi_xxx) → calls POST /v1/payment_intents/{id}/confirm
  3. Payment link — recipient is a Stripe payment link (plink_xxx) → returns the link for human completion (semi-autonomous)

Best for: SaaS subscriptions, Cloudflare invoices, Anthropic billing, and any merchant accepting Stripe.

Setup

STRIPE_SECRET_KEY=sk_live_...
STRIPE_ENV=live # or 'test' for sandbox (default)

Usage

Pay a Stripe invoice by ID

The most common pattern for autonomous agent payments — the agent receives an invoice ID and pays it directly:

const result = await executeAgentPayment(signed, {
recipient: 'in_1Pxyz123abc', // Stripe invoice ID
amount: 47.20,
rail: 'stripe',
memo: 'Cloudflare April invoice',
})
console.log(result.success) // true
console.log(result.txId) // 'pi_1Pxyz123abc...' (PaymentIntent ID)
console.log(result.rail) // 'stripe'

The rail fetches the invoice to verify the amount against the envelope’s maxAmount before paying. If the invoice amount exceeds the envelope cap, the payment is rejected before any charge is made.

Confirm a PaymentIntent

When you’ve already created a PaymentIntent and need to confirm it:

const result = await executeAgentPayment(signed, {
recipient: 'pi_3Qxyz456def', // Stripe PaymentIntent ID
amount: 25.00,
rail: 'stripe',
})

Mock mode (development)

Set PQSAFE_MOCK_MODE=1 to run in mock mode — no real Stripe API calls, returns a simulated pi_sbx_... transaction ID. Safe for integration testing without a Stripe account.

Environment variables

VariableRequiredDescription
STRIPE_SECRET_KEYYesStripe secret key (sk_live_... or sk_test_...)
STRIPE_ENVNolive or test (default: test)
PQSAFE_MOCK_MODENoSet to 1 to skip real API calls

Error codes

CodeCauseFix
CARD_DECLINEDStripe card network declinedCheck card expiry, limit, 3DS
INVOICE_ALREADY_PAIDInvoice was already paidNo action needed
INSUFFICIENT_FUNDSNo funds on payment methodAdd funds or use a different payment method

ACP Adapter (Stripe) — Stripe Agent Commerce Protocol integration
Recipe: Pay Cloudflare Invoice — full end-to-end example
Rails concept page — cross-rail comparison