PHP xml SOAP and laravel - php

I have been trying to figure out how to make a soap request using php/laravel. But from all the research on internet since two days now the only things that I can find are old rusty php codes to make soap requests non of them even worked:
Here is a snipped that I am trying to make it work so I have a general view of those soap requests but I only get errors not able to make a soapclient:
<?php
$aHTTP['http']['header'] = "User-Agent: PHP-SOAP/5.5.11\r\n";
$aHTTP['http']['header'].= "username: XXXXXXXXXXX\r\n"."password: XXXXX\r\n";
$context = stream_context_create($aHTTP);
$client=new SoapClient("http://www.thomas-bayer.com/axis2/services/BLZService?wsdl",array('trace' => 1,"stream_context" => $context));
$result = $client::__getFunctions();
var_dump($result);
since it looks super hard to me to find any info about the soap with php any idea ?

This is a sample of a soap request I currently make to a payment provider via php using curl statements. Basically map the xml request you want to make in a string. The string will be sent in the curl post fields and the response returned.
$soapdata="<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:tns='tns:ns'>
<soapenv:Header>
<tns:CheckOutHeader>
<MERCHANT_ID>$merchantid</MERCHANT_ID>
<PASSWORD>$password</PASSWORD>
<TIMESTAMP>$timestamp</TIMESTAMP>
</tns:CheckOutHeader>
</soapenv:Header>
<soapenv:Body>
<tns:processCheckOutRequest>
<MERCHANT_TRANSACTION_ID>$merchanttransactionid</MERCHANT_TRANSACTION_ID>
<REFERENCE_ID>$referenceid</REFERENCE_ID>
<AMOUNT>$amount</AMOUNT>
<MSISDN>$mobileno</MSISDN>
<!--Optional:-->
<ENC_PARAMS></ENC_PARAMS>
<CALL_BACK_URL>$callbackurl</CALL_BACK_URL>
<CALL_BACK_METHOD>$callbackmethod</CALL_BACK_METHOD>
<TIMESTAMP>$timestamp</TIMESTAMP>
</tns:processCheckOutRequest>
</soapenv:Body>
</soapenv:Envelope>";
//End Soap data
//We call the server for the first time
//end calling function
function makesoaprequest($url, $soapdata)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', 'Authorization: Basic'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$soapdata");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Begin SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//End SSL
$response = curl_exec($ch);
return $response;
curl_close($ch);
}

Related

Posting a SOAP request with php

I'm at a slight loss, havent touched a soap script in forever and looking around stackoverflow and google just confuses the matter more. PHP.net examples seem outdated as well.
The SOAP Request is supposed to POST to a non-WSDL url.
https://some.soapurl.com/provided
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:cam="http://kamp.gw.com/kamp">
<soapenv:Header/>
<soapenv:Body>
<cam:setRolesUpdatedRequest>
<cam:orgCode>username</cam:orgCode>
<cam:password>password</cam:password>
<cam:emails>
<cam:email>abc#dom.com</cam:email>
<cam:email>def#dom.com</cam:email>
<cam:email>ghi#dom.com</cam:email>
</cam:emails>
<cam:updateAllUsers>false</cam:updateAllUsers>
</cam:setRolesUpdatedRequest>
</soapenv:Body>
</soapenv:Envelope>
Just running this snippet returns a 200 OK header, which is good.
try {
$client = new SoapClient("https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated");
}
catch(Exception $e)
{
$e->getMessage();
}
The Response i'm looking to get is supposed to look like
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:returnStatus xmlns:ns1="http://kamp.gw.com/kamp">
<ns1:type>S</ns1:type>
<ns1:desc>Successful</ns1:desc>
</ns1:returnStatus>
</soapenv:Body>
</soapenv:Envelope>
EDIT:
I attempted a curl version to post the xml string directly.
$post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cam="http://kamp.gw.com/kamp">
<soapenv:Header/>
<soapenv:Body>
<cam:setRolesUpdatedRequest>
<cam:orgCode>username</cam:orgCode>
<cam:password>password</cam:password>
<cam:emails>
<cam:email>abc#dom.com</cam:email>
<cam:email>def#dom.com</cam:email>
<cam:email>ghi#dom.com</cam:email>
</cam:emails>
<cam:updateAllUsers>false</cam:updateAllUsers>
</cam:setRolesUpdatedRequest>
</soapenv:Body>
</soapenv:Envelope>';
$user = "username";
$password = "password";
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($xml),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 100000);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 100000);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers); //array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) )
curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password);
$result = curl_exec($soap_do);
$err = curl_error($soap_do);
var_dump($result);
echo "<br /><br />";
var_dump($err);
But unfortunately the result is
bool(false)
string(74) "Failed connect to abc.kamp.group.com:443; Connection timed out"
And i'm not certain if that's my fault or the web service's fault. Even though i get connection timed out, the header returned is still 200 Ok.
First check that the SOAP service url and access credentials are working. Use SoapUI or a similar tool to make a request independent of your PHP SoapClient code.
Also check if there are any IP address restrictions in place when making calls and, if so, create / ask for an exception for the IP address you are making requests from.
If everything checks, use php.net SoapClient examples to make simple calls and build your script logic.
<?php
$client = new SoapClient('http://soap.amazon.com/schemas3/AmazonWebServices.wsdl');
var_dump($client->__getFunctions());
?>
Forgot i was behind a proxy, once i pointed curl to the proxy server everything worked out just fine.

