How do I debug a php nusoap call requiring basic authentication that doesn't respond at all?

Darvanen picture Darvanen · May 1, 2015 · Viewed 11.7k times · Source

I am trying to re-write a Drupal module that has fallen behind the API of the gateway it connects to.

A stripped back version of the code I think is causing the problem is as follows:

$namespace = ($this->testing) ? 'https://api.sandbox.ewaypayments.com/' : 'https://api.ewaypayments.com/';
$endpoint = $this->url;
$httpUsername = $this->user_name;
$httpPassword = $this->password;

$client = new nusoap_client($endpoint, TRUE);
$client->setCredentials($httpUsername, $httpPassword, 'basic');
$client->response_timeout = 50;
$result = $client->call($operation, array('request' => $params), $namespace);

The $result is consistently false. If I put anything like this into my code it also consistently returns empty:

$error = $client->getError(); 
watchdog('connection_message', $error);

I'm a bit out of my depth and without any error messages in my Apache logs or in the Drupal watchdog I cannot see a way forward.

Answer

Drakes picture Drakes · May 4, 2015

1. Turn on PHP error reporting if it's not already on.

Check that the error_reporting, display_errors settings in your php.ini file are set to E_ALL and On respectively when you are developing locally. You can also add these directives at the beginning of your PHP script to set them at run time:

error_reporting(E_ALL);
ini_set('display_errors', 'On');

2. Catch NuSOAP errors like this:

$result = $client->call($operation, array('request' => $params), $namespace);
if ($client->fault) {
    echo 'Error: ';
    print_r($result);
} else {
    // check result
    $err_msg = $client->getError();
    if ($err_msg) {
        // Print error msg
        echo 'Error: '.$err_msg;
    } else {
        // Print result
        echo 'Result: ';
        print_r($result);
    }
}

3. Verify you are using the correct API parameters and endpoint:

From the eWAY API reference, your endpoints are:

https://api.ewaypayments.com/soap.asmx (production)
https://api.sandbox.ewaypayments.com/soap.asmx (sandbox)

4. Similar eWAY API projects that you can reverse-engineer: