> ## 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.

# Finalize HOA

You can finalize your HOA setup via a browser redirect, or with an Ajax call. The following procedure works either way.

1. Include the SOAP Client in your page.

   ```

    <?php
    require_once("Vindicia/Soap/Vindicia.php");
    ?>
   ```

2. Retrieve the WebSession.

   Pass the session ID to this PHP page so you can retrieve the object from Vindicia.

   ```

    <?php
    $session_id = $_GET['session_id'];
    
    $websession = new WebSession();
    $srd = ""; // Soap version 13.0 and higher uses SRD
    $response = $websession->fetchByVid($srd, $session_id);
    $return_code = $response['returnCode'];
    $response_object = $response['data'];
    $websession = $response_object->session;
    ?>
   ```

3. Verify that `fetchBVid` succeeded.

   ```

    <?php
    if (($return_code=="200") && ($websession->apiReturn->returnCode == "200"))
    {
     // All is good to finalize
    else
    {
     // fetchByVid failed
     $error_message = $websession->apiReturn->returnCode . " " . $websession->apiReturn->returnString;
    }
    ?
   ```

4. Finalize WebSession.

   ```

     <?php
     $show_receipt = false;
     $srd = "";
     $response_final = $websession->finalize($srd);
     $response_object_final = $response_final['data'];
     $websession_final = $response_object_final->session;
     if ($response_final['returnCode'] == 200)
     {
     if ($websession_final->apiReturn->returnCode == "200")
     {
     // Created autobill, show receipt page
     $show_receipt = true;
     }
     else
     {
     // finalize failed
     $error_message = $websession_final->apiReturn->returnString;
     }
     }
     else
     {
     // Tried to reuse an old WebSession?
     $error_message = $response_final['returnString'];
     }
    ?>
   ```

5. Show receipt data in the browser from WebSession.

   ```

     <?php
     if ($show_receipt)
     {
     $receipt_values = $websession_final->apiReturnValues->autoBillUpdate->autobill;
     $trans = $websession_final->apiReturnValues->autoBillUpdate->initialTransaction;
     $pay_method = $trans->sourcePaymentMethod;
     
     $account = $receipt_values->account->merchantAccountId;
     $name = $receipt_values->account->name;
     $cc_number = $pay_method->creditCard->account;
     $billing_plan = $receipt_values->billingPlan->description;
     $trans_id = $trans->merchantTransactionId;
     $currency = $trans->currency;
     $amount = $trans->amount;
    ?>
     <h3>Receipt</h3>
     <p>Account: <?php print $account; ?></p>
     <p>Name: <?php print $name; ?></p>
     <p>Transaction: <?php print $trans_id; ?></p>
    
     <table class="table">
     <thead>
     <tr>
     <th>Quantity</th>
     <th>Description</th>
     <th>Amount</th>
     </tr>
     </thead>
     <tbody>
    <?php
     foreach ($trans->transactionItems as $line_item)
     {
     print "<tr>";
     $description = $line_item->name;
     $price = $line_item->price;
     $quantity = $line_item->quantity;
     
     print "<td> . $quantity . "<td>";
     print "<td> . $description . "<td>";
     print "<td> . $price . "<td>";
     print "<tr>";
     }
    ?>
     <tbody>
     <tfoot>
     <tr>
     <td> </td>
     <td> </td>
     <td><strong><?php print $amount; ?></strong></td>
     </tr>
     </tfoot>
     </table>
    <?php
     } // bottom of "if show_receipt"
    ?>
   ```

**Parent topic:**[Implementing HOA with Hosted Fields](../topics/Implementing_HOA_with_Ho)


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