try {
    if (isset($_SESSION['subscriptionId'])) {
        throw new Exception('You must first delete your existing subscription.');
    }
    $events = array();
    if (isset($_REQUEST['subscriptionText'])) {
        $events[] = 'TEXT';
    }
    if (isset($_REQUEST['subscriptionMms'])) {
        $events[] = 'MMS';
    }
    if (count($events) == 0) {
        throw new Exception("You must select at least one of Text or MMS");
    }
    envinit();
    $webhooksSrvc = new WebhooksService(getFqdn(), getSessionToken());
    $callbackData = $_REQUEST['callbackData'];
    if ($callbackData == '') {
        $callbackData = null;
    }
    $args = new CreateSubscriptionArgs(CHANNEL_ID, $events, $callbackData, EXPIRES_IN);
    $response = $webhooksSrvc->createNotificationSubscription($args);
    $subscription = $response->getSubscription();
    $subscriptionId = $subscription->getSubscriptionId();
    $_SESSION['subscriptionId'] = $subscriptionId;
    $_SESSION['subscriptionExpiry'] = EXPIRES_IN + time();
    $arr = array('success' => true, 'text' => 'Subscription created.');
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../lib/Webhooks/WebhooksService.php';
use Att\Api\Webhooks\WebhooksService;
$arr = null;
try {
    if (!isset($_SESSION['subscriptionId'])) {
        throw new Exception('You must first create a subscription.');
    }
    $subscriptionId = $_SESSION['subscriptionId'];
    envinit();
    $token = getFileTokenByScope(NOTIFICATION_SCOPE);
    $webhooksSrvc = new WebhooksService(getFqdn(), $token);
    $webhooksSrvc->deleteNotificationSubscription(CHANNEL_ID, $subscriptionId);
    unset($_SESSION['subscriptionId']);
    $arr = array('success' => true, 'text' => 'Subscription deleted.');
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 private function getChannelId()
 {
     if ($this->channel_id != "") {
         return $this->channel_id;
     }
     $token = $this->getCurrentClientToken();
     $webhooksSrvc = new WebhooksService($this->base_url, $token);
     $channel = new Channel("MIM", "application/json", 1);
     $rsp = null;
     try {
         $rsp = $webhooksSrvc->createNotificationChannel($channel);
         $this->channel_id = $rsp->getChannel()->getChannelId();
         return $this->channel_id;
     } catch (ServiceException $ex) {
         $exObjectParts = explode(":4", $ex->getMessage());
         $exObject = json_decode($exObjectParts[0]);
         if (isset($exObject->RequestError) && isset($exObject->RequestError->MessageId) && $exObject->RequestError->MessageId == "POL1001") {
             $this->channel_id = explode(":", $exObject->RequestError->Variables)[1];
             return $this->channel_id;
         }
         throw $ex;
     }
 }
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/Webhooks/WebhooksService.php';
use Att\Api\Webhooks\WebhooksService;
$arr = null;
try {
    if (!isset($_SESSION['subscriptionId'])) {
        throw new Exception('You must first create a subscription.');
    }
    $subscriptionId = $_SESSION['subscriptionId'];
    envinit();
    $webhooksSrvc = new WebhooksService(getFqdn(), getSessionToken());
    $response = $webhooksSrvc->getNotificationSubscription(CHANNEL_ID, $subscriptionId);
    $arr = array('success' => true, 'tables' => array(array('caption' => 'Subscription Details', 'headers' => array('Subscription Id', 'Expires In', 'Queues', 'Callback Data'), 'values' => array(array($response->getSubscriptionId(), $response->getExpiresIn(), $response->getEvents(), $response->getCallbackData())))));
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
$arr = null;
try {
    if (!isset($_SESSION['subscriptionId'])) {
        throw new Exception('You must first create a subscription.');
    }
    $events = array();
    if (isset($_REQUEST['updateSubscriptionText'])) {
        $events[] = 'TEXT';
    }
    if (isset($_REQUEST['updateSubscriptionMms'])) {
        $events[] = 'MMS';
    }
    if (count($events) == 0) {
        throw new Exception("You must select at least one of Text or MMS");
    }
    $subscriptionId = $_SESSION['subscriptionId'];
    envinit();
    $webhooksSrvc = new WebhooksService(getFqdn(), getSessionToken());
    $callbackData = $_REQUEST['updateCallbackData'];
    if ($callbackData == '') {
        $callbackData = null;
    }
    $args = new UpdateSubscriptionArgs(CHANNEL_ID, $subscriptionId, $events, $callbackData, EXPIRES_IN);
    $webhooksSrvc->UpdateNotificationSubscription($args);
    $_SESSION['subscriptionExpiry'] = EXPIRES_IN + time();
    $arr = array('success' => true, 'text' => 'Subscription updated.');
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */