PayPal\Core\PayPalCredentialManager::getCredentialObject PHP Method

getCredentialObject() public method

Obtain Credential Object based on UserId provided.
public getCredentialObject ( null $userId = null ) : OAuthTokenCredential
$userId null
return PayPal\Auth\OAuthTokenCredential
    public function getCredentialObject($userId = null)
    {
        if ($userId == null && array_key_exists($this->defaultAccountName, $this->credentialHashmap)) {
            $credObj = $this->credentialHashmap[$this->defaultAccountName];
        } elseif (array_key_exists($userId, $this->credentialHashmap)) {
            $credObj = $this->credentialHashmap[$userId];
        }
        if (empty($credObj)) {
            throw new PayPalInvalidCredentialException("Credential not found for " . ($userId ? $userId : " default user") . ". Please make sure your configuration/APIContext has credential information");
        }
        return $credObj;
    }

Usage Example

 /**
  * @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);
 }