Invalid SSL option using the Authorize.NET PHP SDK - php

I am trying to charge a card using Authorize.NET's PHP SDK. But it keeps giving me this error:
Thu, 29 Mar 2018 17:00:56 +0000 ERROR : [_sendRequest] (/lib/shared/AuthorizeNetRequest.php : 100) - ----Request---- Invalid SSL option
It has worked before, but now it keeps giving me a error, I have researched this but have found no answer, I have tried this in my code:
$sale->VERIFY_PEER = false;
I have also updated my cert.pem file but it still gives me a error.
PHP CODE:
<?php
require 'vendor/autoload.php';
use lib\net\authorize\api\contract\v1 as AnetAPI;
use lib\net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
$usermeta = get_user_meta(get_current_user_id(), '_carddetails_', TRUE);
define("AUTHORIZENET_API_LOGIN_ID", "[LOGIN_ID]");
define("AUTHORIZENET_TRANSACTION_KEY", "[TRANSACTION_KEY]");
define("AUTHORIZENET_SANDBOX", true);
$sale = new AuthorizeNetAIM(AUTHORIZENET_API_LOGIN_ID, AUTHORIZENET_TRANSACTION_KEY);
$sale->VERIFY_PEER = false;
$sale->amount = $_POST['grandTotal'];
$sale->card_num = $usermeta['number'];
$sale->exp_date = $usermeta['expdate'];
$sale->addLineItem('item1', // Item Id
'Order 1', // Item Name
'Order 1', // Item Description
'1', // Item Quantity
$_POST['grandTotal'], // Item Unit Price
'N' // Item taxable
);
$customer = (object) array();
$customer->first_name = $usermeta['firstname'];
$customer->last_name = $usermeta['lastname'];
$customer->company = $usermeta['company'];
$customer->address = $usermeta['address'];
$customer->city = $usermeta['city'];
$customer->state = $usermeta['state'];
$customer->zip = $usermeta['zip'];
$customer->country = $usermeta['country'];
$customer->cust_id = 9999;
$customer->customer_ip = $_SERVER['REMOTE_ADDR'];
$sale->setFields($customer);
$response = $sale->authorizeAndCapture();
$responseCode = $response->response_code;
$authCode = $response->authorization_code;
$avsResultCode = $response->avs_response;
$transId = $response->transaction_id;
$transHash = $response->md5_hash;
$accountNumber = $response->account_number;
$accountType = $response->card_type;
$description = $response->description;
if ($response->approved)
{
echo "iT worked";
}
else
{
echo $response->error_message;
}
?>

You should grab the latest cert from https://github.com/AuthorizeNet/sdk-php/tree/master/lib/ssl. It was last updated 5 days ago as of writing this post to include new Authorize certs.
Disabling or changing the default peer and cert verification could be dangerous.

I have figured it out.
I commented this out:
$sale->VERIFY_PEER = false;
And commented line 80 of HttpClient.php
Here is where I found the answer at: https://github.com/AuthorizeNet/sdk-php/issues/223

Related

Tranzila payment gateway : Not Authorized error message in response

