This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTrading.php
260 lines (214 loc) · 6.41 KB
/
Trading.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php namespace rearley\Ebay;
/**
* Ebay Trading API
* @author Rick Earley <[email protected]>
* @category Ebay API
* @package Trading API
* @version 0.1.3
*/
class Trading {
/**
* Gateway URI
* @var array
*/
private $gateway_uri = array(
'sandbox'=>'https://api.sandbox.ebay.com/ws/api.dll',
'production'=>'https://api.ebay.com/ws/api.dll'
);
/**
* By default, the library is set to sandbox mode for testing.
* @var bool
*/
private $sandbox_mode = TRUE;
/**
* Configurable Headers to be sent to the eBay API
* @var array
*/
private $headers = array();
private $content_length = '';
/**
* Developer Information
*/
private $developer_id = ''; //DevID
private $application_id = ''; //AppID
private $certificate_id = ''; //certID
private $user_token ='';
/**
* Input Fields
*/
private $request = '';
/**
* Call Options
*/
private $call_reference = '';
private $site_code = array(
'site_id'=>'0',
'abbreviation'=>'US',
'currency'=>'USD'
); //http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/types/SiteCodeType.html
/**
* Responses
*/
public $error = array();
public $results = FALSE;
function __construct(){
spl_autoload_register(function($className){
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
$fileName = str_replace('rearley\\Ebay\\', '', $fileName);
require $fileName;
});
}
/**
* AddFixedPriceItem Call Reference
* @access public
* @link http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/AddFixedPriceItem.html
* @return boolean
*/
public function AddFixedPriceItem(){
}
/**
* Set user token used on most trading calls
* @access public
* @param string $token
*/
public function CallReference($call_reference){
$this->call_reference = $call_reference;
}
/**
* Set user token used on most trading calls
* @access public
* @param string $token
*/
public function UserToken($token){
$this->user_token = $token;
}
/**
* Set DevID
* @access public
* @param string $devid
*/
public function DevID($devid){
$this->developer_id = trim($devid);
}
/**
* Set AppID
* @access public
* @param string $appid
*/
public function AppID($appid){
$this->application_id = trim($appid);
}
/**
* Set CertID
* @access public
* @param string $certid
*/
public function CertID($certid){
$this->certificate_id = trim($certid);
}
/**
* Returns 1/0 for boolean check
* @param string|boolean $field
* @return int
*/
private function _get_boolean($field){
$boolean = '';
if(is_bool($field)){
if($field){
$boolean = '1';
} else {
$boolean = '0';
}
} else {
if(strtolower($field) == 'true'){
$boolean = '1';
} else {
$boolean = '0';
}
}
return $boolean;
}
/**
* Build Headers
* @access private
* @todo generate an dpopulate content-length
*/
private function _build_headers(){
$this->headers = array(
'X-EBAY-API-COMPATIBILITY-LEVEL: 681',
'X-EBAY-API-DEV-NAME: '.$this->developer_id,
'X-EBAY-API-APP-NAME: '.$this->application_id,
'X-EBAY-API-CERT-NAME: '.$this->certificate_id,
'X-EBAY-API-CALL-NAME: '.$this->call_reference,
'X-EBAY-API-SITEID: '.$this->site_code['site_id'],
//'Content-Type: "text/xml"',
//'Content-Length: '.$this->content_length
);
}
/**
* Builds the RequestCredentials XML
* @access private
*/
private function _build_request_credentials(){
$request = '<RequesterCredentials>';
$request .= '<eBayAuthToken>'.$this->user_token.'</eBayAuthToken>';
$request .= '</RequesterCredentials>';
return $request;
}
/**
* Sends request to Ebay
* @param string $url
* @param array $headers
* @param string $postData
* @return bool|string
*/
private function _send($postData) {
// Build Rquest
$postData = '<?xml version="1.0" encoding="utf-8"?>'.$postData;
// Build Headers
$this->content_length = strlen($postData);
$this->_build_headers();
// Get URL
$url = '';
if($this->sandbox_mode){
$url = $this->gateway_uri['sandbox'];
} else {
$url = $this->gateway_uri['production'];
}
// Setup
$ch = curl_init();
// Options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// Execute
$response = curl_exec($ch);
// Report Errors
if (curl_errno($ch) !== 0) {
$this->error['function'] = 'Send';
$this->error['number'] = curl_errno($ch);
$this->error['message'] = curl_error($ch);
$this->error['curl_info'] = curl_getinfo($ch);
$response = FALSE;
}
// Close
curl_close($ch);
$this->results = $response;
if($response == FALSE){
return FALSE;
} else {
return TRUE;
}
}
}