SOAP: Invalid HTTPS client certificate path - php

When I run the below-given code, the error ERROR: Invalid HTTPS client certificate path is generated. I checked that the path to certificate.pem and test.wsdl is correct. What might be the reason of such error?
$wsdl = 'http://localhost:10088/test/test.wsdl';
$options = array(
'local_cert' => 'http://localhost:10088/test/certificate.pem',
'soap_version' => SOAP_1_1
);
try {
$client = new Zend_Soap_Client($wsdl, $options);
$result = $client->getLastResponse();
print_r($result);
} catch (SoapFault $s) {
die('ERROR: [' . $s->faultcode . '] ' . $s->faultstring);
} catch (Exception $e) {
die('ERROR: ' . $e->getMessage());
}

The value for the option local_cert must be a file path instead of an URL. Change the code to this for $options:
$options = array(
'local_cert' => '/path_where_cert_is_stored/certificate.pem',
'soap_version' => SOAP_1_1
);
Since the documentation for Zend_Soap_Client isn't complete, you can look at PHP: SOAP - Manual for more information, because this what Zend_Soap_Client uses under the hood. In my opinion the possible arguments are better described at PHP: SoapClient::SoapClient - Manual (especially look at the example).

Related

Arbitrage Trading of ETH/BTC using ccxt crypto API throws error while creating buy order

I am working on an app that does ETH/BTC arbitrage trading of crypto-currency using ccxt crypto API for PHP, and i keep receiving this Network Error exception thrown from the API call usually while trying to place a limit buy order.
{"status":-124,"error_message":"Enter the size in units of 0.0000001 ETH.","data":null}
This above exception is thrown from Bitflyer exchange.
My code is as follows:
$name = '\\ccxt\\'.$exchangeId;
$exchange = new $name(array (
'apiKey' => $api_key, // ←------------ replace with your keys
'secret' => $secret_key,
'enableRateLimit' => true,
));
try{
$symbol = 'ETH/BTC';
$type = 'limit'; // # or 'market', or 'Stop' or 'StopLimit'
$side = 'buy'; // 'sell' or 'buy'
$amount = $data['trade_base_amount']; //0.0515996
$price = $data['exchange_rate']; // 0.01938
// extra params and overrides
$params = array();
$response = $exchange->create_order($symbol, $type, $side, $amount, $price, $params);
print_r($response);
}catch (\ccxt\NetworkError $e) {
echo $exchange->id . ' fetch_trades failed due to a network error: '.$e->getMessage () . "\n";
}catch (\ccxt\ExchangeError $e) {
echo $exchange->id . ' fetch_trades failed due to exchange error: ' .$e->getMessage () . "\n";
}catch (\Exception $e) {
echo $exchange->id . ' fetch_trades failed with: ' . $e->getMessage () . "\n";
}
Can anyone please explain why am I getting this error?
Thanks in advance.
Try using amountToPrecision for me worked
get the documentation on CCXT

SSL Certification issue cURL error 60 and Error executing "PutObject"

I am trying to send a .txt file to an s3bucket in AWS but whenever I run my code using mamp I get the following error:
Error:Error executing "PutObject" on "https://dynamics-bucket-qa.s3.eu-west-2.amazonaws.com/folder/Test.txt"; AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
I have placed cacert.pem file which I downloaded from the internet in the extra/ssl folder in MAMP and I have also updated the php.ini file with this curl.cainfo = "C:\MAMP\bin\php\php7.2.10\extras\ssl\cacert.pem"
After all this, it still does not work. I've been trying for a long time but haven't managed to fix it. I'm pretty new to all this.
I'm using PHP version 7.2.10
<?php
// Run:$ composer require aws/aws-sdk-php
require '../vendor/autoload.php';
use Aws\AwsClient;
use Aws\Exception\AwsException;
// AWS Info
$bucketName = 'dynamics-bucket-qa';
$IAM_KEY = 'XXXXXXXXXXXXXXXXXXXXXXX';
$IAM_SECRET = 'XXXXXXXXXXXXXXXX';
// Connect to AWS
try {
// You may need to change the region. It will say in the URL when the bucket is open
// and on creation.
$s3 = Aws\S3\S3Client::factory(
array(
'credentials' => array(
'key' => $IAM_KEY,
'secret' => $IAM_SECRET
),
'version' => 'latest',
'region' => 'eu-west-2'
)
);
} catch (Exception $e) {
die("Error: " . $e->getMessage());
}
// For this, I would generate a unqiue random string for the key name. But you can do whatever.
$keyName = 'folder/' . basename($_FILES["fileToUpload"]['name']);
$pathInS3 = 'https://s3.eu-west-2.amazonaws.com/' . $bucketName . '/' . $keyName;
// Add it to S3
try {
// Uploaded:
$file = $_FILES["fileToUpload"]['tmp_name'];
$s3->putObject(
array(
'Bucket'=>$bucketName,
'Key' => $keyName,
'SourceFile' => $file,
'StorageClass' => 'REDUCED_REDUNDANCY'
)
);
} catch (S3Exception $e) {
die('Error:' . $e->getMessage());
} catch (Exception $e) {
die('Error:' . $e->getMessage());
}
echo 'Done';
//htdocs composer -v
?>

Why is a parameter empty/broken in SoapClient::__getLastRequest() when attempting to use a Soap web service?

We are attempting to call a function OrderInteractive() defined by a wsdl at https://demo2.mvrs.com/AdrConnect/AdrConnectWebService.svc?singlewsdl. It takes two parameters, a communications block with login info, and an order block with data in it. I know the login info is correct, and we are getting a response from the service, but it gives us the default "unknown error has occurred" message. When checking the result of __getLastRequest(), we get this:
<ns1:OrderInteractive>
<ns1:inCommunications>
<Communications>
<Host>Online</Host>
<Account>xxxxx</Account>
<UserID>01</UserID>
<Password>xxxxxxxxx</Password>
<ReportTypes>
<Type>XML2.02</Type>
</ReportTypes>
</Communications>
</ns1:inCommunications>
<ns1:inOrder/>
</ns1:OrderInteractive>
If you look, the order parameter is just empty. My question is why is SOAP stripping the order block, or why is the order block empty? I also tried 2 other methods of calling the function but both result in this logged in my error log:
"The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'OrderInteractive'. End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'InOrder' from namespace ''. Line 2, position 185."
My code is below:
$commsBlock = "<Communications>
<Host>Online</Host>
<Account>xxxxx</Account>
<UserID>01</UserID>
<Password>xxxxxxxxx</Password>
<ReportTypes>
<Type>XML2.02</Type>
</ReportTypes>
</Communications>";
$orderBlock = "<Order>
<Handling>OL</Handling>
<Account>xxxxx</Account>
<ProductID>DL</ProductID>
<State>
<Abbrev>" . $order['state'] . "</Abbrev>
<Full></Full>
</State>
<Subtype>3Y</Subtype>
<Purpose>AA</Purpose>
<License>" . $order['dln'] . "</License>
<FirstName>" . $order['firstname'] . "</FirstName>
<MiddleName>" . $order['middlename'] . "</MiddleName>
<LastName>" . $order['lastname'] . "</LastName>
<DOB>
<Year>" . date('Y', $order['dob']) . "</Year>
<Month>" . date('m', $order['dob']) . "</Month>
<Day>" . date( 'd', $order['dob']) . "</Day>
</DOB>
<Misc>TEST ORDER INTERACTIVE</Misc>
</Order>";
$soap_url = 'https://demo2.mvrs.com/AdrConnect/AdrConnectWebService.svc?singlewsdl'; // test system url
$soap_params = array(
'trace' => true,
'exceptions' => true,
'cache_wsdl' => false
);
$_client = new SoapClient($soap_url, $soap_params);
$params = array("inCommunications" => $commsBlock, "inOrder" => $orderBlock);
// TRY TO SEND
try {
$_client->OrderInteractive($params); // works, but sends broken order node
//$_client->__soapCall('OrderInteractive', $params); // breaks, goes to catch
//$_client->OrderInteractive(new SoapParam($commsBlock, 'InCommunications'), new SoapParam($orderBlock, 'InOrder')); // breaks, goes to catch
} catch(SoapFault $e) {
capDebug(__FILE__, __LINE__, "Error: SoapFault:\n" . $e->getMessage(), '/tmp/SOAP_errors.log');
}
class inOrder {
function inOrder($xml) {
$this->OrderXml = $xml;
}
}
$xml_order = '<Order>
<Handling>OL</Handling>
<ProductID>DL</ProductID>
.
.
.
<Misc>TEST ORDER INTERACTIVE</Misc></Order>';
// create our order object that is needed
$order = new inOrder($xml_order);
// create our OrderInteractive parameters
$parameters = array(
"inCommunications" => $xml_communication,
"inOrder" => $order
);
try {
$xml = $_client->OrderInteractive($parameters);
} catch (Exception $e) {
print $e->getMessage() . "\n"; exit();
}
The code above worked. WSDL expecting a string and an object as params. Created a class for the order and used a string for the communications block, and we are receiving data fine.

if "message" is protected, how do I retrieve SOAP response called "message"?

I'm really stuck on this one. At the bottom of this post, I've attached the API documentation I'm working with. I want to catch the "message" when the response ("ask") isn't "Success". Seems reasonable enough, right? But when I do something like:
sfcSendError('Something went wrong. This is the message from the API: ' . $result->message);
I get a fatal error:
PHP Fatal error: Cannot access protected property SoapFault::$message
I found this seemingly related question on SO, so I tried changing "message" to "getMessage()" but (no surprise) that results in a different fatal error about calling an undefined function.
Here's my code snippet:
$client = mySoapClient(MODULE_SHIPPING_SFC_API_URL);
if (!$client) {
sfcSendError('could not make a SOAP connection. Halting until next CRON. [' . __FILE__ . ':' . __LINE__ . ']', 'SOAP Failure in cron job');
exit; //halt and wait for the next time cron runs
} else {
$HeaderRequest = array(
'customerId' => MODULE_SHIPPING_SFC_ACCOUNT,
'appToken' => MODULE_SHIPPING_SFC_TOKEN,
'appKey' => MODULE_SHIPPING_SFC_KEY
);
$reg = array(
'HeaderRequest' => $HeaderRequest,
'detailLevel' => 1,
'ordersCode' => $_query->fields['sfc_ordersCode']
);
$result = $client->getOrderByCode($reg);
if ($result->ask != "Success") {
sfcSendError('Something went wrong. This is the message from SFC: ' . $result->message, 'SOAP Failure in cron job');
$_query->MoveNext();
continue;
}
}
This is the referenced function:
function mySoapClient($url)
{
try {
$client = #new SoapClient($url, array(
'trace' => 1,
'exceptions' => 0,
'encoding' => 'UTF-8'
));
} catch (SoapFault $e) {
return 0;
}
return $client;
}
What am I doing wrong? Or is this a "bug" with the API where they really shouldn't be using "message" in their response?

How do I access Web Service via SOAP in PHP?

I tried something like this :
try{
$opts = array(
'http'=>array(
'user_agent' => 'PHPSoapClient'
)
);
$context = stream_context_create($opts);
$client = new SoapClient('http://83.166.204.26:7147/TEST/WS/Harmont%20Blaine_TEST/Page/WebItem?wsdl',
array('stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE));
));
print_r($client);
}
catch(Exception $e){
echo $e->getMessage();
}
and the result of my var_dump function is:
SOAP-ERROR: Parsing WSDL: Couldn't load from .... failed to load external entity...
how can i access the web service via soap ? thx.
This is the beginning of the xml :
I just downloaded the file from 83.166.204.26:7147/TEST/WS/Harmont%20Blaine_TEST/Page/WebItem?wsdl. I saved it on wsdl format and now i'm getting the functions
$client = new SoapClient("WebItem.wsdl", array('proxy_host' => "83.166.204.26",
'proxy_port' => 7147,
'proxy_login' => "xxxxxx",
'proxy_password' => "xxxxxxxx"));
echo "<pre>"; var_dump($client->__getFunctions()); echo "</pre>";
Firstly:
URL that you supply required Basic authentication. When using HTTP basic authentication, PHP will only send the credentials when invoking the service, not when fetching the WSDL.
You CAN get a wsdl, if basic authentication is required:
$login = 'xxx';
$password = 'xxx';
$client = new SoapClient(
'http://' . urlencode($login) . ':' . urlencode($password) . '#83.166.204.26:7147/TEST/WS/Harmont%20Blaine_TEST/Page/WebItem?wsdl',
array(
'login' => $login,
'password' => $password
)
);
Secondly :
Your return XML does not look like valid WSDL file. Read SoapClient documentation page for proper usage - first argument of new SoapClient() must be URI of WSDL file or null for non-WSDL usage. (Here is an example of WSDL file ) May be you need to create SoapClient in non-WSDL mode?

Categories