public function testConfigure()
 {
     ChargeBee_Environment::configure("test_site", "test_api_key");
     $defEnvConfig = ChargeBee_Environment::defaultEnv();
     $this->assertEqual("test_site", $defEnvConfig->getSite());
     $this->assertEqual("test_api_key", $defEnvConfig->getApiKey());
     $this->assertEqual("https://test_site.chargebee.com/api/v1", $defEnvConfig->getApiEndpoint());
 }
Esempio n. 2
0
 public static function send($method, $url, $params = array(), $env = null, $headers = array())
 {
     if (is_null($env)) {
         $env = ChargeBee_Environment::defaultEnv();
     }
     if (is_null($env)) {
         throw new Exception("ChargeBee api environment is not set. Set your site & api key in ChargeBee_Environment::configure('your_site', 'your_api_key')");
     }
     $ser_params = ChargeBee_Util::serialize($params);
     $response = ChargeBee_Curl::doRequest($method, $url, $env, $ser_params, $headers);
     if (is_array($response) && array_key_exists("list", $response)) {
         return new ChargeBee_ListResult($response['list'], isset($response['next_offset']) ? $response['next_offset'] : null);
     } else {
         return new ChargeBee_Result($response);
     }
 }
function callingIframeCheckoutPage()
{
    header('Content-Type: application/json');
    validateParameters($_POST);
    $planId = "basic";
    try {
        $result = ChargeBee_HostedPage::CheckoutNew(array("subscription" => array("planId" => $planId), "customer" => $_POST['customer'], "embed" => "true", "iframeMessaging" => "true"));
        /*
         * Sending hosted page url and hosted page id as response.
         */
        $response = array("url" => $result->hostedPage()->url, "hosted_page_id" => $result->hostedPage()->id, "site_name" => ChargeBee_Environment::defaultEnv()->getSite());
        print json_encode($response);
    } catch (ChargeBee_InvalidRequestException $e) {
        handleInvalidRequestErrors($e, "subscription[plan_id]");
    } catch (Exception $e) {
        handleGeneralErrors($e);
    }
}