428d5e4d9604d676a2563259b1d2bef057c858a0
[WP-Plugins/glm-member-db.git] /
1 <?php
2 namespace PayPal\Handler;
3 use PayPal\Auth\PPTokenAuthorization;
4 use PayPal\Auth\PPSubjectAuthorization;
5 use PayPal\Auth\Oauth\AuthSignature;
6 use PayPal\Core\PPConstants;
7 use PayPal\Handler\IPPHandler;
8
9 class PPSignatureAuthHandler implements IPPHandler {
10                 
11         public function handle($httpConfig, $request, $options) {
12                 
13                 $credential = $request->getCredential();
14                 if(!isset($credential)) {
15                         return;
16                 }               
17                 $thirdPartyAuth = $credential->getThirdPartyAuthorization();
18
19                 switch($request->getBindingType()) {
20                         case 'NV':
21                                 if(!$thirdPartyAuth || !$thirdPartyAuth instanceof PPTokenAuthorization) {
22                                         $httpConfig->addHeader('X-PAYPAL-SECURITY-USERID', $credential->getUserName());
23                                         $httpConfig->addHeader('X-PAYPAL-SECURITY-PASSWORD', $credential->getPassword());
24                                         $httpConfig->addHeader('X-PAYPAL-SECURITY-SIGNATURE', $credential->getSignature());
25                                         if($thirdPartyAuth) {
26                                                 $httpConfig->addHeader('X-PAYPAL-SECURITY-SUBJECT', $thirdPartyAuth->getSubject());
27                                         }
28                                 }
29                                 break;
30                         case 'SOAP':
31                                 if($thirdPartyAuth && $thirdPartyAuth instanceof PPTokenAuthorization) {
32                                         $request->addBindingInfo('securityHeader' , '<ns:RequesterCredentials/>');
33                                 } else {
34                                         $securityHeader = '<ns:RequesterCredentials><ebl:Credentials>';
35                                         $securityHeader .= '<ebl:Username>' . $credential->getUserName() . '</ebl:Username>';
36                                         $securityHeader .= '<ebl:Password>' . $credential->getPassword() . '</ebl:Password>';
37                                         $securityHeader .= '<ebl:Signature>' . $credential->getSignature() . '</ebl:Signature>';                                        
38                                         if($thirdPartyAuth && $thirdPartyAuth instanceof PPSubjectAuthorization) {
39                                                 $securityHeader .= '<ebl:Subject>' . $thirdPartyAuth->getSubject() . '</ebl:Subject>';
40                                         }
41                                         $securityHeader .= '</ebl:Credentials></ns:RequesterCredentials>';
42                                         $request->addBindingInfo('securityHeader' , $securityHeader);                                   
43                                 }
44                                 break;
45                 }
46         }
47         
48 }