establishCustomerProfile - SOAP Checkout API

Definition

The equivalent Javascript API call may be found here: establishCustomerProfileImmediately. 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 establishCustomerProfile.

Method Signature

Cart establishCustomerProfile(String merchantId, Cart cart, String email, String password);

Description

This function will create a new customer profile immediately and associate it with the cart. If the customer does not complete their order, the customer profile will still be created.

Parameters

String email – the email address of the customer. String password – the password to be used on the customer profile.

Result

Cart – the updated cart. The global cart variable is automatically updated after this call.

Discussion

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

Example

Here is a method that wraps this soap call into a php function:

  public function registerCustomer($email, $password)
  {
    $result = new CartOperationResult();
    try {
      $cart = $this->soapClient->establishCustomerProfile($this->merchantId, $this->cart, $email, $password, true);
      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, 'Registration was successful, but customer is not logged in.  Strange.');
      }


    } catch (SoapFault $e) {
      $pos = strpos($e->getMessage(), 'A customer profile already exists');
      if ($pos !== false) {
        $result->wasSuccessful = false;
        array_push($result->errorMessages, 'Registration failed. This email address is already registered.');
      } else {
        $result->wasSuccessful = false;
        array_push($result->errorMessages, 'An unexpected error prevented customer registration.  Please contact support.');
        error_log('SoapFault during UltraCart->registerCustomer:' . $e->getMessage());
      }
    }
    return $result;
  }



And this is an example of a call made to 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['registerCustomer'])) {

  if (!isset($_POST['registerEmail']) || !isset($_POST['registerPassword'])) {
    $msg = "Error.  Missing an email or password.  Please enter an email and password to register a customer.  Nothing done.";
  } else {
    $email = $_POST['registerEmail'];
    $password = $_POST['registerPassword'];
    // checkout will update cart, so no need to do it here.
    $result = $uc->registerCustomer($email, $password);
    $msg = 'Registering 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='registerForm' action='./customer_profile.php'>
    <div id='registerCustomerDiv' class='section'>
      <div id='registerCustomerHeader'>Register New Customer</div>
      <div>
        <label for='registerEmail'>Email:</label><input id='registerEmail' name='registerEmail' type='text' size='30' maxlength='50'/>
      </div>
      <div>
        <label for='registerPassword'>Password:</label><input id='registerPassword' name='registerPassword' type='text' size='20' maxlength='20'/>
      </div>
      <input type='submit' name='registerCustomer' value='register customer'/>
    </div>
  </form>  
  
  <?php } ?>

</body>
</html>