PHP - Not able to read xml sub node value

I am calling this soap API with curl and not able read response value properly so can you please guide me what I am doing wrong.
Here is my code:
$wsdl = "http://xxxx/xxxx/xxxx";
$body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:par="http://xxxx.com">
<soapenv:Header/>
<soapenv:Body>
<par:cancelReservationReq>
<par:garageID>47</par:garageID>
<par:orderNumber>orderNumber168</par:orderNumber>
<!--Optional:-->
<par:barCode>barCode168</par:barCode>
<!--Optional:-->
<par:orderTime>2015-11-19T00:30:57.905</par:orderTime>
</par:cancelReservationReq>
</soapenv:Body>
</soapenv:Envelope>';
// initializing cURL with the IPG API URL:
$ch = curl_init($wsdl);
// setting the request type to POST:
curl_setopt($ch, CURLOPT_POST, 1);
// setting the content type:
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
// setting the authorization method to BASIC:
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// filling the request body with your SOAP message:
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
// telling cURL to verify the server certificate:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// telling cURL to return the HTTP response body as operation result
// value when calling curl_exec:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// calling cURL and saving the SOAP response message in a variable which
// contains a string like "<SOAP-ENV:Envelope ...>...</SOAP-ENV:Envelope>":
$result = curl_exec($ch);
// loads the XML
$xml = simplexml_load_string($result);
$soapenv = $xml->children("http://schemas.xmlsoap.org/soap/envelope/");
$tns = $soapenv->Body->children("http://xxxx.com");
echo "success ".$success = $tns->cancelReservationResp->success;
echo "message ".$message = $tns->cancelReservationResp->message;
echo "garageID ".$garageID = $tns->cancelReservationResp->reservations->garageID;
API response data:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<tns:cancelReservationResp xmlns:tns="http://xxxx.com">
<tns:success>true</tns:success>
<tns:message/>
<tns:reservations>
<tns:garageID>47</tns:garageID>
<tns:barCode>barCode168</tns:barCode>
<tns:licensePlate>licensePlate168</tns:licensePlate>
<tns:orderNumber/>
<tns:used>false</tns:used>
<tns:cancelled>true</tns:cancelled>
<tns:startTime>2015-11-20 22:53:45.547</tns:startTime>
<tns:endTime>2015-11-21 22:53:45.547</tns:endTime>
<tns:cancelledTime>2015-11-19 00:51:58.717</tns:cancelledTime>
<tns:checkInTime/>
<tns:checkOutTime/>
<tns:grossPrice>152.6000</tns:grossPrice>
<tns:commFee>162.6000</tns:commFee>
<tns:customerName>customerName168</tns:customerName>
<tns:customerEmail>customerEmail168</tns:customerEmail>
<tns:customerPhone>customerPhone168</tns:customerPhone>
<tns:vehicleMake>vehicleMake168</tns:vehicleMake>
<tns:vehicleModel>vehicleModel68</tns:vehicleModel>
<tns:vehicleColor>vehicleColor168</tns:vehicleColor>
<tns:reentryAllowed>true</tns:reentryAllowed>
</tns:reservations>
</tns:cancelReservationResp>
</soapenv:Body>
</soapenv:Envelope>
I am getting this <tns:success>true</tns:success> value from $success variable but not getting anything from $garageID variable.
Any idea why $garageID is getting blank?
Thanks.

eBay Trading API GetCategories request returns 'Application name invalid'

