本文整理匯總了PHP中PayPal\Rest\ApiContext::getRequestId方法的典型用法代碼示例。如果您正苦於以下問題:PHP ApiContext::getRequestId方法的具體用法?PHP ApiContext::getRequestId怎麽用?PHP ApiContext::getRequestId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PayPal\Rest\ApiContext
的用法示例。
在下文中一共展示了ApiContext::getRequestId方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: handle
/**
* Handle
*
* @param \PayPal\Core\PPHttpConfig $httpConfig
* @param \PayPal\Core\PPRequest $request
* @param array $options
*
* @throws \PayPal\Exception\PPInvalidCredentialException
* @throws \PayPal\Exception\PPMissingCredentialException
*/
public function handle($httpConfig, $request, $options)
{
$credential = $this->apiContext->getCredential();
$config = $this->apiContext->getConfig();
if ($credential == null) {
// Try picking credentials from the config file
$credMgr = PPCredentialManager::getInstance($config);
$credValues = $credMgr->getCredentialObject();
if (!is_array($credValues)) {
throw new PPMissingCredentialException("Empty or invalid credentials passed");
}
$credential = new OAuthTokenCredential($credValues['clientId'], $credValues['clientSecret']);
}
if ($credential == null || !$credential instanceof OAuthTokenCredential) {
throw new PPInvalidCredentialException("Invalid credentials passed");
}
$httpConfig->setUrl(rtrim(trim($this->_getEndpoint($config)), '/') . (isset($options['path']) ? $options['path'] : ''));
if (!array_key_exists("User-Agent", $httpConfig->getHeaders())) {
$httpConfig->addHeader("User-Agent", PPUserAgent::getValue(self::$sdkName, self::$sdkVersion));
}
if (!is_null($credential) && $credential instanceof OAuthTokenCredential) {
$httpConfig->addHeader('Authorization', "Bearer " . $credential->getAccessToken($config));
}
if ($httpConfig->getMethod() == 'POST' || $httpConfig->getMethod() == 'PUT') {
$httpConfig->addHeader('PayPal-Request-Id', $this->apiContext->getRequestId());
}
}
示例2: handle
/**
* @param PayPalHttpConfig $httpConfig
* @param string $request
* @param mixed $options
* @return mixed|void
* @throws PayPalConfigurationException
* @throws PayPalInvalidCredentialException
* @throws PayPalMissingCredentialException
*/
public function handle($httpConfig, $request, $options)
{
$credential = $this->apiContext->getCredential();
$config = $this->apiContext->getConfig();
if ($credential == null) {
// Try picking credentials from the config file
$credMgr = PayPalCredentialManager::getInstance($config);
$credValues = $credMgr->getCredentialObject();
if (!is_array($credValues)) {
throw new PayPalMissingCredentialException("Empty or invalid credentials passed");
}
$credential = new OAuthTokenCredential($credValues['clientId'], $credValues['clientSecret']);
}
if ($credential == null || !$credential instanceof OAuthTokenCredential) {
throw new PayPalInvalidCredentialException("Invalid credentials passed");
}
$httpConfig->setUrl(rtrim(trim($this->_getEndpoint($config)), '/') . (isset($options['path']) ? $options['path'] : ''));
// Overwrite Expect Header to disable 100 Continue Issue
$httpConfig->addHeader("Expect", null);
if (!array_key_exists("User-Agent", $httpConfig->getHeaders())) {
$httpConfig->addHeader("User-Agent", PayPalUserAgent::getValue(PayPalConstants::SDK_NAME, PayPalConstants::SDK_VERSION));
}
if (!is_null($credential) && $credential instanceof OAuthTokenCredential && is_null($httpConfig->getHeader('Authorization'))) {
$httpConfig->addHeader('Authorization', "Bearer " . $credential->getAccessToken($config), false);
}
if ($httpConfig->getMethod() == 'POST' || $httpConfig->getMethod() == 'PUT') {
$httpConfig->addHeader('PayPal-Request-Id', $this->apiContext->getRequestId());
}
// Add any additional Headers that they may have provided
$headers = $this->apiContext->getRequestHeaders();
foreach ($headers as $key => $value) {
$httpConfig->addHeader($key, $value);
}
}
示例3: testResetRequestId
public function testResetRequestId()
{
$requestId = $this->apiContext->getRequestId();
$newRequestId = $this->apiContext->resetRequestId();
$this->assertNotNull($newRequestId);
$this->assertNotEquals($newRequestId, $requestId);
}