> ## Documentation Index
> Fetch the complete documentation index at: https://docs.slm.m1amdocs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# WebSession\_initialize

The `initialize` method creates a `WebSession` object. Call this method before presenting your HOA-based Web order form to your customer. The call returns the new `WebSession` object with a populated `VID` attribute. Embed that VID in the order form as a hidden form element with the name `vin_WebSession_vid` to make it available to HOA at form submission. You only need to pass in the Subscribe API object attributes that you have collected thus far in the customer’s flow. Remaining attributes can be passed in with the `WebSession.finalize` call.

To create a `WebSession` object, set the values for its data members (see [WebSession Data Members](WebSession_Data_Members)) and then call `initialize()` to store the changes in the Vindicia database. Do not set a value for VID because Subscribe automatically generates that when you call `initialize()`.

## Input

*srd*: sparse response description, a SOAP string (which must be a JSON object), in which you specify the elements you want returned.This parameter enables the calling system to constrain a `method` call to return only components you specify. This gives you greater control over returned content, and improves response time within the Vindicia platform by reducing the processing needed for the call.

Some fields are required, either practically or in the WSDL, and will be returned regardless of the *srd*. A null *srd* returns the complete response. session : the WebSession object to create.

## Output

*return*: an object of type `Return` that indicates the success or failure of the call.

*session*: the `WebSession` object that contains the data that you passed, the VID, and the `expireTime` value assigned by Subscribe.

## Returns

In addition to those listed in [The Return Object](The_Return_Object), this call returns:

| Return Code | Return String |
| - | - |
| 400 | The following: - `This Credit Card already exists—Policy Violation" (eradicate the newly created but failed one or ensure it is set INACTIVE).` You receive this error message when you have the Credit\_Card\_Constraints merchant option enabled on your site. This message means that someone is attempting to use a credit card that is already being used as the payment method on an existing account. This is not allowed. |
| 402 | One of the following: - `Missing required parameter: version *version*.` - `Invalid parameter: Unsupported version.` - `Missing required parameter: method` - `Invalid parameter: Unsupported method.` - `Missing required parameter: returnURL.` |

## Example

```

// to create a WebSession object
$ws = new WebSession();

// HOA should make an AutoBill.update call when the form is submitted
$ws->setMethod('AutoBill_Update');

// Customer's IP address. When customer submits the form
// it should come from the same IP address
$ws->setIpAddress("124.23.210.175");

// Page to which HOA will redirect customer's browser 
// after successfully making the AutoBill.update call when the 
// customer submits the form
$ws->setReturnURL("https://merchant.com/subscribe/success.php");

// Page to which HOA will redirect customer's browser
// if the AutoBill.update call it makes when the customer submits
// the form unsuccessful

$ws->setErrorURL("https://merchant.com/subscribe/failed.php");

// Private name values pairs. These are needed to create the
// AutoBill object, but we do not want them to appear in the
// form the customer fills in

$pnv1 = new NameValuePair();

// The name is flattened Object name concatenated
// with attribute names with an underscore. 

// The Subscribe Account object for which HOA should create the
// AutoBill object
$pnv1->setName('Account_VID');
$pnv1->setValue('36c8de2cb74b2c2b08b259cf231ac8d90d1bb3b8'); 

// The Subscribe Product object HOA should use in constructing
// the AutoBill object
$pnv2 = new NameValuePair();
$pnv2->setName('Product_merchantProductId');
$pnv2->setValue('StartWars II'); 

$pnv3 = new NameValuePair();
$pnv3->setName('vin_BillingPlan_merchantBillingPlanId');

// When customer submits the form, the billing plan
// should be one of the two comma separated values
$pnv3->setValue('GoldAccess2010, PlatinumAccess2010'); 

$ws->setPrivateFormValues(array($pnv1, $pnv2, $pnv3));

// Method parameter name values pairs. These are needed to make the 
// AutoBill.update call which takes parameters in addition to the 
// AutoBill object itself. We do not want these to come from the form 
// submission because that makes them susceptible to hacking

$mpnv1 = new NameValuePair();

// The name is flattened object name, method name, and parameter 
// name concatenated with an underscore. 

$mpnv1->setName('AutoBill_Update_minChargebackProbability');
$mpnv1->setValue('80'); 

// Leave other parameter values to their default values
$ws->setMethodParamValues(array($mpnv1));

// Now create the WebSession object on Vindicia servers
// by making the SOAP call to initialize the object

$response = $ws->initialize();

if ($response->['returnCode'] == 200) {

   $ret_ws = $response['data']->session;

   // The VID of the WebSession object serves as session id

   $sessionId = $ret_ws->getVID();

   // Embed the sessionId as hidden field in the order web form
   // Compose and present the order web form here
}
else {
// Return error to the customer who requested the web order form
} 
```

**Parent topic:**[WebSession Methods](../topics/WebSession_Methods)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.