Packages
@prood/checkout-host
Next.js checkout session host with Upstash Redis persistence and webhook forwarding.
@prood/checkout-host wraps @prood/checkout with session persistence in Upstash Redis, provider factory integration, and webhook forwarding to the Commerce API.
Used by apps/checkout.
Installation
pnpm add @prood/checkout-hostRequires UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.
Create a session
import { createCheckoutSession } from '@prood/checkout-host'
const session = await createCheckoutSession({
orderId: 'ord_123',
amount: 9999,
currency: 'EUR',
tenantId: 'org_demo',
returnUrl: 'https://store.example.com/order-confirmation',
customerInfo: { email: '...', firstName: '...', lastName: '...' },
fulfillment: 'shipping',
provider: 'stripe',
})
// session.id → 'cs_abc123'
// checkoutUrl → 'http://localhost:3004/c/cs_abc123'Internally:
- Builds
PaymentProviderfrom tenant integration config - Creates
CheckoutSessionstate machine - Saves snapshot to Redis with TTL
- Returns session ID and payment URL
Load and hydrate
import { loadSession, loadAndHydrate } from '@prood/checkout-host'
// Read snapshot
const snapshot = await loadSession('cs_abc123')
// Rehydrate with live provider
const session = await loadAndHydrate('cs_abc123', async (providerId) =>
getPaymentProvider(providerId, tenantId)
)Save session
import { saveSession } from '@prood/checkout-host'
await saveSession(session.id, session.toSnapshot())Called after every state transition to persist updated state.
Payment links
import { createPaymentLink } from '@prood/checkout-host'
const link = await createPaymentLink({
amount: 4500,
currency: 'EUR',
tenantId: 'org_demo',
description: 'Invoice #1234',
expiresIn: 86400000, // 24 hours
})
// link.url → 'http://localhost:3004/c/cs_link_abc'Webhook forwarding
import { forwardPaymentWebhook } from '@prood/checkout-host'
await forwardPaymentWebhook({
provider: 'stripe',
orgId: 'org_demo',
payload: rawBody,
signature: req.headers.get('stripe-signature'),
})Forwards to {COMMERCE_API_URL}/webhooks/payments/{provider}?org={orgId} with x-checkout-secret.
Redis key schema
| Key | TTL | Value |
|---|---|---|
checkout:session:{id} | Session expiresIn or 30 min | CheckoutSnapshot JSON |
Exports
export {
CHECKOUT_SESSION_PATH,
buildCheckoutSessionUrl,
resolveCheckoutBaseUrl,
createCheckoutSession,
createPaymentLink,
loadSession,
loadAndHydrate,
saveSession,
forwardPaymentWebhook,
} from '@prood/checkout-host'