How to develop an automated MLM commission system?
A Complete Guide to Building an Automated MLM Commission Engine Using PHP and MySQL
How to Develop an Automated MLM Commission System Using PHP and MySQL?
Introduction
An automated MLM commission system is one of the most important components of Multi-Level Marketing (MLM) software. It automatically calculates, distributes, and manages commissions based on predefined business rules and member activities.
In a network marketing business, members may earn different types of commissions, such as direct referral bonuses, binary matching bonuses, level income, generation bonuses, repurchase commissions, and leadership incentives.
Manually calculating these commissions can become difficult when a business has thousands or millions of members. An automated MLM commission engine helps businesses process commission calculations accurately, maintain transaction records, and manage member earnings efficiently.
PHP and MySQL provide a flexible technology stack for developing a customized MLM commission management system.
In this guide, we will explain how to develop an automated MLM commission system using PHP and MySQL, including database design, commission calculation algorithms, binary matching logic, carry-forward business, wallet management, commission capping, and automated payouts.
1. Understand the MLM Commission Structure
Before developing an automated commission system, you must understand the compensation plan.
Different MLM plans use different commission calculation methods.
Common MLM commission types include:
Direct Referral Bonus
Members earn a commission when they successfully refer an eligible new member or generate a qualifying sale, according to the business compensation plan.
Example:
-
Package Amount: ₹10,000
-
Direct Commission: 10%
Commission = ₹10,000 × 10%
Direct Referral Bonus = ₹1,000
Binary Matching Bonus
In a Binary MLM plan, members build two teams:
-
Left Team
-
Right Team
The matching commission is calculated using eligible business volume from both teams.
Example:
-
Left Business: ₹10,000
-
Right Business: ₹8,000
-
Matching Percentage: 10%
Matching Business = ₹8,000
Matching Bonus = ₹8,000 × 10%
Binary Matching Bonus = ₹800
Level Commission
Members may earn commissions from eligible business generated at different levels of their downline.
Example:
| Level | Commission Rate |
|---|---|
| Level 1 | 10% |
| Level 2 | 5% |
| Level 3 | 3% |
| Level 4 | 2% |
| Level 5 | 1% |
Actual rates and eligibility conditions depend on the approved compensation plan.
Generation Bonus
Generation commissions distribute eligible business income across predefined generations of qualified members.
Repurchase Bonus
Members may receive commissions from eligible product repurchases made by their network.
Leadership Bonus
Leadership bonuses reward members who meet predefined business performance and qualification conditions.
Your commission engine should support configurable commission types instead of hardcoding every commission percentage into PHP files.
2. Choose the Technology Stack
For developing professional MLM commission software, you can use the following technologies.
| Technology | Purpose |
|---|---|
| PHP | Backend commission processing |
| MySQL | Database management |
| PDO | Secure database operations |
| HTML5 | Frontend structure |
| CSS3 | User interface |
| Bootstrap 5 | Responsive dashboard |
| JavaScript | Frontend interactions |
| AJAX | Dynamic commission reports |
| Chart.js | Commission analytics |
| PHPMailer | Email notifications |
| Payment Gateway API | Deposits and payments |
You can develop the application using Core PHP or Laravel.
For traditional cPanel hosting, Core PHP with PDO and MySQL is also a practical option.
3. Design the MySQL Database Structure
A properly designed database is essential for an automated MLM commission system.
Your application should maintain separate records for:
-
Member registration.
-
Package purchases.
-
Business volume.
-
Commission rules.
-
Commission transactions.
-
Wallet balances.
-
Wallet transactions.
-
Withdrawals.
-
Payment records.
Avoid storing all commission information in one table.
A. Create the Users Table
This table stores member registration information.
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id VARCHAR(50) NOT NULL UNIQUE,
sponsor_id VARCHAR(50) DEFAULT NULL,
name VARCHAR(150) NOT NULL,
email VARCHAR(150),
mobile VARCHAR(20),
status TINYINT DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_sponsor (sponsor_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
B. Create the Packages Table
This table stores package information.
CREATE TABLE packages (
id INT AUTO_INCREMENT PRIMARY KEY,
package_name VARCHAR(150) NOT NULL,
package_amount DECIMAL(15,2) NOT NULL,
business_volume DECIMAL(15,2) DEFAULT 0,
status TINYINT DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
C. Create the Commission Rules Table
This table stores commission percentages and calculation rules.
CREATE TABLE commission_rules (
id INT AUTO_INCREMENT PRIMARY KEY,
commission_type VARCHAR(50) NOT NULL,
percentage DECIMAL(8,4) NOT NULL DEFAULT 0,
level_no INT DEFAULT 0,
min_business DECIMAL(15,2) DEFAULT 0,
max_commission DECIMAL(15,2) DEFAULT 0,
status TINYINT DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_type (commission_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
For production, commission rules should also have effective dates, qualification requirements, plan versions, and an audit trail.
D. Create the Business Transactions Table
This table records eligible business transactions.
CREATE TABLE business_transactions (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
transaction_ref VARCHAR(100) NOT NULL UNIQUE,
user_id VARCHAR(50) NOT NULL,
package_id INT NOT NULL,
business_volume DECIMAL(15,2) NOT NULL,
transaction_status VARCHAR(20) DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_user (user_id),
INDEX idx_status (transaction_status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Only verified and eligible business transactions should enter the commission calculation process.
E. Create the Commission Transactions Table
This table stores calculated commissions.
CREATE TABLE commission_transactions (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
transaction_ref VARCHAR(100) NOT NULL,
beneficiary_id VARCHAR(50) NOT NULL,
source_user_id VARCHAR(50),
commission_type VARCHAR(50) NOT NULL,
level_no INT DEFAULT 0,
commission_amount DECIMAL(15,2) NOT NULL,
commission_status VARCHAR(20) DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY unique_commission (
transaction_ref,
beneficiary_id,
commission_type,
level_no
),
INDEX idx_beneficiary (beneficiary_id),
INDEX idx_status (commission_status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
The unique key helps prevent duplicate commission entries for the same business event and commission type.
If your system permits multiple legitimate commission components of the same type, add a unique calculation component or rule ID to the key.
4. Develop the Member Wallet System
After calculating commissions, the system must credit eligible earnings to member wallets.
You can create a wallet table to maintain the current balance.
CREATE TABLE wallets (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id VARCHAR(50) NOT NULL UNIQUE,
balance DECIMAL(15,2) NOT NULL DEFAULT 0.00,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
You should also maintain a separate wallet transaction ledger.
CREATE TABLE wallet_transactions (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
transaction_ref VARCHAR(100) NOT NULL UNIQUE,
user_id VARCHAR(50) NOT NULL,
transaction_type VARCHAR(20) NOT NULL,
amount DECIMAL(15,2) NOT NULL,
description VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_user_date (user_id, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
The wallet transaction ledger should be the financial audit record. Never depend only on the wallet balance column.
5. Develop the PHP Database Connection
Create a file named db.php.
<?php
$host = "localhost";
$dbname = "mlm_database";
$username = "root";
$password = "";
try {
$pdo = new PDO(
"mysql:host=$host;dbname=$dbname;charset=utf8mb4",
$username,
$password,
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false
]
);
} catch (PDOException $e) {
error_log($e->getMessage());
die("Database connection failed.");
}
?>
Use environment-based credentials in production instead of keeping database passwords directly in publicly accessible source files.
6. Develop the Direct Referral Commission Calculation
The direct referral commission is one of the simplest commission types.
Suppose a member purchases an eligible package worth ₹10,000 and the sponsor receives a 10% commission.
The calculation is:
Package Amount = ₹10,000
Direct Commission = 10%
Commission = 10,000 × 10 / 100
Total Commission = ₹1,000
PHP Commission Calculation Function
<?php
function calculateDirectCommission(
float $business,
float $percentage
): float {
if ($business < 0 || $percentage < 0) {
throw new InvalidArgumentException(
"Invalid commission values."
);
}
return round(
($business * $percentage) / 100,
2
);
}
$business = 10000;
$percentage = 10;
$commission = calculateDirectCommission(
$business,
$percentage
);
echo $commission;
?>
Output:
1000
This function calculates the amount only. The application must separately validate the sponsor, transaction status, commission eligibility, capping, and duplicate processing before recording the commission.
7. Develop the Binary Matching Bonus Calculation
Binary matching is an important feature of Binary MLM software.
Each member has two teams:
-
Left Team Business
-
Right Team Business
The system calculates eligible matching business according to the configured compensation plan.
Example:
| Description | Amount |
|---|---|
| Left Business | ₹15,000 |
| Right Business | ₹12,000 |
| Matching Business | ₹12,000 |
| Matching Percentage | 10% |
| Matching Bonus | ₹1,200 |
Binary Matching Formula
Matching Business = MIN(Left Business, Right Business)
Matching Bonus = Matching Business × Commission Rate / 100
PHP Example
<?php
function calculateBinaryBonus(
float $leftBusiness,
float $rightBusiness,
float $percentage
): float {
$matchingBusiness = min(
$leftBusiness,
$rightBusiness
);
return round(
($matchingBusiness * $percentage) / 100,
2
);
}
$leftBusiness = 15000;
$rightBusiness = 12000;
$percentage = 10;
$bonus = calculateBinaryBonus(
$leftBusiness,
$rightBusiness,
$percentage
);
echo "Binary Bonus: " . $bonus;
?>
Output:
Binary Bonus: 1200
A complete binary commission engine must also manage previous carry-forward business, matched business deduction, daily capping, member eligibility, and payout conditions.
8. Develop the Business Carry-Forward System
Carry-forward is an important part of many Binary MLM compensation plans.
Suppose a member has:
-
Left Business: ₹15,000
-
Right Business: ₹12,000
The system matches ₹12,000 from both sides.
Remaining business:
Left Carry Forward = ₹15,000 - ₹12,000
Left Carry Forward = ₹3,000
Right Carry Forward = ₹0
Example database table:
CREATE TABLE binary_business (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id VARCHAR(50) NOT NULL UNIQUE,
left_business DECIMAL(15,2) DEFAULT 0,
right_business DECIMAL(15,2) DEFAULT 0,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
The calculation process should:
-
Retrieve eligible Left Business.
-
Retrieve eligible Right Business.
-
Calculate matching business.
-
Calculate matching commission.
-
Deduct matched business.
-
Preserve remaining business.
-
Record the commission calculation.
-
Update the carry-forward balances.
For financial accuracy, store each matching calculation in a separate audit table and perform all balance changes inside a database transaction.
9. Develop the Level Commission Calculation
Level commissions are calculated based on the eligible business generated by members at different downline levels.
Example compensation structure:
| Level | Business | Rate | Commission |
|---|---|---|---|
| Level 1 | ₹10,000 | 10% | ₹1,000 |
| Level 2 | ₹8,000 | 5% | ₹400 |
| Level 3 | ₹5,000 | 3% | ₹150 |
| Level 4 | ₹4,000 | 2% | ₹80 |
| Level 5 | ₹2,000 | 1% | ₹20 |
| Total | ₹29,000 | ₹1,650 |
The commission engine should identify eligible uplines, verify their qualifications, retrieve the applicable commission percentage, and create separate commission records.
For large networks, avoid processing every upline through an individual database query. Use indexed genealogy data and batch processing.
10. Develop the Commission Capping System
Commission capping limits the amount a member can earn under predefined compensation rules.
Example:
-
Daily Commission Cap: ₹5,000
-
Already Earned Today: ₹3,500
-
New Eligible Commission: ₹2,000
Remaining Daily Cap:
₹5,000 - ₹3,500 = ₹1,500
Payable Commission:
MIN(₹2,000, ₹1,500) = ₹1,500
The remaining ₹500 should be handled according to the compensation plan. It might be forfeited, deferred, or carried forward only if the plan explicitly permits it.
Never silently discard commission amounts.
11. Create the Automated Commission Processing Function
Now combine the business transaction, commission rules, and commission records into an automated processing workflow.
The recommended process is:
Verified Business Transaction
|
v
Validate Transaction
|
v
Load Commission Rules
|
v
Check Member Eligibility
|
v
Calculate Commission
|
v
Apply Commission Capping
|
v
Create Commission Records
|
v
Credit Eligible Wallet
|
v
Save Audit Records
A simplified PHP example for recording a commission and crediting a wallet is shown below.
<?php
function creditCommission(
PDO $pdo,
string $transactionRef,
string $userId,
float $amount
): bool {
if ($amount <= 0) {
return false;
}
try {
$pdo->beginTransaction();
// Insert commission record.
$stmt = $pdo->prepare("
INSERT INTO commission_transactions
(
transaction_ref,
beneficiary_id,
commission_type,
commission_amount,
commission_status
)
VALUES (?, ?, 'direct', ?, 'approved')
");
$stmt->execute([
$transactionRef,
$userId,
$amount
]);
// Ensure wallet exists.
$stmt = $pdo->prepare("
INSERT IGNORE INTO wallets
(user_id, balance)
VALUES (?, 0)
");
$stmt->execute([$userId]);
// Credit wallet atomically.
$stmt = $pdo->prepare("
UPDATE wallets
SET balance = balance + ?
WHERE user_id = ?
");
$stmt->execute([
$amount,
$userId
]);
// Record wallet transaction.
$walletRef = bin2hex(random_bytes(16));
$stmt = $pdo->prepare("
INSERT INTO wallet_transactions
(
transaction_ref,
user_id,
transaction_type,
amount,
description
)
VALUES (?, ?, 'credit', ?, ?)
");
$stmt->execute([
$walletRef,
$userId,
$amount,
'MLM Direct Commission'
]);
$pdo->commit();
return true;
} catch (Throwable $e) {
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
error_log($e->getMessage());
return false;
}
}
?>
This example demonstrates atomic commission crediting, but it is not a complete commission engine. Before using it in production, add transaction eligibility verification, commission rule validation, beneficiary qualification checks, duplicate processing protection, and appropriate approval controls.
12. Implement Duplicate Commission Prevention
Duplicate commission processing can create serious financial problems.
For example, if a payment callback runs multiple times, the system must not credit the same commission repeatedly.
Use a unique transaction reference for every business event.
The commission table should have a unique key based on:
-
Business transaction reference.
-
Beneficiary member ID.
-
Commission type.
-
Level or calculation component.
Before crediting a wallet, check whether the corresponding commission record already exists.
Use database unique constraints as the final protection rather than relying only on PHP checks.
13. Develop Automated Commission Processing Using Cron Jobs
For large MLM networks, processing all commissions during member registration may slow down the application.
A better approach is to use background processing.
You can use:
-
PHP CLI scripts.
-
cPanel Cron Jobs.
-
Queue processing.
-
Scheduled commission calculations.
Example PHP script:
<?php
require_once "db.php";
// Process pending commission jobs here.
echo "Commission processing completed.";
?>
Example cPanel Cron Job:
/usr/local/bin/php /home/username/public_html/cron/commission.php
You can schedule this script to run every minute or at another suitable interval.
For production systems, maintain a dedicated job queue with statuses such as pending, processing, completed, and failed.
Use row locking or atomic job claiming to prevent two workers from processing the same business event.
14. Develop the Automated Withdrawal System
Once commissions are credited to member wallets, members may request withdrawals according to the approved payout rules.
Important withdrawal features include:
-
Minimum withdrawal amount.
-
Maximum withdrawal amount.
-
Bank account verification.
-
UPI details.
-
Admin approval.
-
TDS calculation where applicable.
-
Applicable administrative charges.
-
Payment transaction reference.
-
Withdrawal history.
Example withdrawal table:
CREATE TABLE withdrawals (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
request_ref VARCHAR(100) NOT NULL UNIQUE,
user_id VARCHAR(50) NOT NULL,
amount DECIMAL(15,2) NOT NULL,
admin_charge DECIMAL(15,2) DEFAULT 0,
tax_amount DECIMAL(15,2) DEFAULT 0,
payable_amount DECIMAL(15,2) NOT NULL,
status VARCHAR(20) DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_user (user_id),
INDEX idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
The system should reserve the withdrawal amount when a request is accepted, prevent concurrent withdrawals from exceeding the available balance, and release or settle the reserved amount according to the final payment status.
Do not deduct the same withdrawal amount twice.
15. Develop the Admin Commission Dashboard
The admin dashboard should provide complete visibility into commission processing.
Recommended dashboard statistics:
-
Total Business Volume.
-
Total Direct Commission.
-
Total Binary Commission.
-
Total Level Commission.
-
Total Generation Bonus.
-
Total Commission Paid.
-
Pending Commission.
-
Total Wallet Balance.
-
Pending Withdrawals.
-
Completed Withdrawals.
Additional admin modules should include:
-
Commission Rules Management.
-
Commission Reports.
-
Member Commission History.
-
Business Transaction Reports.
-
Wallet Management.
-
Withdrawal Management.
-
Commission Reversal.
-
Audit Logs.
Administrators should have controlled permissions for changing commission rules and processing financial adjustments.
16. Develop the Member Commission Dashboard
Members should be able to understand their earnings and financial transactions.
Recommended member dashboard features:
-
Today's Commission.
-
Total Commission.
-
Direct Referral Income.
-
Binary Matching Bonus.
-
Level Income.
-
Repurchase Bonus.
-
Available Wallet Balance.
-
Pending Withdrawal.
-
Paid Withdrawal.
-
Commission History.
-
Wallet Transaction History.
Use Bootstrap 5 to create a responsive interface for desktop and mobile users.
Chart.js can be used to display daily, weekly, and monthly commission trends.
17. Implement Security and Financial Accuracy
Security is extremely important in MLM commission software because it manages financial transactions and member earnings.
Follow these practices:
-
Use PDO prepared statements.
-
Validate all transaction inputs.
-
Use database transactions.
-
Implement unique transaction references.
-
Prevent duplicate commission processing.
-
Use secure session management.
-
Implement CSRF protection.
-
Enforce role-based access control.
-
Maintain financial audit logs.
-
Verify payment gateway signatures.
-
Protect commission rules from unauthorized changes.
-
Perform regular database backups.
Use a Reversal System
Never delete financial commission records when a payment is refunded or a business transaction is reversed.
Instead, create a reversal entry referencing the original transaction.
This maintains a complete financial history and makes reconciliation easier.
Use Decimal Arithmetic
For financial calculations, use MySQL DECIMAL columns and avoid PHP floating-point arithmetic for production monetary calculations.
You can use integer minor units or a decimal arithmetic library to ensure precise calculations.
18. Testing the Automated MLM Commission System
Before deploying your MLM software, test every commission module carefully.
Important testing scenarios include:
-
Direct referral commission.
-
Binary matching bonus.
-
Left and Right carry-forward.
-
Level commission.
-
Generation commission.
-
Repurchase commission.
-
Daily commission capping.
-
Duplicate payment callbacks.
-
Duplicate commission processing.
-
Wallet credit and debit.
-
Withdrawal requests.
-
Payment reversals.
-
Concurrent transactions.
-
Commission rule changes.
-
Large network performance.
Test the commission calculations with sample business data before processing real transactions.
Maintain test cases with expected commission amounts so that every change to the commission engine can be verified.
19. Legal and Business Compliance
An automated MLM commission system must support legitimate and transparent direct-selling business operations.
For businesses operating in India, consider applicable requirements under the Consumer Protection (Direct Selling) Rules, 2021, as amended, along with relevant tax, consumer protection, payment, and data protection requirements.
The compensation plan should be based on legitimate product or service transactions and should not reward recruitment alone.
Clearly disclose commission conditions, deductions, payout rules, refund policies, and eligibility requirements.
Conclusion
Developing an automated MLM commission system using PHP and MySQL requires proper database architecture, configurable commission rules, accurate calculation algorithms, binary matching logic, carry-forward management, commission capping, wallet integration, and secure payout processing.
A well-designed commission engine can automate complex business calculations, reduce manual work, improve financial transparency, and help MLM companies manage growing member networks.
Whether you are developing Binary MLM, Unilevel MLM, Matrix MLM, Generation MLM, or Hybrid MLM software, the commission engine should be flexible, scalable, secure, and easy to maintain.
Looking for Professional MLM Software Development?
Togle.in provides custom MLM software development solutions for businesses with different network marketing requirements.
Our development solutions include:
-
Binary MLM Software
-
Unilevel MLM Software
-
Matrix MLM Software
-
Forced Matrix MLM Software
-
Generation MLM Software
-
Hybrid MLM Software
-
Automated MLM Commission Engine
-
E-Wallet and Payment Integration
-
Custom MLM Software Development
Whether you need a new MLM platform or want to automate your existing commission management system, Togle.in can help you build a customized PHP and MySQL-based solution.
???? Website: https://togle.in/
Contact Togle.in for Custom MLM Software Development.
Like & Comments
Found this article helpful? Share your thoughts with us.
Leave a comment