Trying to integrate tranzila payment gateway in my php project and testing with dummy credit card numbers on localhost before go live.I get php code from tranzila official document.
code given below
`
$tranzila_api_host = 'secure5.tranzila.com';
$tranzila_api_path = '/cgi-bin/tranzila71u.cgi';
// Prepare transaction parameters
$query_parameters['supplier'] = 'TERMINAL_NAME'; // 'TERMINAL_NAME' should be replaced by actual terminal name
$query_parameters['sum'] = '45'; // Transaction sum
$query_parameters['currency'] = '1'; // Type of currency 1 NIS, 2 USD, 978 EUR, 826 GBP, 392 JPY
$query_parameters['ccno'] = '12312312'; // Test card number
$query_parameters['expdate']= '0820'; // Card expiry date: mmyy
$query_parameters['myid'] = '12312312'; // ID number if required
$query_parameters['mycvv'] = '123'; // number if required
$query_parameters['cred_type'] = '1'; // This field specifies the type of transaction, 1 - normal transaction, 6 - credit, 8 - payments
// $query_parameters['TranzilaPW'] = 'TranzilaPW' ;
$query_string = '' ;
foreach($query_parameters as $name => $value) {
$query_string .= $name.'='.$value.'&' ;
}
$query_string = substr($query_string , 0 , - 1 ) ; // Remove trailing '&'
// Initiate CURL
$cr = curl_init();
curl_setopt($cr,CURLOPT_URL ,"https://$tranzila_api_host$tranzila_api_path");
curl_setopt($cr,CURLOPT_POST,1);
curl_setopt($cr,CURLOPT_FAILONERROR,true);
curl_setopt($cr,CURLOPT_POSTFIELDS,$query_string) ;
curl_setopt($cr,CURLOPT_RETURNTRANSFER,1);
curl_setopt($cr,CURLOPT_SSL_VERIFYPEER,0);
// Execute request
$result = curl_exec($cr);
$error = curl_error($cr);
if(!empty($error)){
die( $error );
}
curl_close ($cr);
// Preparing associative array with response data
$response_array = explode('&',$result);
$response_assoc = array();
if(count($response_array) > 1){
foreach($response_array as $value){
$tmp = explode('=',$value);
if (count($tmp) > 1 ){
$response_assoc [$tmp[0]] = $tmp[1];
}
}
}
// Analyze the result string
if(!isset($response_assoc['Response'])){
die($result."\n");
/**
* When there is no 'Response' parameter it either means
* that some pre-transaction error happened (like authentication
* problems), in which case the result string will be in HTML format,
* explaining the error, or the request was made for generate token only
* (in this case the response string will only contain 'TranzilaTK'
* parameter)
*/
}else if($response_assoc['Response'] !== '000'){
die($response_assoc['Response']."\n");
// Any other than '000' code means transaction failure
// (bad card, expiry, etc ..)
}else{
die("Success \n");
}
`
Here i replaced supplier with my original supplier name which i can't show here for security reasons.When run this code with actual supplier i got 'Not Authorized' error.

PHP Bitwasp, signing a bitcoin-cash transaction

