ThreeScaleClient::authorize PHP Method

authorize() public method

Authorize an application.
See also: ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and contains additional information about the usage status.
See also: ThreeScaleResponse
See also: ThreeScaleAuthorizeResponse
public authorize ( $appId, $appKey = null, $serviceId = null, $usage = null ) : ThreeScaleResponse
$appId application id.
$appKey secret application key.
$serviceId service id, only required in the case of multiple services
return ThreeScaleResponse object containing additional authorization information. If both provider key and application id are valid, the returned object is actually
    public function authorize($appId, $appKey = null, $serviceId = null, $usage = null)
    {
        $url = "http://" . $this->getHost() . "/transactions/authorize.xml";
        $params = array('provider_key' => $this->getProviderKey(), 'app_id' => $appId);
        if ($appKey) {
            $params['app_key'] = $appKey;
        }
        if ($serviceId) {
            $params['service_id'] = $serviceId;
        }
        if ($usage) {
            $params['usage'] = $usage;
        }
        $httpResponse = $this->httpClient->get($url, $params);
        if (self::isHttpSuccess($httpResponse)) {
            return $this->buildAuthorizeResponse($httpResponse->body);
        } else {
            return $this->processError($httpResponse);
        }
    }

Usage Example

Example #1
0
if (isset($Params['appid'])) {
    $appid = $Params['appid'];
} else {
    $appid = "";
}
if (isset($Params['appkey'])) {
    $appkey = $Params['appkey'];
} else {
    $appkey = "";
}
$client = new ThreeScaleClient($three_scale_provider_key);
//echo "appid: " . $appid . "<br />";
//echo "appkey: " . $appkey . "<br />";
if ($appid != '' && $appkey != '') {
    // Auth the application
    $response = $client->authorize($appid, $appkey);
    $Plan = $response->getPlan();
    $Plan = str_replace(" (custom)", "", $Plan);
    //echo $Plan . "<br />";
    $usageReports = $response->getUsageReports();
    $usageReport = $usageReports[0];
    $Exceeded = $usageReport->isExceeded();
    if ($response->isSuccess()) {
        $usageReports = $response->getUsageReports();
        //echo "Success:";
        //echo "  Plan: " .          $response->getPlan();
        //echo "  Usage reports: " . var_export($usageReports, true);
        if ($Plan == "Internal" || $Plan == "Platform") {
            include "methods/platform.php";
            include "methods/utility.php";
        } elseif ($Plan == "Personal") {
All Usage Examples Of ThreeScaleClient::authorize