[MP] Category Balance 💰

Overview #

[MP] Category Balance lets authors earn a balance from approved threads posted in specific forums on your XenForo site. Users can withdraw their accumulated balance via IBAN, while admins manage the process with advanced reports.


Requirements #

  • XenForo: 2.2 or higher
  • MySQL: 5.7+ or MariaDB: 10.3+ (for JSON and functional indexes)
  • PHP: 7.4+ (8.0+ recommended)

Setup #

  1. Copy the add‑on files to src/addons/MusaPekel/KatagoriBakiye/ on your server.
  2. In Admin Panel → Add‑ons, find "[MP] Category Balance" and click Install.
  3. During install, the following DB changes are applied:
    • Adds mp_kb_price column to xf_forum.
    • Creates xf_mp_kb_transactions table (stores all transactions).
    • Creates xf_mp_kb_user_balance table (optional cache).
  4. After install, go to Admin Panel → Forums → edit the forum and set "Price per Thread".

User Flow #

  1. User opens a thread in a priced forum; the thread requires approval.
  2. When a moderator/admin approves it, the forum’s price is credited to the user balance.
  3. User can view current balance and recent transactions at /bakiye.
  4. After reaching the minimum threshold, the user submits a withdrawal request at /odeme with IBAN info. Amount is deducted immediately.
  5. Admin reviews the request, pays manually, then marks it as "Paid" in the panel.

Access & Routes #

User (Public) Routes

  • /bakiye: Current balance and history.
  • /odeme: New withdrawal request form.
  • /odeme/submit: Form submit endpoint.

Admin Routes

  • admin.php?mpkb-withdraw: Pending withdrawal requests.
  • admin.php?mpkb-reports/payouts: Paid report.
  • admin.php?mpkb-reports/totals: Totals report.

Settings & Permissions #

All options live under Admin Panel → Options → [MP] Category Balance.

Basic Settings

Enable Add‑on: Turn the system on/off.
Currency: Currency to display in UI and reports (TRY, USD, EUR).
Minimum Withdrawal: Minimum balance required to request payout.
Reference Prefix: Prefix for payout reference codes (e.g., KB-).

User Permissions

Use group permissions to grant mpKb_view_balance so selected users can access the balance system.


Core Concepts (Technical) #

Transactions

All balance movements are stored in xf_mp_kb_transactions. Each row represents a credit or withdraw action. Withdrawals have pending and paid states.

Balance Calculation

A user’s available balance is calculated on the fly as:
Balance = (sum of all 'credit') − (sum of all 'withdraw' with status 'pending' and 'paid')
This prevents re‑using funds while a request is still pending.


Developer API Notes #

Core functionality lives in the Repository layer and can be reused by other add‑ons.

Balance Repository

  • creditForApprovedThread(): Credits the user when a thread is approved.
  • requestWithdraw(): Validates balance/limits and creates a new withdrawal.
  • getUserBalance(): Computes a user’s real‑time balance.

Report Repository

Provides data for admin reports (e.g., getPaidTotals, getTopPaidUsers).


Templates & Language Support #

All texts use phrases so they can be localized easily. Phrases start with the mp_kb_ prefix.

User Templates

  • mp_kb_balance_index
  • mp_kb_withdraw_request

Admin Templates

  • mp_kb_admin_withdraw_list
  • mp_kb_admin_report_payouts
  • mp_kb_admin_report_totals

Common Errors #

I get "invalid_action / invalid_controller".

Ensure routes are defined correctly. Check namespace and Controller class names.

User wasn’t credited on thread approval.

Make sure the forum’s mp_kb_price is greater than 0 and the thread is in an approval workflow.


Frequently Asked Questions #

Why is balance deducted immediately when creating a withdrawal?

It prevents the user from re‑using the same funds while the request is still being processed.

Why no PayPal or other methods?

This version focuses on the common scenario in Türkiye: payout requests via IBAN, keeping the UI simple.

What happens if I uninstall the add‑on?

Uninstall removes all tables (xf_mp_kb_*) and the column (xf_forum.mp_kb_price). This deletes all balances and history. Back up your DB if you need the data.