Module System
CloudBill Pro's module system lets you extend the platform with custom payment gateways, server provisioners, domain registrars, and more.
Module Types
| Type | Directory | Purpose |
|---|---|---|
| Gateway | modules/gateways/{name}/ | Accept payments (Stripe, PayPal, etc.) |
| Server | modules/servers/{name}/ | Provision hosting accounts (cPanel, Plesk, etc.) |
| Registrar | modules/registrars/{name}/ | Register/manage domains (eNom, Namecheap, etc.) |
modules/mail/{name}/ | Email delivery providers (SMTP, Mailgun, etc.) | |
| Fraud | modules/fraud/{name}/ | Fraud detection checks |
| Notification | modules/notifications/{name}/ | Slack, Telegram, SMS alerts |
| Addon | modules/addons/{name}/ | Custom admin panel features |
Module Structure
Every module needs at least two files:
modules/
gateways/
mygateway/
config.php ← Module metadata and settings definition
mygateway.php ← Main class file
Creating a Gateway Module
1. config.php
'mygateway',
'display_name' => 'My Payment Gateway',
'description' => 'Accept payments via My Gateway',
'version' => '1.0.0',
'author' => 'Your Name',
'type' => 'gateway',
'supports' => ['one_time', 'refund'],
'fields' => [
'api_key' => [
'label' => 'API Key',
'type' => 'password',
'required' => true,
'encrypted' => true,
],
'test_mode' => [
'label' => 'Sandbox Mode',
'type' => 'checkbox',
'default' => true,
],
],
];
2. mygateway.php
app = $app;
// Load settings from database
$db = $app->db();
$rows = $db->fetchAll("SELECT name, value FROM `{$db->table('gateway_settings')}` WHERE gateway = 'mygateway'");
foreach ($rows as $r) {
$this->settings[$r['name']] = $r['value'];
}
}
/**
* Render the payment form HTML for an invoice
*/
public function renderPaymentForm(array $invoice): string
{
$callbackUrl = $this->app->baseUrl('/gateway/callback/mygateway');
return <<
HTML;
}
/**
* Handle the gateway callback (POST from gateway)
* Return array with invoice_id, amount, transaction_id on success
* Return false on failure
*/
public function handleCallback(array $data): array|false
{
$invoiceId = (int)($data['invoice_id'] ?? 0);
$amount = (float)($data['amount'] ?? 0);
// Verify the payment with your gateway API
$isValid = $this->verifyPayment($data);
if (!$isValid) return false;
return [
'invoice_id' => $invoiceId,
'amount' => $amount,
'transaction_id' => $data['transaction_id'] ?? uniqid(),
];
}
private function verifyPayment(array $data): bool
{
// Add your verification logic here
return !empty($data['invoice_id']) && !empty($data['amount']);
}
}
Creating a Server Module
Server modules must implement: create(), suspend(), unsuspend(), terminate(), changePassword(), getUsage(), testConnection().
See the included modules/servers/cpanel/cpanel.php for a complete example.
Creating a Registrar Module
Registrar modules must implement: checkAvailability(), register(), renew(), updateNameservers(), getExpiryDate().
See the included modules/registrars/enom/enom.php for a complete example.
Installing a Module
- Upload the module folder to the appropriate directory (e.g.,
modules/gateways/mygateway/) - Navigate to Admin → Gateways (or Servers/Registrars)
- Your module will appear automatically — click Configure
- Fill in the required settings and click Save
- Enable the module with the toggle