> ## Documentation Index
> Fetch the complete documentation index at: https://docs.result.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Payments

> Stripe and Razorpay checkout, subscriptions and webhooks.

One-time setup - connects your Stripe account and auto-configures webhooks:

```bash theme={"dark"}
npx @resultdev/cli payments connect stripe --env test --secret-key sk_test_...
npx @resultdev/cli payments status stripe
```

Use `--env test` with `sk_test_...` first; switch to `--env live` when ready.

## Checkout

Create products and prices in the Stripe Dashboard, then:

```ts theme={"dark"}
const { data, error } = await backend.payments.stripe.createCheckoutSession("test", {
  mode: "payment", // or "subscription"
  lineItems: [{ priceId: "price_123", quantity: 1 }],
  successUrl: `${window.location.origin}/checkout/success`,
  cancelUrl: `${window.location.origin}/pricing`,
  customerEmail: user?.email ?? null,
  idempotencyKey: `order:${orderId}`,
});
if (data?.checkoutSession.url) window.location.assign(data.checkoutSession.url);
```

## Customer portal

```ts theme={"dark"}
const portal = await backend.payments.stripe.createCustomerPortalSession("test", {
  subject: { type: "user", id: userId },
  returnUrl: `${window.location.origin}/billing`,
});
```

## Fulfillment

<Warning>
  Never fulfill from the success URL alone - anyone can open that URL. Verified
  webhook events land in the backend's `payments.webhook_events` table; drive
  fulfillment from those rows.
</Warning>

## Razorpay

Same shape under `backend.payments.razorpay` (`createOrder`,
`createSubscription`, `verifyOrder`, ...). Connect it with:

```bash theme={"dark"}
npx @resultdev/cli payments connect razorpay --env test --key-id rzp_test_... --secret-key ...
```
