Display delivery status from UPS - php

I am using the UPS courier service for the delivery of the packages. In my website I need to display the delivery status of a particular order using the tracking number, I used the following example,
https://github.com/chetan/php-ups-api
I added the access key, username and password in the config file. and I am using tracking.php file fro this library for testing purpose. But I get the following error,
Fatal error: require_once(): Failed opening required 'XML/Unserializer.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/project/php-ups-api-master/UpsAPI/Client.php on line 119
Can anyone please tell me where can I get this file.
I have also tried using
https://www.ups.com/upsdeveloperkit/downloadresource?loc=en_US
\project\TrackingPACKAGE\TRACKINGWebServices\CodeSamples\Track\PHP\SoapTrackClient.php file
I have added,
$wsdl = "../../../SCHEMAS-WSDLs/Track.wsdl";
as the parameter.
But get the following error,
SoapFault Object ( [message:protected] => An exception has been raised as a result of client data. [string:Exception:private] => [code:protected] => 0 [file:protected] => /home/project/TrackingPACKAGE/TRACKINGWebServices/CodeSamples/Track/PHP/SoapTrackClient.php [line:protected] => 62 [trace:Exception:private] => Array ( [0] => Array ( [file] => /home/project/TrackingPACKAGE/TRACKINGWebServices/CodeSamples/Track/PHP/SoapTrackClient.php [line] => 62 [function] => __soapCall [class] => SoapClient [type] => -> [args] => Array ( [0] => ProcessTrack [1] => Array ( [0] => ) ) ) ) [previous:Exception:private] => [faultstring] => An exception has been raised as a result of client data. [faultcode] => Client [faultcodens] => http://schemas.xmlsoap.org/soap/envelope/ [detail] => stdClass Object ( [Errors] => stdClass Object ( [ErrorDetail] => stdClass Object ( [Severity] => Authentication [PrimaryErrorCode] => stdClass Object ( [Code] => 250002 [Description] => Invalid Authentication Information. ) ) ) ) [xdebug_message] => ( ! ) SoapFault: An exception has been raised as a result of client data. in /home/project/TrackingPACKAGE/TRACKINGWebServices/CodeSamples/Track/PHP/SoapTrackClient.php on line 62 Call Stack #TimeMemoryFunctionLocation 10.0006132036{main}( )../SoapTrackClient.php:0 20.0079240060SoapClient->__soapCall( )../SoapTrackClient.php:62 )
Please help me.

Error message tell that you need install PEAR Serializer package: https://pear.php.net/package/XML_Serializer/

Related

How to parse an exception object in php symfony

I have an exception object which looks like:
Exception Object ( [message:protected] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'selectPROFILEID,SUBSCRIPTION,MOD_DT,ACTIVATED,INCOMPLETE from newjs.JPROFILE whe' at line 1 [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/html/JsMain/web/commonFiles/mysql_multiple_connections.php [line:protected] => 92 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/www/html/JsMain/web/jsadmin/add_edit_fields.php [line] => 46 [function] => mysql_error_js [args] => Array ( ) ) ) [previous:Exception:private] => )
I want to access message in this object using .message and so on for other values.
print_r(($Var.message));
It doesn't work at all. Please tell me how can I access?
Did you try $var->getMessage(); as it is an Exception object.
http://php.net/manual/en/class.exception.php

How to send SOAP requests in php

