2 namespace PayPal\Handler;
3 use PayPal\Auth\PPSignatureCredential;
4 use PayPal\Auth\PPCertificateCredential;
5 use PayPal\Auth\PPTokenAuthorization;
6 use PayPal\Auth\Oauth\AuthSignature;
7 use PayPal\Handler\IPPHandler;
8 use PayPal\Handler\PPSignatureAuthHandler;
9 use PayPal\Handler\PPCertificateAuthHandler;
10 use PayPal\Exception\PPInvalidCredentialException;
13 class PPAuthenticationHandler implements IPPHandler {
15 public function handle($httpConfig, $request, $options) {
16 $credential = $request->getCredential();
17 if(isset($credential)) {
18 $thirdPartyAuth = $credential->getThirdPartyAuthorization();
19 if($thirdPartyAuth && $thirdPartyAuth instanceof PPTokenAuthorization) {
20 $authSignature = AuthSignature::generateFullAuthString($credential->getUsername(), $credential->getPassword(), $thirdPartyAuth->getAccessToken(), $thirdPartyAuth->getTokenSecret(), $httpConfig->getMethod(), $httpConfig->getUrl());
21 if($options['port'] == 'PayPalAPI' || $options['port'] == 'PayPalAPIAA') {
22 $httpConfig->addHeader('X-PP-AUTHORIZATION', $authSignature);
25 $httpConfig->addHeader('X-PAYPAL-AUTHORIZATION', $authSignature);
28 if($credential instanceof PPSignatureCredential) {
29 $handler = new PPSignatureAuthHandler($credential);
30 } else if($credential instanceof PPCertificateCredential) {
31 $handler = new PPCertificateAuthHandler($credential);
33 throw new PPInvalidCredentialException();
35 $handler->handle($httpConfig, $request, $options);