function firstStep()
{
    validateParameters($_POST);
    $planId = "basic";
    $passThrough = array("address" => $_POST['addr'], "extended_addr" => $_POST['extended_addr'], "city" => $_POST['city'], "state" => $_POST['state'], "zip_code" => $_POST['zip_code']);
    try {
        /*
         * Calling ChargeBee Checkout new Hosted Page API to checkout a new subscription
         * by passing plan id the customer would like to subscribe and also passing customer 
         * first name, last name, email and phone details. The resposne returned by ChargeBee
         * has hosted page url and the customer will be redirected to that url.
         * 
         * Note: Parameter embed(Boolean.TRUE) can be shown in iframe
         *       whereas parameter embed(Boolean.FALSE) can be shown as seperate page.
         * Note : Here customer object received from client side is sent directly 
         *        to ChargeBee.It is possible as the html form's input names are 
         *        in the format customer[<attribute name>] eg: customer[first_name] 
         *        and hence the $_POST["customer"] returns an associative array of the attributes.              
         */
        $hostUrl = getHostUrl();
        $result = Chargebee_HostedPage::CheckoutNew(array("subscription" => array("planId" => $planId), "customer" => $_POST['customer'], "embed" => "false", "passThruContent" => json_encode($passThrough), "redirectUrl" => $hostUrl . "/checkout_two_step/redirect_handler", "cancelUrl" => $hostUrl . "/checkout_two_step/signup.html"));
        $redirectUrl = $result->hostedPage()->url;
        $jsonResponse = array("forward" => $redirectUrl);
        print json_encode($jsonResponse, true);
    } catch (ChargeBee_InvalidRequestException $e) {
        handleInvalidRequestErrors($e, "subscription[plan_id]");
    } catch (Exception $e) {
        handleGeneralErrors($e);
    }
}
<?php

/*
 * Adding ChargeBee php libraries and configuration files.
 */
require_once dirname(__FILE__) . "/Config.php";
require_once dirname(__FILE__) . "/Util.php";
require_once dirname(__FILE__) . "/ErrorHandler.php";
/* Checkouts the existing subscription to active state for the passed 
 * subscription id which is in trial state.
 */
if ($_POST) {
    validateParameters($_POST);
    try {
        /* Request the ChargeBee server to get the hosted page url.
         * Passing Timestamp as ZERO to the trial end will immediately change the 
         * subscription from trial state to active state.
         * Note: Parameter embed specifies the returned hosted page URL 
         *       is shown in iframe or as seperate page.
         */
        $hostUrl = getHostUrl();
        $result = Chargebee_HostedPage::checkoutExisting(array("subscription" => array("id" => $_POST["subscription_id"], "trial_end" => 0), "embed" => "false", "redirect_url" => $hostUrl . "/checkout_existing/redirect_handler", "cancel_url" => $hostUrl . "/checkout_existing/profile.html"));
        $redirectURL = $result->hostedPage()->url;
        /* 
         * This will redirect to the ChargeBee server.
         */
        header("Location: {$redirectURL}");
    } catch (Exception $e) {
        customError500($e);
    }
}
<?php

/*
 * Adding ChargeBee php libraries and configuration files.
 */
require_once dirname(__FILE__) . "/Config.php";
require_once dirname(__FILE__) . "/Util.php";
require_once dirname(__FILE__) . "/ErrorHandler.php";
/*
 * Calling Checkout New Hosted Page API to create a new Subscription for the
 * passed plan id. The customers are redirected to the ChargeBee hosted page
 * with the returned response hosted page url. 
 *
 * Since it is demo, plan with id 'basic' is hard coded here.
 */
$planId = "basic";
$hostUrl = getHostUrl();
$result = Chargebee_HostedPage::CheckoutNew(array("subscription" => array("planId" => $planId), "embed" => "false", "redirectUrl" => $hostUrl . "/checkout_new/redirect_handler", "cancelUrl" => $hostUrl . "/checkout_new/index.html"));
$hostedPageUrl = $result->hostedPage()->url;
/* 
 * This will redirect the customers to the ChargeBee server.
 */
header("Location: {$hostedPageUrl}");