PHP code example of eugenefvdm / whmcs-api

1. Go to this page and download the library: Download eugenefvdm/whmcs-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eugenefvdm / whmcs-api example snippets




return [
    'url' => env('WHMCS_URL'),
    'admin_url' => env('WHMCS_ADMIN_URL'),
    'api_identifier' => env('WHMCS_API_IDENTIFIER'),
    'api_secret' => env('WHMCS_API_SECRET'),
    'debug' => env('WHMCS_DEBUG'),
    'limitnum' => env('WHMCS_LIMITNUM', 10000),
    'default_payment_method' => env('WHMCS_DEFAULT_PAYMENT_METHOD', 'mailin'),
    'default_reg_period' => env('WHMCS_DEFAULT_REG_PERIOD', 1),
    'verify_ssl' => env('WHMCS_VERIFY_SSL', true),
];

test('it can create a new client in WHMCS', function () {
    $customfields = base64_encode(
        serialize(
            [
                8 => '50-100',
            ]
        )
    );

    $client = [
        'firstname' => $this->faker->firstName,
        'lastname' => $this->faker->lastName,
        'email' => $this->faker->email,
        'address1' => $this->faker->numberBetween(1, 100).' '.$this->faker->streetName,
        'address2' => $this->faker->secondaryAddress,
        'city' => $this->faker->city,
        'state' => $this->faker->state,
        'postcode' => $this->faker->postcode,
        'country' => config('whmcs.default_country'),
        'phonenumber' => $this->faker->phoneNumber,
        'password2' => bin2hex(random_bytes(8)),
        'customfields' => $customfields,
    ];

    $result = Whmcs::addClient($client);

    expect($result)->toHaveKey('result')
        ->and($result['result'] == 'success');
})->only();



use WHMCS\Database\Capsule;

if (!defined("WHMCS"))
    die("This file cannot be accessed directly");

try {
    $client = Capsule::table('tblclients')
        ->where("phonenumber", $_REQUEST['phonenumber'])
        ->first();

    if ($client) {
        $apiresults = [
            "result" => "success",
            "message" => "ok",
            'clientid' => $client->id,
        ];
    } else {
        $apiresults = [
            "result" => "error",
            "message" => "not found",
        ];
    }
} catch (Exception $e) {
    $apiresults = ["result" => "error", "message" => $e->getMessage()];
}



use Eugenefvdm\Whmcs\Whmcs;

utable(__DIR__);
$dotenv->load();

$api = Whmcs::connect([
    'url' => env('WHMCS_URL'),
    'api_identifier' => env('WHMCS_API_IDENTIFIER'),
    'api_secret' => env('WHMCS_API_SECRET'),
]);

$result = $api->getClients();

use Eugenefvdm\Whmcs\Facades\Whmcs;

$result = Whmcs::getClientsDetails(['clientid' => 1]);

use Eugenefvdm\Whmcs\Whmcs;

$api = Whmcs::connect([
    'url' => env('WHMCS_URL2'),
    'api_identifier' => env('WHMCS_API_IDENTIFIER2'),
    'api_secret' => env('WHMCS_API_SECRET2'),
]);

$result = $api->getClientsDetails(['clientid' => 1]);

$orders = Whmcs::getOrders(['userid' => $clientId]);
$items = Whmcs::ordersList($orders);

$paginator = Whmcs::ordersPaginator([
    'userid' => $clientId,
    'page' => 1,
    'limitnum' => 25,
]);

Whmcs::addDomainRegistrationOrder(
    clientId: $clientId,
    domain: 'example.com',
    paymentMethod: 'mailin',
    regPeriod: 1, // optional; defaults to config('whmcs.default_reg_period')
);

$statuses = Whmcs::getOrderStatuses();

Whmcs::changePlan($serviceId);

use Eugenefvdm\Whmcs\WhmcsApiException;

try {
    Whmcs::getOrders(['userid' => $clientId]);
} catch (WhmcsApiException $e) {
    $e->action;    // e.g. 'GetOrders'
    $e->response;  // full WHMCS JSON body
    $e->getMessage();
}

use Eugenefvdm\Whmcs\WhmcsResponse;

$clients = WhmcsResponse::list($response, 'clients', 'client');
$total = WhmcsResponse::total($response);
bash
php artisan vendor:publish --provider="Eugenefvdm\Whmcs\WhmcsServiceProvider" 
bash
#!/bin/bash
echo "Present Working Directory:"
pwd
echo "Copying $1 to WHMCS install directory"

cp