I try to sign test bitcoin-cash transaction, and then broadcast.
For bitwasp version 0.0.35.0, the code is:
$utxoOwnerPrivateKey = 'MyPrIvAtEKey';//public key is "16Dbmp13CqdLVwjXrd6amF48t7L8gYSGBj", note - the real private key is another
$utxo = '5e44cdab9cb4a4f1871f2137ab568bf9ef2760e52816971fbaf0198f19e28378';
$utxoAmount = 598558;
$reciverPublicKey = '1EjCxux1FcohsBNGzY9KdF59Dz7MYHQyPN';
$fee = 1000;
$addressCreator = new \Btccom\BitcoinCash\Address\AddressCreator();
$networkObject = \Btccom\BitcoinCash\Network\NetworkFactory::bitcoinCash();
$keyPairInput = \BitWasp\Bitcoin\Key\PrivateKeyFactory::fromWif($utxoOwnerPrivateKey, null, $networkObject);
$outpoint = new \BitWasp\Bitcoin\Transaction\OutPoint(\BitWasp\Buffertools\Buffer::hex($utxo, 32), 0);
$transaction = \BitWasp\Bitcoin\Transaction\TransactionFactory::build()
->spendOutPoint($outpoint)
->payToAddress($utxoAmount - $fee, $addressCreator->fromString($reciverPublicKey, $networkObject) )
->get();
echo "Unsigned transaction: " . $transaction->getHex() . '<BR><BR>';
$signScript = \BitWasp\Bitcoin\Script\ScriptFactory::scriptPubKey()->payToPubKeyHash($keyPairInput->getPublicKey()->getPubKeyHash());
$txOut = new \BitWasp\Bitcoin\Transaction\TransactionOutput($utxoAmount - $fee, $signScript);
$signer = new \BitWasp\Bitcoin\Transaction\Factory\Signer($transaction);
$signatureChecker = \Btccom\BitcoinCash\Transaction\Factory\Checker\CheckerCreator::fromEcAdapter( \BitWasp\Bitcoin\Bitcoin::getEcAdapter() ); // for version 0.0.35
$signer->setCheckerCreator( $signatureChecker ); // for version 0.0.35
$input = $signer->input(0, $txOut);
$signatureType = \Btccom\BitcoinCash\Transaction\SignatureHash\SigHash::ALL | \Btccom\BitcoinCash\Transaction\SignatureHash\SigHash::BITCOINCASH;
$input->sign($keyPairInput, $signatureType);
$signed = $signer->get();
echo "Witness serialized transaction: " . $signed->getHex() . '<BR><BR>';
echo "Base serialized transaction: " . $signed->getBaseSerialization()->getHex() . '<BR><BR>';
echo "Script validation result: " . ($input->verify() ? "yes\n" : "no\n"). '<BR><BR>';
die();
In this case I get the result:
Script validation result: no
Trying to broadcast the BCH transaction gives an error:
An error occured:
16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation). Code:-26
I think, it means, that signature is wrong. If we remove the flag $signatureType (keep this default), then Script validation result will be yes, but broadcasting will give an error:
16: mandatory-script-verify-flag-failed (Signature must use SIGHASH_FORKID). Code:-26
I think, it means - transaction signed as in bitcoin network, must to be signed by bitcoin-cash rules. Maybe I'm wrong. But bitcoin transaction signing is fine. Bitwasp has no manuals, how to sign a bitcoin-cash transactions, I have the same code for bitwasp v.0.0.34.2 (without addon "btccom/bitwasp-bitcoin-bch-addon", using $signer->redeemBitcoinCash(true); function) but it gives the same result.
It is interesting that in code of bitcoin-cash signer it takes the inner variable amount and include it in hash:
$hasher = new V1Hasher($this->transaction, $this->amount);
But for bitcoin bitwasp doesn't take the amount, presumably it takes an amount from the transaction.
Help me please to sign the transaction, bitwasp has only bitcoin examples, not bitcoin-cash. It is very difficult to find any informaion about php altcoins signing without third-party software. Regards.
This code to sign a bitcoin-cash transaction with PHP bitwasp v.0.0.35 library is works!
$unspendedTx = '49343e0a4ef29b819f87df1371c6f8eafa1f235074a27fb6aa5f4ab4c48e5c16';
$utxOutputIndex = 0;
$utxoPrivateKey = 'MyPrIvAtEKey';
$utxoAmount = 300000;
$reciverPublicKey = '1E8XaWNsCWyVaZaWTLh8uBdAZjLQqwWmzM';
$fee = 1000;
$networkObject = \Btccom\BitcoinCash\Network\NetworkFactory::bitcoinCash();
$outpoint = new \BitWasp\Bitcoin\Transaction\OutPoint(\BitWasp\Buffertools\Buffer::hex($unspendedTx, 32), $utxOutputIndex /* index of utxo in transaction, generated it */);
$destination = \BitWasp\Bitcoin\Script\ScriptFactory::scriptPubKey()->payToPubKeyHash( (new \Btccom\BitcoinCash\Address\AddressCreator())->fromString($reciverPublicKey)->getHash() );
$transaction = \BitWasp\Bitcoin\Transaction\TransactionFactory::build()
->spendOutPoint($outpoint)
->output($utxoAmount - $fee, $destination)
->get();
echo "Unsigned transaction: " . $transaction->getHex() . '<BR><BR>';
$keyPairInput = \BitWasp\Bitcoin\Key\PrivateKeyFactory::fromWif($utxoPrivateKey, null, $networkObject);
$txOut = new \BitWasp\Bitcoin\Transaction\TransactionOutput($utxoAmount, \BitWasp\Bitcoin\Script\ScriptFactory::scriptPubKey()->payToPubKeyHash( $keyPairInput->getPubKeyHash() ) );
$signer = new \BitWasp\Bitcoin\Transaction\Factory\Signer($transaction);
$signatureChecker = \Btccom\BitcoinCash\Transaction\Factory\Checker\CheckerCreator::fromEcAdapter( \BitWasp\Bitcoin\Bitcoin::getEcAdapter() ); // for version 0.0.35
$signer->setCheckerCreator( $signatureChecker ); // for version 0.0.35
$input = $signer->input(0, $txOut);
$signatureType = \Btccom\BitcoinCash\Transaction\SignatureHash\SigHash::ALL | \Btccom\BitcoinCash\Transaction\SignatureHash\SigHash::BITCOINCASH;
$input->sign($keyPairInput, $signatureType);
$signed = $signer->get();
echo "Transaction: " . $signed->getHex() . '<BR><BR>';
die();
I had broadcasted this PHP-generated test transaction, see link to tx. Problaly the problem was in
->payToAddress($utxoAmount - $fee, $addressCreator->fromString($reciverPublicKey, $networkObject) )
Maybe payToAddress has a bug, because "hand" script creation gives another transaction. Second:
$txOut = new \BitWasp\Bitcoin\Transaction\TransactionOutput($utxoAmount - $fee, $signScript);
We must to create tx input(previous output) without the fee.
Used libraries ( composer.json ):
{
"require" : {
"php" : ">=7.0",
"bitwasp/bitcoin": "0.0.35.0",
"btccom/bitwasp-bitcoin-bch-addon" : "0.0.2"
}
}
Hope, this will help for all altcoin api creators on PHP.

