PayPal\Handler\PPAuthenticationHandler::handle PHP Метод

handle() публичный Метод

public handle ( $httpConfig, $request, $options )
    public function handle($httpConfig, $request, $options)
    {
        $credential = $request->getCredential();
        if (isset($credential)) {
            $thirdPartyAuth = $credential->getThirdPartyAuthorization();
            if ($thirdPartyAuth && $thirdPartyAuth instanceof PPTokenAuthorization) {
                $authSignature = AuthSignature::generateFullAuthString($credential->getUsername(), $credential->getPassword(), $thirdPartyAuth->getAccessToken(), $thirdPartyAuth->getTokenSecret(), $httpConfig->getMethod(), $httpConfig->getUrl());
                if (isset($options['port']) && ($options['port'] == 'PayPalAPI' || $options['port'] == 'PayPalAPIAA')) {
                    $httpConfig->addHeader('X-PP-AUTHORIZATION', $authSignature);
                } else {
                    $httpConfig->addHeader('X-PAYPAL-AUTHORIZATION', $authSignature);
                }
            }
            if ($credential instanceof PPSignatureCredential) {
                $handler = new PPSignatureAuthHandler($credential);
            } else {
                if ($credential instanceof PPCertificateCredential) {
                    $handler = new PPCertificateAuthHandler($credential);
                } else {
                    throw new PPInvalidCredentialException();
                }
            }
            $handler->handle($httpConfig, $request, $options);
        }
    }

Usage Example

 /**
  * @test
  */
 public function testValidConfiguration()
 {
     $credential = new PPSignatureCredential('user', 'pass', 'sign');
     $credential->setThirdPartyAuthorization(new PPTokenAuthorization('accessToken', 'tokenSecret'));
     $options = array('config' => array('mode' => 'sandbox'), 'serviceName' => 'DoExpressCheckout', 'port' => 'PayPalAPI');
     $req = new PPRequest(new StdClass(), 'SOAP');
     $req->setCredential($credential);
     $httpConfig = new PPHttpConfig('http://api.paypal.com');
     $handler = new PPAuthenticationHandler();
     $handler->handle($httpConfig, $req, $options);
     $this->assertArrayHasKey('X-PP-AUTHORIZATION', $httpConfig->getHeaders());
     $options['port'] = 'abc';
     $handler->handle($httpConfig, $req, $options);
     $this->assertArrayHasKey('X-PAYPAL-AUTHORIZATION', $httpConfig->getHeaders());
     unset($options['port']);
     $handler->handle($httpConfig, $req, $options);
     $this->assertArrayHasKey('X-PAYPAL-AUTHORIZATION', $httpConfig->getHeaders());
 }
All Usage Examples Of PayPal\Handler\PPAuthenticationHandler::handle
PPAuthenticationHandler