SoapFault exception: [HTTP] Bad Request In eway - soap

I am going to integrate the eway token payment integration and i am facing this problem.
SoapFault exception: [HTTP] Bad Request
the wsdl file is here
https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?wsdl
and the xml format is here
https://www.eway.com.au/gateway/ManagedPaymentService/test/managedcreditcardpayment.asmx?op=CreateCustomer
and i get the xml file with $client->__getLastRequest(); script is
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="https://www.eway.com.au/gateway/managedpayment" xmlns:ns2="eWAYHeader">
<env:Header>
<ns2:http://www.eway.com.au/gateway/managedPayment>
<item>
<key>eWAYCustomerID</key><value>87654321</value>
</item>
<item><key>Username</key><value>test#eway.com.au</value>
</item>
<item><key>Password</key><value>test123</value>
</item>
</ns2:http://www.eway.com.au/gateway/managedPayment>
</env:Header><env:Body>
<ns1:CreateCustomer>
<ns1:Title>Mr.</ns1:Title>
<ns1:FirstName>Joe</ns1:FirstName>
<ns1:LastName>Bloggs</ns1:LastName>
<ns1:Address>Bloggs Enterprise</ns1:Address>
<ns1:Suburb>Capital City</ns1:Suburb>
<ns1:State>ACT</ns1:State>
<ns1:Company>Bloggs</ns1:Company>
<ns1:PostCode>2111</ns1:PostCode>
<ns1:Country>au</ns1:Country>
<ns1:Email>test#eway.com.au</ns1:Email>
<ns1:Fax>0298989898</ns1:Fax>
<ns1:Phone>0297979797</ns1:Phone>
<ns1:Mobile>9841381980</ns1:Mobile>
<ns1:CustomerRef>Ref123</ns1:CustomerRef>
<ns1:JobDesc>Web developer</ns1:JobDesc>
<ns1:Comments>Please Ship ASASP</ns1:Comments>
<ns1:URL>http://www.test.com.au</ns1:URL>
<ns1:CCNumber>4444333322221111</ns1:CCNumber>
<ns1:CCNameOnCard>Test Account </ns1:CCNameOnCard>
<ns1:CCExpiryMonth>1</ns1:CCExpiryMonth>
<ns1:CCExpiryYear>13</ns1:CCExpiryYear>
</ns1:CreateCustomer>
</env:Body>
</env:Envelope>
Is there both xml structure effets to soap:
Or is this something like problem of soap header?
i have set header like this
$data = array('eWAYCustomerID'=>'87654321',
'Username' => "test#eway.com.au",
'Password' => "test123"
);
$header = new SoapHeader('eWAYHeader',$url,$data);
$client->__setSoapHeaders($header);
I am getting:
SoapFault exception: [HTTP] Bad Request in D:\wamp\www\eway\newfile.php:196
Stack trace:
#0 [internal function]: SoapClient->__doRequest('__call('CreateCustomer', Array)
#2 D:\wamp\www\eway\newfile.php(196): SoapClient->CreateCustomer(Array)
#3 {main}
This error always while i call this function
$customerinfo =
array(
'Title'=>'Mr.',
'FirstName' => 'Joe',
'LastName'=>'Bloggs',
'Address'=>'Bloggs Enterprise',
'Suburb'=>'Capital City',
'State'=>'ACT',
'Company'=>'Bloggs',
'PostCode'=>'2111',
'Country'=>'au',
'Email'=>'test#eway.com.au',
'Fax'=>'0298989898',
'Phone'=>'0297979797',
'Mobile'=>'9841381980',
'CustomerRef'=>'Ref123',
'JobDesc'=>'Web developer',
'Comments'=>'Please Ship ASASP',
'URL'=>'http://www.test.com.au',
'CCNumber'=>'4444333322221111',
'CCNameOnCard'=>'Test Account ',
'CCExpiryMonth'=>'01',
'CCExpiryYear'=>'13'
);
$client->CreateCustomer($customerinfo);
Any help will be more valuable.
Thanks in advance.

