Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * APIProfile encapsulates Profile data
4
 *
5
 * $Id: API.php 696 2011-09-08 09:08:23Z tiefland $
6
 *
7
 * Modified for 3-token authentication, DHarvey, 3/5/2006
8
 *
9
 * @package PayPal
10
 */
11
 
12
/**
13
 * Include parent and package classes.
14
 */
15
require_once 'PayPal.php';
16
require_once 'PayPal/Profile.php';
17
 
18
/**
19
 * Stores API Profile information used for performing transactions on the PayPal API
20
 *
21
 * @package PayPal
22
 */
23
class APIProfile extends Profile
24
{
25
    /**
26
     * The API username to make API calls with. Must be a valid PayPal
27
     * API account (not a paypal.com account or developer.paypal.com
28
     * account).
29
     *
30
     * @access private
31
     */
32
    var $_username;
33
 
34
    /**
35
     * The API password to use. This must be set before making any API
36
     * calls; it is not stored by the ProfileHandler backend.
37
     *
38
     * @see setAPIPassword()
39
     *
40
     * @access private
41
     */
42
    var $_password;
43
 
44
    /**
45
     * The 3-token signature
46
     *
47
     * @see setSignature()
48
     *
49
     * @access private
50
     */
51
    var $_signature;
52
 
53
    /**
54
     * The location of the user's private certificate. This should be
55
     * a .pem file.
56
     *
57
     * @access private
58
     */
59
    var $_certificateFile;
60
 
61
    /**
62
     * The password, if any, on the user's private certificate. This
63
     * must be set before making any API calls; it is not stored by
64
     * the ProfileHandler backend.
65
     *
66
     * @see setCertificatePassword()
67
     *
68
     * @access private
69
     */
70
    var $_certificatePassword;
71
 
72
    /**
73
     * Subject to be used when making API calls. This is for making
74
     * calls on behalf of another PayPal user with your own API
75
     * account.
76
     *
77
     * @access private
78
     */
79
    var $_subject;
80
 
81
    /**
82
     * Constructor
83
     *
84
     * @param string         $id       A unique id for the profile.
85
     * @param ProfileHandler $handler  A handler object where the profile is stored.
86
     *
87
     */
88
    function APIProfile($id, &$handler)
89
    {
90
        parent::Profile($id, $handler);
91
    }
92
 
93
    /**
94
     * Validates the profile data currently loaded before use.
95
     *
96
     * @return mixed true if the data is valid, or a PayPal_Error object on failure.
97
     */
98
    function validate()
99
    {
100
       // Either certificate or signature is required
101
       if (empty($this->_username) ||
102
            empty($this->_password) ||
103
            (empty($this->_certificateFile) && empty($this->_signature)) ||
104
            empty($this->_environment)) {
105
            return PayPal::raiseError("API Username, Password, Certificate File and Environment must all be set");
106
        }
107
 
108
        if (! empty($this->_certificateFile) && !file_exists($this->_certificateFile)) {
109
            return PayPal::raiseError("Could not find certificate file '{$this->_certificateFile}'");
110
        }
111
 
112
        if (!in_array(strtolower($this->_environment), $this->_validEnvironments, true)) {
113
            return PayPal::raiseError("Environment '{$this->_environment}' is not a valid environment.");
114
        }
115
 
116
        return true;
117
    }
118
 
119
    /**
120
     * Sets the API username for the profile.
121
     *
122
     * @param string The API username.
123
     */
124
    function setAPIUsername($username)
125
    {
126
        $this->_username = $username;
127
    }
128
 
129
    /**
130
     * Returns the API username for the profile.
131
     *
132
     * @return string The API username.
133
     */
134
    function getAPIUsername()
135
    {
136
        return $this->_username;
137
    }
138
 
139
    /**
140
     * Sets the API password for the profile.
141
     *
142
     * @param string The password for the profile.
143
     */
144
    function setAPIPassword($password)
145
    {
146
        $this->_password = $password;
147
    }
148
 
149
    /**
150
     * Get the API password for the profile.
151
     *
152
     * @return string The password for the profile.
153
     */
154
    function getAPIPassword()
155
    {
156
        return $this->_password;
157
    }
158
 
159
    /**
160
     * Sets the 3-token signature
161
     *
162
     * @param string The password for the profile.
163
     */
164
    function setSignature($signature)
165
    {
166
        $this->_signature = $signature;
167
    }
168
 
169
    /**
170
     * Get the 3-token signature.
171
     *
172
     * @return string The password for the profile.
173
     */
174
    function getSignature()
175
    {
176
        return $this->_signature;
177
    }
178
 
179
    /**
180
     * Get the Certificate file associated with the profile.
181
     *
182
     * @return string The certificate file associated with the profile.
183
     */
184
    function getCertificateFile()
185
    {
186
        return $this->_certificateFile;
187
    }
188
 
189
    /**
190
     * Set the certificate file associated with the profile.
191
     *
192
     * @param string The certificate file associated with the profile.
193
     */
194
    function setCertificateFile($filename)
195
    {
196
        $this->_certificateFile = $filename;
197
    }
198
 
199
    /**
200
     * Set the certificate password.
201
     *
202
     * @param string The certificate password.
203
     */
204
    function setCertificatePassword($password)
205
    {
206
        $this->_certificatePassword = $password;
207
    }
208
 
209
    /**
210
     * Get the certificate password.
211
     *
212
     * @return string  The certificate password.
213
     */
214
    function getCertificatePassword()
215
    {
216
        return $this->_certificatePassword;
217
    }
218
 
219
    /**
220
     * Set the subject associated with the profile.
221
     *
222
     * @param string The subject of the profile.
223
     */
224
    function setSubject($subject)
225
    {
226
        $this->_subject = $subject;
227
    }
228
 
229
    /**
230
     * Get the subject of the associated profile.
231
     *
232
     * @return string The subject associated with the profile.
233
     */
234
    function getSubject()
235
    {
236
        return $this->_subject;
237
    }
238
 
239
    /**
240
     * Returns an array of member variables names which should be
241
     * included when storing the profile.
242
     *
243
     * @return array An array of member variable names which should be included.
244
     * @access protected
245
     */
246
    function _getSerializeList()
247
    {
248
        return array('username', 'certificateFile',
249
                     'subject', 'environment');
250
    }
251
 
252
    function getInstance($id, &$handler)
253
    {
254
        $classname = __CLASS__;
255
        $inst = &new $classname($id, $handler);
256
 
257
        $result = $inst->_load();
258
        if (PayPal::isError($result)) {
259
            return $result;
260
        }
261
 
262
        $result = $inst->loadEnvironments();
263
        if (PayPal::isError($result)) {
264
            return $result;
265
        }
266
 
267
        return $inst;
268
    }
269
 
270
}