-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feature for Apigee X monetization phase2 (#182)
- Loading branch information
1 parent
daa25ab
commit e86bd31
Showing
25 changed files
with
1,224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
namespace Apigee\Edge\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\ApigeeX\Entity\BillingTypeInterface; | ||
use Apigee\Edge\Api\ApigeeX\Serializer\BillingTypeSerializer; | ||
use Apigee\Edge\Api\Monetization\Controller\EntityController; | ||
use Apigee\Edge\ClientInterface; | ||
use Apigee\Edge\Controller\EntityListingControllerTrait; | ||
use Apigee\Edge\Controller\EntityLoadOperationControllerTrait; | ||
use Apigee\Edge\Serializer\EntitySerializerInterface; | ||
|
||
abstract class BillingTypeController extends EntityController implements BillingTypeControllerInterface | ||
{ | ||
use EntityListingControllerTrait; | ||
use EntityLoadOperationControllerTrait; | ||
use PaginatedListingHelperTrait; | ||
|
||
/** | ||
* BillingTypeController constructor. | ||
* | ||
* @param string $organization | ||
* @param \Apigee\Edge\ClientInterface $client | ||
* @param \Apigee\Edge\Serializer\EntitySerializerInterface|null $entitySerializer | ||
*/ | ||
public function __construct(string $organization, ClientInterface $client, ?EntitySerializerInterface $entitySerializer = null) | ||
{ | ||
$entitySerializer = $entitySerializer ?? new BillingTypeSerializer(); | ||
parent::__construct($organization, $client, $entitySerializer); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAllBillingDetails(): BillingTypeInterface | ||
{ | ||
return $this->getDeveloperBillingType(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function updateBillingType($billingtype): BillingTypeInterface | ||
{ | ||
$response = $this->client->put( | ||
$this->getBaseEndpointUri(), | ||
(string) json_encode((object) [ | ||
'billingType' => $billingtype, | ||
]) | ||
); | ||
|
||
return $this->entitySerializer->deserialize( | ||
(string) $response->getBody(), | ||
$this->getEntityClass(), | ||
'json' | ||
); | ||
} | ||
|
||
/** | ||
* Helper function for getting the billing type. | ||
* | ||
* @return \Apigee\Edge\Api\ApigeeX\Entity\BillingTypeInterface | ||
*/ | ||
private function getDeveloperBillingType(): BillingTypeInterface | ||
{ | ||
$item = $this->getRawSingleList($this->getBaseEndpointUri()); | ||
|
||
/** @var \Apigee\Edge\Entity\EntityInterface $tmp */ | ||
$tmp = $this->getEntitySerializer()->denormalize( | ||
$item, | ||
BillingTypeInterface::class, | ||
'json' | ||
); | ||
|
||
return $tmp; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Api/ApigeeX/Controller/BillingTypeControllerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
namespace Apigee\Edge\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\ApigeeX\Entity\BillingTypeInterface; | ||
use Apigee\Edge\Controller\EntityControllerInterface; | ||
use Apigee\Edge\Controller\EntityLoadOperationControllerInterface; | ||
|
||
/** | ||
* Interface BillingTypeControllerInterface. | ||
* | ||
* TODO: Add reference documentation link | ||
*/ | ||
interface BillingTypeControllerInterface extends | ||
EntityControllerInterface, | ||
EntityLoadOperationControllerInterface | ||
{ | ||
/** | ||
* Gets the billingtype. | ||
* | ||
* @return \Apigee\Edge\Api\ApigeeX\Entity\BillingTypeInterface | ||
*/ | ||
public function getAllBillingDetails(): BillingTypeInterface; | ||
|
||
/** | ||
* Update the billing type of the developer. | ||
* | ||
* @param $billingtype | ||
* Billing type that is switched to. | ||
*/ | ||
public function updateBillingType($billingtype): BillingTypeInterface; | ||
} |
66 changes: 66 additions & 0 deletions
66
src/Api/ApigeeX/Controller/DeveloperBillingTypeController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
namespace Apigee\Edge\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\ApigeeX\Entity\DeveloperBillingType; | ||
use Apigee\Edge\ClientInterface; | ||
use Apigee\Edge\Serializer\EntitySerializerInterface; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
class DeveloperBillingTypeController extends BillingTypeController | ||
{ | ||
/** | ||
* Email address of a developer. | ||
* | ||
* @var string | ||
*/ | ||
protected $developer; | ||
|
||
/** | ||
* DeveloperBillingTypeController constructor. | ||
* | ||
* @param string $developerId | ||
* @param string $organization | ||
* @param \Apigee\Edge\ClientInterface $client | ||
* @param \Apigee\Edge\Serializer\EntitySerializerInterface|null $entitySerializer | ||
*/ | ||
public function __construct(string $developerId, string $organization, ClientInterface $client, ?EntitySerializerInterface $entitySerializer = null) | ||
{ | ||
parent::__construct($organization, $client, $entitySerializer); | ||
$this->developer = $developerId; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getBaseEndpointUri(): UriInterface | ||
{ | ||
$developerId = rawurlencode($this->developer); | ||
|
||
return $this->client->getUriFactory()->createUri("/organizations/{$this->organization}/developers/{$developerId}/monetizationConfig"); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getEntityClass(): string | ||
{ | ||
return DeveloperBillingType::class; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/Api/ApigeeX/Controller/DeveloperPrepaidBalanceController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
namespace Apigee\Edge\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\ClientInterface; | ||
use Apigee\Edge\Serializer\EntitySerializerInterface; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
class DeveloperPrepaidBalanceController extends PrepaidBalanceController implements DeveloperPrepaidBalanceControllerInterface | ||
{ | ||
/** | ||
* Email address of a developer. | ||
* | ||
* @var string | ||
*/ | ||
protected $developerId; | ||
|
||
/** | ||
* DeveloperPrepaidBalanceController constructor. | ||
* | ||
* @param string $developerId | ||
* @param string $organization | ||
* @param \Apigee\Edge\ClientInterface $client | ||
* @param \Apigee\Edge\Serializer\EntitySerializerInterface|null $entitySerializer | ||
*/ | ||
public function __construct(string $developerId, string $organization, ClientInterface $client, ?EntitySerializerInterface $entitySerializer = null) | ||
{ | ||
parent::__construct($organization, $client, $entitySerializer); | ||
$this->developerId = $developerId; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getBaseEndpointUri(): UriInterface | ||
{ | ||
$developerId = rawurlencode($this->developerId); | ||
|
||
return $this->client->getUriFactory()->createUri("/organizations/{$this->organization}/developers/{$developerId}/balance:credit"); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getPrepaidBalanceEndpoint(): UriInterface | ||
{ | ||
$developerId = rawurlencode($this->developerId); | ||
|
||
return $this->client->getUriFactory()->createUri("/organizations/{$this->organization}/developers/{$developerId}/balance"); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Api/ApigeeX/Controller/DeveloperPrepaidBalanceControllerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
namespace Apigee\Edge\Api\ApigeeX\Controller; | ||
|
||
/** | ||
* Interface DeveloperPrepaidBalanceControllerInterface. | ||
*/ | ||
interface DeveloperPrepaidBalanceControllerInterface extends PrepaidBalanceControllerInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.