PayPalCredentialManager holds all the credential information in one place.
コード例 #1
0
ファイル: RestHandler.php プロジェクト: r8filipe/LAPR
 /**
  * @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);
     }
 }
コード例 #2
0
 /**
  * @test
  */
 public function testGetRestCredentialObject()
 {
     $cred = $this->object->getCredentialObject('acct1');
     $this->assertNotNull($cred);
     $this->assertAttributeEquals($this->config['acct1.ClientId'], 'clientId', $cred);
     $this->assertAttributeEquals($this->config['acct1.ClientSecret'], 'clientSecret', $cred);
 }
コード例 #3
0
ファイル: ApiContext.php プロジェクト: r8filipe/LAPR
 /**
  * Get Credential
  *
  * @return \PayPal\Auth\OAuthTokenCredential
  */
 public function getCredential()
 {
     if ($this->credential == null) {
         return PayPalCredentialManager::getInstance()->getCredentialObject();
     }
     return $this->credential;
 }
コード例 #4
0
ファイル: Setup.php プロジェクト: johnmicahmiguel/yodaphp
 public static function SetUpForFunctionalTests(\PHPUnit_Framework_TestCase &$test)
 {
     $context = new ApiContext();
     $context->setConfig(array('mode' => 'sandbox', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => true, 'log.FileName' => '../PayPal.log', 'log.LogLevel' => 'FINE', 'validation.level' => 'warning'));
     PayPalCredentialManager::getInstance()->setCredentialObject(PayPalCredentialManager::getInstance()->getCredentialObject('acct1'));
     self::$mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
     if (self::$mode != 'sandbox') {
         // Mock PayPalRest Caller if mode set to mock
         $test->mockPayPalRestCall = $test->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
         $test->mockPayPalRestCall->expects($test->any())->method('execute')->will($test->returnValue($test->response));
     }
 }
コード例 #5
0
ファイル: Setup.php プロジェクト: Roc4rdho/app
 public static function SetUpForFunctionalTests(\PHPUnit_Framework_TestCase &$test)
 {
     $configs = array('mode' => 'sandbox', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => true, 'log.FileName' => '../PayPal.log', 'log.LogLevel' => 'FINE', 'validation.level' => 'log');
     $test->apiContext = new ApiContext(new OAuthTokenCredential('AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS', 'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL'));
     $test->apiContext->setConfig($configs);
     //PayPalConfigManager::getInstance()->addConfigFromIni(__DIR__. '/../../../sdk_config.ini');
     //PayPalConfigManager::getInstance()->addConfigs($configs);
     PayPalCredentialManager::getInstance()->setCredentialObject(PayPalCredentialManager::getInstance()->getCredentialObject('acct1'));
     self::$mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
     if (self::$mode != 'sandbox') {
         // Mock PayPalRest Caller if mode set to mock
         $test->mockPayPalRestCall = $test->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
         $test->mockPayPalRestCall->expects($test->any())->method('execute')->will($test->returnValue($test->response));
     }
 }