# Stripe Payments Integration

## Overview
Integrate Stripe payment processing to support one-time payments and subscriptions for {{plan_name}} in {{currency}} currency.

## Acceptance Criteria

### AC-1: Checkout Session Creation
- Create a Stripe checkout session for {{plan_name}} with currency {{currency}}
- Return a redirect URL to the hosted Stripe payment page
- Store the session ID for reconciliation

### AC-2: Webhook Processing
- Handle incoming Stripe events at {{webhook_endpoint}}
- Verify HMAC signature using `Stripe-Signature` header
- Process `checkout.session.completed` and `invoice.payment_failed` events
- Idempotently handle duplicate webhook deliveries

### AC-3: Subscription Management
- Retrieve subscription status from Stripe API
- Cancel subscriptions on user request
- Expose subscription status in user profile response

### AC-4: Error Handling
- Return user-friendly errors when payment fails
- Log Stripe API errors with request IDs for debugging
- Handle network timeouts with retry logic (max 3 attempts)

## Technical Notes
- Store Stripe customer IDs and subscription IDs in the database, never card data
- All prices defined in cents to avoid floating-point errors
- Use Stripe's idempotency keys for all write operations
