Habify BaseHabify Base
Kỹ thuật Nền tảng Habify (Core Billing & Ledger Team)Updated: 2026-11-2410 min read

Build End-User Prepaid Wallets & Auto-Renew Subscriptions with Billing Kit

Available from the Starter plan upward, Project Billing Kit provisions immutable wallet ledgers, subscription scheduling, automated renewal reminders, and tax-aware React pickers inside your project's own habify_sys schema.

Key Takeaways

  • Append-only wallet ledger enforced by PostgreSQL triggers, row locks, and idempotency keys
  • Configurable seller tax profile supporting VAT companies (0/5/8/10%/KCT) or non-VAT sales receipts
  • Automated renewal scheduler sending reminders 7, 3, and 1 days before expiry and on the due date via your BYO Email or Zalo OA
  • Signed dual-secret webhooks (subscription.renewed, subscription.past_due) to sync access state

Step 1: Define End-User Plans with Seller Tax Rate

Use your server-only hb_sk_* client to define plans in habify_sys.billing_plans aligned with your e-invoice seller profile.

ts
await habifyServer.billing.savePlan({
  code: "pro_monthly",
  name: "Gói Pro Hàng Tháng",
  price_minor: 199000,
  currency: "VND",
  billing_cycle_months: 1,
  tax_rate: "10", // hoặc "none" với HKD
  invoice_type: "vat",
  features: { projects: 5, ai_credits: 1000 }
});

Step 2: Embed <PlanPicker /> and <WalletTopup /> in React / Next.js

Drop in <PlanPicker /> and <WalletTopup /> from @habifybase/sdk/react to render localized plans, tax breakdowns, and BYO checkout forms.

tsx
import { PlanPicker, WalletTopup } from "@habifybase/sdk/react";

export function AccountBilling({ client, endUserJwt }: Props) {
  return (
    <div className="space-y-8">
      <PlanPicker
        client={client}
        locale="vi"
        countryCode="VN"
        isAuthenticated={Boolean(endUserJwt)}
        onRequireAuth={() => window.location.assign("/api/auth/habify/start")}
      />
      <WalletTopup client={client} locale="vi" countryCode="VN" />
    </div>
  );
}

Step 3: Verify Renewal Webhooks Using Dual-Secret HMAC

Validate incoming webhook signatures using verifyWebhookSignature() with built-in 24-hour previous-secret rotation grace.

Frequently Asked Questions

Are Billing Kit tables included when exporting a .hpb backup?

Yes. All habify_sys billing tables and immutable ledger histories are included in every .hpb export.