diff --git a/composer.json b/composer.json index 108ab77e..46615a65 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ "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", @@ -26,7 +25,6 @@ "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", @@ -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": { diff --git a/src/Api/Monetization/Controller/AcceptedRatePlanController.php b/src/Api/Monetization/Controller/AcceptedRatePlanController.php index f9257bfc..62d4e091 100644 --- a/src/Api/Monetization/Controller/AcceptedRatePlanController.php +++ b/src/Api/Monetization/Controller/AcceptedRatePlanController.php @@ -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); @@ -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. * diff --git a/src/Api/Monetization/Controller/DeveloperAcceptedRatePlanController.php b/src/Api/Monetization/Controller/DeveloperAcceptedRatePlanController.php index e169ec3f..48489ef6 100644 --- a/src/Api/Monetization/Controller/DeveloperAcceptedRatePlanController.php +++ b/src/Api/Monetization/Controller/DeveloperAcceptedRatePlanController.php @@ -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; @@ -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(); + } } diff --git a/tests/Api/Monetization/Controller/AcceptedRatePlanControllerTestBase.php b/tests/Api/Monetization/Controller/AcceptedRatePlanControllerTestBase.php index 2c06d416..3e67ffc2 100644 --- a/tests/Api/Monetization/Controller/AcceptedRatePlanControllerTestBase.php +++ b/tests/Api/Monetization/Controller/AcceptedRatePlanControllerTestBase.php @@ -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; @@ -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); @@ -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 */ diff --git a/tests/Api/Monetization/Controller/CompanyAcceptedRatePlanControllerTest.php b/tests/Api/Monetization/Controller/CompanyAcceptedRatePlanControllerTest.php index e4d10e7e..65ceb9ed 100644 --- a/tests/Api/Monetization/Controller/CompanyAcceptedRatePlanControllerTest.php +++ b/tests/Api/Monetization/Controller/CompanyAcceptedRatePlanControllerTest.php @@ -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; @@ -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; + } } diff --git a/tests/Api/Monetization/Controller/DeveloperAcceptedRatePlanControllerTest.php b/tests/Api/Monetization/Controller/DeveloperAcceptedRatePlanControllerTest.php index 86dc5edc..bbf8ec39 100644 --- a/tests/Api/Monetization/Controller/DeveloperAcceptedRatePlanControllerTest.php +++ b/tests/Api/Monetization/Controller/DeveloperAcceptedRatePlanControllerTest.php @@ -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; @@ -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; + } } diff --git a/tests/offline-test-data/v1/mint/organizations/phpunit/companies/phpunit/developer-rateplans/phpunit/POST.json b/tests/offline-test-data/v1/mint/organizations/phpunit/companies/phpunit/developer-rateplans/phpunit/POST.json index e84d7c16..e110967b 100644 --- a/tests/offline-test-data/v1/mint/organizations/phpunit/companies/phpunit/developer-rateplans/phpunit/POST.json +++ b/tests/offline-test-data/v1/mint/organizations/phpunit/companies/phpunit/developer-rateplans/phpunit/POST.json @@ -1,4 +1,4 @@ -{GET +{ "created": "2018-09-25 23:42:49", "developer": { "approxTaxRate": 123.4567, diff --git a/tests/offline-test-data/v1/mint/organizations/phpunit/companies/phpunit/developer-rateplans/phpunit/PUT.json b/tests/offline-test-data/v1/mint/organizations/phpunit/companies/phpunit/developer-rateplans/phpunit/PUT.json index e84d7c16..e110967b 100644 --- a/tests/offline-test-data/v1/mint/organizations/phpunit/companies/phpunit/developer-rateplans/phpunit/PUT.json +++ b/tests/offline-test-data/v1/mint/organizations/phpunit/companies/phpunit/developer-rateplans/phpunit/PUT.json @@ -1,4 +1,4 @@ -{GET +{ "created": "2018-09-25 23:42:49", "developer": { "approxTaxRate": 123.4567,