How do I debug a php nusoap call that requires basic authentication that doesn't respond at all?
I'm trying to overwrite a Drupal module that is lagging behind the gateway API it connects to.
The stripped-down version of the code that I think is causing the problem is this:
$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);
$result
consistently false. If I add something like this to my code, it also returns sequentially empty
:
$error = $client->getError();
watchdog('connection_message', $error);
I'm a little out of the way and no error reporting in my Apache logs or Drupal watchdog player. I can't see the way forward.
source to share
1. Enable PHP error reporting if it is not already enabled.
Make sure the settings error_reporting
, display_errors
in your file php.ini
are installed at E_ALL
and On
, respectively, for the local development. You can also add these directives at the beginning of your PHP script to set them at runtime:
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. Make sure 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 projects for the eWAY API that you can deploy:
- EWAY trading for Drupal (latest release March 2014)
- eWAY-RapidAPI (uses JSON and cURL)
- eWay-PHP-API (uses XML and cURL)
- eWay Payment Gateway (uses SOAPClient)
source to share
In this case, I would like to say a couple of things.
First, why should you use this library? You can use Zend_Soap_Client
(if you don't have it, you can install it with composer :
http://framework.zend.com/downloads/composer (search zendframework/zend-soap
)
Then you can download the trial version of PHPStorm . Its debugging tools when using http://xdebug.org are really awesome, you can check the whole variable and environment space at runtime.
Finally, you can use a friendly bug management tool like http://raygun.io , you paste a few lines of code, create a trial account in there, and in a few minutes you will get all the errors that happen in your application.
In your case, you can see, for example, the current value $operation
that appears to be calling a function in the webservice.
Here's the code to test all the features offered in the webservice with Zend_Soap_Client
:
$endpoint = 'http://your.example.endpoint/?wsdl';
$soapClient = new Zend_Soap_Client($endpoint);
$functions = $soapClient->getFunctions();
var_dump($functions);
source to share
Since you are using SOAP requests your endpoint is wrong, it must be https://api.ewaypayments.com/soap.asmx or https://api.sandbox.ewaypayments.com/soap.asmx
source to share
You can disable nusoap debugging to improve performance.
To check, edit the /include/nusoap/nusoap.php file and set the debug level to 0, do the following:
['nusoap_base']->globalDebugLevel = 0;
One more step is to remove all lines starting with:
$this->debug(
or
$this->appendDebug(
Source:
http://kb.omni-ts.com/entry/245/
source to share
You can try this module: https://www.drupal.org/project/eway_integration
We are currently working with eWay to test this module together. It works with Drupal Commerce and implements the EWay RAPID 3.1 API and is PCI compliant.
source to share