Skip to content

Commit

Permalink
Merge pull request #42 from mxr576/2.x
Browse files Browse the repository at this point in the history
Fixes unsubscribe from a developer rate plan call
  • Loading branch information
mxr576 authored Jan 23, 2019
2 parents 053e6ae + 0e84933 commit 3e23f5e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 9 deletions.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
"ext-reflection": "*",
"fightbulc/moment": "^1.26",
"league/period": "^3.4",
"php-http/cache-plugin": "^1.4",
"php-http/client-common": "^1.9",
"php-http/client-implementation": "^1.0",
"php-http/discovery": "^1.0",
"php-http/httplug": "^1.1",
"php-http/message": "^1.0",
"php-http/message-factory": "^1.0",
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0",
"psr/cache": "^1.0",
"psr/http-message": "^1.0",
"symfony/options-resolver": "^3.4 || ^4.0",
"symfony/property-access": "^3.4 || ^4.0",
Expand All @@ -46,7 +44,7 @@
"phpmetrics/phpmetrics": "^2.3",
"phpunit/phpunit": "^6.4.0",
"sebastian/comparator": "^2.1",
"symfony/cache": "~3.4|~4.0",
"symfony/cache": "~3.4 || ~4.0",
"vimeo/psalm": "^2.0.0"
},
"conflict": {
Expand Down
11 changes: 11 additions & 0 deletions src/Api/Monetization/Controller/AcceptedRatePlanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function updateSubscription(AcceptedRatePlanInterface $acceptedRatePlan,
if (null !== $waveTerminationCharge) {
$tmp['waveTerminationCharge'] = $waveTerminationCharge ? 'true' : 'false';
}
$this->alterRequestPayload($tmp, $acceptedRatePlan);
$payload = json_encode($tmp);
// Update an existing entity.
$response = $this->client->put($this->getEntityEndpointUri($acceptedRatePlan->id()), $payload);
Expand All @@ -147,6 +148,16 @@ abstract protected function buildContextForEntityTransformerInCreate(): array;
*/
abstract protected function getAcceptedRatePlansEndpoint(): UriInterface;

/**
* Allows to alter payload before it gets sent to the API.
*
* @param array $payload
* API request payload.
*/
protected function alterRequestPayload(array &$payload, AcceptedRatePlanInterface $acceptedRatePlan): void
{
}

/**
* Helper function for listing accepted rate plans.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace Apigee\Edge\Api\Monetization\Controller;

use Apigee\Edge\Api\Monetization\Entity\AcceptedRatePlanInterface;
use Apigee\Edge\Api\Monetization\Entity\DeveloperAcceptedRatePlan;
use Apigee\Edge\Api\Monetization\Normalizer\EntityNormalizer;
use Apigee\Edge\ClientInterface;
Expand Down Expand Up @@ -87,4 +88,19 @@ protected function getAcceptedRatePlansEndpoint(): UriInterface
// https://apidocs.apigee.com/monetize/apis/get/organizations/%7Borg_name%7D/developers/%7Bdeveloper_id%7D/developer-accepted-rateplans
return $this->client->getUriFactory()->createUri("/mint/organizations/{$this->organization}/developers/{$this->developer}/developer-accepted-rateplans");
}

/**
* @inheritdoc
*
* @psalm-suppress UndefinedMethod - getDeveloper() exists on the annotated
* interface.
*/
protected function alterRequestPayload(array &$payload, AcceptedRatePlanInterface $acceptedRatePlan): void
{
/* @var \Apigee\Edge\Api\Monetization\Entity\DeveloperAcceptedRatePlanInterface $acceptedRatePlan */
// We should prefer developer email addresses over developer ids
// (UUIDs) when we are communicating with the Monetization API.
// @see https://github.com/apigee/apigee-client-php/issues/36
$payload['developer']['id'] = $acceptedRatePlan->getDeveloper()->getEmail();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Apigee\Edge\Tests\Api\Monetization\Controller;

use Apigee\Edge\Api\Monetization\Controller\RatePlanController;
use Apigee\Edge\Api\Monetization\Entity\RatePlanInterface;
use Apigee\Edge\Tests\Api\Monetization\EntitySerializer\AcceptedRatePlanSerializerValidator;
use Apigee\Edge\Tests\Test\Controller\MockClientAwareTrait;
use Apigee\Edge\Tests\Test\EntitySerializer\EntitySerializerValidatorInterface;
Expand Down Expand Up @@ -61,12 +61,10 @@ public function testGetPaginatedAcceptedRatePlanList(): void
public function testAcceptRatePlan(): void
{
$httpClient = static::mockApiClient()->getMockHttpClient();
/** @var \Apigee\Edge\Api\Monetization\Controller\RatePlanControllerInterface $ratePlanController */
$ratePlanController = new RatePlanController('phpunit', static::defaultTestOrganization(static::defaultAPIClient()), static::defaultAPIClient());
/** @var \Apigee\Edge\Api\Monetization\Controller\AcceptedRatePlanControllerInterface $acceptedController */
$acceptedController = static::entityController(static::mockApiClient());
/** @var \Apigee\Edge\Api\Monetization\Entity\RatePlanInterface $ratePlan */
$ratePlan = $ratePlanController->load('standard-rev');
$ratePlan = $this->getRatePlanToAccept();
$startDate = new \DateTimeImmutable('now');
$response = $this->getAcceptRatePlanResponse();
$httpClient->addResponse($response);
Expand Down Expand Up @@ -145,6 +143,11 @@ public function testUpdateSubscription(): void
*/
abstract protected function getAcceptRatePlanResponse(): ResponseInterface;

/**
* @return \Apigee\Edge\Api\Monetization\Entity\RatePlanInterface
*/
abstract protected function getRatePlanToAccept(): RatePlanInterface;

/**
* @inheritdoc
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
namespace Apigee\Edge\Tests\Api\Monetization\Controller;

use Apigee\Edge\Api\Monetization\Controller\CompanyAcceptedRatePlanController;
use Apigee\Edge\Api\Monetization\Controller\RatePlanController;
use Apigee\Edge\Api\Monetization\Entity\RatePlanInterface;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Tests\Test\Controller\EntityControllerTester;
use Apigee\Edge\Tests\Test\Controller\EntityControllerTesterInterface;
Expand Down Expand Up @@ -55,4 +57,17 @@ protected function getAcceptRatePlanResponse(): ResponseInterface

return (new FileSystemResponseFactory())->createResponseForRequest(new Request('GET', "v1/mint/organizations/phpunit/companies/{$id}/developer-rateplans/phpunit"));
}

/**
* @inheritdoc
*/
protected function getRatePlanToAccept(): RatePlanInterface
{
/** @var \Apigee\Edge\Api\Monetization\Controller\RatePlanControllerInterface $ratePlanController */
$ratePlanController = new RatePlanController('phpunit', static::defaultTestOrganization(static::defaultAPIClient()), static::defaultAPIClient());
/** @var \Apigee\Edge\Api\Monetization\Entity\CompanyRatePlanInterface $ratePlan */
$ratePlan = $ratePlanController->load('company-rev');

return $ratePlan;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
namespace Apigee\Edge\Tests\Api\Monetization\Controller;

use Apigee\Edge\Api\Monetization\Controller\DeveloperAcceptedRatePlanController;
use Apigee\Edge\Api\Monetization\Controller\RatePlanController;
use Apigee\Edge\Api\Monetization\Entity\RatePlanInterface;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Tests\Test\Controller\EntityControllerTester;
use Apigee\Edge\Tests\Test\Controller\EntityControllerTesterInterface;
Expand Down Expand Up @@ -55,4 +57,17 @@ protected function getAcceptRatePlanResponse(): ResponseInterface

return (new FileSystemResponseFactory())->createResponseForRequest(new Request('GET', "v1/mint/organizations/phpunit/developers/{$id}/developer-rateplans/phpunit"));
}

/**
* @inheritdoc
*/
protected function getRatePlanToAccept(): RatePlanInterface
{
/** @var \Apigee\Edge\Api\Monetization\Controller\RatePlanControllerInterface $ratePlanController */
$ratePlanController = new RatePlanController('phpunit', static::defaultTestOrganization(static::defaultAPIClient()), static::defaultAPIClient());
/** @var \Apigee\Edge\Api\Monetization\Entity\DeveloperRatePlanInterface $ratePlan */
$ratePlan = $ratePlanController->load('developer-rev');

return $ratePlan;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{GET
{
"created": "2018-09-25 23:42:49",
"developer": {
"approxTaxRate": 123.4567,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{GET
{
"created": "2018-09-25 23:42:49",
"developer": {
"approxTaxRate": 123.4567,
Expand Down

0 comments on commit 3e23f5e

Please sign in to comment.