When I tried to retreive all categories through the eBay Trading API with the method getCategories, I got this error:
FailureApplication name invalid.API application "222277"
invalid.127Error222277RequestError895E895_INTL_APICATALOG_17257399_R1
The header used is:
$headers = array(
'Content-Type:text/xml',
'X-EBAY-API-COMPATIBILITY-LEVEL: 895',
'X-EBAY-API-DEV-NAME: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'X-EBAY-API-APP-NAME: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx',
'X-EBAY-API-CERT-NAME: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'X-EBAY-API-CALL-NAME: GetCategories',
'X-EBAY-API-SITEID: 0'
);
The XML postfields:
$body = <<<BODY
<?xml version="1.0" encoding="utf-8"?>
<GetCategoriesRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>auth token......</eBayAuthToken>
</RequesterCredentials>
<CategorySiteID>0</CategorySiteID>
<DetailLevel>ReturnAll</DetailLevel>
</GetCategoriesRequest>
BODY;
and curl code:
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $endpoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $body);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
Ebay provides an API test tool.
It will pre-populate your credentials and let you make a test call.
Test Tool
This will help you debug any errors that you might get.
Unfortunately, eBay recently discontinued their API test tool. However, there are some 3rd party ones that may suffice.
For your issue, I recommend using the simpler Shopping API call called GetCategoryInfo. You don't need to POST your request or send any HTTP headers, and you can build your entire call into 1 URL/REST/GET request. This makes debugging much easier.
Either way you go about it, I don't think you can retrieve all of eBay's categories with 1 request. Instead, plan to loop through the category tree at each level, collecting the child category names and IDs.

Send userservice request to openfire

I'm using codeigniter and I want to send an add request to openfire, but i don't really understand what I have to do. I'm a beginner, I read this guide User Service and i tried to add a new user with curl Curl lib, but I'm stuck. Openfire is correctly configured because if I make request from browser the add works
This is my code
$this->load->library('curl');
$username='usertest';
$password='password';
$header='Authorization';
$content='mykey';
$this->curl->create('http://myserver.net', 9090);
$this->curl->http_header($header, $content);
$this->curl->http_header('Content-Type', 'application/xml');
$this->curl->post(array('username'=>$username,'password'=>$password));
$this->curl->execute();
But users are not added
I'm sorry for my bad English
Here is one implementation of user service client (it is based on Curl but not on codeigniter):
$url = "http://localhost:9090/plugins/userService/users";
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<user>
<username>'.$user['username'].'</username>
<password>'.$user['password'].'</password>
<name>'.$user['name'].'</name>
<email>'.$user['email'].'</email>
</user>';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: secret',
'Content-Type: application/xml'
));
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml );
#curl_setopt($ch,CURLOPT_POSTFIELDSPOST, count($fields));
#curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
ob_start(); // outer buffer
#echo "Code: $http_status | Username: {$user['name']}\n";
ob_end_flush();
//close connection
curl_close($ch);
if ($http_status == 201) {
return true;
}
else return false;
You should set the Content Type and and Authorization as array in a header.
And your XML content looks wrong. It is not only username / password in array.

integrating POLi payment with PHP

I need help in integrating POLi payment with custom PHP(no cms)
here is a link to a official pdf file
May be i need this section of code to integrate with php (from this pdf file)
->GenerateURL Request
To generate a Payment URL, the merchant performs a HTTP(S) post to the POLi™
PaymentAPI REST URL with the request content-­‐type set to ‘text/xml’ and the following
XML data in the request body.
Manual request (RequestType = ‘Manual’)
<?xml version="1.0" encoding="utf-­‐8"?>
<PaymentDataRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-­‐instance">
<MerchantCode>PriceBusterDVD</MerchantCode>
<AuthenticationCode>MerchantPassword</AuthenticationCode>
<RequestType>Manual</RequestType>
<PaymentAmount>123.11</PaymentAmount>
<PaymentReference>LandingPageReferenceText</PaymentReference>
<ConfirmationEmail>No</ConfirmationEmail>
<CustomerReference>No</CustomerReference>
<RecipientName></RecipientName>
<RecipientEmail></RecipientEmail>
</PaymentDataRequest>
To do this without any framework will require the use of CURL and sending the XML with the post fields.
$payload = '<?xml version="1.0" encoding="utf-­‐8"?>
<PaymentDataRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-­‐instance">
<MerchantCode>PriceBusterDVD</MerchantCode>
<AuthenticationCode>MerchantPassword</AuthenticationCode>
<RequestType>Manual</RequestType>
<PaymentAmount>123.11</PaymentAmount>
<PaymentReference>LandingPageReferenceText</PaymentReference>
<ConfirmationEmail>No</ConfirmationEmail>
<CustomerReference>No</CustomerReference>
<RecipientName></RecipientName>
<RecipientEmail></RecipientEmail>
</PaymentDataRequest>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://polipaymenturl.com');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
See the PHP cURL book for more information about using cURL.
(Note the example I have given isn't tested and is missing the correct URL but this should set you on the right path)

Categories