public function __construct($attribs = [])
{
foreach ($attribs as $kind => $value) {
if ($kind == 'environment') {
CredentialsParser::assertValidEnvironment($value);
$this->_environment = $value;
}
if ($kind == 'merchantId') {
$this->_merchantId = $value;
}
if ($kind == 'publicKey') {
$this->_publicKey = $value;
}
if ($kind == 'privateKey') {
$this->_privateKey = $value;
}
}
if (isset($attribs['clientId']) || isset($attribs['accessToken'])) {
if (isset($attribs['environment']) || isset($attribs['merchantId']) || isset($attribs['publicKey']) || isset($attribs['privateKey'])) {
throw new Exception\Configuration('Cannot mix OAuth credentials (clientId, clientSecret, accessToken) with key credentials (publicKey, privateKey, environment, merchantId).');
}
$parsedCredentials = new CredentialsParser($attribs);
$this->_environment = $parsedCredentials->getEnvironment();
$this->_merchantId = $parsedCredentials->getMerchantId();
$this->_clientId = $parsedCredentials->getClientId();
$this->_clientSecret = $parsedCredentials->getClientSecret();
$this->_accessToken = $parsedCredentials->getAccessToken();
}
}