Permalink
Browse files

Added support for service_id

  • Loading branch information...
1 parent 508ab02 commit 70f0ba60a6f250443cd7d7772685b414b0bf1123 @solso solso committed Apr 24, 2012
Showing with 22 additions and 9 deletions.
  1. +22 −9 lib/ThreeScaleClient.php
View
@@ -66,6 +66,7 @@ public function getHost() {
*
* @param $appId application id.
* @param $appKey secret application key.
+ * @param $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
@@ -82,6 +83,7 @@ public function getHost() {
* <code>
* <?php
* $response = $client->authorize('app-id', 'app-key');
+ * // or $response = $client->authorize('app-id', 'app-key', 'service_id');
*
* if ($response->isSuccess()) {
* // ok.
@@ -91,14 +93,18 @@ public function getHost() {
* ?>
* </code>
*/
- public function authorize($appId, $appKey = null) {
+ public function authorize($appId, $appKey = null, $serviceId = 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;
+ }
+
$httpResponse = $this->httpClient->get($url, $params);
if (self::isHttpSuccess($httpResponse)) {
@@ -112,6 +118,7 @@ public function authorize($appId, $appKey = null) {
* Authorize an application.
*
* @param $userKey user key.
+ * @param $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
@@ -128,6 +135,7 @@ public function authorize($appId, $appKey = null) {
* <code>
* <?php
* $response = $client->authorize_with_user_key('user-key');
+ * // or $response = $client->authorize_with_user_key('user-key','service_id');
*
* if ($response->isSuccess()) {
* // ok.
@@ -138,10 +146,13 @@ public function authorize($appId, $appKey = null) {
* </code>
*/
- public function authorize_with_user_key($userKey) {
+ public function authorize_with_user_key($userKey, $serviceId = null) {
$url = "http://" . $this->getHost() . "/transactions/authorize.xml";
$params = array('provider_key' => $this->getProviderKey(), 'user_key' => $userKey);
-
+
+ if ($serviceId) {
+ $params['service_id'] = $serviceId;
+ }
$httpResponse = $this->httpClient->get($url, $params);
@@ -158,7 +169,6 @@ public function authorize_with_user_key($userKey) {
*
* @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
@@ -175,6 +185,7 @@ public function authorize_with_user_key($userKey) {
* <code>
* <?php
* $response = $client->authorize('app-id', 'app-key');
+ * // or $response = $client->authorize('app-id', 'app-key','service_id');
*
* if ($response->isSuccess()) {
* // ok.
@@ -185,7 +196,7 @@ public function authorize_with_user_key($userKey) {
* </code>
*/
- public function authrep($appId, $appKey = null, $usage = null, $userId = null, $object = null, $no_body = null) {
+ public function authrep($appId, $appKey = null, $usage = null, $userId = null, $object = null, $no_body = null, $serviceId = null) {
$url = "http://" . $this->getHost() . "/transactions/authrep.xml";
$params = array('provider_key' => $this->getProviderKey(), 'app_id' => $appId);
@@ -195,7 +206,7 @@ public function authrep($appId, $appKey = null, $usage = null, $userId = null, $
if ($object) $params['object'] = $object;
if ($usage) $params['usage'] = $usage;
if ($no_body) $params['no_body'] = $no_body;
-
+ if ($serviceId) $params['service_id'] = $serviceId;
$httpResponse = $this->httpClient->get($url, $params);
@@ -207,7 +218,7 @@ public function authrep($appId, $appKey = null, $usage = null, $userId = null, $
}
- public function authrep_with_user_key($userKey, $usage = null, $userId = null, $object = null, $no_body = null) {
+ public function authrep_with_user_key($userKey, $usage = null, $userId = null, $object = null, $no_body = null, $serviceId = null) {
$url = "http://" . $this->getHost() . "/transactions/authrep.xml";
$params = array('provider_key' => $this->getProviderKey(), 'user_key' => $userKey);
@@ -216,6 +227,7 @@ public function authrep_with_user_key($userKey, $usage = null, $userId = null, $
if ($object) $params['object'] = $object;
if ($usage) $params['usage'] = $usage;
if ($no_body) $params['no_body'] = $no_body;
+ if ($serviceId) $params['service_id'] = $serviceId;
$httpResponse = $this->httpClient->get($url, $params);
@@ -283,7 +295,7 @@ public function authrep_with_user_key($userKey, $usage = null, $userId = null, $
* ?>
* </code>
*/
- public function report($transactions) {
+ public function report($transactions, $serviceId = null) {
if (empty($transactions)) {
throw new InvalidArgumentException('no transactions to report');
}
@@ -292,6 +304,7 @@ public function report($transactions) {
$params = array();
$params['provider_key'] = urlencode($this->getProviderKey());
+ if ($serviceId) $params['service_id'] = urleconde($serviceId);
$params['transactions'] = $this->encodeTransactions($transactions);
$httpResponse = $this->httpClient->post($url, $params);

0 comments on commit 70f0ba6

Please sign in to comment.