function __construct($clientid, $secret) { //Get oauth token to access Itero API $verbose = fopen('php://stderr', 'w'); $curl = curl_init(); $data = http_build_query(array('grant_type' => 'client_credentials')); curl_setopt_array($curl, array(CURLOPT_URL => self::$oAuth, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => "{$clientid}:{$secret}", CURLOPT_RETURNTRANSFER => true, CURLOPT_VERBOSE => true, CURLOPT_STDERR => $verbose)); $response = curl_exec($curl); $this->exit_on_error($curl); $token = json_decode($response); self::$auth = "Authorization: Bearer " . $token->access_token; }
<?php include 'config.php'; include 'iteroapi.php'; //Get event data $json = json_decode(file_get_contents('php://input')); $event = $json->Event; $contractid = $json->ContractId; //Exit if received event is not an "account created" event if ($event != 'AccountCreated') { handle_error(422, "Not an 'account created' event"); } //Fetch contract and customer data from Itero $itero = new IteroAPI($clientid, $clientsecret); if (!$itero) { handle_error(500, "Could not initialise itero"); } $contract = $itero->get_contract($contractid); if (!$contract) { handle_error(500, "Could not fetch contract"); } $customer = $itero->get_customer($contract->CustomerId); if (!$customer) { handle_error(500, "Could not fetch customer"); } //Get mongodb instance $m = new MongoClient($GLOBALS['mongodb'], array("connect" => TRUE)); //$m = new MongoClient(); if (!$m) { handle_error(500, "Could not open mongodb"); }
<?php include 'config.php'; include 'iteroapi.php'; $contractid = $_GET['contractid']; // Get a default self service portal URL // from Itero for a sepcific contract $itero = new IteroAPI($clientid, $clientsecret); $token = $itero->get_selfservice_token($contractid); if (!$token) { handle_error(500, "Could not fetch token"); } $portalurl = $token->Url; ?> <!doctype html> <html> <head> <title>Customer Portal</title> </head> <body> <a href="/customers.php">Back to customer list</a> <iframe width="100%" height="2000px" src="<?php echo $portalurl; ?> "></iframe> </body> </html>