Skip to content

Latest commit

 

History

History
216 lines (162 loc) · 5.75 KB

File metadata and controls

216 lines (162 loc) · 5.75 KB

✅ Top-Up Implementation - COMPLETE

Status: LIVE AND OPERATIONAL

Top-up (one-time purchase) functionality is now fully implemented and deployed!


🎯 What's Implemented

Backend Changes ✅

Location: droid@192.168.178.30:/home/droid/.ssh/sprite-pipeline-backend

Configuration (app/config.py):

  • Added stripe_topup_100_price_id
  • Added stripe_topup_250_price_id
  • Added topup_100_units: int = 100
  • Added topup_250_units: int = 250

Environment Variables (.env):

SPRITE_STRIPE_TOPUP_100_PRICE_ID=price_1SziYe43zM5TljobOZybQDpn
SPRITE_STRIPE_TOPUP_250_PRICE_ID=price_1SziZI43zM5TljobS2qSK2dZ

Billing Routes (app/routes/billing.py):

  • Updated _get_price_id() to support topup_100 and topup_250
  • Added _get_units() helper function for credit allocation
  • Updated /billing/checkout to support mode="payment" for top-ups
  • Updated webhook checkout.session.completed to allocate credits for one-time purchases
  • Logs "topup_processed" events for monitoring

Backend Commit: e6e1b70 - "Add top-up support" Status: Restarted and operational ✅

Frontend Changes ✅

Location: C:\Users\fbrmp\Projekte\sprite-pipeline-web

New Component (src/components/react/TopUpButton.tsx):

  • React component for one-time purchase buttons
  • Calls createCheckout(plan, returnUrl) API
  • Redirects to Stripe checkout
  • Shows loading state during redirect

Dashboard Update (src/components/react/DashboardOverview.tsx):

  • Added "Need More Pictures?" section
  • Two top-up options displayed:
    • 100 pictures for $9 (topup_100)
    • 250 pictures for $20 (topup_250)
  • Buttons use branded styling

Frontend Commit: 19dcf1f - "Implement top-up (one-time purchase) support" Deployment: Vercel (auto-deployed) ✅


💰 Pricing Structure

Subscriptions (Monthly)

  • Free: 0 pictures/month (BYOK only)
  • Starter (Tier 1): $9/month → 100 pictures = $0.09/picture
  • Pro (Tier 2): $29/month → 500 pictures = $0.058/picture

Top-Ups (One-Time)

  • 100 pictures: $9 = $0.09/picture (same as Starter monthly)
  • 250 pictures: $20 = $0.08/picture (better value for larger purchase)

Pricing Strategy:

  • Top-ups slightly more expensive per-picture than subscriptions
  • Encourages subscriptions for regular users
  • Provides flexibility for occasional users
  • No subscription commitment required

🔄 User Flow

Subscription Flow (Existing)

  1. User clicks "Get Started" on Starter/Pro plan
  2. Redirected to Stripe checkout (mode=subscription)
  3. Enters payment details
  4. Subscription created
  5. Monthly credits allocated via webhook
  6. Auto-renewal every month

Top-Up Flow (New)

  1. User visits dashboard
  2. Sees "Need More Pictures?" section
  3. Clicks "100 pictures $9" or "250 pictures $20"
  4. Redirected to Stripe checkout (mode=payment)
  5. Enters payment details (one-time charge)
  6. Payment completed
  7. checkout.session.completed webhook fires
  8. Credits immediately added to user quota
  9. No subscription created
  10. User can purchase again anytime

🎉 What Works Now

For Users:

Dashboard top-ups - Buy 100 or 250 pictures anytime ✅ One-time payment - No subscription required ✅ Immediate credits - Available right after payment ✅ Works with any plan - Free, Starter, or Pro users can top up ✅ Stripe checkout - Secure payment via Stripe ✅ Credit tracking - Shows in dashboard quota

For You (Admin):

Webhook logging - See "topup_processed" in backend logs ✅ Stripe dashboard - Track one-time payments separately ✅ Revenue tracking - Both subscriptions and top-ups visible ✅ Credit ledger - All allocations recorded with topup_ prefix


📊 Testing

Test Flow:

# 1. Login to dashboard
open https://fabslabssprites.com/dashboard

# 2. Scroll to "Need More Pictures?" section

# 3. Click "100 pictures $9" button

# 4. Use Stripe test card
# Card: 4242 4242 4242 4242
# Date: Any future date
# CVC: Any 3 digits

# 5. Complete payment

# 6. Redirect to dashboard

# 7. Check quota increased by 100

# 8. Verify backend logs
ssh droid@192.168.178.30
docker compose logs backend | grep "topup_processed"

Monitor Top-Ups:

# See all top-up events
docker compose logs backend | grep "topup_processed"

# See recent top-ups
docker compose logs backend | grep "topup_processed" | tail -10

# Watch for new top-ups
docker compose logs backend -f | grep "topup_processed"

🔍 Technical Details

Stripe Price IDs:

  • topup_100: price_1SziYe43zM5TljobOZybQDpn
  • topup_250: price_1SziZI43zM5TljobS2qSK2dZ

API Endpoint:

POST /billing/checkout
Query params: plan=topup_100 or plan=topup_250

Webhook Event:

Event: checkout.session.completed
Mode: payment (not subscription)
Metadata: { user_id, plan: "topup_100" }
Payment Intent: pi_xxxxx

Credit Allocation:

# In webhook handler
units = _get_units(plan)  # 100 or 250
await add_quota(db, user.id, units, f"topup_{payment_intent}")

Database:

  • Credits added to user's units_total and units_remaining
  • Recorded in credit ledger with reason: topup_pi_xxxxx
  • No subscription or plan change

🎊 Summary

Top-up functionality is fully operational!

Users can now:

  • ✅ Purchase credits without subscribing
  • ✅ Choose between 100 ($9) or 250 ($20) pictures
  • ✅ Get instant access to purchased credits
  • ✅ Top up as many times as needed
  • ✅ Works alongside subscriptions

No additional setup needed!

The system handles:

  • ✅ Payment processing via Stripe
  • ✅ Credit allocation via webhooks
  • ✅ Quota updates in real-time
  • ✅ Logging for monitoring

Implementation Date: 2026-02-12 Status: ✅ LIVE Both subscriptions AND top-ups working! 🎉