loginCustomer - 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 loginCustomer(String merchantId, Cart cart, String email, String password);

Description

Logs in a customer profile for the given cart using the email address and password specified. This will allow the cart to reflected the discounted prices that are available to them as well as utilize their address book.

Parameters

String merchantId
Cart cart
String email – email address of the customer profile
String password – password of the customer profile.

Result

Cart – If the login is unsuccessful then the result of this call will be null. This does not mean that the cart has been lost. It's just a way of indicating an error condition so be careful to just check the result and not assign it to your cart variable in the page.

Discussion

This SOAP call is implemented in the UltraCart php class within the loginCustomer method. You may view this source in the zip file available on the main page.

Example

  public function loginCustomer($email, $password)
  {
    $result = new CartOperationResult();
    $cart = $this->soapClient->loginCustomer($this->merchantId, $this->cart, $email, $password);
    if (!is_null($cart)) {
      $this->cart = $cart;
      $this->hasCart = true;

      $this->updateLoginState();
      $this->updateItemState();

      // to be successful, the loggedIn property should be true.
      if ($this->loggedIn) {
        $result->wasSuccessful = true;
      } else {
        $result->wasSuccessful = false;
        array_push($result->errorMessages, 'Login was successful, but customer is not logged in.  Strange.');
      }

    } else {
      $result->wasSuccessful = false;
      array_push($result->errorMessages, 'Login failed.  Invalid email address or password.');
    }

    return $result;
  }

Here is an example that uses 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;

  }
}

?>

<!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>