-
Notifications
You must be signed in to change notification settings - Fork 3
Adding a Function
Adding a new API function for use within this framework is easy. To start, add a new .php file to the Functions directory with your function name as the file name. For example, AddCredit.php.
Use the following template for your new file:
<?php
namespace WHMCSAPI\Functions;
class AddCredit
{
public static $action = 'AddCredit';
public const ATTRIBUTES = [
'clientid', 'description', 'amount',
'date', 'adminid', 'type',
];
public const REQUIRED_ATTRIBUTES = [
'clientid', 'description', 'amount',
];
public const ADDITIONAL_REQUIREMENTS = [
'clientid' => 'numeric',
'amount' => 'float',
'date' => 'date',
'adminid' => 'numeric',
'type' => [
'add', 'remove',
],
];
public const DEFAULTS = [
'type' => 'add',
];
}
All four of the above attributes should be present:
| Parameter | Type | Description |
|---|---|---|
| $action | string | The name of the class or API function being called. |
| ATTRIBUTES | array | All attributes that the function can support. |
| REQUIRED_ATTRIBUTES | array | Any attributes which must be specified before execute. |
| ADDITIONAL_REQUIREMENTS | array | Not necessarily required, but must adhere to specific requirements if set. e.g. array, datetime, date, ipaddress, email or an array of accepted strings |
| DEFAULTS | array | A key/value pair or 'attribute' => 'default' which sets a default value on initialization. |
After creating your function file, create a file in the tests directory named after your function, with Test.php appended. (e.g. AddCreditTest.php)
Finally, ensure the test covers at minimum:
- Calling the command
- Failing when required attributes are not set
- Ensuring attributes (minimum the required attributes)
- That the API call can be made
WHMCSAPI was created by Peter Bishop. It comes with absolutely no guarantee or warranty.
Please do not contact WHMCS Technical Support for issues with this library. This software is not designed, nor shipped by them and so no support would be provided. All support requests must be requested via the GitHub Issue Tracker.