Php Soap connection refusal - php

Guys I have an issue I have been learning soap the last few days, I've been trying to connect to a web service for online store to verify users tv licenses before they can purchase a tv set.
I have written the following code to test the web service provided by TV licenses company.
<?php
$wdsl = "https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc?wsdl";
$options = array(
'trace' => true,
'exceptions' => true,
'connection_timeout' => 1
);
try{
$client = new SoapClient($wdsl,$options);
$apiauth = array(
'Rquid' => '3600cd32-28b9-4a4f-a522-4326def4a9c2',
'ApiKey' => '5957237e-101c-4ff2-8fdc-4bd6c9393a1d',
'AccountIdentifier' => '9211186012088',
'AccountIdentifierType' => 'SaidNumber');
$header = new SoapHeader('http://tempuri.org/','Auth',$apiauth,true);
$client->__setSoapHeaders($header);
$account = $client->GetAccount();
var_dump($account);
echo "<pre>";
var_dump($client);
echo "</pre>";
}catch (Exception $e) {
echo "Error!";
echo $e->getMessage() . "<br>";
echo 'Last response: ' . $client->__getLastResponse();
}
?>
The wdsl does not require a client certificate, the api key above is for testing only.
The problem I always hit
unable to connect to host
But if I write an invalid function I get an error that the function is invalid for this services, When I use __GetFunctions() I do see the functions in the services, but when I try to use one of them I hit could not connect to host, Can guys help me out to connect to this service.

hopefully this should get you going, I assume that the live wsdl will work correctly without having to call __setLocation()
<?php
$wdsl = "https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc?wsdl";
$options = array(
'trace' => true,
'exceptions' => true,
'connection_timeout' => 1
);
try {
$client = new SoapClient($wdsl, $options);
// use https location - the host for http (http://jhb-tvlicweb2.sabc.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc) dosn't exist
$client->__setLocation('https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc');
// setup parameters
$arrParams = array(
'request' => array(
'Header' => array(
'Rquid' => '3600cd32-28b9-4a4f-a522-4326def4a9c2',
'ApiKey' => '5957237e-101c-4ff2-8fdc-4bd6c9393a1d'
),
'AccountIdentifier' => '9211186012088',
'AccountIdentifierType' => 'SaidNumber'
)
);
// request parameters passed in the body not the header
$account = $client->GetAccount($arrParams);
var_dump($account);
echo "<pre>";
var_dump($client);
echo "</pre>";
} catch (\Exception $e) {
echo "Error!";
echo $e->getMessage() . "<br>";
echo 'Last response: ' . $client->__getLastResponse();
}

Related

An error occurred: 40030: Customer Not Found, using UsaEpay soap API

Hi Stackoverflow community,
I am attempting to implement the "convertPaymentMethodToToken" method from USAePay soap api documentations. For the function to work, it is required to fetch the customer number from the UsaEpay acct, and it generates a Method ID through a "getCustomer" request, that will be used for the conversion. However, the implementation works only for a single customer and fails when I try to process multiple customers at once. The error message I receive is: "An error occurred while fetching details of customer 'customer1': 40030: Customer Not Found......".
I have a large customer database of over 20,000 customers, and my goal is to convert each of their payment methods to tokens efficiently, without having to perform individual conversions for each customer. The USAePay documentation only provides information on how to implement the feature for a single customer.
here is my code by getting Method ID for a single customer
<?php
$wsdl = "https://secure.usaepay.com/soap/gate/INBGTWZC/usaepay.wsdl";
$sourceKey = "your soruce key";
$pin = "1234";
function getClient($wsdl) {
return new SoapClient($wsdl, array(
'trace' => 1,
'exceptions' => 1,
'stream_context' => stream_context_create(
array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
)
)
));
}
function getToken($sourceKey, $pin) {
$seed = time() . rand();
return array(
'SourceKey' => $sourceKey,
'PinHash' => array(
'Type' => 'sha1',
'Seed' => $seed,
'HashValue' => sha1($sourceKey . $seed . $pin)
),
'ClientIP' => $_SERVER['REMOTE_ADDR']
);
}
$client = getClient($wsdl);
$token = getToken($sourceKey, $pin);
try {
$custnum='customer number';
print_r($client->getCustomer($token,$custnum));
} catch (Exception $e) {
// Code to handle the exception
echo "An error occurred: " . $e->getMessage();
}
?>
and here the successful response I get back (with the Method ID included)
Successful response.
here Is the code I'm trying it to do with multiple customers
<?php
$wsdl = "https://sandbox.usaepay.com/soap/gate/43R1QPKU/usaepay.wsdl";
$sourceKey = "your api key";
$pin = "1234";
function getClient($wsdl) {
return new SoapClient($wsdl, array(
'trace' => 1,
'exceptions' => 1,
'stream_context' => stream_context_create(
array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
)
)
));
}
function getToken($sourceKey, $pin) {
$seed = time() . rand();
return array(
'SourceKey' => $sourceKey,
'PinHash' => array(
'Type' => 'sha1',
'Seed' => $seed,
'HashValue' => sha1($sourceKey . $seed . $pin)
),
'ClientIP' => $_SERVER['REMOTE_ADDR']
);
}
$client = getClient($wsdl);
$token = getToken($sourceKey, $pin);
$custnums = array();
for ($i = 1; $i <= 3; $i++) {
$custnums[] = 'customer' . $i;
}
$methodIDs = array();
foreach ($custnums as $custnum) {
try {
$result = $client->getCustomer($token, $custnum);
$methodID = $result[0]->MethodID;
$methodIDs[] = $methodID;
error_log("Method ID for customer $custnum: $methodID");
} catch (Exception $e) {
echo " An error occurred: " . $e->getMessage();
}
}
?>
I've already been working on it all day,
Can anyone help me with this?
Thanks in advance

SOAP java.lang.NullPointerException Error

I made a research on web but I couldn't find the exact answer for my question. I am trying to make a request to a SOAP service. I can get a proper response when I try with SOAPUI but I can't get anything when I try it with PHP.
Here is a screenshot of SOAPUI: (Backup URL: http://i.hizliresim.com/qGaOOd.png)
Here is my PHP code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$wsdl = "http://www.estes-express.com/shipmenttracking/services/ShipmentTrackingService?wsdl";
$options = array(
'auth' => array(
'user' => 'myuser',
'password' => 'mypass'
)
);
$request = array(
'search' => array(
'requestID' => '0841824923',
'pro' => '0841824923'
)
);
$client = new SoapClient($wsdl, $options);
echo '<pre>'.print_r($client,true).'</pre>';
try{
$response = $client->__soapCall('trackShipments', array($request));
print_r($response);
} catch(SoapFault $ex){
echo $ex->getMessage();
}
print "\n";
When I run this script, it returns this error: "java.lang.NullPointerException"
Any solutions? Thanks in advance.

PHP SoapClient unable to access webservice using proxy

Using SoapClient in PHP, I've come across a problem I have not been able to find a solution to.
I'm using a local copy of the wsdl file and I am using this setup:
$this->client = new \SoapClient(__DIR__ . '/../../some.wsdl',
array(
'proxy_host' => $ip,
'proxy_port' => $port,
'trace' => 1,
'exceptions' => true,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
This gives error : "Forbidden" when calling :
$this->client->__call($method, $params)
I have tried calling __getFunctions()
$this->client->__getFunctions()
that gives the list of all function in my WSDL file.
Am I missing something?
Debug code with like this :
<?php
try{
$client = new SoapClient($wsdl, $params);
$out = $client;
}catch(Exception $e){
$out = array('error' => $e, 'libxml' => libxml_get_last_error());
}catch(SoapFault $s){
$out = array('error' => $s, 'libxml' => libxml_get_last_error());
}
var_dump($out);
exit();

Object reference not set to an instance of an object on https soap call

Getting the below error when trying to make a SOAP call using HTTPS.
Below is the code. I have tried different ways around it with no luck.
Link is http://dev.jp-websolutions.co.uk/teletrac/getsafetydata/test
The error that I'm seeing is SoapFault exception: [soap:Receiver] Server was unable to process request. ---> Object reference not set to an instance of an object.
This is what I'm using right now.
header("Content-Type: text/plain");
$params = array(
"UserName" => "xxx",
"Password" => "xxx",
);
$opts = array(
'ssl' => array('ciphers'=>'RC4-SHA')
);
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient("https://onlineavl2dev-uk.navmanwireless.com/OnlineAVL/API/v1.3/Service.asmx?wsdl", array('trace' => 1, 'soap_version' => SOAP_1_2, "encoding"=>"ISO-8859-1",
'stream_context' => stream_context_create($opts)));
#print_r($client); die;
#$response = $client->DoLogin($params);
//print_r($client->__getFunctions());
//print_r($client->__getTypes());
try {
echo "<pre>\n";
$result = $client->DoLogin(array(
"UserName" => "xxx",
"Password" => "xxx",
));
print_r($result);
echo "\n";
}
catch (SoapFault $exception) {
echo $exception;
}
print_r($response); die;

How to debug SOAP connections

Setting up my first SOAP connection. Code below. I can pull down AvailableContent method but cant seem to access any other objects. Is there anything immediately wrong with my code, or is there something I can ask the service provider.
$soapClient = new SoapClient('http://contentcafe2.btol.com/contentcafe/contentcafe.asmx?wsdl', array("trace" => 1, "exception" => 0));
$auth = array(
'userID' => 'XXXXXXX',
'password' => 'XXXXXXX',
'key' => '9781608198214',
'content' => 'AvailableContent'
);
try{
$response = $soapClient->Single($auth);
echo "<pre>";
print_r($response);
echo "</pre>";
}catch (Exception $e) {
}
I think you should use a SOAP client such as SoapUI - http://www.soapui.org/ - to test your soap handshake instead of writing a code to do same.

Categories