forked from LiveCarta/PayPal-PHP-SDK
Adding resetRequestId in ApiContext to enable multiple create calls in succession
This commit is contained in:
@@ -32,6 +32,19 @@ class ApiContext
|
||||
*/
|
||||
private $credential;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param \PayPal\Auth\OAuthTokenCredential $credential
|
||||
* @param string|null $requestId
|
||||
*/
|
||||
public function __construct($credential = null, $requestId = null)
|
||||
{
|
||||
$this->requestId = $requestId;
|
||||
$this->credential = $credential;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Credential
|
||||
*
|
||||
@@ -60,15 +73,16 @@ class ApiContext
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct
|
||||
* Resets the requestId that can be used to set the PayPal-request-id
|
||||
* header used for idempotency. In cases where you need to make multiple create calls
|
||||
* using the same ApiContext object, you need to reset request Id.
|
||||
*
|
||||
* @param \PayPal\Auth\OAuthTokenCredential $credential
|
||||
* @param string|null $requestId
|
||||
* @return string
|
||||
*/
|
||||
public function __construct($credential = null, $requestId = null)
|
||||
public function resetRequestId()
|
||||
{
|
||||
$this->requestId = $requestId;
|
||||
$this->credential = $credential;
|
||||
$this->requestId = $this->generateRequestId();
|
||||
return $this->getrequestId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
37
tests/PayPal/Test/Rest/ApiContextTest.php
Normal file
37
tests/PayPal/Test/Rest/ApiContextTest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
/**
|
||||
* Test class for PPAPIService.
|
||||
*
|
||||
*/
|
||||
class ApiContextTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ApiContext
|
||||
*/
|
||||
public $apiContext;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->apiContext = new ApiContext();
|
||||
}
|
||||
|
||||
public function testGetRequestId()
|
||||
{
|
||||
$requestId = $this->apiContext->getrequestId();
|
||||
$this->assertNotNull($requestId);
|
||||
$this->assertEquals($requestId, $this->apiContext->getrequestId());
|
||||
}
|
||||
|
||||
public function testResetRequestId()
|
||||
{
|
||||
$requestId = $this->apiContext->getrequestId();
|
||||
$newRequestId = $this->apiContext->resetRequestId();
|
||||
$this->assertNotNull($newRequestId);
|
||||
$this->assertNotEquals($newRequestId, $requestId);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user