427487fb5e26f2ee584095c88fc893da86d3b2d8
[WP-Plugins/glm-member-db-registrations.git] /
1 <?php
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;
11
12
13 class PPAuthenticationHandler implements IPPHandler {   
14         
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);
23                                 }
24                                 else {
25                                         $httpConfig->addHeader('X-PAYPAL-AUTHORIZATION', $authSignature);
26                                 }
27                         }
28                         if($credential instanceof PPSignatureCredential) {
29                                 $handler = new PPSignatureAuthHandler($credential);
30                         } else if($credential instanceof PPCertificateCredential) {
31                                 $handler = new PPCertificateAuthHandler($credential);
32                         } else {
33                                 throw new PPInvalidCredentialException();
34                         }
35                         $handler->handle($httpConfig, $request, $options);
36                 }
37         }
38 }