Stop auto-generating PayPal-Request-Id

- Allow manual setting of PayPal-Request-Id
This commit is contained in:
brluk and dkatz
2016-12-13 20:47:37 +00:00
parent 37569ce82c
commit a2c75921cb
2 changed files with 27 additions and 7 deletions

View File

@@ -85,11 +85,17 @@ class ApiContext
*/ */
public function getRequestId() public function getRequestId()
{ {
if ($this->requestId == null) { return $this->requestId;
$this->requestId = $this->generateRequestId();
} }
return $this->requestId; /**
* Sets the request ID
*
* @param string $requestId the PayPal-Request-Id value to use
*/
public function setRequestId($requestId)
{
$this->requestId = $requestId;
} }
/** /**

View File

@@ -22,13 +22,27 @@ class ApiContextTest extends PHPUnit_Framework_TestCase
public function testGetRequestId() public function testGetRequestId()
{ {
$requestId = $this->apiContext->getRequestId(); $requestId = $this->apiContext->getRequestId();
$this->assertNotNull($requestId); $this->assertNull($requestId);
$this->assertEquals($requestId, $this->apiContext->getRequestId()); }
public function testSetRequestId()
{
$this->assertNull($this->apiContext->getRequestId());
$expectedRequestId = 'random-value';
$this->apiContext->setRequestId($expectedRequestId);
$requestId = $this->apiContext->getRequestId();
$this->assertEquals($expectedRequestId, $requestId);
} }
public function testResetRequestId() public function testResetRequestId()
{ {
$requestId = $this->apiContext->getRequestId(); $this->assertNull($this->apiContext->getRequestId());
$requestId = $this->apiContext->resetRequestId();
$this->assertNotNull($requestId);
// Tests that another resetRequestId call will generate a new ID
$newRequestId = $this->apiContext->resetRequestId(); $newRequestId = $this->apiContext->resetRequestId();
$this->assertNotNull($newRequestId); $this->assertNotNull($newRequestId);
$this->assertNotEquals($newRequestId, $requestId); $this->assertNotEquals($newRequestId, $requestId);