function redirectHandler()
{
    $id = $_GET['id'];
    $result = ChargeBee_HostedPage::retrieve($id);
    $hostedPage = $result->hostedPage();
    if ($hostedPage->state != "succeeded") {
        header("HTTP/1.0 400 Error");
        include $_SERVER["DOCUMENT_ROOT"] . "/error_pages/400.html";
    } else {
        header("Location: thankyou.php?subscription_id=" . URLencode($hostedPage->content()->subscription()->id));
    }
}
function redirectHandler()
{
    $hostedPageId = $_GET['id'];
    /* Requesting ChargeBee server about the Hosted page state and 
     * getting the details of the created subscription.
     */
    $result = ChargeBee_HostedPage::retrieve($hostedPageId);
    $hostedPage = $result->hostedPage();
    /*
     * Checking the state of the hosted page. If the state is not "succeeded",
     * then cusotmer checkout is considered as failed.
     */
    if ($hostedPage->state != "succeeded") {
        header("HTTP/1.0 400 Error");
        include $_SERVER["DOCUMENT_ROOT"] . "/error_pages/400.html";
        return;
    }
    $subscriptionId = $hostedPage->content()->subscription()->id;
    addShippingAddress($subscriptionId, $result);
    header("Location: thankyou?subscription_id=" . URLencode($subscriptionId));
}
function redirectFromChargeBee()
{
    /* The request will have hosted page id and state of the customer card
     * update status.
     */
    if ("succeeded" == $_GET['state']) {
        /* Request the ChargeBee server about the Update Card Hosted Page state 
         * and provides details about the customer.
         */
        $result = ChargeBee_HostedPage::retrieve($_GET['id']);
        $hostedPage = $result->hostedPage();
        if ($hostedPage->state != "succeeded") {
            header("HTTP/1.0 400 Error");
            include $_SERVER["DOCUMENT_ROOT"] . "/error_pages/400.html";
            return;
        }
        $customerId = $hostedPage->content()->customer()->id;
        $queryParameters = "customer_id=" . urlencode($customerId) . "&updated=" . urlencode("true");
        header("Location: profile?" . $queryParameters);
    } else {
        header("HTTP/1.0 400 Error");
        include $_SERVER["DOCUMENT_ROOT"] . "/error_pages/400.html";
    }
}
/*
 * Adding ChargeBee php libraries and configuration files.
 */
require_once dirname(__FILE__) . "/Config.php";
/* This php file is configured as redirect url for the hosted page in ChargeBee 
 * app. Hosted page Id and state of the hosted page will be sent along the request
 */
$hostedPageId = $_GET['id'];
$status = $_GET['state'];
try {
    if ($status == "succeeded") {
        /* 
         * Retrieving the hosted page and getting the details
         * of the subscription created through hosted page.
         */
        $result = ChargeBee_HostedPage::retrieve($hostedPageId);
        $hostedPage = $result->hostedPage();
        if ($hostedPage->state != "succeeded") {
            header("HTTP/1.0 400 Error");
            include $_SERVER["DOCUMENT_ROOT"] . "/error_pages/400.html";
            return;
        }
        /* 
         * Forwarding the user to thank you page.
         */
        $content = $hostedPage->content();
        $queryParameters = "name=" . $content->customer()->firstName . "&planId=" . $content->subscription()->planId;
        header("Location:thankyou.html?" . $queryParameters);
    } else {
        /* 
         * If the state is not success then displaying the 
function redirectHandler()
{
    $id = $_GET['id'];
    $result = ChargeBee_HostedPage::retrieve($id);
    if ($result->hostedPage()->state == "succeeded") {
        header("Location: /ssp-php/subscription");
    } else {
        customError400();
    }
}