This document outlines the setup and deployment process for the ForgeScan monetization flow using Stripe Checkout.
The monetization flow allows users to purchase a detailed PDF fix guide for £9.99 when their domain scan reveals security issues. The flow includes:
Create a .env.local file (for local development) and set the following Cloudflare secrets:
# Stripe Configuration
STRIPE_SECRET_KEY=sk_live_xxx
STRIPE_PRICE_ID=price_xxx
STRIPE_WEBHOOK_SECRET=whsec_xxx
# Site Configuration
PUBLIC_BASE_URL=https://www.domainforge.co.uk
PRICE_GBP=9.99
# Email Configuration
EMAIL_PROVIDER=resend
RESEND_API_KEY=re_xxx
POSTMARK_TOKEN=xxx
# Storage Configuration
DOWNLOAD_TOKEN_TTL_SECONDS=86400
# Brand Colors
BRAND_PRIMARY_HEX=#FF7A00
BRAND_BG_DARK_HEX=#0B1220
Create two KV namespaces:
# Scan data storage
wrangler kv:namespace create "SCAN_DATA"
wrangler kv:namespace create "SCAN_DATA" --preview
# Download tokens storage
wrangler kv:namespace create "DOWNLOAD_TOKENS"
wrangler kv:namespace create "DOWNLOAD_TOKENS" --preview
Create an R2 bucket for PDF storage:
wrangler r2 bucket create domainforge-pdfs
Replace the placeholder IDs in wrangler.toml with your actual KV and R2 IDs.
price_)https://your-domain.com/api/stripe-webhookcheckout.session.completedwhsec_)EMAIL_PROVIDER=resend and RESEND_API_KEY=re_xxxEMAIL_PROVIDER=postmark and POSTMARK_TOKEN=xxxnpm install
Copy env.example to .env.local and fill in your test values.
npm start
# Install Stripe CLI
brew install stripe/stripe-cli/stripe
# Forward webhooks to local server
stripe listen --forward-to localhost:8788/api/stripe-webhook
# Copy the webhook secret from CLI output and add to .dev.vars
STRIPE_WEBHOOK_SECRET=whsec_xxx_from_cli_output
https://www.domainforge.co.uk/api/stripe-webhookcheckout.session.completedwhsec_)wrangler pages secret put STRIPE_WEBHOOK_SECRET --project-name=domain-forge-site
# Test if webhook secret is configured (DELETE BEFORE PRODUCTION)
curl http://localhost:8788/api/webhook-test
Use these Stripe test cards:
4242 4242 4242 42424000 0000 0000 00024000 0025 0000 3155npm run build
wrangler pages deploy dist
wrangler secret put STRIPE_SECRET_KEY
wrangler secret put STRIPE_PRICE_ID
wrangler secret put STRIPE_WEBHOOK_SECRET
wrangler secret put RESEND_API_KEY
wrangler secret put PUBLIC_BASE_URL
wrangler secret put EMAIL_PROVIDER
wrangler secret put PRICE_GBP
wrangler secret put DOWNLOAD_TOKEN_TTL_SECONDS
Update your Stripe webhook endpoint to point to your production domain.
Creates a Stripe checkout session.
Request:
{
"email": "[email protected]",
"scanKey": "scan_1234567890_abc123"
}
Response:
{
"url": "https://checkout.stripe.com/pay/cs_test_..."
}
Handles Stripe webhook events (internal use only).
Features:
stripe.webhooks.constructEvent()checkout.session.completed eventsscanKey and email from session metadataSecurity:
stripe-signature headerReturns session status for the thanks page.
Response:
{
"status": "completed",
"downloadUrl": "https://domain.com/api/download/token123"
}
Serves the PDF file with proper headers.
Monitor API usage and errors in Cloudflare Analytics.
Track payments, webhook deliveries, and customer data in Stripe Dashboard.
Monitor email delivery rates and bounces.
Webhook Not Receiving Events
PDF Not Generating
Email Not Sending
Download Link Expired
Enable debug logging by setting DEBUG=true in environment variables.
For issues or questions: