Send soap xml data in php - php

Please how can I send the following xml to a remote webservice(**/quick.svc?wsdl) using soap in php
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quic="http://services.interswitchng.com/quicktellerservice/">
<soapenv:Header/>
<soapenv:Body>
<quic:SendBillPaymentAdvice>
<!--Optional:-->
<quic:xmlParams>
<![CDATA[<BillPaymentAdvice>
<Amount>10000</Amount>
<PaymentCode>145536</PaymentCode>
<CustomerMobile>0856534</CustomerMobile>
<CustomerEmail>luvysols#gmail.com</CustomerEmail>
<CustomerId>Trdfg001</CustomerId>
<TerminalId>2323001</TerminalId>
<RequestReference>123456789</RequestReference>
</BillPaymentAdvice>]]>
</quic:xmlParams>
</quic:SendBillPaymentAdvice>
</soapenv:Body>
</soapenv:Envelope>

The SoapClient class provides a client for SOAP 1.1, SOAP 1.2 servers. It can be used in WSDL or non-WSDL mode.
$url = "";
$client = new SoapClient($url, array("trace" => 1, "exception" => 0));
Ref: http://php.net/manual/en/class.soapclient.php

First Include the nusoap.php and after it add this code.
$sen_code='XML CODE';
$client->debug($headers,$sen_code);
$client->decode_utf8 = FALSE;
$rel_lgoin = $client->call('method_for_call');

Related

Soap request working in SoapUI but not in Wordpress plugin

I've been searching around for a solution to my problem, but to no avail. I'm trying to send a soap request through a Wordpress plugin using the following:
function soapRequest($soapUsername, $soapNonce, $soapDateTime, $soapPassword) {
$wsdl = 'http://www.beautyfort.com/api/wsdl/v2/wsdl.wsdl';
$trace = true;
$exceptions = false;
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
// Must be a stdClass (and not an array)
$auth = new stdClass();
$auth->Username = $soapUsername;
$auth->Nonce = $soapNonce;
$auth->Created = $soapDateTime;
$auth->Password = $soapPassword;
$header = new SoapHeader('http://www.beautyfort.com/api/', 'AuthHeader', $auth);
$client->__setSoapHeaders($header);
$xml_array['TestMode'] = 'true';
$xml_array['StockFileFormat'] = 'JSON';
$xml_array['SortBy'] = 'StockCode';
try {
$response = $client->GetStockFile($xml_array);
}
catch (Exception $e) {
log_me("Error!");
log_me($e -> getMessage());
log_me('Last response: '. $client->__getLastResponse());
}
log_me('Last request: '. $client->__getLastRequest());
log_me($response);
}
This produces the following request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.beautyfort.com/api/">
<SOAP-ENV:Header>
<ns1:AuthHeader>
<ns1:Username>joetest</ns1:Username>
<ns1:Nonce>htflFfIKM4</ns1:Nonce>
<ns1:Created>2019-02-09T10:13:51.000Z</ns1:Created>
<ns1:Password>NGFjYTJiNzJmOWY2MzBmY2M2MjJkNjg1MDgyMWRjMzQxOGY1YTNjYQ==</ns1:Password>
</ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetStockFileRequest>
<ns1:TestMode>true</ns1:TestMode>
<ns1:StockFileFormat>JSON</ns1:StockFileFormat>
<ns1:SortBy>StockCode</ns1:SortBy>
</ns1:GetStockFileRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And I get an invalid credentials error. I've also been testing in SoupUI and the following request works:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:api="http://www.beautyfort.com/api/">
<soapenv:Header>
<api:AuthHeader>
<api:Username>joetest</api:Username>
<api:Nonce>tJrsRlQt6i</api:Nonce>
<api:Created>2019-02-06T23:34:11.000Z</api:Created>
<api:Password>ZTBhMmE5OGY4YTNlZWIzZTE0ZTc2ZjZiZDBhM2RhMjJmNzAxNzYwZA==</api:Password>
</api:AuthHeader>
</soapenv:Header>
<soapenv:Body>
<api:GetStockFileRequest>
<api:TestMode>true</api:TestMode>
<api:StockFileFormat>JSON</api:StockFileFormat>
<!--Optional:-->
<api:FieldDelimiter>,</api:FieldDelimiter>
<!--Optional:-->
<api:StockFileFields>
<!--1 or more repetitions:-->
<api:StockFileField>StockCode</api:StockFileField>
<api:StockFileField>Category</api:StockFileField>
<api:StockFileField>Brand</api:StockFileField>
<api:StockFileField>Collection</api:StockFileField>
<api:StockFileField>Category</api:StockFileField>
</api:StockFileFields>
<api:SortBy>StockCode</api:SortBy>
</api:GetStockFileRequest>
</soapenv:Body>
</soapenv:Envelope>
Now the only differences I can see (apart from the optional fields) is the names of the namespace, and the use of the Xml tag at the top of the request. Both of these shouldn't matter right? I'd really appreciate your help on this as I've been scratching my head for ages.
Thank you in advance!
Your perfect just need to set UTC timezone and secret format like below:
base64 encoded(sha1(Nonce . Created . Secret))

SOAP envelope with header authentication call php

I have to consume a webservice, but can't find a proper way to create the call.
This is the xml the company provide as example
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Qpay.POS.Gateway.ServiceContracts" xmlns:urn1="urn:Qpay.POS.Gateway.DataContracts">
<soapenv:Header/>
<soapenv:Body>
<urn:GetProvidersRequest>
<!--Optional:-->
<urn:Header>
<urn1:CertPublicKey>XX-XX-XX-XX-XX</urn1:CertPublicKey>
<!--Optional:-->
<urn1:UIID>XX</urn1:UIID>
<urn1:User>XXXX</urn1:User>
</urn:Header>
</urn:GetProvidersRequest>
</soapenv:Body>
</soapenv:Envelope>
Tried using this:
$soapURL = "https://pos.qpay123.biz/dBar/Gateway.svc?" ;
$soapParameters = Array('UIID' => "63", 'User' => "System") ;
$soapFunction = "GetProvidersRequest" ;
$soapClient = new SoapClient($soapURL, $soapParameters);
$soapResult = $soapClient->__soapCall($soapFunction) ;
var_dump($soapResult);
But i get a false as var dump, can you point me on the right direction to solve it?
Thanks

How can I create PHP SOAP request to call web service implemented in ColdFusion

I have implemented web service in ColdFusion. I am trying to call that webservice using php. But getting errors.
Can someone help me to prepare SAOP request in php? xml request is below in SOAP UI.
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://localhost:8501/webservice">
<soapenv:Header/>
<soapenv:Body>
<web:ASK soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
<AgentID> 1 </AgentID>
<Passwd> 12345 </Passwd>
<TransactionNumber >XXX </TransactionNumber >
<Sign >XXX </Sign >
</soapenv:Body>
</soapenv:Envelope>
I have used below code in php
$soapUrl = "http://domain.com/webservice/transaction.cfc?WSDL"; // asmx URL of WSDL
$xml_post_string = '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://localhost:8501/webservice">
<soapenv:Header/>
<soapenv:Body>
<web:ASK soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
<AgentID> 1 </AgentID>
<Passwd> 12345 </Passwd>
<TransactionNumber >XXX </TransactionNumber >
<Sign >XXX </Sign >
</soapenv:Body>
</soapenv:Envelope>';
$xml_array['AgentID'] = '1';
$xml_array['Passwd'] = "12345";
$xml_array['TransactionNumber'] = "XXX";
$client = new SoapClient($soapUrl, array( 'soap_version'=>SOAP_1_1, 'trace'=>1));
$xml= $client-> ASK($xml_array,$soapUrl,"POST",0);
(OR)
$xml= $client-> ASK($xml_post_string ,$soapUrl,"POST",0);
print "<pre>";
print_r($xml);
print "</pre>";
?>
Returns below error in both case
Fatal error: Uncaught SoapFault exception: [Server.userException] No such operation 'ASK' in C:\xampp\htdocs\webservice\

Tiger API Soap request. Highly confusing

