Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * @package PayPal
4
 *
5
 * $Id: EWP.php 696 2011-09-08 09:08:23Z tiefland $
6
 */
7
 
8
/**
9
 * Include parent and package classes.
10
 */
11
require_once 'PayPal.php';
12
require_once 'PayPal/Profile.php';
13
require_once 'PayPal/EWPServices.php';
14
 
15
/**
16
 * Stores EWP Profile information used for encrypting buttons and PayPal forms.
17
 *
18
 * @package PayPal
19
 */
20
class EWPProfile extends Profile
21
{
22
    /**
23
     * The private Key file
24
     *
25
     * @access private
26
     */
27
    var $_privateKeyFile;
28
 
29
    /**
30
     * The password on the private key.
31
     *
32
     * @access private
33
     */
34
    var $_privateKeyPassword;
35
 
36
    /**
37
     * The URL to the button image
38
     *
39
     * @access private
40
     */
41
    var $_buttonImageURL;
42
 
43
    /**
44
     * The URL the button posts to
45
     *
46
     * @access private
47
     */
48
    var $_buttonURL;
49
 
50
    /**
51
     * The PayPal-assigned id of the certificate.
52
     *
53
     * @access private
54
     */
55
    var $_certificateId;
56
 
57
    /**
58
     * The location of the .pem certificate file.
59
     *
60
     * @access private
61
     */
62
    var $_certificateFile;
63
 
64
    /**
65
     * Class constructor
66
     *
67
     * @param ProfileHandler &$handler  A handler where the profile should be stored.
68
     */
69
    function EWPProfile($id, &$handler)
70
    {
71
        parent::Profile($id, $handler);
72
    }
73
 
74
    /**
75
     * Validates the profile data currently loaded before use.
76
     *
77
     * @return mixed true if the data is valid, or a PayPal_Error object on failure.
78
     */
79
    function validate()
80
    {
81
        if (empty($this->_certificateFile)) {
82
            return PayPal::raiseError("Certificate File must be set!");
83
        }
84
        if (empty($this->_certificateId)) {
85
            return PayPal::raiseError("Certificate ID must be set.");
86
        }
87
        if (empty($this->_environment)) {
88
            return PayPal::raiseError("Environment must be set.");
89
        }
90
        if (!file_exists($this->_certificateFile)) {
91
            return PayPal::raiseError("Could not find certificate file '{$this->_certificateFile}'");
92
        }
93
        if (!in_array(strtolower($this->_environment), $this->_validEnvironments, true)) {
94
            return PayPal::raiseError("Environment '{$this->_environment}' is not a valid environment.");
95
        }
96
 
97
        return true;
98
    }
99
 
100
    /**
101
     * Get the merchant certificate id associated with the profile
102
     *
103
     * @return string The certificate id associated with the profile
104
     */
105
    function getCertificateId()
106
    {
107
        return $this->_certificateId;
108
    }
109
 
110
    /**
111
     * Set the merchant certificate id associated with the profile
112
     *
113
     * @param string The certificate id associated with the profile
114
     */
115
    function setCertificateId($filename)
116
    {
117
        $this->_certificateId = $filename;
118
    }
119
 
120
    /**
121
     * Get the merchant certificate file associated with the profile
122
     *
123
     * @return string The certificate file associated with the profile
124
     */
125
    function getCertificateFile()
126
    {
127
        return $this->_certificateFile;
128
    }
129
 
130
    /**
131
     * Set the merchant certificate file associated with the profile
132
     *
133
     * @param string The certificate file associated with the profile
134
     */
135
    function setCertificateFile($filename)
136
    {
137
        if (!file_exists($filename)) {
138
            return PayPal::raiseError("The private key '$filename' does not exist");
139
        }
140
 
141
        $this->_certificateFile = $filename;
142
    }
143
 
144
    /**
145
     * Returns the URL where the button image is
146
     *
147
     * @return string The URL to the button image
148
     */
149
    function getButtonImage()
150
    {
151
        return $this->_buttonImageURL;
152
    }
153
 
154
    /**
155
     * Set the URL where the button image is
156
     *
157
     * @param string The URL to the button image
158
     */
159
    function setButtonImage($url)
160
    {
161
        $this->_buttonImageURL = $url;
162
    }
163
 
164
    /**
165
     * Returns the URL where the button will post to
166
     *
167
     * @return string The URL where the button will post to
168
     */
169
    function getUrl()
170
    {
171
        return $this->_buttonURL;
172
    }
173
 
174
    /**
175
     * Sets the URL where the button will post to
176
     *
177
     * @param string The URL where the button should post to
178
     */
179
    function setUrl($url)
180
    {
181
        $this->_buttonURL = $url;
182
    }
183
 
184
    /**
185
     * Set the Merchant private key file
186
     *
187
     * @param string The Merchant Private Key File
188
     * @return mixed True on success, a PayPal error object on faliure
189
     */
190
    function setPrivateKeyFile($filename)
191
    {
192
        if (!file_exists($filename)) {
193
            return PayPal::raiseError("The private key '$filename' does not exist");
194
        }
195
 
196
        $this->_privateKeyFile = $filename;
197
 
198
        return true;
199
    }
200
 
201
    /**
202
     * Get the merchant private key file associated with the profile
203
     *
204
     * @return string The merchant private key file associated with the profile
205
     */
206
    function getPrivateKeyFile()
207
    {
208
        return $this->_privateKeyFile;
209
    }
210
 
211
    /**
212
     * Set the merchant private key password
213
     *
214
     * @param string The private key password
215
     */
216
    function setPrivateKeyPassword($password)
217
    {
218
        $this->_privateKeyPassword = $password;
219
    }
220
 
221
    /**
222
     * Get the merchant private key password
223
     *
224
     * @return string  The private key password.
225
     */
226
    function getPrivateKeyPassword()
227
    {
228
        return $this->_privateKeyPassword;
229
    }
230
 
231
    /**
232
     * Returns an array of member variables names which should be included
233
     * when storing the profile.
234
     *
235
     * @return array An array of member variable names which should be included
236
     * @access protected
237
     */
238
    function _getSerializeList()
239
    {
240
        return array('environment', 'certificateId', 'certificateFile', 'privateKeyFile', 'buttonImageURL', 'buttonURL');
241
    }
242
 
243
    /**
244
     * Factory for creating instances of the EWPProfile. Used when
245
     * providing an existing Profile ID to load from
246
     *
247
     * @param string The Profile ID of this instance
248
     * @param object A valid Profile Handler instance
249
     * @return object A new instance of EWPProfile for the given ID or a PayPal error object on failure
250
     */
251
    function getInstance($id, &$handler)
252
    {
253
        $classname = __CLASS__;
254
        $inst = new $classname($id, $handler);
255
        $result = $inst->_load();
256
 
257
        if (PayPal::isError($result)) {
258
            return $result;
259
        }
260
 
261
        return $inst;
262
    }
263
 
264
}