Baik.

Berikut VERSI FINAL – END-TO-END, production-ready, rapi, dan bisa langsung dipakai / diajarkan.

Saya susun dari NOL sampai LIVE dalam SATU ALUR UTUH:


✅ FINAL SYSTEM

React + Supabase + Midtrans Snap + Edge Functions + RLS + Cron + Invoice


🧱 ARSITEKTUR FINAL

React (Auth)
 └── request payment
      ↓
Supabase Edge Function
 ├── create-transaction
 ├── midtrans-webhook
 ├── generate-invoice (optional)
      ↓
Supabase Database (RLS ON)
 ├── orders
 ├── order_items
 ├── order_payments
 └── storage (invoice pdf)
      ↓
Cron (expire order)


1️⃣ SQL — DATABASE FINAL

📄 TABEL orders (INTI SISTEM)

create table orders (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null,
  order_id text not null unique,
  invoice_number text unique,
  gross_amount integer not null,
  status text not null default 'pending',
  snap_token text,
  expired_at timestamptz,
  invoice_pdf_url text,
  created_at timestamptz default now()
);


📄 TABEL order_items

create table order_items (
  id uuid primary key default gen_random_uuid(),
  order_id text not null references orders(order_id) on delete cascade,
  name text not null,
  price integer not null,
  quantity integer not null
);


📄 TABEL order_payments (AUDIT LOG)

create table order_payments (
  id bigserial primary key,
  order_id text not null,
  transaction_status text,
  payment_type text,
  raw_response jsonb,
  created_at timestamptz default now()
);