How can I fix this error implementing CommWeb on my website?

I am trying to implement CommWeb on my PHP site. It isn't working. I am getting following error message:
HTTP Status - 400
E5000: Required field vpc_AccessCode was not present in the request
How can I fix this? I haven't found anything helpful in the documentation.
Here is my code:
<?php
//Merchant Admin URL: https://migs.mastercard.com.au/ma/CBA
//Merchant ID: TEST
//Operator ID: Admin
//Password: d#test
// Access Code AEFTEST 1A22FTESTTEST
$session_id = 1;
$finalprice = 50;
$testarr = array(
"vpc_Amount" => $finalprice*100,//Final price should be multifly by 100
"vpc_AccessCode" => "AEFTEST",//Put your access code here
"vpc_Command"=> "pay",
"vpc_Locale"=> "en",
"vpc_MerchTxnRef"=> "CLI".$session_id, //This should be something unique number, i have used the session id for this
"vpc_Merchant"=> "TEST",//Add your merchant number here
"vpc_OrderInfo"=> "1A22FTESTTEST",//this also better to be a unique number
"vpc_ReturnURL"=> "http://localhost/test1/index.php/commweb/",//Add the return url here so you have to code here to capture whether the payment done successfully or not
"vpc_Version"=> "1");
ksort($testarr); // You have to ksort the arry to make it according to the order that it needs
$SECURE_SECRET = "d#test";//Add the secure secret you have get
$securehash = $SECURE_SECRET;
$url = "https://migs.mastercard.com.au/ma/CBA";
foreach ($testarr as $key => $value)
{
$securehash .= $value;
$url .= $key."=".urlencode($value)."&";
}
$securehash = md5($securehash);//Encoding
$url .= "vpc_SecureHash=".$securehash;
header("location:https://migs.mastercard.com.au/vpcpay?$url");
?>

PHP [function.file-get-contents]: Failed to open stream

