Stripe Integration
Stripe powers all monetary transactions in Honeycomb. The integration spans three areas: platform subscriptions (users paying Mindhyv), Stripe Connect (creators receiving payouts), and webhook processing (keeping the database in sync with Stripe events).
SDK Setup
Section titled “SDK Setup”The Stripe client is initialised as a lazy singleton in src/lib/server/stripe.ts:
import Stripe from "stripe";import { STRIPE_SECRET_KEY } from "$env/static/private";
export const stripe = new Stripe(STRIPE_SECRET_KEY);The same module exports the platform fee constant and plan definitions:
export const PLATFORM_FEE_PERCENT = 5;
export const PLANS = { starter: { name: "Starter", priceMonthly: 9, features: ["Business profile", "1 extension", "Basic analytics", "Standard support"], }, pro: { name: "Pro", priceMonthly: 29, features: [ "Business profile", "Unlimited extensions", "Advanced analytics", "Priority support", "Custom domain", "API access", ], },} as const;API Route — /api/stripe
Section titled “API Route — /api/stripe”All Stripe operations go through a single POST endpoint at src/routes/(app)/api/stripe/+server.ts. The action field in the request body determines the operation.
Actions
Section titled “Actions”Creates a Stripe Express connected account for the user (if one does not exist) and returns an Account Links onboarding URL.
Flow:
- Check
business_accountsfor an existingstripe_account_id. - If missing, call
stripe.accounts.create({ type: "express" }). - Upsert the
business_accountsrow and set the profiletypeto"business". - Generate an onboarding link via
stripe.accountLinks.create(). - Return
{ url }to the client, which redirects the user.
Retrieves the connected account from Stripe and syncs the onboarding flags (details_submitted, charges_enabled, payouts_enabled) back to the business_accounts table.
Creates a Stripe Checkout session in subscription mode for the platform plans (Starter or Pro).
- Gets or creates a
stripe_customer_idon theprofilestable. - Builds
line_itemsdynamically from thePLANSconstant. - Redirects the user to Stripe Checkout.
Creates a Checkout session in payment mode on behalf of a connected account. This is the core marketplace flow:
payment_intent_data: { application_fee_amount: feeCents, transfer_data: { destination: connectedAccountId },}The platform_fee_percent is read from the seller’s business_accounts row and defaults to 5 %.
Creates a Checkout session for a Honeycomb membership package. Supports both one-time and recurring intervals. The session routes funds to the room creator’s connected account with the platform fee applied.
Returns a Stripe Express Dashboard login link so creators can view their earnings.
Webhook Handler
Section titled “Webhook Handler”The webhook endpoint lives at src/routes/api/stripe/webhook/+server.ts (note: outside the (app) group so no auth middleware runs).
Signature Verification
Section titled “Signature Verification”const event = stripe.webhooks.constructEvent(body, signature, STRIPE_WEBHOOK_SECRET);Handled Events
Section titled “Handled Events”| Event | Action |
|---|---|
customer.subscription.created | Update profile subscription_status, subscription_plan, subscription_expires_at |
customer.subscription.updated | Same as above |
customer.subscription.deleted | Set status to "canceled", clear plan |
account.updated | Sync stripe_onboarding_complete, charges_enabled, payouts_enabled on business_accounts |
checkout.session.completed | Route to app-specific handlers based on metadata.app_slug |
App-Specific Payment Routing
Section titled “App-Specific Payment Routing”When a checkout.session.completed event arrives with metadata.seller_id, the handler:
- Records a
wallet_transactionsentry for the seller. - Reads
metadata.app_slugto dynamically import the correct service handler.
Supported app slugs: courses, live-sessions, events, products, bundles, subscriptions, honeycomb-membership, honeycomb-tip.
Key Files
Section titled “Key Files”| File | Purpose |
|---|---|
src/lib/server/stripe.ts | SDK singleton, plans, fee constant |
src/routes/(app)/api/stripe/+server.ts | Client-facing Stripe API route |
src/routes/api/stripe/webhook/+server.ts | Webhook receiver |
src/routes/(app)/business/upgrade/+page.server.ts | Loads subscription and Connect status for the upgrade page |
Connect Flow Diagram
Section titled “Connect Flow Diagram”User clicks "Upgrade to Business" -> POST /api/stripe { action: "connectOnboard" } -> Server creates Express account + onboarding link -> User completes Stripe onboarding -> Redirect back to /business/upgrade?success=true -> POST /api/stripe { action: "connectStatus" } -> Server syncs onboarding flags to DB