Try to use the following code instead:
<?php
$apiUrl = 'https://www.eway.com.au/gateway/ManagedPaymentService/test/managedcreditcardpayment.asmx?WSDL';
$options = array( 'trace' => 1, 'exceptions' => 1);
try{
$client = new SoapClient($apiUrl, $options);
$data = array(
'eWAYCustomerID' => '87654321',
'Username' => "test#eway.com.au",
'Password' => "test123"
);
$header = new SoapHeader('https://www.eway.com.au/gateway/managedpayment', 'eWAYHeader', $data, false);
$client->__setSoapHeaders($header);
$customerinfo = array(
'Title'=>'Mr.',
'FirstName' => 'Joe',
'LastName'=>'Bloggs',
'Address'=>'Bloggs Enterprise',
'Suburb'=>'Capital City',
'State'=>'ACT',
'Company'=>'Bloggs',
'PostCode'=>'2111',
'Country'=>'au',
'Email'=>'test#eway.com.au',
'Fax'=>'0298989898',
'Phone'=>'0297979797',
'Mobile'=>'9841381980',
'CustomerRef'=>'Ref123',
'JobDesc'=>'Web developer',
'Comments'=>'Please Ship ASASP',
'URL'=>'http://www.test.com.au',
'CCNumber'=>'4444333322221111',
'CCNameOnCard'=>'Test Account ',
'CCExpiryMonth'=>'01',
'CCExpiryYear'=>'13'
);
$result = $client->CreateCustomer($customerinfo);
var_dump($result);
}catch(Exception $e){
echo $e->getMessage();
}
which worked for me.
Notes:
1. Always try to wrap the code in try{} catch{} block
2. Make sure to check php_openssl extension is enabled or not
3. Disable the wsdl cache & enable the exceptions
4. Note the SoapHeader constructor.
Hope this helps you.
Regards

Related

xmlrpc getting an error xmpp user register

I have working o ejabberd and xmpp but while register user i am getting an error
Notice: xmlrpc: Error -118 A problem '{error,access_rules_unauthorized}' occurred executing the command register with arguments
I am using this code
$request = xmlrpc_encode_request($command, $params, (array('encoding' => 'utf-8')));
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "User-Agent: XMLRPC::Client mod_xmlrpc\r\n" .
"Content-Type: text/xml\r\n" .
"Content-Length: " . strlen($request),
'content' => $request
)));
// echo '<pre>'; print_R($context); die;
$file = file_get_contents('http://192.168.1.22:4560/RPC2', false, $context);
//echo '<pre>'; print_R($file); die;
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
return $response;
}
I have tried everything but still getting an error.
So, you finally solved the previous problem you had in what else to do to enable XML-RPC in ejabberd? ? You can add an explanation there to help other people, or at least mark the problem as solved, so other people don't waste their time investigating something that you no longer care about.

JWT: Why am I always getting token_not_provided?

I am sending a PUT request to an API endpoint I have created. Using jwt, I am able to successfully register and get a token back.
Using Postman, my request(s) work perfectly.
I am using Guzzle within my application to send the PUT request. This is what it looks like:
$client = new \Guzzle\Http\Client('http://foo.mysite.dev/api/');
$uri = 'user/123';
$post_data = array(
'token' => eyJ0eXAiOiJKV1QiLCJhbGc..., // whole token
'name' => 'Name',
'email' => name#email.com,
'suspended' => 1,
);
$data = json_encode($post_data);
$request = $client->put($uri, array(
'content-type' => 'application/json'
));
$request->setBody($data);
$response = $request->send();
$json = $response->json();
} catch (\Exception $e) {
error_log('Error: Could not update user:');
error_log($e->getResponse()->getBody());
}
When I log the $data variable to see what it looks like, this is what is returned.
error_log(print_r($data, true));
{"token":"eyJ0eXAiOiJKV1QiL...","name":"Name","email":"name#email.com","suspended":1}
Error: Could not suspend user:
{"error":"token_not_provided"}
It seems like all data is getting populated correctly, I am not sure why the system is not finding the token. Running the "same" query through Postman (as a PUT) along with the same params works great.
Any suggestions are greatly appreciated!
The token should be set in the authorization header, not as a post data parameter
$request->addHeader('Authorization', 'Basic eyJ0eXAiOiJKV1QiL...');

Moodle - calling web service returns error/restore_not_executable_awaiting_required

