I've followed the instructions on the readme to get the integration setup and tested in the first instance. When I run `php PaymentTransactions/get-an-accept-payment-page.php` via terminal, I get a response string.
When I try and run it via a web browser, I'm getting errors:
Fatal error: Uncaught exception 'Exception' with message 'Error getting valid response from api. Check log file for error details' in /Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/ApiOperationBase.php on line 126 ( ! ) Exception: Error getting valid response from api. Check log file for error details in /Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/ApiOperationBase.php on line 126
...and the error log:
Sun, 07 May 2017 12:16:22 -0500 INFO : [execute] (/Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/ApiOperationBase.php : 114) - Request Serialization Begin Sun, 07 May 2017 12:16:22 -0500 DEBUG : [execute] (/Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/ApiOperationBase.php : 115) - net\authorize\api\contract\v1\GetHostedPaymentPageRequest Object ( [transactionRequest:net\authorize\api\contract\v1\GetHostedPaymentPageRequest:private] => net\authorize\api\contract\v1\TransactionRequestType Object ( [transactionType:net\authorize\api\contract\v1\TransactionRequestType:private] => authCaptureTransaction [amount:net\authorize\api\contract\v1\TransactionRequestType:private] => 12.23 [currencyCode:net\authorize\api\contract\v1\TransactionRequestType:private] => [payment:net\authorize\api\contract\v1\TransactionRequestType:private] => [profile:net\authorize\api\contract\v1\TransactionRequestType:private] => [solution:net\authorize\api\contract\v1\TransactionRequestType:private] => [callId:net\authorize\api\contract\v1\TransactionRequestType:private] => [terminalNumber:net\authorize\api\contract\v1\TransactionRequestType:private] => [authCode:net\authorize\api\contract\v1\TransactionRequestType:private] => [refTransId:net\authorize\api\contract\v1\TransactionRequestType:private] => [splitTenderId:net\authorize\api\contract\v1\TransactionRequestType:private] => [order:net\authorize\api\contract\v1\TransactionRequestType:private] => [lineItems:net\authorize\api\contract\v1\TransactionRequestType:private] => [tax:net\authorize\api\contract\v1\TransactionRequestType:private] => [duty:net\authorize\api\contract\v1\TransactionRequestType:private] => [shipping:net\authorize\api\contract\v1\TransactionRequestType:private] => [taxExempt:net\authorize\api\contract\v1\TransactionRequestType:private] => [poNumber:net\authorize\api\contract\v1\TransactionRequestType:private] => [customer:net\authorize\api\contract\v1\TransactionRequestType:private] => [billTo:net\authorize\api\contract\v1\TransactionRequestType:private] => [shipTo:net\authorize\api\contract\v1\TransactionRequestType:private] => [customerIP:net\authorize\api\contract\v1\TransactionRequestType:private] => [cardholderAuthentication:net\authorize\api\contract\v1\TransactionRequestType:private] => [retail:net\authorize\api\contract\v1\TransactionRequestType:private] => [employeeId:net\authorize\api\contract\v1\TransactionRequestType:private] => [transactionSettings:net\authorize\api\contract\v1\TransactionRequestType:private] => [userFields:net\authorize\api\contract\v1\TransactionRequestType:private] => ) [hostedPaymentSettings:net\authorize\api\contract\v1\GetHostedPaymentPageRequest:private] => Array ( [0] => net\authorize\api\contract\v1\SettingType Object ( [settingName:net\authorize\api\contract\v1\SettingType:private] => hostedPaymentButtonOptions [settingValue:net\authorize\api\contract\v1\SettingType:private] => {"text": "Pay"} ) [1] => net\authorize\api\contract\v1\SettingType Object ( [settingName:net\authorize\api\contract\v1\SettingType:private] => hostedPaymentOrderOptions [settingValue:net\authorize\api\contract\v1\SettingType:private] => {"show": true} ) [2] => net\authorize\api\contract\v1\SettingType Object ( [settingName:net\authorize\api\contract\v1\SettingType:private] => hostedPaymentReturnOptions [settingValue:net\authorize\api\contract\v1\SettingType:private] => {"url": "http://test.com", "cancelUrl": "http://test.com", "showReceipt": false} ) ) [merchantAuthentication:net\authorize\api\contract\v1\ANetApiRequestType:private] => net\authorize\api\contract\v1\MerchantAuthenticationType Object ( [name:net\authorize\api\contract\v1\MerchantAuthenticationType:private] => 5KP3u95bQpv [transactionKey:net\authorize\api\contract\v1\MerchantAuthenticationType:private] => xxxx [sessionToken:net\authorize\api\contract\v1\MerchantAuthenticationType:private] => [password:net\authorize\api\contract\v1\MerchantAuthenticationType:private] => [impersonationAuthentication:net\authorize\api\contract\v1\MerchantAuthenticationType:private] => [fingerPrint:net\authorize\api\contract\v1\MerchantAuthenticationType:private] => [clientKey:net\authorize\api\contract\v1\MerchantAuthenticationType:private] => [mobileDeviceId:net\authorize\api\contract\v1\MerchantAuthenticationType:private] => ) [clientId:net\authorize\api\contract\v1\ANetApiRequestType:private] => sdk-php-1.9.3 [refId:net\authorize\api\contract\v1\ANetApiRequestType:private] => ) Sun, 07 May 2017 12:16:23 -0500 INFO : [execute] (/Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/ApiOperationBase.php : 118) - Request Serialization End Sun, 07 May 2017 12:16:23 -0500 INFO : [_sendRequest] (/Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/util/HttpClient.php : 75) - Url: https://apitest.authorize.net/xml/v1/request.api Sun, 07 May 2017 12:16:23 -0500 INFO : [_sendRequest] (/Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/util/HttpClient.php : 77) - Request to AnetApi: <?xml version="1.0" encoding="UTF-8"?> <getHostedPaymentPageRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <merchantAuthentication> <name><![CDATA[5KP3u95bQpv]]></name> <transactionKey>xxxx</transactionKey> </merchantAuthentication> <clientId><![CDATA[sdk-php-1.9.3]]></clientId> <transactionRequest> <transactionType><![CDATA[authCaptureTransaction]]></transactionType> <amount>12.23</amount> </transactionRequest> <hostedPaymentSettings> <setting> <settingName><![CDATA[hostedPaymentButtonOptions]]></settingName> <settingValue><![CDATA[{"text": "Pay"}]]></settingValue> </setting> <setting> <settingName><![CDATA[hostedPaymentOrderOptions]]></settingName> <settingValue><![CDATA[{"show": true}]]></settingValue> </setting> <setting> <settingName><![CDATA[hostedPaymentReturnOptions]]></settingName> <settingValue><![CDATA[{"url": "http://test.com", "cancelUrl": "http://test.com", "showReceipt": false}]]></settingValue> </setting> </hostedPaymentSettings> </getHostedPaymentPageRequest> Sun, 07 May 2017 12:16:23 -0500 INFO : [_sendRequest] (/Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/util/HttpClient.php : 89) - Sending 'XML' Request type Sun, 07 May 2017 12:16:23 -0500 INFO : [_sendRequest] (/Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/util/HttpClient.php : 94) - Sending http request via Curl Sun, 07 May 2017 12:16:23 -0500 INFO : [_sendRequest] (/Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/util/HttpClient.php : 96) - Response from AnetApi: Sun, 07 May 2017 12:16:23 -0500 ERROR : [_sendRequest] (/Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/util/HttpClient.php : 106) - CURL ERROR: Unknown SSL protocol error in connection to apitest.authorize.net:443
I'm not sure what I'm doing wrong here.
05-07-2017 10:17 AM
What version of cURL and Openssl are you using on your server? You can use the test script below, to see what version TLS your cURL is using to connect:
<?php $ch = curl_init('https://www.howsmyssl.com/a/check'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); curl_close($ch); $json = json_decode($data); echo $json->tls_version ."\n";
05-07-2017 12:19 PM
tls 1.0.
05-10-2017 10:37 AM
There is your issue, the sandbox is now only accepting TLS 1.2 connections. You may be able to resolve it by updating your cURL and Openssl. Your server should support TLS 1.2 connections as well in order to be PCI compliant.
05-11-2017 02:12 AM
In in some versions of CentOS 6 even if cURL TLS 1.2 is available, the default behavior is to NOT use this. In your SDK HttpClient.php ...
/Applications/MAMP/htdocs/_SandBox/auth_net/sample-code-php/vendor/authorizenet/authorizenet/lib/net/authorize/util/HttpClient.php
You could try adding:
curl_setopt($curl_request, CURLOPT_SSLVERSION, 6);
to the block of cURL options starting around line 69.
05-11-2017 06:04 AM
Hi
On my server TLS 1.2 is available and I have try to add
curl_setopt($curl_request, CURLOPT_SSLVERSION, 6);
on line number 69 where cURL is available but still I am facing the same issue..
and
here is code where i have added line:
public function _sendRequest($xmlRequest)
{
$xmlResponse = "";
$post_url = $this->_getPostUrl();
$curl_request = curl_init($post_url);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $xmlRequest);
curl_setopt($curl_request, CURLOPT_HEADER, 0);
curl_setopt($curl_request, CURLOPT_TIMEOUT, 45);
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_request, CURLOPT_SSLVERSION, 6);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);
$this->logger->info(sprintf(" Url: %s", $post_url));
// Do not log requests that could contain CC info.
$this->logger->info(sprintf("Request to AnetApi: \n%s", $xmlRequest));
if ($this->VERIFY_PEER) {
curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/../../ssl/cert.pem');
} else {
$this->logger->error("Invalid SSL option for the request");
return false;
}
if (preg_match('/xml/',$post_url)) {
curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
// file_put_contents($this->_log_file, "\nSending 'XML' Request type", FILE_APPEND);
$this->logger->info("Sending 'XML' Request type");
}
try
{
$this->logger->info("Sending http request via Curl");
$xmlResponse = curl_exec($curl_request);
$this->logger->info("Response from AnetApi: $xmlResponse");
} catch (\Exception $ex)
{
$errorMessage = sprintf("\n%s:Error making http request via curl: Code:'%s', Message:'%s', Trace:'%s', File:'%s':'%s'",
$this->now(), $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), $ex->getFile(), $ex->getLine() );
$this->logger->error($errorMessage);
}
if ($this->logger && $this->logger->getLogFile()) {
if ($curl_error = curl_error($curl_request)) {
$this->logger->error("CURL ERROR: $curl_error");
}
}
curl_close($curl_request);
return $xmlResponse;
}
Here is link to check the ssl version:
http://justredata.org/dev/ui/dodo1.php
Kindly update if there is something more I have check..
Thanks
Rahul Thakral
thakral.rahul1310@gmail.com
04-11-2018 06:21 AM - edited 04-11-2018 06:25 AM