# Social Dynamics AI Suite — Stripe + Razorpay

## Customer payment flow

1. Customer starts with the existing 14-day free trial; no card is required.
2. In Subscription & Billing, the customer chooses a paid plan.
3. The customer selects **Stripe** or **Razorpay**.
4. Stripe redirects to hosted Checkout. Razorpay opens Standard Checkout.
5. The backend verifies the payment/provider event and updates the same `subscriptions` table tied to that user.
6. Failed recurring payments create `past_due`, start the existing three-day grace period and trigger notifications.
7. If unresolved, the existing subscription worker suspends product access.
8. Successful payment restores active access.

## Stripe security

- Secret key stays server-side.
- Checkout Session is created server-side.
- Webhook signature is verified using `STRIPE_WEBHOOK_SECRET`.
- Stripe Customer Portal is available when a Stripe customer is linked.

## Razorpay security

- Key Secret stays server-side.
- Subscription is created server-side using a configured Razorpay Plan ID.
- Standard Checkout receives only `key_id` and `subscription_id` plus display/prefill data.
- Checkout success signature is verified server-side using the Razorpay subscription verification formula.
- Webhooks are verified against the raw request body using `X-Razorpay-Signature` and `RAZORPAY_WEBHOOK_SECRET`.
- Payment records are idempotently keyed by Razorpay payment ID in application logic.

## Production note

Use test-mode credentials first. Verify tax, invoices, refunds, settlement, international payment availability and recurring-payment rules directly in the applicable Stripe/Razorpay account before launch. Legal and payment-method availability depend on merchant account configuration and region.
