8f563661aaa221814eb7ef88b478ef17f60facf4
[WP-Plugins/glm-member-db-registrations.git] /
1 <?php
2 namespace PayPal\Handler;
3 use PayPal\Exception\PPConfigurationException;
4 use PayPal\Auth\PPSignatureCredential;
5 use PayPal\Auth\PPCertificateCredential;
6 use PayPal\Core\PPConstants;
7 class PPMerchantServiceHandler extends PPGenericServiceHandler {
8         private $endpoint;
9         private $config;
10         public function handle($httpConfig, $request, $options) {
11                 parent::handle($httpConfig, $request, $options);
12                 $this->config = $options['config'];
13                 $credential = $request->getCredential();
14                 if($options['port'] != null && isset($this->config['service.EndPoint.'.$options['port']]))
15                 {
16                         $this->endpoint = $this->config['service.EndPoint.'.$options['port']];
17                 }
18                 // for backward compatibilty (for those who are using old config files with 'service.EndPoint')
19                 else if (isset($this->config['service.EndPoint']))
20                 {
21                         $this->endpoint = $this->config['service.EndPoint'];
22                 }
23                 else if (isset($this->config['mode']))
24                 {
25                         if(strtoupper($this->config['mode']) == 'SANDBOX')
26                         {
27                                 if($credential instanceof PPSignatureCredential)
28                                 {
29                                         $this->endpoint = PPConstants::MERCHANT_SANDBOX_SIGNATURE_ENDPOINT;
30                                 }
31                                 else if($credential instanceof PPCertificateCredential)
32                                 {
33                                         $this->endpoint = PPConstants::MERCHANT_SANDBOX_CERT_ENDPOINT;
34                                 }
35                         }
36                         else if(strtoupper($this->config['mode']) == 'LIVE')
37                         {
38                         if($credential instanceof PPSignatureCredential)
39                                 {
40                                         $this->endpoint = PPConstants::MERCHANT_LIVE_SIGNATURE_ENDPOINT;
41                                 }
42                                 else if($credential instanceof PPCertificateCredential)
43                                 {
44                                         $this->endpoint = PPConstants::MERCHANT_LIVE_CERT_ENDPOINT;
45                                 }
46                         }
47                 }
48                 else
49                 {
50                         throw new PPConfigurationException('endpoint Not Set');
51                 }
52                 
53                 if($options['serviceBinding'] == 'SOAP' )
54                 {
55                         $httpConfig->setUrl($this->endpoint);
56                 }
57                 else 
58                 {
59                         throw new PPConfigurationException('expecting service binding to be SOAP');
60                 }
61                 
62                 $request->addBindingInfo("namespace", "xmlns:ns=\"urn:ebay:api:PayPalAPI\" xmlns:ebl=\"urn:ebay:apis:eBLBaseComponents\" xmlns:cc=\"urn:ebay:apis:CoreComponentTypes\" xmlns:ed=\"urn:ebay:apis:EnhancedDataTypes\"");
63         }
64 }