SOAP API: PHP Code doesn't work, but SOAP UI works

Viewed 217

I'm trying to create a rental module for my work's website. When I use the same parameters in SmartBear's SOAP UI, it works. So, I'm assuming that it's something to do with my code, but I cannot find the error.

<?php //Submit Reservation
require("connect.php");
$sessionId = $_SESSION['sessionId'];
$moveInDate = date("yy-m-d", strtotime($_POST['moveIn']));
$billDate = date("d", strtotime($_POST['moveIn']));
$rentalOptions = array(
    "customer.company" =>$company,
    "account.startDate"=> $moveInDate,
    "contact.firstName"=>$_POST['fname'],
    "contact.lastName"=>$_POST['lname'],
    "contact.companyName"=>$_POST['companyName'],
    "contact.street1"=>$_POST['street'],
    "contact.street2"=>"",
    "contact.city"=>$_POST['city'],
    "contact.state"=>$_POST['state'],
    "contact.zip"=>$_POST['zip'],
    "contact.country"=>"US",
    "phone.1" => $_POST['mobile'],
    "contact.email"=>$_POST['email'],
    "account.currency"=>"1",
    "account.billDay"=> $billDate,
    "user.paymentMethod"=>"1",
    "user.draftDay"=>"",
    "unit.id"=>$_POST['unit-name'],
    "postAccount"=>"Y",
    "promotionId"=>$_POST['promo'],
    "insuranceId"=>$_POST['insurance']
    );
var_dump($rentalOptions);

echo "<br/>". $sessionId ."<br/><a href=\"teststorage.php\">Return</a>";

$client = new SoapClient("https://api.doorswap.com/service/system.wsdl");

// Make API Call
    $dsReceiver = "customer";
    $dsAction = "saveNewCustomer";
    $result = $client->makeReceiverCall($sessionId, $dsReceiver, $dsAction, $rentalOptions);
    //if($result["success"] == "true") {    
    //}
?>

The var_dump() and print_r() displays correct variables from the previous form. In fact, ALL variables are correctly output. I just do not understand WHY it isn't working. It's not giving me an error, it's just not POSTING.

FYI: I have tried using javascript SOAP and I run into similar issues. The code is right, the variables are correct, but the addition to the system is not going through.

I'm open to trying anything.

2 Answers

Initialization of the SoapClient class

First of all inialize your soap client the right way. The soap client class takes several options to debug your application. In the following example a soap client is initalized with some options, that will make your life more easy when testing.

try {
     $client = new SoapClient('https://api.doorswap.com/service/system.wsdl', [
         'exceptions' => true,
         'trace' => true,
     ]);
} catch (SoapFault $fault) {
    var_dump($fault->getMessage());

    if ($client instanceof SoapClient) {
        var_dump(
            $client->__getLastRequest(),
            $client->__getLastResponse()
        );
    }
}

As you can see the soap client class is initialized with different option parameters. The exception option is set to true so that the soap client class throws exceptions, when an error occurs. That 's why the code is wrapped in a try and catch block. The trace option allows us to see, what the last request and response looks like. If the soap client was initialized you can use the build in methods __getLastRequest() and __getLastResponse() to see what the sent and received xml looks like. Keep in mind, that these can be empty if the xml wasn 't compiled by the client.

The makeReceiverCall method was a "name"/"value" system. So the above array of $rentalOptions SHOULD have been done as such. This is currently working, and has been flawless in execution.

$rentalOptions = array(
    array("name"=> "customer.company","value"=> $company),
    array("name"=> "account.startDate", "value"=> $moveInDate),
...
);

This was the error that I had run into and finally figured out. Thank you to all those who tried to help.

Related