Skip to content

Commit

Permalink
Merge pull request #406 from AuthorizeNet/022021-hotfix
Browse files Browse the repository at this point in the history
Hotfix for BOM character issue
  • Loading branch information
gnongsie authored Feb 4, 2021
2 parents cba5827 + 8cc56b4 commit 23de64e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ override the new secure-http default setting)*.
{
"require": {
"php": ">=5.6",
"authorizenet/authorizenet": "2.0.0"
"authorizenet/authorizenet": "2.0.1"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion lib/net/authorize/api/constants/ANetEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class ANetEnvironment
const SANDBOX = "https://apitest.authorize.net";
const PRODUCTION = "https://api2.authorize.net";

const VERSION = "2.0.0";
const VERSION = "2.0.1";
}
14 changes: 11 additions & 3 deletions lib/net/authorize/api/controller/base/ApiOperationBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function execute($endPoint = \net\authorize\api\constants\ANetEnvironment
{
$this->beforeExecute();

$this->apiRequest->setClientId("sdk-php-" . \net\authorize\api\constants\ANetEnvironment::VERSION);
$this->apiRequest->setClientId("sdk-php-" . \net\authorize\api\constants\ANetEnvironment::VERSION);

$this->logger->info("Request Creation Begin");
$this->logger->debug($this->apiRequest);
Expand All @@ -122,7 +122,7 @@ public function execute($endPoint = \net\authorize\api\constants\ANetEnvironment
$requestRoot = $mapper->getXmlName((new \ReflectionClass($this->apiRequest))->getName());

$requestArray = [$requestRoot => $this->apiRequest];
$this->logger->info("Request Creation End");

$this->httpClient->setPostUrl( $endPoint);
Expand All @@ -138,7 +138,15 @@ public function execute($endPoint = \net\authorize\api\constants\ANetEnvironment
$jsonResponse = $this->httpClient->_sendRequest(json_encode($requestArray));
if($jsonResponse != null){
//decoding json and removing bom
$response = json_decode( substr($jsonResponse,3), true);
$possibleBOM = substr($jsonResponse, 0, 3);
$utfBOM = pack("CCC", 0xef, 0xbb, 0xbf);

if (0 === strncmp($possibleBOM, $utfBOM, 3)) {
$response = json_decode( substr($jsonResponse,3), true);
}
else {
$response = json_decode($jsonResponse, true);
}
$this->apiResponse = new $this->apiResponseType();
$this->apiResponse->set($response);
}
Expand Down

0 comments on commit 23de64e

Please sign in to comment.