PayPal\Handler\PPCertificateAuthHandler::handle PHP Method

handle() public method

public handle ( $httpConfig, $request, $options )
    public function handle($httpConfig, $request, $options)
    {
        /** @var PPCertificateCredential $credential */
        $credential = $request->getCredential();
        if (!isset($credential)) {
            return;
        }
        $httpConfig->setSSLCert($credential->getCertificatePath(), $credential->getCertificatePassPhrase());
        $thirdPartyAuth = $credential->getThirdPartyAuthorization();
        switch ($request->getBindingType()) {
            case 'NV':
                if (!$thirdPartyAuth || !$thirdPartyAuth instanceof PPTokenAuthorization) {
                    $httpConfig->addHeader('X-PAYPAL-SECURITY-USERID', $credential->getUserName());
                    $httpConfig->addHeader('X-PAYPAL-SECURITY-PASSWORD', $credential->getPassword());
                    if ($thirdPartyAuth) {
                        $httpConfig->addHeader('X-PAYPAL-SECURITY-SUBJECT', $thirdPartyAuth->getSubject());
                    }
                }
                break;
            case 'SOAP':
                if ($thirdPartyAuth && $thirdPartyAuth instanceof PPTokenAuthorization) {
                    $request->addBindingInfo('securityHeader', '<ns:RequesterCredentials/>');
                } else {
                    $securityHeader = '<ns:RequesterCredentials><ebl:Credentials>';
                    $securityHeader .= '<ebl:Username>' . $credential->getUserName() . '</ebl:Username>';
                    $securityHeader .= '<ebl:Password>' . $credential->getPassword() . '</ebl:Password>';
                    if ($thirdPartyAuth && $thirdPartyAuth instanceof PPSubjectAuthorization) {
                        $securityHeader .= '<ebl:Subject>' . $thirdPartyAuth->getSubject() . '</ebl:Subject>';
                    }
                    $securityHeader .= '</ebl:Credentials></ns:RequesterCredentials>';
                    $request->addBindingInfo('securityHeader', $securityHeader);
                }
                break;
        }
    }

Usage Example

 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);
     }
 }
All Usage Examples Of PayPal\Handler\PPCertificateAuthHandler::handle
PPCertificateAuthHandler