Okay so I have a Python server running and I've been using "suds" as a client side which has been surprisingly easy, when I tried to run a similar code in PHP I got very confused since I was a beginner with it?
from suds.client import Client
url = 'http://localhost:8080/FlightService?wsdl'
client = Client(url=url)
output = client.service.getFlightList("dxb","ksa")
print(output)
is there something with this ease in php or can anyone show me a sample code which would return the same result?
Considering the server receives this:
class Input(complextypes.ComplexType):
dpt = str
arr = str
and returns a list of flights
class flight(complextypes.ComplexType):
id = int
dpt = str
arr = str
price = float
date = str
tickets = int
this is the webservice:
#webservice(_params=Input,_returns=[flight])
def getFlightList(self, input):
my PHP segment:
<?php
$url = 'http://172.27.130.98:8080/FlightService?wsdl';
$client = new SoapClient($url);
echo("Hello!");
$result = $client->bookFlight("dxb","ksa");
$result2 = $client->handle();
echo($result);
echo($result2);
?>
PHP Error:
Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in C:\wamp\www\soap\soap.php:6 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://172.27.1...', 'http://172.27.1...', 1, 0) #1 C:\wamp\www\soap\soap.php(6): SoapClient->__call('getFlightList', Array) #2 C:\wamp\www\soap\soap.php(6): SoapClient->getFlightList('dxb', 'ksa') #3 {main} thrown in C:\wamp\www\soap\soap.php on line 6
Exception info:
SoapFault Object ( [message:protected] => Error Fetching http headers [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\wamp\www\soap\soap.php [line:protected] => 6 [trace:Exception:private] => Array ( [0] => Array ( [function] => __doRequest [class] => SoapClient [type] => -> [args] => Array ( [0] => ksa [1] => http://172.27.130.98:8080/FlightService [2] => http://172.27.130.98:8080/FlightService/getFlightList [3] => 1 [4] => 0 ) ) [1] => Array ( [file] => C:\wamp\www\soap\soap.php [line] => 6 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => getFlightList [1] => Array ( [0] => dxb [1] => ksa ) ) ) [2] => Array ( [file] => C:\wamp\www\soap\soap.php [line] => 6 [function] => getFlightList [class] => SoapClient [type] => -> [args] => Array ( [0] => dxb [1] => ksa ) ) ) [previous:Exception:private] => [faultstring] => Error Fetching http headers [faultcode] => HTTP [xdebug_message] => ( ! ) SoapFault: Error Fetching http headers in C:\wamp\www\soap\soap.php on line 6 Call Stack #TimeMemoryFunctionLocation 10.0006243160{main}( )..\soap.php:0 20.0758264872getFlightList ( )..\soap.php:6 30.0758265336__call ( )..\soap.php:6 )
this solution worked for me, i instantiated an associative array with the name of variables i'm expecting at server side then used var_dump to get the result of the output
<?php
$url = 'http://172.27.130.98:8080/FlightService?wsdl';
$client = new SoapClient($url);
echo("Hello!");
$trip["dpt"] = "dxb";
$trip["arr"] = "krt";
try{ $output = $client->getFlightList($trip);
}
catch(soapFault $e)
{
print_r($e);
}
var_dump($output);
?>

WSDL TO PHP implementation

I got converted WSDL to PHP script but something is not working very I am trying to connect http://www.regcheck.org.uk/api/reg.asmx?wsdl, but getting this error
Array ( [RegCheckServiceCheck::Check] => SoapFault Object ( [message:protected] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at webtropy.CarReg.Check(String RegistrationNumber, String username) in c:\inetpub\wwwroot\regcheck.org.uk\api\reg.asmx:line 26 --- End of inner exception stack trace --- [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line:protected] => 32 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line] => 32 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => Check [1] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) ) [1] => Array ( [file] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line] => 32 [function] => Check [class] => SoapClient [type] => -> [args] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) [2] => Array ( [file] => C:\xampp\htdocs\sample-regcheck.php [line] => 46 [function] => Check [class] => RegCheckServiceCheck [type] => -> [args] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) ) [previous:Exception:private] => [faultstring] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at webtropy.CarReg.Check(String RegistrationNumber, String username) in c:\inetpub\wwwroot\regcheck.org.uk\api\reg.asmx:line 26 --- End of inner exception stack trace --- [faultcode] => soap:Server [detail] => ) )
I am sure something is missing in config files, mybe someone got idea ?
It's possible to call that web service via a HTTP GET request as follows;
<?php
$username = 'Your username here';
$regNumber = 'SK08KPT';
$xmlData = file_get_contents("https://www.regcheck.org.uk/api/reg.asmx/Check?RegistrationNumber=" . $regNumber ."&username=" . $username);
$xml=simplexml_load_string($xmlData);
$strJson = $xml->vehicleJson;
$json = json_decode($strJson);
print_r($json->Description);
?>
Not as elegant as a SOAP call, but simpler.
Script open source files
You can see all main files
https://www.wsdltophp.com/Wsdls/8a71627601a684624c5694104cce023f/RegCheck-1-0-1-1-1-1-0-0-0-0

Wsdl methods not calling via SoapClient, server is create in YII

