Overview
AdRecon integrates with Fanbasis through:- Webhook endpoint (
/api/fanbasis/webhook) that receives payment events - Admin dashboard (
/app/admin/fanbasis) for managing products and monitoring activity - Automated provisioning that creates Supabase auth users and sends magic links
- Access revocation for refunds, disputes, and chargebacks
All webhook events are logged to
fanbasis_webhook_log for full audit visibility, regardless of whether they trigger provisioning.Setup
1. Configure API Key
Set the Fanbasis API key in your environment:2. Register Webhook
From the Fanbasis admin page (/app/admin/fanbasis):
- Click Test Connection to verify your API key
- Click Register Webhook to set up the endpoint at
/api/fanbasis/webhook - The system automatically subscribes to these events:
payment.succeededpayment.failedpayment.expiredpayment.canceledpayment.refunded(optional)payment.dispute.opened(optional)product.purchasedsubscription.createdsubscription.renewedsubscription.completedsubscription.canceled
The webhook secret is automatically stored in
integration_secrets table. Re-registering will clean up stale subscriptions to prevent secret mismatches.3. Sync Products
Click Sync Products to import all Fanbasis products intofanbasis_enabled_offers. Products are matched by:
- Product ID (
service_id) — the canonical identifier used in webhooks - Checkout Session ID — extracted from
payment_linkURL for fallback matching
4. Enable Offers
Toggle which products should trigger user provisioning:- Products default to disabled (enabled: false)
- Only enabled offers will provision users on purchase
- If no offers are enabled, all products with “AdRecon” in the title are allowed through
Webhook Processing
Purchase Events
When Fanbasis sends a purchase webhook (payment.succeeded, product.purchased, subscription.created, subscription.renewed):
api/fanbasis/webhook.js:380
Magic links are sent with
shouldCreateUser: false because the user was already created by the admin API above.Refund & Dispute Events
When Fanbasis sends a refund or dispute webhook:api/fanbasis/webhook.js:304
payment.refundedpayment.dispute.openedsubscription.canceledsubscription.completed- Any event type containing “refund”, “dispute”, or “chargeback”
Admin Dashboard
The Fanbasis admin page (/app/admin/fanbasis) provides:
Status Cards
- API Key: Shows “Connected” when
FANBASIS_API_KEYis set - Webhook: Shows “Registered” when webhook secret exists in database
- Active Offers: Count of enabled products
Actions
Webhook Activity Log
Real-time log of all webhook events with:- Event type (e.g.,
payment.succeeded,payment.refunded) - Fan email extracted from payload
- Result badge showing outcome:
User Created— new account provisionedUser Exists— existing user updatedReactivated— previously revoked user restoredRevoked— access removed due to refund/disputeOffer N/A— product not enabled for provisioningNo Email— payload missing buyer emailError— provisioning failed
- Raw payload (expandable JSON)
- Manual provision button for retrying failed events
The log is paginated (25 events per page) and ordered by
created_at DESC. Use the search to filter by email or service ID.Manual Provisioning
Admins can manually provision users from the webhook log:src/components/FanbasisAdmin.tsx:362
- Retrying failed provisioning attempts
- Granting access to users whose webhook was missed
- Testing the provisioning flow with real emails
Database Schema
supabase/migrations/20260225020000_add_fanbasis_tables.sql
Row Level Security
- fanbasis_enabled_offers: All authenticated users can read; only admins can insert/update/delete
- fanbasis_webhook_log: Only admins can read; no user writes (logged by webhook endpoint)
Environment Variables
| Variable | Required | Description |
|---|---|---|
FANBASIS_API_KEY | Yes | API key for Fanbasis API |
FANBASIS_MAGIC_LINK_REDIRECT_URL | No | Redirect URL for magic links (defaults to /app) |
AUTH_MAGIC_LINK_REDIRECT_URL | No | Fallback for magic link redirect |
Troubleshooting
Webhook not receiving events
- Check webhook registration status on admin page
- Verify
FANBASIS_API_KEYis set correctly - Test connection using “Test Connection” button
- Send a test webhook using “Send Test” button
- Check webhook log for error messages
User not created on purchase
- Check webhook log for the event
- Verify result is not
skipped_offer_not_enabled - Confirm the product is enabled in the offers list
- Check for error_message in the log entry
- Use “Provision User” button to retry manually
Magic link not sent
- Check Supabase email template configuration
- Verify
FANBASIS_MAGIC_LINK_REDIRECT_URLis set - Check webhook log for magic link error messages
- Confirm Supabase SMTP settings are configured
Duplicate offers after sync
This occurs when a product’s checkout session ID differs from its product ID. The sync migrates old entries:api/admin/fanbasis.js:214
API Reference
Admin Endpoints
Webhook Endpoint
POST /api/fanbasis/webhook