Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Base PayPal SDK file.
4
 *
5
 * @package PayPal
6
 */
7
 
8
/**
9
 * Include our error class and the PEAR base class.
10
 */
11
require_once 'PEAR.php';
12
require_once 'PayPal/Error.php';
13
 
14
/**
15
 * End point for users to access the PayPal API, provides utility
16
 * methods used internally as well as factory methods.
17
 *
18
 * $Id: PayPal.php 696 2011-09-08 09:08:23Z tiefland $
19
 *
20
 * @static
21
 * @package PayPal
22
 */
23
class PayPal extends PEAR
24
{
25
    /**
26
     * Raise an error when one occurs
27
     *
28
     * @static
29
     */
30
    function raiseError($message, $code = null)
31
    {
32
        return parent::raiseError($message, $code, null, null, null, 'PayPal_Error');
33
    }
34
 
35
    /**
36
     * Try to instantiate the class for $type. Looks inside the Type/
37
     * directory containing all generated types. Allows for run-time
38
     * loading of needed types.
39
     *
40
     * @param string $type  The name of the type (eg. AbstractRequestType).
41
     *
42
     * @return mixed XSDType | PayPal_Error  Either an instance of $type or an error.
43
     *
44
     * @static
45
     */
46
    function &getType($type)
47
    {
48
        $type = basename($type);
49
        @include_once 'PayPal/Type/' . $type . '.php';
50
        if (!class_exists($type)) {
51
            $t = PayPal::raiseError("Type $type is not defined");
52
        } else {
53
            $t = new $type();
54
        }
55
        return $t;
56
    }
57
 
58
    /**
59
     * Load a CallerServices object for making API calls.
60
     *
61
     * @param APIProfile $profile  The profile with the username, password,
62
     *                             and any other information necessary to use
63
     *                             CallerServices.
64
     *
65
     * @return CallerServices  A PayPal API caller object.
66
     *
67
     * @static
68
     */
69
    function &getCallerServices($profile)
70
    {
71
        if (!defined('CURLOPT_SSLCERT')) {
72
            $e = PayPal::raiseError("The PayPal SDK requires curl with SSL support");
73
            return $e;
74
        }
75
 
76
        if (!is_a($profile, 'APIProfile')) {
77
            $e = PayPal::raiseError("You must provide a valid APIProfile");
78
            return $e;
79
        }
80
 
81
        $result = $profile->validate();
82
        if (PayPal::isError($result)) {
83
            return $result;
84
        }
85
 
86
        include_once 'PayPal/CallerServices.php';
87
        $c =& new CallerServices($profile);
88
        return $c;
89
    }
90
 
91
    /**
92
     * Load an EWPServices object for performing encryption
93
     * operations.
94
     *
95
     * @param EWPProfile $profile  The profile with the username, password,
96
     *                             and any other information necessary to use
97
     *                             EWPServices.
98
     *
99
     * @return EWPServices  A PayPal EWP services object.
100
     *
101
     * @static
102
     */
103
    function &getEWPServices($profile)
104
    {
105
        if (!is_a($profile, 'EWPProfile')) {
106
            return parent::raiseError("You must provide a valid EWPProfile");
107
        }
108
 
109
        $result = $profile->validate();
110
        if (PayPal::isError($result)) {
111
            return $result;
112
        }
113
 
114
        include_once 'PayPal/EWPServices.php';
115
        return $c =& new EWPServices($profile);
116
    }
117
 
118
    /**
119
     * Returns the package root directory.
120
     *
121
     * @return string  The path where the package is installed.
122
     *
123
     * @static
124
     */
125
    function getPackageRoot()
126
    {
127
        return dirname(__FILE__) . '/PayPal';
128
    }
129
 
130
    /**
131
     * Returns the version of the WSDL that this SDK is built against.
132
     *
133
     * @return float  The WSDL version.
134
     *
135
     * @static
136
     */
137
    function getWSDLVersion()
138
    {
139
        include_once 'PayPal/CallerServices.php';
140
        return PAYPAL_WSDL_VERSION;
141
    }
142
 
143
    /**
144
     * Returns the endpoint map.
145
     *
146
     * @return mixed The Paypal endpoint map or a Paypal error object on failure
147
     * @static
148
     */
149
    function getEndpoints()
150
    {
151
        $package_root = PayPal::getPackageRoot();
152
        $file = "$package_root/wsdl/paypal-endpoints.php";
153
        if (@include $file) {
154
            if (!isset($PayPalEndpoints)) {
155
                return PayPal::raiseError("Endpoint map file found, but no data was found.");
156
            }
157
 
158
            return $PayPalEndpoints;
159
        }
160
 
161
        return PayPal::raiseError("Could not load endpoint mapping from '$file', please rebuild SDK.");
162
    }
163
 
164
    /**
165
     * Get information describing all types provided by the SDK.
166
     * @static
167
     */
168
    function getTypeList()
169
    {
170
        $root_dir = PayPal::getPackageRoot();
171
        $types = "$root_dir/Type/*.php";
172
 
173
        $files = glob($types);
174
 
175
        if (count($files) < 2) {
176
            return PayPal::raiseError("Types not found in package! (Looked for '$types')");
177
        }
178
 
179
        $retval = array();
180
 
181
        foreach ($files as $type_files) {
182
            $retval[] = basename(substr($type_files, 0, strpos($type_files, '.')));
183
        }
184
 
185
        return $retval;
186
    }
187
 
188
    /**
189
     * Get information describing which methods are available.
190
     * @static
191
     */
192
    function getCallerServicesIntrospection()
193
    {
194
        include_once 'PayPal/CallerServices.php';
195
        return unserialize(PAYPAL_WSDL_METHODS);
196
    }
197
 
198
}