I'm at the beginning of setting up the Tiger Air API. They have given few URLs for testing but these doesn't seem to work. Following are the details I received from them
Contact mail:
For testing, we have linked this account to your
xxxxxx agency in TEST (currency SGD).
Username: xxx
P/W: xxx (password will have to be changed on first login)
Domain: xxx
RoleCode: xxx
The URL’s for the API to test for connectivity are as follows:
Test: https://trtestr3xapi.navitaire.com/sessionmanager.svc
For the access to the various services, you will want to make your calls to the following DNS:
Test: https://trtestr3xapi.navitaire.com
SOAP sample request
The above two URLs don't seem to work at all. Its surprising that they did not provide the WSDL url. I have got the sample request from them.
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:web="http://schemas.navitaire.com/WebServices"
xmlns:ses="http://schemas.navitaire.com/WebServices/ServiceContracts/SessionService"
xmlns:ses1="http://schemas.navitaire.com/WebServices/DataContracts/Session"
>
<soapenv:Header>
<web:ContractVersion>320</web:ContractVersion>
</soapenv:Header>
<soapenv:Body>
<ses:LogonRequest>
<!--Optional:-->
<ses:logonRequestData>
<!--Optional:-->
<ses1:DomainCode>EXT</ses1:DomainCode>
<!--Optional:-->
<ses1:AgentName>MyAgent</ses1:AgentName>
<!--Optional:-->
<ses1:Password>P#ssword</ses1:Password>
<!--Optional:-->
<ses1:LocationCode></ses1:LocationCode>
<!--Optional:-->
<ses1:RoleCode></ses1:RoleCode>
<!--Optional:-->
<ses1:TerminalInfo></ses1:TerminalInfo>
</ses:logonRequestData>
</ses:LogonRequest>
</soapenv:Body>
</soapenv:Envelope>
I was struggling for a long time trying to figure out the basic setup but going into a loop.
your server ip need to be allowed for requests on this link
<?
$Username = 'xxx';
$Password: 'xxx';
$Domain: 'xxx';
$url = "https://trtestr3xapi.navitaire.com/SessionManager.svc?wsdl";
$client = new SoapClient($url);
$params = array(
'logonRequestData' => array(
'DomainCode' => $Domain,
'AgentName' => $Username,
'Password' => $Password,
)
);
print_r($client->Logon($params));
?>
another useful code
<?
$url = "https://trtestr3xapi.navitaire.com/SessionManager.svc?wsdl";
$client = new SoapClient($url);
print_r($client->__getFunctions());
print_r($client->__getTypes());
?>
and
<?
$url = "https://trtestr3xapi.navitaire.com/BookingManager.svc?wsdl";
$client = new SoapClient($url);
print_r($client->__getFunctions());
print_r($client->__getTypes());
?>

Create this SOAP XML request with PHP's SOAP extension

I'm trying to recreate this XML request using PHP's SOAP extension and having trouble doing it:
<?xml version="1.0"?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.web.stormpost.skylist.com">
<soapenv:Header>
<authInfo xmlns:soap="http://skylist.com/services/SoapRequestProcessor" xsi:type="soap:authentication">
<!--You may enter the following 2 items in any order-->
<username xsi:type="xsd:string">****#example.com</username>
<password xsi:type="xsd:string">*******</password>
</authInfo>
</soapenv:Header>
<soapenv:Body>
<ser:doImportFromTemplate soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<impTempId xsi:type="xsd:int">7</impTempId>
<data xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soapenc:string">
Joe|Doe|joe#example.com John|Doe|john#example.com </data>
</ser:doImportFromTemplate>
</soapenv:Body>
</soapenv:Envelope>
Here is my testing code so far:
// set connection params
$wsdl = 'http://api.stormpost.datranmedia.com/services/SoapRequestProcessor?wsdl';
$namespace = 'https://api.stormpost.datranmedia.com/services/SoapRequestProcessor';
$credentials = (object)array(
'username' => '****#example.com',
'password' => '*******'
);
$auth_values = new SoapVar($credentials, SOAP_ENC_OBJECT);
$header = new SoapHeader($namespace, "authInfo", $auth_values);
// set client, headers, and call function
$client = new SoapClient($wsdl, array('trace' => true));
$client->__setSoapHeaders(array($header));
$client->__soapCall("doImportFromTemplate", array(7, 'Joe|Doe|joe#example.com John|Doe|john#example.com'));
It doesn't seem to be implementing the authInfo node correctly with the xsi:type="soap:authentication" among other things. How should I change my code to output this XML? I'm having trouble finding good implementation examples.
I struggled with the php SOAP client myself a while ago, i didn't really got a full understanding but this worked for me:
$auth_values = array('username' => '****#example.com', 'password' => '*******');
$header = new SoapHeader($namespace, "authInfo", $auth_values, false);
// set client, headers, and call function
$client = new SoapClient($wsdl, array('trace' => true));
$client->__setSoapHeaders(array($header));

Categories