PayPal\Core\PayPalCredentialManager::setCredentialObject PHP Method

setCredentialObject() public method

Sets credential object for users
public setCredentialObject ( OAuthTokenCredential $credential, string | null $userId = null, boolean $default = true )
$credential PayPal\Auth\OAuthTokenCredential
$userId string | null User Id associated with the account
$default boolean If set, it would make it as a default credential for all requests
    public function setCredentialObject(OAuthTokenCredential $credential, $userId = null, $default = true)
    {
        $key = $userId == null ? 'default' : $userId;
        $this->credentialHashmap[$key] = $credential;
        if ($default) {
            $this->defaultAccountName = $key;
        }
        return $this;
    }

Usage Example

コード例 #1
0
 /**
  * @after testGetDefaultCredentialObject
  *
  * @throws \PayPal\Exception\PayPalInvalidCredentialException
  */
 public function testSetCredentialObjectWithoutDefault()
 {
     $authObject = $this->getMockBuilder('\\Paypal\\Auth\\OAuthTokenCredential')->disableOriginalConstructor()->getMock();
     $cred = $this->object->setCredentialObject($authObject, null, false)->getCredentialObject();
     $this->assertNotNull($cred);
     $this->assertNotSame($this->object->getCredentialObject(), $authObject);
 }