3

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.

Darvanen
  • 626
  • 1
  • 9
  • 19

5 Answers5

9

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:

Community
  • 1
  • 1
Drakes
  • 23,254
  • 3
  • 51
  • 94
  • Yeah it's Commerce eWAY for Drupal that I'm trying to update, it doesn't have support for the Rapid API and tokens don't currently seem to work. – Darvanen May 04 '15 at 03:29
  • Your endpoint may be wrong, but you should still receive some error messages. Try checking for that 'fault' flag that I put in my answer as well as enabling PHP errors just in case. – Drakes May 04 '15 at 03:32
  • Your code for catching errors did the trick, thanks very much! Somehow my authentication isn't working, now I know where to look. Answer accepted. – Darvanen May 04 '15 at 03:40
  • Awesome! I went through the NuSoap source to find the way it reports errors. Glad to be of help. – Drakes May 04 '15 at 03:42
1

There are a couple of things I would like to say in this case.

First, why do you have to use that library ? You can use Zend_Soap_Client (if you don't have it you can install it using composer:

http://framework.zend.com/downloads/composer (look for zendframework/zend-soap)

Then, you can download a trial version of PHPStorm. Its debugging tools when used with http://xdebug.org are really awesome, you can inspect the entire variable and environment space in runtime.

Finally, you can use a friendly error managing tool like http://raygun.io, you insert a few lines of code, create a trial account in there, and in minutes you get all errors that are happening in your application.

In your case, you can see for example the current value of $operation, which seems the function being called on the webservice.

Here's the code for inspecting all functions being offered in a webservice using Zend_Soap_Client:

$endpoint = 'http://your.example.endpoint/?wsdl';
$soapClient = new Zend_Soap_Client($endpoint);
$functions  = $soapClient->getFunctions();
var_dump($functions);
Niloct
  • 9,491
  • 3
  • 44
  • 57
1

Since you are using SOAP requests your endpoint is incorrect, it should be https://api.ewaypayments.com/soap.asmx or https://api.sandbox.ewaypayments.com/soap.asmx

Jonathan
  • 2,778
  • 13
  • 23
  • Ah yes, of course, those values were an attempt to get some kind of error out of the system. They did end in soap.asmx originally, thanks for pointing it out. – Darvanen May 04 '15 at 03:34
  • Oh, my bad, the endpoint is set much earlier in the code and stored in `$this->url;` the values are as you have described. Looks like the namespace shouldn't have soap.asmx at the end... – Darvanen May 04 '15 at 03:36
  • can you just scrap the namespace it really shouldn't be needed. – Jonathan May 04 '15 at 03:37
0

For better performance you may think to disable nusoap debugging.

To check, edit the /include/nusoap/nusoap.php file and set the debug level to 0, like this:

['nusoap_base']->globalDebugLevel = 0;

One step even further is to remove all lines that start with:

$this->debug(

or

$this->appendDebug(

Source:

http://kb.omni-ts.com/entry/245/
Nuri Akman
  • 792
  • 3
  • 18
  • 41
0

You could give this module a try: 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 eWay's RAPID 3.1 API and is PCI compliant.

Invisigoth
  • 121
  • 1
  • 3