Permalink
Browse files

add authrep to php plugin

  • Loading branch information...
1 parent 5a7b399 commit e4d49110530be83b0902c61f59c61727548ae81b @solso solso committed Mar 22, 2011
Showing with 63 additions and 1 deletion.
  1. +1 −1 examples/authorize_and_report.php
  2. +62 −0 lib/ThreeScaleClient.php
@@ -30,7 +30,7 @@
// Something's wrong with this app.
echo "Error: " . $response->getErrorMessage();
}
-
+
// Report some usages
$response = $client->report(
array(
View
@@ -108,6 +108,68 @@ public function authorize($appId, $appKey = null) {
}
}
+/**
+ * Authorize and report in a single shot.
+ *
+ * @param $appId application id.
+ * @param $appKey secret application key.
+ *
+ *
+ * @return ThreeScaleResponse object containing additional authorization information.
+ * If both provider key and application id are valid, the returned object is actually
+ * @see ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and
+ * contains additional information about the usage status.
+ *
+ * @see ThreeScaleResponse
+ * @see ThreeScaleAuthorizeResponse
+ *
+ * @throws ThreeScaleServerError in case of unexpected internal server error
+ *
+ * Example:
+ *
+ * <code>
+ * <?php
+ * $response = $client->authorize('app-id', 'app-key');
+ *
+ * if ($response->isSuccess()) {
+ * // ok.
+ * } else {
+ * // something is wrong.
+ * }
+ * ?>
+ * </code>
+ */
+
+ public function authrep($appId, $appKey = null, $usage = null, $userId = null, $object = null, $no_body = null) {
+ $url = "http://" . $this->getHost() . "/transactions/authrep.xml";
+
+ $params = array('provider_key' => $this->getProviderKey(), 'app_id' => $appId);
+
+ if ($appKey) $params['app_key'] = $appKey;
+ if ($userId) $params['user_id'] = $userId;
+ if ($object) $params['object'] = $object;
+ if ($usage) $params['usage'] = $usage;
+ if ($no_body) $params['no_body'] = $no_body;
+
+
+ $httpResponse = $this->httpClient->get($url, $params);
+
+ if ($no_body) {
+
+ echo ">>" . curl_errno($this->httpClient->handle) . "\n";
+
+ return true;
+ }
+ else {
+ if (self::isHttpSuccess($httpResponse)) {
+ return $this->buildAuthorizeResponse($httpResponse->body);
+ } else {
+ return $this->processError($httpResponse);
+ }
+ }
+
+ }
+
/**
* Report transaction(s).
*

0 comments on commit e4d4911

Please sign in to comment.