This is really annoying me, the php script was working and returning the weather from open weather map but literally all of a sudden the php script takes forever to execute and the following error is produced:
Warning: file_get_contents(http://api.openweathermap.org/data/2.5/weather?lat=&lon=&units=metric&cnt=7&lang=en&key=f38a36af9e4965dd5192ba4282abe070) [function.file-get-contents]: failed to open stream: Connection timed out in /xxx/xxx/public_html/fullweather.php on line 15
Any help would be appreciated. The php script can be viewed below. Only the beginning is important (first 18 lines) but I have included the full thing.
<?php
$lat = $_POST["latitude"];
$lon = $_POST["longitude"];
$url="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&units=metric&cnt=7&lang=en&key=f38a36af9e4965dd5192ba4282abe070";
// Make call with cURL
$session = curl_init($url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$json = curl_exec($session);
$json=file_get_contents($url);
$data=json_decode($json,true);
class weatherdata
{
public $temp = "";
public $weather = "";
public $clouds = "";
public $area = "";
public $humidity = "";
public $humidpressure = "";
public $weatherdesc = "";
public $tempmin = "";
public $tempmax = "";
public $windspeed = "";
public $winddirec = "";
}
$data1 = $data['main']['temp'];
$data2 = $data['weather'][0]['main'];
$data3 = $data['clouds']['all'];
$data4 = $data['name'];
$data5 = $data['main']['humidity'];
$data6 = $data['main']['pressure'];
$data7 = $data['weather'][0]['description'];
$data8 = $data['main']['temp_min'];
$data9 = $data['main']['temp_max'];
$data10 = $data['wind']['speed'];
$data12 = $data['wind']['deg'];
$weatherdata = new weatherdata();
$weatherdata->temp = $data1;
$weatherdata->weather = $data2;
$weatherdata->clouds = $data3;
$weatherdata->area = $data4;
$weatherdata->humidity = $data5;
$weatherdata->humidpressure = $data6;
$weatherdata->weatherdesc = $data7;
$weatherdata->tempmin = $data8;
$weatherdata->tempmax = $data9;
$weatherdata->windspeed = $data10;
$weatherdata->winddirec = $data12;
$output[] = $weatherdata;
print(json_encode($output));
?>
I think the API was just down, cause the link is working for me right now.
Try one more time.
May be the API had change it's url by the time. Try to check the documentation for any updated information. I think that they could change it and your code couldnt find because this $url doesn't exist anymore.
i added https instead of http in url and it worked.
so maybe change http in url like this url.
$url="https://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&units=metric&cnt=7&lang=en&key=f38a36af9e4965dd5192ba4282abe070";
Edit
Also you should not show your api key to anyone as some one can use it.

PHP-EWS fails on more than one attachment

I use James Armes's PHP-EWS library.
The following code works fine with single attachments, but fails with multiply files.
<?php
$msgRequest->MessageDisposition = 'SaveOnly';
$msgResponse = $ews->CreateItem($msgRequest);
$msgResponseItems = $msgResponse->ResponseMessages->CreateItemResponseMessage->Items;
// Create attachment(s)
$attachments = array();
$i = 0;
foreach ($message_details['attachment'] as $attachment) {
$attachments[$i] = new EWSType_FileAttachmentType();
$attachments[$i]->Content = file_get_contents($attachment['path'] . '/' . $attachment['file']);
$attachments[$i]->Name = $attachment['file'];
$i++;
}
//
// Attach files to message
$attRequest = new EWSType_CreateAttachmentType();
$attRequest->ParentItemId = $msgResponseItems->Message->ItemId;
$attRequest->Attachments = new EWSType_NonEmptyArrayOfAttachmentsType();
$attRequest->Attachments->FileAttachment = $attachments;
$attResponse = $ews->CreateAttachment($attRequest);
$attResponseId = $attResponse->ResponseMessages->CreateAttachmentResponseMessage->Attachments->FileAttachment->AttachmentId;
// Save message id from create attachment response
$msgItemId = new EWSType_ItemIdType();
$msgItemId->ChangeKey = $attResponseId->RootItemChangeKey;
$msgItemId->Id = $attResponseId->RootItemId;
// Send and save message
$msgSendRequest = new EWSType_SendItemType();
$msgSendRequest->ItemIds = new EWSType_NonEmptyArrayOfBaseItemIdsType();
$msgSendRequest->ItemIds->ItemId = $msgItemId;
$msgSendRequest->SaveItemToFolder = true;
$msgSendResponse = $ews->SendItem($msgSendRequest);
$response = $msgSendResponse->ResponseMessages->SendItemResponseMessage;
?>
$ews->SendItem() returns this error:
Uncaught SoapFault exception: [a:ErrorSchemaValidation] The request
failed schema validation: The required attribute 'Id' is missing.
What do I miss here?
Found the answer here:
https://github.com/jamesiarmes/php-ews/issues/132
Basically Exchange does not use an array if there is only one attachment, so an additional check is required to determine where to get the ID from.
if(!is_array($attResponse->ResponseMessages->CreateAttachmentResponseMessage))
$attResponseId = $attResponse->ResponseMessages->CreateAttachmentResponseMessage->Attachments->FileAttachment->AttachmentId;
else {
$attResponseId = $attResponse->ResponseMessages->CreateAttachmentResponseMessage[0]->Attachments->FileAttachment->AttachmentId;
}
Exchange uses the same structure with recipients. I find this inconsistent, however I am sure there is a reason behind it.
I hope someone will benefit from raising this.

Categories