logoutCustomer - SOAP Checkout API
Definition
Because the SOAP API is a server side technology, live demos lack usefulness. However, there are Javascript demos online in the Integration Center (Developer Tools) that show how to use loginCustomer.
Method Signature |
Cart logoutCustomer(String merchantId, Cart cart); |
---|---|
Description |
Logs out a customer profile from a cart. |
Parameters |
merchantID - the merchant Id |
Result |
Cart – the updated cart reflecting the customer profile logout. The prices will return to retail levels. The global cart variable is automatically updated after this call. |
Discussion
This SOAP call is implemented in the UltraCart php class within the logoutCustomer
method. You may view this source in the zip file available on the main page.
Example
Here is the SOAP call wrapped in a php function (taken from UltraCart.php):
public function logoutCustomer() { $result = new CartOperationResult(); $cart = $this->soapClient->logoutCustomer($this->merchantId, $this->cart); if (!is_null($cart)) { $this->cart = $cart; $this->hasCart = true; } $this->updateLoginState(); $this->updateItemState(); // to be successful, the loggedIn property should now be false if (!$this->loggedIn) { $result->wasSuccessful = true; } else { $result->wasSuccessful = false; array_push($result->errorMessages, 'Logout was successful, but customer is still showing as logged in. Strange.'); } return $result; }
And here is an example using the above function
<?php require_once './UltraCart_v1.1.php'; $merchantId = 'DEMO'; $uc = new UltraCart($merchantId); $result = null; $msg = null; if ($uc->hasCart && isset($_POST['loginCustomer'])) { if (!isset($_POST['loginEmail']) || !isset($_POST['loginPassword'])) { $msg = "Error. Missing an email or password. Please enter an email and password to login a customer. Nothing done."; } else { $email = $_POST['loginEmail']; $password = $_POST['loginPassword']; // checkout will update cart, so no need to do it here. $result = $uc->loginCustomer($email, $password); $msg = 'Logging In Customer, Status=' . (bool)$result->wasSuccessful; } } if ($uc->hasCart && isset($_POST['logoutCustomer'])) { $result = $uc->logoutCustomer(); $msg = 'Logging Out Customer, Status=' . (bool)$result->wasSuccessful; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> </head> <body> <?php // you probably don't want this in a production environment if (!is_null($msg)) { echo "<div class='msg'>$msg</div>"; } ?> <?php if ($uc->loggedIn) { ?> <?php $profile = $uc->cart->customerProfile; ?> <form method='post' id='registerForm' action='./customer_profile.php'> <input type='submit' name='logoutCustomer' value='logout customer'/> </form> <table> <tbody> <tr> <td>First Name</td> <td><?php echo $profile->firstName; ?></td> </tr> <tr> <td>Last Name</td> <td><?php echo $profile->lastName; ?></td> </tr> <tr> <td>Address 1</td> <td><?php echo $profile->address1; ?></td> </tr> <tr> <td>Address 2</td> <td><?php echo $profile->address2; ?></td> </tr> <tr> <td>City</td> <td><?php echo $profile->city; ?></td> </tr> <tr> <td>State</td> <td><?php echo $profile->state; ?></td> </tr> </tbody> </table> <?php } else { ?> <form method='post' id='loginForm' action='./customer_profile.php'> <div id='loginCustomerDiv' class='section'> <div id='loginCustomerHeader'>Login Existing Customer</div> <div> <label for='loginEmail'>Email:</label><input id='loginEmail' name='loginEmail' type='text' size='30' maxlength='50'/> </div> <div> <label for='loginPassword'>Password:</label><input id='loginPassword' name='loginPassword' type='text' size='20' maxlength='20'/> </div> <input type='submit' name='loginCustomer' value='login customer'/> </div> </form> <?php } ?> </body> </html>