Membership billing.
In production.

Multi-tenant recurring membership billing with live ToyyibPay payments, Postgres RLS isolation, and cron-based subscription lifecycle management.

Live ToyyibPay charges
Real webhook callbacks
Postgres RLS enforced

What's built in

Each layer of the stack runs in production mode — no mock APIs, no faked data, no skipped parts.

01

Multi-tenant RLS isolation

Every org is scoped by Postgres Row Level Security. No cross-tenant data leakage — enforced at the database layer, not application logic.

02

Live billing pipeline

Real RM 0.10 ToyyibPay transactions in production mode. Not sandbox — real charges that verify the end-to-end payment flow.

03

Webhook reliability

Every ToyyibPay callback is stored raw in webhook_logs before processing. Full audit trail, idempotent status updates.

04

Subscription lifecycle

Active → Overdue → Churned state machine. next_due_date advances on payment. Auto-churn triggers after N days overdue.

05

Cron automation

Supabase Edge Functions run daily, scanning for overdue members and triggering Resend email reminders without manual intervention.

06

MRR analytics

Revenue calculated live from active plan subscriptions. Overdue and churn breakdowns surface the billing health of the org.

The billing pipeline

Exactly what runs when a member pays — no hand-waving.

POST createBill

ToyyibPay API · live mode

ToyyibPay payment page

Member enters card details

POST /api/webhooks/…

form-encoded callback · status=1

members.status = paid

Postgres update · RLS enforced

Webhook parsed as form-encoded

ToyyibPay sends application/x-www-form-urlencoded, not JSON. Most demos get this wrong.

Raw payload stored first

webhook_logs receives the raw callback before any processing. Idempotency key prevents double-processing.

Status chain is atomic

payments.status → paid and members.status → active happen in the same Postgres transaction.

Production stack

Every tool chosen for real-world applicability.

Next.js 14App Router · Server Actions · API Routes
SupabasePostgres · Auth · Edge Functions · RLS
ToyyibPayLive billing API · Webhook verification
ResendTransactional email · Overdue reminders
VercelHosting · Edge runtime · Cron triggers
Tailwind CSSUtility-first styling · Design tokens

Run the billing pipeline end-to-end.

No account needed. Create a workspace and explore the full lifecycle.

Get Started →
DuesPortfolio project · Muhammad Idzham
GitHub