I'm stuck with this error.
Trying to call custom web service, that performs duplication of quiz (duplicate_module()), its editation (quiz_update_instance()) and finally cache clearance (rebuild_course_cache).
It works perfectly until I add an question to the quiz. Then it returns error:
error/restore_not_executable_awaiting_required | ERRORCODE: restore_not_executable_awaiting_required. Fault code: 78563441. Actual reply from server: <?xml version="1.0" encoding="UTF-8"?> <methodResponse><fault><value><struct><member><name>faultCode</name><value><int>78563441</int></value></member><member><name>faultString</name><value><string>error/restore_not_executable_awaiting_required | ERRORCODE: restore_not_executable_awaiting_required</string></value></member></struct></value></fault></methodResponse>
Server settings:
max_execution_time=14400
max_input_time=14400
Code:
$context = stream_context_create(array('http' => array( 'method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request, 'timeout' => 14000000, )));
$path = $this->url . "/webservice/xmlrpc/server.php?wstoken=" . $this->token;
$file = file_get_contents($path, false, $context);
Could you please help me find the cause of the error? Thank you!
I had the same problem after upgrading Moodle 3.1 to 3.5.1, and found a fix for this on Moodle 3.5.2, which I cherry-picked:
https://tracker.moodle.org/browse/MDL-62897

SOAP Client Request --> Bad Request

I've been asked to look into syncing data using a SOAP service. I don't really know SOAP very well at all and I get a Bad Request Error.
The function I'm trying to call is a test echo function:
public string EchoAuthenticated(string text)
Each time I call it I get an error.
I have commented out the username / password setting as I don't know the username and password right now and my contact person is on leave :( Right now though I'd be perfectly happy just to get an authentication failed message rather than an error...
If anyone could point me in the right direction here please...
Thanks,
John
<?php
$apiUrl = 'https://exdev.api.propctrl.co.za/v3/Integration.svc?wsdl';
$options = array( 'trace' => 1, 'exceptions' => 1, 'soap_version' => SOAP_1_2);
try
{
$client = new SoapClient($apiUrl, $options);
//$data = array(
// 'Username' => "test",
// 'Password' => "test"
//);
//$header = new SoapHeader('https://exdev.api.propctrl.co.za/v3/', 'CredentialsHeader', $data, false);
//$client->__setSoapHeaders($header);
var_dump($client->__getFunctions());
print $client->EchoAuthenticated("Test String");
var_dump($client->__getLastRequest());
}
catch(Exception $e)
{
echo $e->getMessage();
}
?>
You might try something like:
...
$client = new SoapClient($apiUrl, $options);
var_dump($client->__getFunctions());
$auth = array("Username" => "John", "Password" => "secret",
"IsP24Credentials" => false);
$header = new SoapHeader("https://www.propctrl.com/", "CredentialsHeader",
$auth, FALSE);
$client->__setSoapHeaders($header);
print $client->EchoAuthenticated(array(
"text" => "My text to be echoed."
));
var_dump($client->__getLastRequest());
...
This should result in a request SOAP request like this:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="https://www.propctrl.com/v3" xmlns:ns2="https://www.propctrl.com/">
<env:Header>
<ns2:CredentialsHeader>
<ns2:IsP24Credentials>false</ns2:IsP24Credentials>
<ns2:Password>secret</ns2:Password>
<ns2:Username>John</ns2:Username>
</ns2:CredentialsHeader>
</env:Header>
<env:Body>
<ns1:EchoAuthenticated>
<ns1:text>My text to be echoed.</ns1:text>
</ns1:EchoAuthenticated>
</env:Body>
</env:Envelope>
As a side note, you might have a look at http://www.soapui.org/. This tool helps greatly with web service development.

Getting Response Body using Zend_http_Client

I am succesfully calling a REST API with the following code
$client = new Zend_Http_Client();
$client->setMethod(Zend_Http_Client::POST);
$client->setUri('http://www.example.com/api/type/');
$client->setParameterPost(array(
'useremail' => '******#*****.***',
'apikey' => 'secretkey',
'description' => 'TEST WEB API',
'amount' => '5000.00'
));
However I would like to get both the header value-(201) and Response Body that are returned after the execution.
How do I proceed with that?
I am assuming that you're actually executing the request via:
$response = $client->request();
At that point all you need is in the $response object,
//Dump headers
print_r($response->headers);
//Dump body
echo $response->getBody();
Refer to the Zend_Http_Response docs at:
http://framework.zend.com/apidoc/1.10/
for more methods that are available.
this should work...
$client->setUri ( $image_source_urls );
$response = $client->request ( 'GET' );
$folder_content = $response->getBody ();