This is the bare bones code with most of it pulled from the WHMCS docs.
$success= []; // used to check results
$url = "https://.../api.php";
$username = "...";
$password = "...";
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "addclient";
$postfields["firstname"] = 'firstName';
$postfields["lastname"] = 'lastName';
$postfields["email"] = 'test@test.com';
$postfields["address1"] = '55 Road Rd.';
$postfields["city"] = 'Las Vegas';
$postfields["state"] = 'Nevada';
$postfields["postcode"] = '89135';
$postfields["country"] = 'US';
$postfields["phonenumber"] = '702-555-1212';
$postfields["password2"] = 'password';
$postfields["cctype"] = 'Visa';
$postfields["cardnum"] = 4111111111111111;
$postfields["expdate"] = 1116;
$postfields["cvv"] = 123;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);
$data = explode(";",$data);
foreach ($data AS $temp) {
$temp = explode("=",$temp);
$results[$temp[0]] = $temp[1];
}
if ($results["result"]=="success") {
# Result was OK!
$success[] = 'client added';
$postfields["clientid"] = $results["clientid"];
unset ($results);
} else {
# An error occured
echo "The following error occured: ".$results["message"];
}
$postfields["action"] = "addorder";
$postfields["pid"] = 47;
$postfields["billingcycle"] = "Monthly";
$postfields["paymentmethod"] = "paypal";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);
$data = explode(";",$data);
foreach ($data AS $temp) {
$temp = explode("=",$temp);
$results[$temp[0]] = $temp[1];
}
if ($results["result"]=="success") {
# Result was OK!
$success[] = $results;
} else {
# An error occured
var_dump($results);
}
var_dump($success);