Jump to content

Curl error: couldn't connect to host in .../WHMCS/Terminus.php on line 0


Mike_B

Recommended Posts

Hello,

 

I'm using the API functions to add a client, add an order and capture payment. Things were working fine but now I'm getting the following error after making the call to add an order.

 

Fatal error: Curl error: couldn't connect to host in .../includes/classes/WHMCS/Terminus.php on line 0

 

This isn't $results['message'] but the first element of an array. Here's the vardump of $results

 

array(1) { [" Fatal error: Curl error: couldn't connect to host in .../includes/classes/WHMCS/Terminus.php on line 0 "]=> NULL }

 

Despite this error, when I view the client list the client has been added as well as the order for that client. The invoice is generated too. Unfortunately, the return is not "success".

 

I've read many pages that mention to whitelist the IP or talk about a firewall or port issue. The IP has been whitelisted. The server admin states that the server WHMCS is on hasn't been updated or changed for days before this issue arose. Also tried many different curl options and tested bare bones API access with hard coded client details. Anyone know what's going on here?

 

My workaround has been to make a call to get the client details for the new client and pluck the invoice id out of that. Then I make a call to capture payment with that invoice id. It works but it's sloppy and can't stay this way.

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

I also thought multiple calls might conflict but I just tested with the following. It only adds the order to an existing client. It did add the order and generated an invoice but still returned the same error.

 

$success= []; // used to check results

$url = "https://.../api.php";
$username = "...";
$password = "...";

$postfields["username"] = $username;
$postfields["password"] = md5($password);


$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);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated