### Install Project Dependencies Source: https://github.com/fossbilling/fossbilling.org/blob/main/README.md Installs all necessary dependencies for the project. Use `npm install` if not starting from a clean state. ```bash npm ci ``` -------------------------------- ### Start Local Development Server Source: https://github.com/fossbilling/fossbilling.org/blob/main/README.md Starts a local development server for live previewing changes. The server typically runs at `http://localhost:3000` and reflects most changes without a restart. ```bash npm run dev ``` -------------------------------- ### Make Guest API GET Request Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/developing-fossbilling/javascript/page.mdx Example of making a GET request to the guest API endpoint for system version. Includes success and error handlers. ```javascript API.guest.get("system/version", {}, function(response) { // handle successful response }, function(error) { // handle error response }); ``` -------------------------------- ### Database Configuration Example Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/maintaining-fossbilling/admin-manual-reset/page.mdx This snippet shows an example of the database configuration array, typically found in a config file. Ensure the 'name' field matches your FOSSBilling database name. ```php 'db' => array ( 'type' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'name' => 'fossbilling', 'user' => 'fossbilling_user', 'password' => 'fossbilling_password', ), ``` -------------------------------- ### Guest API: Get System Version Source: https://context7.com/fossbilling/fossbilling.org/llms.txt This example demonstrates how to retrieve the FOSSBilling system version using the guest API. This endpoint does not require authentication. ```APIDOC ## POST /api/guest/system/version ### Description Retrieves the current version of the FOSSBilling system. This is a public endpoint and does not require authentication. ### Method POST ### Endpoint https://example.com/api/guest/system/version ### Parameters No specific parameters are required for this endpoint. ### Request Example ```json {} ``` ### Response #### Success Response (200) - **result** (string) - The current version of the FOSSBilling system. - **error** (null) - Null if the operation was successful. #### Response Example ```json { "result": "0.7.2", "error": null } ``` ``` -------------------------------- ### Admin API: Get Client List Source: https://context7.com/fossbilling/fossbilling.org/llms.txt This example shows how to retrieve a list of clients using the admin API. It supports pagination parameters and requires administrator authentication. ```APIDOC ## POST /api/admin/client/get_list ### Description Retrieves a list of clients from the FOSSBilling system. This endpoint is accessible to authenticated administrators and supports pagination. ### Method POST ### Endpoint https://example.com/api/admin/client/get_list ### Parameters #### Query Parameters - **per_page** (integer) - Optional - The number of clients to return per page. - **page** (integer) - Optional - The page number to retrieve. #### Request Body - **per_page** (integer) - Optional - The number of clients to return per page. - **page** (integer) - Optional - The page number to retrieve. ### Request Example ```json { "per_page": 10, "page": 1 } ``` ### Response #### Success Response (200) - **result** (object) - An object containing the list of clients and total count. - **list** (array) - An array of client objects. - **total** (integer) - The total number of clients available. - **error** (null) - Null if the operation was successful. #### Response Example ```json { "result": { "list": [...], "total": 42 }, "error": null } ``` ``` -------------------------------- ### NGINX Configuration for FOSSBilling Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/getting-started/installation/page.mdx This NGINX configuration serves as a starting point for FOSSBilling. Remember to replace placeholders like %%DOMAIN%% and %%SOURCE_PATH%% with your specific server details. Adjust SSL settings and the fastcgi_pass directive based on your server's PHP-FPM setup. ```conf server { listen 80; server_name %%DOMAIN%% return 301 https://%%DOMAIN%%/request_uri/; } server { listen 443 ssl http2; ssl_certificate /path/to/ssl/certicate.crt; ssl_certificate_key /path/to/ssl/certicate.key; ssl_stapling on; ssl_stapling_verify on; set $root_path '%%SOURCE_PATH%%'; server_name %%DOMAIN%%; index index.php; root $root_path; try_files $uri $uri/ @rewrite; sendfile off; include /etc/nginx/mime.types; # Block access to sensitive files location ~* .(ini|sh|inc|bak|twig|sql)$ { return 403; } # Block /vendor completely location ^~ /vendor/ { return 403; } # Block direct access to config.php location = /config.php { return 403; } # Block access to hidden files except .well-known location ~ /\.(?!well-known\/) { return 403; } # Disable PHP execution in /uploads location ~* /uploads/.*\.php$ { return 403; } # Deny access to /data, except /assets/gateways location ~* /data/(?!(assets/gateways/)) { return 403; } location @rewrite { rewrite ^/page/(.*)$ /index.php?_url=/custompages/$1; rewrite ^/(.*)$ /index.php?_url=/$1; } location ~ \.php { fastcgi_split_path_info ^(.+\.php)(/.+); # fastcgi_pass need to be changed according your server setup: # phpx.x is your server setup # examples: /var/run/phpx.x-fpm.sock, /var/run/php/phpx.x-fpm.sock or /run/php/phpx.x-fpm.sock are all valid options # Or even localhost:port (Default 9000 will work fine) # Please check your server setup fastcgi_pass unix:/run/php/phpx.x-fpm.sock; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; include fastcgi_params; } location ~* ^/(css|img|js|flv|swf|download)/(.+)$ { root $root_path; expires off; } } ``` -------------------------------- ### JavaScript API Wrapper: Guest GET Request Source: https://context7.com/fossbilling/fossbilling.org/llms.txt Demonstrates how to make a GET request to the guest API using the FOSSBilling JavaScript API wrapper. This is useful for fetching public system information. ```APIDOC ## API.guest.get(endpoint, params, callback, errorCallback) ### Description Makes a GET request to the guest API. No authentication is required. ### Parameters - **endpoint** (string) - Required - The API endpoint to call (e.g., "system/version"). - **params** (object) - Optional - Parameters to send with the request. - **callback** (function) - Required - Function to handle the successful response. - **errorCallback** (function) - Optional - Function to handle errors. ### Example Usage ```javascript API.guest.get("system/version", {}, function(response) { console.log("FOSSBilling version:", response); }, function(error) { console.error("Error:", error); }); ``` ``` -------------------------------- ### Make Admin API POST Request Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/developing-fossbilling/javascript/page.mdx Example of making a POST request to the admin API endpoint to get a list of clients. Includes success and error handlers. ```javascript API.admin.post("client/get_list", {}, function(response) { // handle successful response }, function(error) { // handle error response }); ``` -------------------------------- ### Apply Permissions to Folders and Files Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/troubleshooting/page.mdx Use these commands to set correct file and folder permissions for FOSSBilling installations. Ensure you are in the document root before executing. ```bash find . -type d -exec chmod 755 {} \; ``` ```bash find . -type f -exec chmod 644 {} \; ``` -------------------------------- ### FOSSBilling Configuration File Example Source: https://context7.com/fossbilling/fossbilling.org/llms.txt A representative configuration file for FOSSBilling, controlling core behavior including URL, security settings, internationalization, database connection, API limits, and logging. ```php 'https://example.com/', 'admin_area_prefix' => '/admin', 'salt' => 'CHANGE_ME_TO_RANDOM_STRING', 'debug' => false, 'update_branch' => 'release', // 'release' or 'preview' 'security' => [ 'mode' => 'strict', // 'strict' or 'regular' 'force_https' => true, 'session_lifespan' => 7200, // seconds (2 hours) ], 'i18n' => [ 'locale' => 'en_US', 'timezone' => 'UTC', 'date_format' => 'medium', // 'none','short','medium','long' 'time_format' => 'short', 'datetime_pattern' => '', // overrides date/time_format when set ], 'db' => [ 'type' => 'mysql', 'host' => '127.0.0.1', 'name' => 'fossbilling', 'user' => 'db_user', 'password' => 'db_password', 'port' => 3306, ], 'api' => [ 'require_referrer_header' => false, 'allowed_ips' => [], // empty = allow all 'rate_span' => 60, // seconds 'rate_limit' => 1000, // requests per rate_span 'rate_span_login' => 60, 'rate_limit_login' => 20, 'CSRFPrevention' => true, ], 'maintenance_mode' => [ 'enabled' => false, 'allowed_urls' => ['/api/guest/system/ping'], 'allowed_ips' => ['192.168.1.0/24'], ], 'twig' => [ 'debug' => false, 'auto_reload' => true, 'cache' => '/var/www/fossbilling/data/cache', ], 'log_stacktrace' => false, 'stacktrace_length' => 25, 'disable_auto_cron' => false, // set true in production for cron stability ]; ``` -------------------------------- ### Install NPM Dependencies Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/getting-started/building/page.mdx Install the necessary Node Package Manager (NPM) dependencies for the project. This is required before building front-end assets. ```bash npm i ``` -------------------------------- ### Simple License Plugin Example Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/product-types/license/page.mdx Demonstrates a basic license generation plugin. It creates a license key with a default length, optional prefix, and formatted for readability. This plugin uses uppercase letters and digits 1-9. ```php MYAPP-ABCD1-EFGH2-IJKL3-MNOP4 ``` -------------------------------- ### Admin API Endpoint Example Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/developing-fossbilling/api/page.mdx This example demonstrates how to make a POST request to an admin API endpoint using cURL, including authentication and a JSON payload. Replace 'YOUR_API_KEY' with your actual API key. ```APIDOC ## POST /api/admin/staff/create ### Description Creates a new staff member in the FOSSBilling system. ### Method POST ### Endpoint `https://example.com/api/admin/staff/create` ### Parameters #### Request Body - **email** (string) - Required - The email address of the new staff member. - **password** (string) - Required - The password for the new staff member. - **name** (string) - Required - The full name of the new staff member. - **admin_group_id** (integer) - Required - The ID of the administrator group. - **status** (string) - Required - The status of the staff member (e.g., 'active'). ### Request Example ```json { "email": "hello@fossbilling.org", "password": "Testing123+", "name": "John Doe", "admin_group_id": 1, "status": "active" } ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the newly created staff member. - **message** (string) - A success message. #### Response Example ```json { "id": 1, "message": "Staff member created successfully." } ``` ``` -------------------------------- ### Install Composer Dependencies Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/getting-started/building/page.mdx Install the PHP Composer dependencies for FOSSBilling. Ensure you have Composer installed and a supported PHP version. ```bash composer install ``` -------------------------------- ### Authenticate and Create Staff User (curl) Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/developing-fossbilling/api/page.mdx Example using curl to authenticate with an API key and send a POST request to create a staff user. Ensure to replace 'YOUR_API_KEY' with your actual key and adjust the JSON payload as necessary. ```bash # Example curl request to authenticate and call an admin API endpoint curl -X POST "https://example.com/api/admin/staff/create" \ -H "Authorization: Basic $(echo -n 'admin:YOUR_API_KEY' | base64)" \ -H "Content-Type: application/json" \ -d '{ "email": "hello@fossbilling.org", "password": "Testing123+", "name": "John Doe", "admin_group_id": 1, "status": "active" }' # Replace YOUR_API_KEY with your actual API key and adjust the payload as needed. ``` -------------------------------- ### Check Permissions (Detailed) Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/developing-fossbilling/guides/creating-a-module/page.mdx This example demonstrates how to check for a specific permission using the `hasPermission` method and manually throw an exception with a custom message and status code if the permission is denied. ```PHP $staff_service = $this->di['mod_service']('Staff'); if (!$staff_service->hasPermission(null, 'example', 'delete_something')) { throw new \FOSSBilling\InformationException('You do not have permission to perform this action', [], 403); } ``` -------------------------------- ### Authenticate and Create Staff User (JavaScript) Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/developing-fossbilling/api/page.mdx Example using JavaScript's fetch API to authenticate with Basic Auth and send a POST request to create a staff user. Remember to replace 'YOUR_API_KEY' with your actual key and adjust the payload. ```javascript // Example JavaScript request to authenticate and call an admin API endpoint const url = "https://example.com/api/admin/staff/create"; // /api/{role}/{module}/{endpoint} const apiKey = "YOUR_API_KEY"; const payload = { email: "hello@fossbilling.org", password: "Testing123+", name: "John Doe", admin_group_id: 1, status: "active" }; const headers = new Headers(); headers.set("Content-Type", "application/json"); headers.set("Authorization", "Basic " + btoa("admin:" + apiKey)); fetch(url, { method: "POST", headers: headers, body: JSON.stringify(payload) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error("Error:", error)); // Replace YOUR_API_KEY with your actual API key and adjust the request as needed. ``` -------------------------------- ### Get Available License Plugins Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/product-types/license/page.mdx Retrieve a list of available license validation plugins. This is useful for understanding the different licensing strategies supported by FOSSBilling. ```json { "result": { "Simple": "Simple", "PluginB": "PluginB" }, "error": null } ``` -------------------------------- ### Authenticate and Create Staff User (Python) Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/developing-fossbilling/api/page.mdx Example using Python's requests library to authenticate with HTTP Basic Auth and send a POST request to create a staff user. Replace 'YOUR_API_KEY' with your actual key and modify the payload. ```python # Example Python request to authenticate and call an admin API endpoint import requests from requests.auth import HTTPBasicAuth url = "https://example.com/api/admin/staff/create" # /api/{role}/{module}/{endpoint} api_key = "YOUR_API_KEY" payload = { "email": "hello@fossbilling.org", "password": "Testing123+", "name": "John Doe", "admin_group_id": 1, "status": "active" } auth = HTTPBasicAuth('admin', api_key) headers = { "Content-Type": "application/json" } response = requests.post(url, json=payload, auth=auth) print(response.json()) # Replace YOUR_API_KEY with your actual API key and adjust the request as needed. ``` -------------------------------- ### Admin API: Create Staff Member Source: https://context7.com/fossbilling/fossbilling.org/llms.txt This example demonstrates how to create a new staff member using the admin API. It requires administrator authentication and sends staff details in JSON format. ```APIDOC ## POST /api/admin/staff/create ### Description Creates a new staff member in the FOSSBilling system. This endpoint is accessible only to authenticated administrators. ### Method POST ### Endpoint https://example.com/api/admin/staff/create ### Parameters #### Request Body - **email** (string) - Required - The email address for the new staff member. - **password** (string) - Required - The password for the new staff member. - **name** (string) - Required - The full name of the staff member. - **admin_group_id** (integer) - Required - The ID of the administrator group to assign. - **status** (string) - Required - The status of the staff member (e.g., "active"). ### Request Example ```json { "email": "hello@fossbilling.org", "password": "Testing123+", "name": "John Doe", "admin_group_id": 1, "status": "active" } ``` ### Response #### Success Response (200) - **result** (boolean) - Indicates if the operation was successful. - **error** (null) - Null if the operation was successful. #### Response Example ```json { "result": true, "error": null } ``` ``` -------------------------------- ### Get Client List via Admin API (Python) Source: https://context7.com/fossbilling/fossbilling.org/llms.txt This Python script demonstrates how to fetch a list of clients using the admin API. It utilizes the requests library for HTTP communication and Basic Authentication. ```python import requests from requests.auth import HTTPBasicAuth response = requests.post( "https://example.com/api/admin/client/get_list", json={"per_page": 10, "page": 1}, auth=HTTPBasicAuth('admin', 'YOUR_API_KEY') ) print(response.json()) ``` -------------------------------- ### Build for Production Source: https://github.com/fossbilling/fossbilling.org/blob/main/README.md Creates a production-ready build of the website, including Pagefind indexing. ```bash npm run build ``` -------------------------------- ### ExamplePay Payment Adapter Implementation Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/developing-fossbilling/guides/creating-a-payment-gateway/page.mdx This class implements the FOSSBilling payment adapter interface for the fictional ExamplePay gateway. It includes configuration validation, dependency injection handling, and defines gateway capabilities and form fields. ```php config['test_mode']) { if (empty($this->config['test_merchant_id'])) { throw new Payment_Exception( 'The ":pay_gateway" payment gateway is not fully configured. Please configure the :missing', [':pay_gateway' => 'ExamplePay', ':missing' => 'Test Merchant ID'], 4001 ); } } else { if (empty($this->config['merchant_id'])) { throw new Payment_Exception( 'The ":pay_gateway" payment gateway is not fully configured. Please configure the :missing', [':pay_gateway' => 'ExamplePay', ':missing' => 'Merchant ID'], 4001 ); } if (empty($this->config['secret_key'])) { throw new Payment_Exception( 'The ":pay_gateway" payment gateway is not fully configured. Please configure the :missing', [':pay_gateway' => 'ExamplePay', ':missing' => 'Secret Key'], 4001 ); } } } public function setDi(Pimple\Container $di): void { $this->di = $di; } public function getDi(): ?Pimple\Container { return $this->di; } /** * Gateway configuration: capabilities, description, and admin form fields. */ public static function getConfig(): array { return [ 'supports_one_time_payments' => true, 'supports_subscriptions' => false, 'can_load_in_iframe' => false, 'description' => 'Accept payments via ExamplePay. Enter your merchant credentials to get started.', 'logo' => [ 'logo' => 'examplepay.png', 'height' => '30px', 'width' => '80px', ], 'form' => [ 'merchant_id' => [ 'text', [ 'label' => 'Live Merchant ID:', ], ], 'secret_key' => [ 'text', [ 'label' => 'Live Secret Key:', ], ], 'test_merchant_id' => [ 'text', [ 'label' => 'Test Merchant ID:', 'required' => false, ], ], ], ]; } /** * Generate the payment form shown to the client. */ public function getHtml($api_admin, $invoice_id, $subscription): string { $invoice = $api_admin->invoice_get(['id' => $invoice_id]); $merchantId = $this->config['test_mode'] ? $this->config['test_merchant_id'] : $this->config['merchant_id']; $amount = number_format($invoice['total'], 2, '.', ''); $fields = [ 'merchant_id' => $merchantId, 'amount' => $amount, 'currency' => $invoice['currency'], 'description' => 'Payment for invoice ' . $invoice['serie_nr'], 'reference' => $invoice['id'], 'callback_url' => $this->config['notify_url'], 'success_url' => $this->config['thankyou_url'], 'cancel_url' => $this->config['cancel_url'], 'customer_email'=> $invoice['buyer']['email'], ]; // Build a hidden form that redirects to ExamplePay's checkout page $gatewayUrl = $this->config['test_mode'] ? 'https://sandbox.examplepay.com/checkout' : 'https://checkout.examplepay.com/pay'; $form = '
' . PHP_EOL; // Auto-redirect if configured if (!empty($this->config['auto_redirect'])) { $form .= " ``` -------------------------------- ### Access Invoice Data via DI Container Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/developing-fossbilling/guides/creating-a-payment-gateway/page.mdx Use the DI container to get the raw `Model_Invoice` RedBeanPHP model. This is useful when direct interaction with services is needed, such as calculating totals. ```php $this->di['db']->load('Invoice', $invoice_id) ``` -------------------------------- ### Clone FOSSBilling Repository Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/getting-started/building/page.mdx Clone the FOSSBilling repository and navigate into the created directory. This is the first step to building from source. ```bash git clone https://github.com/FOSSBilling/FOSSBilling.git && cd FOSSBilling ``` -------------------------------- ### API Key Response Example Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/product-types/apikeys/page.mdx This JSON response indicates a successful update operation for an API key. Note that this endpoint cannot change the API key itself; use the 'reset' endpoint for regeneration. ```json { "result":true, "error":null } ``` -------------------------------- ### Configure FOSSBilling Cron Job Source: https://github.com/fossbilling/fossbilling.org/blob/main/app/docs/getting-started/docker/page.mdx After installation, configure a cron job on the host system to ensure FOSSBilling's scheduled tasks run correctly. Replace '