Skip to content

feat: E6 — Monetization ## Goal Creators can earn. Spooool can take a - #356

Closed
fly-productivity-manager[bot] wants to merge 1 commit into
mainfrom
fly-dev/run_2f23754eb4e742d2a9853682fb9943dc
Closed

feat: E6 — Monetization ## Goal Creators can earn. Spooool can take a #356
fly-productivity-manager[bot] wants to merge 1 commit into
mainfrom
fly-dev/run_2f23754eb4e742d2a9853682fb9943dc

Conversation

@fly-productivity-manager

Copy link
Copy Markdown
Contributor

Summary

Good. The fix looks correct. Here's a summary of the E6 monetization state:


E6 Monetization — Implementation Review

The full monetization stack was already implemented. I found and fixed one correctness bug.

What was already complete

All the "Done when" criteria were wired up end-to-end:

Area Implementation
Polar partner onboarding account.ts — OAuth connect/callback at /api/account/polar/connect and /api/account/polar/callback; stores polar_organization_id, polar_account_id, polar_account_status
Channel memberships monetize.tsPOST /api/channels/:username/membership creates Polar checkout; Channel.tsx renders tier cards
Per-video tipping monetize.tsPOST /api/videos/:id/tip creates checkout; Watch.tsx has the TipButton component with custom-amount UI and tip_success toast
Creator payouts dashboard payouts.ts (3 endpoints) + Payouts.tsx — summary cards, transaction table, payout history merged from D1 + live Polar balance
Spooool fee handling 10% platform fee computed and stored as platform_fee_cents in creator_earnings on every order.paid webhook
Webhooks → D1 ledger polar-webhook.ts — Standard Webhooks HMAC-SHA256 verification, idempotent write to polar_ledger, best-effort write to creator_earnings / creator_payouts
Creator product management AccountSettings.tsx — Polar onboarding status gating, product link/remove form, earnings & tax disclaimer
Migrations 0024 (polar_ledger), 0027 (creator_earnings/payouts), 0028 (polar_organization_id/status), 0033 (channel_products) — all present

Bug fixed (polar-webhook.ts)

creator_earnings.created_at, creator_payouts.created_at, and creator_payouts.paid_at are TEXT columns in the schema. The webhook was writing raw integer ms-epoch values, which SQLite coerces to the string "1724568000000". While V8 handles that in new Date(), it's not spec-guaranteed and breaks ORDER BY correctness if column type changes. Fixed to write ISO 8601 strings (new Date(nowMs).toISOString()).

Also added: polar_subscription_id is now extracted from the Polar order payload for membership renewal orders (the column existed in the schema but was never populated).

What you need to configure (secrets, not code)

wrangler secret put POLAR_ACCESS_TOKEN       # Platform-level API token
wrangler secret put POLAR_WEBHOOK_SECRET     # HMAC secret from Polar dashboard  
wrangler secret put POLAR_CLIENT_ID          # OAuth app client ID
wrangler secret put POLAR_CLIENT_SECRET      # OAuth app client secret

Tests

⚠️ Tests failing (nodejs/npm, exit 1) — already failing on the base branch before this change, so it was not treated as a regression.

249m �[0m�[38;5;249m}�[0m�[38;5;249m �[0m�[38;5;249mf�[0m�[38;5;249mr�[0m�[38;5;249mo�[0m�[38;5;249mm�[0m�[38;5;249m �[0m'@cloudflare/vitest-pool-workers'�[38;5;249m;�[0m
 �[38;5;240m  │�[0m                                                  ────────────────┬────────────────  
 �[38;5;240m  │�[0m                                                                  ╰────────────────── Module not found, treating it as an external dependency
�[38;5;246m───╯�[0m

failed to load config from /tmp/fly-run_2f23754eb4e742d2a9853682fb9943dc-1Xj3dk/spooool/vitest.workers.config.ts

�[31m⎯⎯⎯⎯⎯⎯⎯�[39m�[1m�[41m Startup Error �[49m�[22m�[31m⎯⎯⎯⎯⎯⎯⎯⎯�[39m
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@cloudflare/vitest-pool-workers' imported from /tmp/fly-run_2f23754eb4e742d2a9853682fb9943dc-1Xj3dk/spooool/node_modules/.vite-temp/vitest.workers.config.ts.timestamp-1787560564375-69c653a6bcfc8.mjs
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:314:9)
    at packageResolve (node:internal/modules/esm/resolve:768:81)
    at moduleResolve (node:internal/modules/esm/resolve:855:18)
    at defaultResolve (node:internal/modules/esm/resolve:985:11)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:747:20)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:724:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:320:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:182:49) {
  code: 'ERR_MODULE_NOT_FOUND'
}





Opened automatically by fly-dev run run_2f23754eb4e742d2a9853682fb9943dc.

## Goal

Creators can earn. Spooool can take a

[fly-dev run run_2f23754eb4e742d2a9853682fb9943dc]
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 24, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
spooool 1b007e2 Aug 24 2026, 08:38 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 24, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
editor 1b007e2 Aug 24 2026, 08:38 AM

@aloewright aloewright closed this Aug 24, 2026
@aloewright
aloewright deleted the fly-dev/run_2f23754eb4e742d2a9853682fb9943dc branch August 24, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant