/
RTSCreditClient.php
513 lines (468 loc) · 14.9 KB
/
RTSCreditClient.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<?php
/**
*
* RTS Credit Webservice Client - PHP 5 class for RTSCredit.com Broker Webservice
*
* PHP Version 5
*
* Required Extensions
* Soap
* SimpleXML
*
* The MIT License
*
* Copyright (c) 2010 Musa Ulker
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author Musa Ulker <musaulker@gmail.com>
* @copyright Musa Ulker 2010
* @license MIT
* @package RTSCreditClient
* @version 1.0
* @link http://github.com/musaulker/RTS-Credit-Webservice-Client
*
*/
class RTSCreditClient{
private $_userID;
private $_userPass;
private $_endpointURL;
private $_soapClient;
private $_userToken;
private $_userType;
private $_availableSearches;
private $_userIsValid;
private $_latestReturnCode;
private $_latestDescription;
/**
*
* Class constructor
*
*/
public function __construct() {
/* check if soap extension is available */
if(! extension_loaded('soap')){
echo "I cannot continue because Soap Extension isn't enabled. Sorry. Check this link for how to install & configure: http://tr.php.net/manual/en/book.soap.php \n";
exit();
}
/* check if simplexml is available */
if(! function_exists("simplexml_load_string")){
echo "I cannot continue because SimpleXML doesn't exist. Sorry. Check this link for how to install & configure: http://php.net/manual/en/book.simplexml.php \n";
exit();
}
$this->_endpointURL = "http://webservice.rtscredit.com/CreditReport.asmx?WSDL";
$this->_soapClient = new SoapClient($this->_endpointURL, array("soap_version" => SOAP_1_2, "trace" => false));
}
/**
*
* Class destructor
*
*/
public function __destruct() {
// empty
}
/**
*
* Set the webservice proxy
*
* @param string $host Proxy hostname or ip
* @param integer Proxy port number
* @param string Proxy username
* @param string Proxy user password
*
*/
public function setProxy($host, $port, $login, $password){
$this->_soapClient = new SoapClient($this->_endpointURL, array(
"soap_version" => SOAP_1_2,
"trace" => false,
"proxy_host" => $host,
"proxy_port" => $port,
"proxy_login" => $login,
"proxy_password" => $password));
}
/**
*
* set user ID for the webservice login
*
* @param string $userID userID for webservice login
*
*/
public function setUserID($userID) {
$this->_userID = $userID;
}
/**
*
* set user password for the webservice login
*
* @param $userPass user password for the webservice login
*
*/
public function setUserPass($userPass) {
$this->_userPass = $userPass;
}
/**
*
* Method to login to the RTS Credit Web Service and receive a session token.
* This token must be used when calling any other methods in this service and will expire in 24 hours.
*
* @return boolean true on success, false on failure
*
*/
public function login() {
try{
$loginResponse = $this->_soapClient
->__soapCall("Login", array("Login" => array("UserID" => $this->_userID, "UserPass" => $this->_userPass)));
$this->_userType = $loginResponse->LoginResult->UserDetails->UserType;
$this->_availableSearches = $loginResponse->LoginResult->UserDetails->AvailableSearches;
$this->_userIsValid = $loginResponse->LoginResult->UserDetails->UserIsValid;
$this->_latestReturnCode = $loginResponse->LoginResult->ReturnCode->Code;
$this->_latestDescription = $loginResponse->LoginResult->ReturnCode->Description;
/* First checking if login is successful? */
if($this->_userIsValid){
/* Lets get the token returning from webservice */
$this->_userToken = $loginResponse->LoginResult->UserToken;
return true;
}else{
return false;
}
}
catch(Exception $ex){
echo $ex->getMessage();
return false;
}
}
/**
*
* Use this method for a broad search of the RTS Credit database. With the exception of the session token, all or some of the parameters may be passed.
*
* @param string $MCNumber Optional. 6 digit Motor Carrier Number, "Shipper","F/F", or "EXEMPT"
* @param string $name Optional. Full or partial name of broker
* @param string $city Optional. Full or partial city name
* @param string $state Optional. Any two character state abbreviation
* @param string $zip Optional. Any valid US zip code
*
* @return mixed array of brokers on success if more then one broker found, broker if only one broker found, boolean false on failure
*
*/
public function BrokerSearch($MCNumber, $name, $city, $state, $zip) {
try{
if($this->_userIsValid){
$brokerSearchResponse = $this->_soapClient->__soapCall("BrokerSearch", array("BrokerSearch" => array("UserToken" => $this->_userToken, "MCNumber" => $MCNumber, "Name" => $name, "City" => $city, "St" => $state, "Zip" => $zip)));
$this->_latestReturnCode = $brokerSearchResponse->BrokerSearchResult->ReturnCode->Code;
$this->_latestDescription = $brokerSearchResponse->BrokerSearchResult->ReturnCode->Description;
if($this->_latestReturnCode == 200){
if(is_array($brokerSearchResponse->BrokerSearchResult->BrokerList)){
return $this->xml2array($brokerSearchResponse->BrokerSearchResult->BrokerList);
}else{
return $brokerSearchResponse->BrokerSearchResult->BrokerList->Broker;
}
}else{
return false;
}
}else{
return false;
}
}
catch(Exception $ex){
echo $ex->getMessage();
return false;
}
}
/**
*
* Use this method for a search of the RTS Credit database by city and/or state.
*
* @param string $city Optional. Full or partial city name
* @param string $state Optional. Any two character state abbreviation
*
* @return mixed array of brokers on success if more then one broker found, broker if only one broker found, boolean false on failure
*
*/
public function BrokerSearchByCityState($city, $state) {
try{
if($this->_userIsValid){
$brokerSearchByCityResponse = $this->_soapClient->__soapCall("BrokerSearchByCityState", array("BrokerSearchByCityState" => array("UserToken" => $this->_userToken, "City" => $city, "St" => $state)));
$this->_latestReturnCode = $brokerSearchByCityResponse->BrokerSearchByCityStateResult->ReturnCode->Code;
$this->_latestDescription = $brokerSearchByCityResponse->BrokerSearchByCityStateResult->ReturnCode->Description;
if($this->_latestReturnCode == 200){
if(is_array($brokerSearchByCityResponse->BrokerSearchByCityStateResult->BrokerList)){
return $this->xml2array($brokerSearchByCityResponse->BrokerSearchByCityStateResult->BrokerList);
}else{
return $brokerSearchByCityResponse->BrokerSearchByCityStateResult->BrokerList->Broker;
}
}else{
return false;
}
}else{
return false;
}
}
catch(Exception $ex){
echo $ex->getMessage();
return false;
}
}
/**
*
* Use this method for a search of the RTS Credit database by MC Number.
*
* @param string $MCNumber Optional. 6 digit Motor Carrier Number, "Shipper","F/F", or "EXEMPT"
*
* @return mixed array of brokers on success if more then one broker found, broker if only one broker found, boolean false on failure
*
*/
public function BrokerSearchByMC($MCNumber) {
try{
if($this->_userIsValid){
$brokerSearchByMCResponse = $this->_soapClient->__soapCall("BrokerSearchByMC", array("BrokerSearchByMC" => array("UserToken" => $this->_userToken, "MCNumber" => $MCNumber)));
$this->_latestReturnCode = $brokerSearchByMCResponse->BrokerSearchByMCResult->ReturnCode->Code;
$this->_latestDescription = $brokerSearchByMCResponse->BrokerSearchByMCResult->ReturnCode->Description;
if($this->_latestReturnCode == 200){
if(is_array($brokerSearchByMCResponse->BrokerSearchByMCResult->BrokerList)){
return $this->xml2array($brokerSearchByMCResponse->BrokerSearchByMCResult->BrokerList);
}else{
return $brokerSearchByMCResponse->BrokerSearchByMCResult->BrokerList->Broker;
}
}else{
return false;
}
}else{
return false;
}
}
catch(Exception $ex){
echo $ex->getMessage();
return false;
}
}
/**
*
* Use this method for a search of the RTS Credit database by broker name.
*
* @param string $name Optional. Full or partial name of broker
*
* @return mixed array of brokers on success if more then one broker found, broker if only one broker found, boolean false on failure
*
*/
public function BrokerSearchByName($name) {
try{
if($this->_userIsValid){
$brokerSearchByNameResponse = $this->_soapClient->__soapCall("BrokerSearchByName", array("BrokerSearchByName" => array("UserToken" => $this->_userToken, "Name" => $name)));
$this->_latestReturnCode = $brokerSearchByNameResponse->BrokerSearchByNameResult->ReturnCode->Code;
$this->_latestDescription = $brokerSearchByNameResponse->BrokerSearchByNameResult->ReturnCode->Description;
if($this->_latestReturnCode == 200){
if(is_array($brokerSearchByNameResponse->BrokerSearchByNameResult->BrokerList)){
return $this->xml2array($brokerSearchByNameResponse->BrokerSearchByNameResult->BrokerList);
}else{
return $brokerSearchByNameResponse->BrokerSearchByNameResult->BrokerList->Broker;
}
}else{
return false;
}
}else{
return false;
}
}
catch(Exception $ex){
echo $ex->getMessage();
return false;
}
}
/**
*
* Use this method for a search of the RTS Credit database by zipcode.
*
* @param string $zip Optional. Any valid US zip code
*
* @return mixed array of brokers on success if more then one broker found, broker if only one broker found, boolean false on failure
*
*/
public function BrokerSearchByZip($zip) {
try{
if($this->_userIsValid){
$brokerSearchByZipResponse = $this->_soapClient->__soapCall("BrokerSearchByZip", array("BrokerSearchByZip" => array("UserToken" => $this->_userToken, "Zip" => $zip)));
$this->_latestReturnCode = $brokerSearchByZipResponse->BrokerSearchByZipResult->ReturnCode->Code;
$this->_latestDescription = $brokerSearchByZipResponse->BrokerSearchByZipResult->ReturnCode->Description;
if($this->_latestReturnCode == 200){
if(is_array($brokerSearchByZipResponse->BrokerSearchByZipResult->BrokerList)){
return $this->xml2array($brokerSearchByZipResponse->BrokerSearchByZipResult->BrokerList);
}else{
return $brokerSearchByZipResponse->BrokerSearchByZipResult->BrokerList->Broker;
}
}else{
return false;
}
}else{
return false;
}
}
catch(Exception $ex){
echo $ex->getMessage();
return false;
}
}
/**
*
* Use this method to obtain a full credit report from the RTS CRedit database.
*
* @param string $id Required. The value of the ID node returned from any of the search methods
*
* @return mixed array of brokers on success if more then one broker found, broker if only one broker found, boolean false on failure
*
*/
public function GetBrokerDetail($id) {
if(!$id){
return false;
}
try{
if($this->_userIsValid){
$getBrokerDetailResponse = $this->_soapClient->__soapCall("GetBrokerDetail", array("GetBrokerDetail" => array("UserToken" => $this->_userToken, "ID" => $id)));
$this->_latestReturnCode = $getBrokerDetailResponse->GetBrokerDetailResult->ReturnCode->Code;
$this->_latestDescription = $getBrokerDetailResponse->GetBrokerDetailResult->ReturnCode->Description;
if($this->_latestReturnCode == 200){
return $getBrokerDetailResponse->GetBrokerDetailResult->BrokerDetail;
}else{
return false;
}
}else{
return false;
}
}
catch(Exception $ex){
echo $ex->getMessage();
return false;
}
}
/**
*
* convert XML result to array
*
* @param string $xmlstr the XML string
*
* @return array
*
*/
private function xml2array($xmlstr) {
$children = array();
$i = 0;
$xml = simplexml_load_string($xmlstr);
foreach($xml->children() as $child){
foreach($child->attributes() as $key => $val){
$children[$i][$key] = (string) $val;
}
$i ++;
}
return $children;
}
/**
*
* Returns user type
*
* @return string
*
*/
public function getUserType() {
return $this->_userType;
}
/**
*
* Returns user accounts available search
*
* @return integer
*
*/
public function getAvailableSearches() {
return $this->_availableSearches;
}
/**
*
* Returns user account is valid or not
*
* @return boolean
*
*/
public function getUserIsValid() {
return $this->_userIsValid;
}
/**
*
* Get latest return code from webservice call
*
* @return string
*
*/
public function getLatestReturnCode() {
return $this->_latestReturnCode;
}
/**
*
* Get latest description from webservice call
*
* @return string
*
*/
public function getLatestDescription() {
return $this->_latestDescription;
}
/**
*
* Returns the SOAP headers from the last request.
*
* @return string
*
*/
public function getLastRequetHeaders() {
return $this->_soapClient
->__getLastRequestHeaders();
}
/**
*
* Returns the XML sent in the last SOAP request.
*
* @return mixed XML string
*
*/
public function getLastRequest() {
return $this->_soapClient
->__getLastRequest();
}
/**
*
* Returns the SOAP headers from the last response.
*
* @return string
*
*/
public function getLastResponseHeaders() {
return $this->_soapClient
->__getLastResponseHeaders();
}
/**
*
* Returns the XML sent in the last SOAP response.
*
* @return mixed XML string
*
*/
public function getLastResponse() {
return $this->_soapClient
->__getLastResponse();
}
}
?>