Skip to content

Commit

Permalink
Send developer email instead of UUID.
Browse files Browse the repository at this point in the history
Fixes apigee#36.
  • Loading branch information
mxr576 committed Feb 6, 2019
1 parent c751fc6 commit abdf89f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
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;
}
}

0 comments on commit abdf89f

Please sign in to comment.