i have create yii framework based wsdl service:
from the link :-
http://www.yiiframework.com/doc/guide/1.1/en/topics.webservice
and facing the issues that is their in the comment
http://www.yiiframework.com/doc/guide/1.1/en/topics.webservice#c6656
and server create fine as i am able to see the wsdl file
but when i try to access the method by the code from external file not in yii site folder
below file is inside another folder not in mysite_yii folder hope that not create any issue as it has to call the wsdl file
$client=new SoapClient('http://localhost/mysite_yii/index.php?r=stock/quote');
try
{
echo $client->getPrice('GOOGLE');
}
catch(Exception $e)
{
echo "<pre>";
print_r($e);
}
i am getting the following exception
SoapFault Object
(
[message:protected] => Function ("getPrice") is not a valid method for this service
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /var/www/serverclient/stock.php
[line:protected] => 9
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /var/www/serverclient/stock.php
[line] => 9
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => getPrice
[1] => Array
(
[0] => GOOGLE
)
)
)
[1] => Array
(
[file] => /var/www/serverclient/stock.php
[line] => 9
[function] => getPrice
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => GOOGLE
)
)
)
[previous:Exception:private] =>
[faultstring] => Function ("getPrice") is not a valid method for this service
[faultcode] => Client
[faultcodens] => http://schemas.xmlsoap.org/soap/envelope/
)
i have done the same changes as suggested in the comment but not able to call that method
any suggestions ?
Thanks in advance
you must off the server cache for soap, u can off it by adding
ini_set("soap.wsdl_cache_enabled", "0"); to your code

Facebook API couldn't connect to host and timeout errors

A few days ago I released a beta version of a game on Facebook.
Unfortunately, I'm not so lucky, and in the first most important days of the application when users first use it, they keep getting errors resulting from errors on my PHP Apache server which gets the following errors from Facebook API -
couldn't connect to host
connect() timed out!
My server runs on a free server I got from Joyent for facebook developers.
I'm not a big expert with web servers so I got no idea if the problems are from my side or Facebook side.
And how can I fix this problem quickly!
Thanks a lot!
Edit:
For some reason I forgot about the code samples and error examples -
Here's an example for a simple query against facebook -
$session = $facebook->getSession();
$currentID = $facebook->api('/me?fields=id');
Here's the error stack trace -
couldn't connect to host StackTrace: Array
(
[0] => Array
(
[file] => /users/home/aagnt2sv/web/public/Facebook/facebook-php-sdk-7d538d3/src/facebook.php
[line] => 523
[function] => makeRequest
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => https://graph.facebook.com/me?fields=id
[1] => Array
(
[method] => GET
[access_token] => 104269778819|2.AQAKqpIXE0jqFuoU.3600.1311008400.1-785849095|qxtBqmWWRMc_GpM77CK77RbO4YA
)
)
)
[1] => Array
(
[file] => /users/home/aagnt2sv/web/public/Facebook/facebook-php-sdk-7d538d3/src/facebook.php
[line] => 491
[function] => _oauthRequest
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => https://graph.facebook.com/me?fields=id
[1] => Array
(
[method] => GET
)
)
)
[2] => Array
(
[function] => _graph
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => /me?fields=id
)
)
[3] => Array
(
[file] => /users/home/aagnt2sv/web/public/Facebook/facebook-php-sdk-7d538d3/src/facebook.php
[line] => 444
[function] => call_user_func_array
[args] => Array
(
[0] => Array
(
[0] => Facebook Object
(
[appId:protected] => *censored*
[apiSecret:protected] => *censored*
[session:protected] => Array
(
[uid] => *censored*
[access_token] => 104269778819|2.AQAKqpIXE0jqFuoU.3600.1311008400.1-785849095|qxtBqmWWRMc_GpM77CK77RbO4YA
[expires] => 1311008400
[sig] => ddf14dcaa953cb64d3f98b0649b60613
)
[signedRequest:protected] =>
[sessionLoaded:protected] => 1
[cookieSupport:protected] => 1
[baseDomain:protected] =>
)
[1] => _graph
)
[1] => Array
(
[0] => /me?fields=id
)
)
)
[4] => Array
(
[file] => /users/home/aagnt2sv/web/public/edamometer/EdamometerWS.php
[line] => 31
[function] => api
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => /me?fields=id
)
)
Thanks again!
This was somehow fixed by itself after several days. Maybe it was a temporary problem on my server or on Facebook's servers.
Get user id with
$fb = new Facebook(array(
'appId' => 'your_app_id',
'secret' => 'your_app_secret',
));
$user = $fb->getUser();// returns user id
I'm currently having this problem with my server (using PHP to access the Facebook API), as well. Based upon the nature of the error message, obviously the problem is the connection between my server (running on the Amazon cloud, btw) and Facebook's server(s).
What is throwing me for a loop, though, is that some commands are working properly. That is, attempting to log in with one Facebook token is working fine, while another in causing this error message.
The only reasonable explanation I can come up with is that the Facebook servers are experiencing some sort of temporary hiccup... but even that does a poor job of explaining the problem, since it is somehow tied to the token which is being used. The only way it makes sense is if there's some sort of bug where Facebook's servers are timing out in processing the specific token I'm giving them...

Categories