a33ab969ccd31f2bd170a26a28151e3c67679a27
[WP-Plugins/glm-member-db.git] /
1 <?php
2 namespace PayPal\Auth;
3 use PayPal\Exception\PPMissingCredentialException;
4 use PayPal\Auth\IPPCredential;
5 /**
6  * 
7  * Client certificate based credentials
8  */
9 class PPCertificateCredential extends IPPCredential {
10         
11         /**
12          * API username
13          * @var string
14          */
15         protected $userName;
16         
17         /**
18          * API password
19          * @var string
20          */
21         protected $password;
22
23         /**
24          * Path to PEM encoded API certificate on local filesystem
25          * @var string
26          */
27         protected $certificatePath;
28
29         /**
30          * Password used to protect the API certificate
31          * @var string
32          */
33         protected $certificatePassPhrase;
34         
35         /**
36          * Application Id that uniquely identifies an application that uses the
37          * Platform APIs - Not required for Express Checkout / MassPay / DCC etc
38          * The application Id is issued by PayPal.
39          * Test application Ids are available for the sandbox environment
40          * @var string
41          */
42         protected $applicationId;       
43         
44         /**
45          * Constructs a new certificate credential object
46          * 
47          * @param string $userName      API username
48          * @param string $password      API password
49          * @param string $certPath      Path to PEM encoded client certificate file
50          * @param string $certificatePassPhrase password need to use the certificate
51          */
52         public function __construct($userName, $password, $certPath, $certificatePassPhrase=NULL) {
53                 $this->userName = trim($userName);
54                 $this->password = trim($password);
55                 $this->certificatePath = trim($certPath);
56                 $this->certificatePassPhrase = $certificatePassPhrase; 
57                 $this->validate();
58         }
59         
60         public function validate() {
61                 
62                 if (empty($this->userName)) {
63                         throw new PPMissingCredentialException("username cannot be empty");
64                 }
65                 if (empty($this->password)) {
66                         throw new PPMissingCredentialException("password cannot be empty");
67                 }               
68                 if (empty($this->certificatePath)) {
69                         throw new PPMissingCredentialException("certificate cannot be empty");
70                 }
71         }
72
73         public function getUserName() {
74                 return $this->userName;
75         }
76
77         public function getPassword() {
78                 return $this->password;
79         }
80         
81         public function getCertificatePath() {
82                 if (realpath($this->certificatePath)) {
83                         return realpath($this->certificatePath);
84                 } else if(defined('PP_CONFIG_PATH')) {
85                         return constant('PP_CONFIG_PATH') . DIRECTORY_SEPARATOR . $this->certificatePath;
86                 } else {
87                         return realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . ".."  .DIRECTORY_SEPARATOR . ".."     . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . $this->certificatePath);
88                 }
89         }
90
91         public function getCertificatePassPhrase() {
92                 return $this->certificatePassPhrase;
93         }
94         
95         public function setApplicationId($applicationId) {
96                 $this->applicationId = trim($applicationId);
97         }
98         
99         public function getApplicationId() {
100                 return $this->applicationId;
101         }
102
103 }