Skip to content

Commit 46953cf

Browse files
committed
Issue : 115
Removed date_default_timezone_set usages.
2 parents a018827 + 976e57d commit 46953cf

15 files changed

Lines changed: 128 additions & 57 deletions

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "sample-code-php"]
22
path = sample-code-php
3-
url = https://github.com/Authorizenet/sample-code-php.git
3+
url = https://github.com/AuthorizeNet/sample-code-php.git

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ language: php
33
php:
44
- 5.6
55
- 7.0
6-
6+
77
sudo: false
88

99
before_script:
1010
- pecl install xmldiff
1111
- composer install --prefer-dist --ignore-platform-reqs
12-
- chmod +x ./test-sample-codes.sh
13-
- git submodule update --recursive
14-
12+
- git submodule update --remote --recursive
13+
1514
script:
1615
- vendor/phpunit/phpunit/phpunit --coverage-clover=coverage.clover
16+
- cd sample-code-php
17+
- composer install --prefer-dist --ignore-platform-reqs
18+
- vendor/phpunit/phpunit/phpunit test-runner.php .
1719

1820
after_script:
1921
- wget https://scrutinizer-ci.com/ocular.phar
2022
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
21-
- ./test-sample-codes.sh

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Authorize.Net PHP SDK
22
======================
33

4-
[![Build Status] (https://travis-ci.org/AuthorizeNet/sdk-php.png?branch=master)]
4+
[![Build Status] (https://travis-ci.org/AuthorizeNet/sdk-php.png?branch=future)]
55
(https://travis-ci.org/AuthorizeNet/sdk-php)
66

77

doc/SIM.markdown

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ a Server Integration Method solution.
1111
Hosted Order/Receipt Page
1212
-------------------------
1313

14-
The AuthorizeNetSIM_Form class aims to make it easier to setup the hidden
14+
The `AuthorizeNetSIM_Form` class aims to make it easier to setup the hidden
1515
fields necessary for creating a SIM experience. While it is not necessary
16-
to use the AuthorizeNetSIM_Form class to implement SIM, it may be handy for
16+
to use the `AuthorizeNetSIM_Form` class to implement SIM, it may be handy for
1717
reference.
1818

1919
The code below will generate a buy now button that leads to a hosted order page:
@@ -44,7 +44,7 @@ echo $sim->getHiddenFieldString();?>
4444
Fingerprint Generation
4545
----------------------
4646

47-
To generate the fingerprint needed for a SIM transaction call the getFingerprint method:
47+
To generate the fingerprint needed for a SIM transaction call the `getFingerprint` method:
4848

4949
```PHP
5050
$fingerprint = AuthorizeNetSIM_Form::getFingerprint($api_login_id, $transaction_key, $amount, $fp_sequence, $fp_timestamp);
@@ -53,15 +53,15 @@ $fingerprint = AuthorizeNetSIM_Form::getFingerprint($api_login_id, $transaction_
5353
Relay Response
5454
--------------
5555

56-
The PHP SDK includes a AuthorizeNetSIM class for handling a relay response from
56+
The PHP SDK includes a `AuthorizeNetSIM` class for handling a relay response from
5757
Authorize.Net.
5858

5959
To receive a relay response from Authorize.Net you can either configure the
6060
url in the Merchant Interface or specify the url when submitting a transaction
6161
with SIM using the "x_relay_url" field.
6262

6363
When a transaction occurs, Authorize.Net will post the transaction details to
64-
this url. You can then craete a page on your server at a url such as
64+
this url. You can then create a page on your server at a url such as
6565
http://yourdomain.com/response_handler.php and execute any logic you want
6666
when a transaction occurs. The AuthorizeNetSIM class makes it easy to verify
6767
the transaction came from Authorize.Net and parse the response:

lib/net/authorize/api/controller/base/ApiOperationBase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ abstract class ApiOperationBase implements IApiOperation
4848
*/
4949
public function __construct(\net\authorize\api\contract\v1\AnetApiRequestType $request, $responseType)
5050
{
51-
date_default_timezone_set('UTC');
5251
$this->logger = LogFactory::getLog(get_class($this));
5352

5453
if ( null == $request)

lib/net/authorize/util/Helpers.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public static function now()
1919
//init only once
2020
if ( ! self::$initialized)
2121
{
22-
date_default_timezone_set('UTC');
2322
self::$initialized = true;
2423
}
2524
return date( DATE_RFC2822);

lib/net/authorize/util/HttpClient.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@ class HttpClient
1515
private $_Url = "";
1616

1717
public $VERIFY_PEER = true; // attempt trust validation of SSL certificates when establishing secure connections.
18-
private $_log_file = false;
1918
private $logger = NULL;
2019
/**
2120
* Constructor.
2221
*
2322
*/
2423
public function __construct()
2524
{
26-
$this->_log_file = (defined('AUTHORIZENET_LOG_FILE') ? AUTHORIZENET_LOG_FILE : false);
2725
$this->logger = LogFactory::getLog(get_class($this));
28-
date_default_timezone_set('UTC');
2926
}
3027

3128
/**
@@ -54,7 +51,7 @@ public function _getPostUrl()
5451
*/
5552
public function setLogFile($filepath)
5653
{
57-
$this->_log_file = $filepath;
54+
$this->logger->setLogFile($filepath);
5855
}
5956

6057
/**
@@ -82,7 +79,7 @@ public function _sendRequest($xmlRequest)
8279
if ($this->VERIFY_PEER) {
8380
curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/../../ssl/cert.pem');
8481
} else {
85-
$this->logger("Invalid SSL option for the request");
82+
$this->logger->error("Invalid SSL option for the request");
8683
return false;
8784
}
8885

@@ -104,7 +101,7 @@ public function _sendRequest($xmlRequest)
104101
$this->now(), $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), $ex->getFile(), $ex->getLine() );
105102
$this->logger->error($errorMessage);
106103
}
107-
if ($this->_log_file) {
104+
if ($this->logger && $this->logger->getLogFile()) {
108105
if ($curl_error = curl_error($curl_request)) {
109106
$this->logger->error("CURL ERROR: $curl_error");
110107
}

lib/net/authorize/util/Log.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use net\authorize\util\ANetSensitiveFields;
55

66
define ("ANET_LOG_FILES_APPEND",true);
7-
define ("ANET_LOG_FILE","phplog");
87

98
define("ANET_LOG_DEBUG_PREFIX","DEBUG");
109
define("ANET_LOG_INFO_PREFIX","INFO");
@@ -30,6 +29,7 @@
3029
class Log
3130
{
3231
private $sensitiveXmlTags = NULL;
32+
private $logFile = '';
3333

3434
/**
3535
* Takes a regex pattern (string) as argument and adds the forward slash delimiter.
@@ -247,6 +247,7 @@ private function getMasked($raw)
247247
}
248248

249249
private function log($logLevelPrefix, $logMessage, $flags){
250+
if (!$this->logFile) return;
250251
//masking
251252
$logMessage = $this->getMasked($logMessage);
252253

@@ -264,7 +265,7 @@ private function log($logLevelPrefix, $logMessage, $flags){
264265
//Add timestamp, log level, method, file, line
265266
$logString = sprintf("\n %s %s : [%s] (%s : %s) - %s", \net\authorize\util\Helpers::now(), $logLevelPrefix,
266267
$methodName, $fileName, $lineNumber, $logMessage);
267-
file_put_contents(ANET_LOG_FILE, $logString, $flags);
268+
file_put_contents($this->logFile, $logString, $flags);
268269
}
269270

270271
public function debug($logMessage, $flags=FILE_APPEND)
@@ -298,9 +299,9 @@ private function logFormat($logLevelPrefix, $format, $objects, $flags){
298299
$objects[$i] = $this->getMasked($testObject);
299300
}
300301
$logMessage = vsprintf($format, $objects);
301-
log($logLevelPrefix, $logMessage, $flags);
302+
$this->log($logLevelPrefix, $logMessage, $flags);
302303
}
303-
catch(Exception $e){
304+
catch(\Exception $e){
304305
$this->debug("Incorrect log message format: " . $e->getMessage());
305306
}
306307
}
@@ -329,6 +330,20 @@ public function errorFormat($format, $args=array(), $flags=FILE_APPEND){
329330
$this->logFormat(ANET_LOG_ERROR_PREFIX, $format, $args , $flags);
330331
}
331332
}
333+
334+
/**
335+
* @param string $logFile
336+
*/
337+
public function setLogFile($logFile){
338+
$this->logFile = $logFile;
339+
}
340+
341+
/**
342+
* @return string
343+
*/
344+
public function getLogFile(){
345+
return $this->logFile;
346+
}
332347

333348
public function __construct(){
334349
$this->sensitiveXmlTags = ANetSensitiveFields::getSensitiveXmlTags();

lib/net/authorize/util/LogFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class LogFactory
77
public static function getLog($classType){
88
if(NULL == self::$logger){
99
self::$logger = new Log();
10+
if(defined('AUTHORIZENET_LOG_FILE')){
11+
self::$logger->setLogFile(AUTHORIZENET_LOG_FILE);
12+
}
1013
}
1114
return self::$logger;
1215
}

lib/shared/AuthorizeNetRequest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
use net\authorize\util\LogFactory;
3+
24
/**
35
* Sends requests to the Authorize.Net gateways.
46
*
@@ -13,7 +15,7 @@ abstract class AuthorizeNetRequest
1315
protected $_post_string;
1416
public $VERIFY_PEER = true; // attempt trust validation of SSL certificates when establishing secure connections.
1517
protected $_sandbox = true;
16-
protected $_log_file = false;
18+
protected $_logger = null;
1719

1820
/**
1921
* Set the _post_string
@@ -42,7 +44,7 @@ public function __construct($api_login_id = false, $transaction_key = false)
4244
$this->_api_login = ($api_login_id ? $api_login_id : (defined('AUTHORIZENET_API_LOGIN_ID') ? AUTHORIZENET_API_LOGIN_ID : ""));
4345
$this->_transaction_key = ($transaction_key ? $transaction_key : (defined('AUTHORIZENET_TRANSACTION_KEY') ? AUTHORIZENET_TRANSACTION_KEY : ""));
4446
$this->_sandbox = (defined('AUTHORIZENET_SANDBOX') ? AUTHORIZENET_SANDBOX : true);
45-
$this->_log_file = (defined('AUTHORIZENET_LOG_FILE') ? AUTHORIZENET_LOG_FILE : false);
47+
$this->_logger = LogFactory::getLog(get_class($this));
4648
}
4749

4850
/**
@@ -62,7 +64,7 @@ public function setSandbox($bool)
6264
*/
6365
public function setLogFile($filepath)
6466
{
65-
$this->_log_file = $filepath;
67+
$this->_logger->setLogFile($filepath);
6668
}
6769

6870
/**
@@ -94,9 +96,9 @@ protected function _sendRequest()
9496
if ($this->VERIFY_PEER) {
9597
curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/ssl/cert.pem');
9698
} else {
97-
if ($this->_log_file) {
98-
file_put_contents($this->_log_file, "----Request----\nInvalid SSL option\n", FILE_APPEND);
99-
}
99+
if ($this->_logger) {
100+
$this->_logger->error("----Request----\nInvalid SSL option\n");
101+
}
100102
return false;
101103
}
102104

@@ -106,15 +108,13 @@ protected function _sendRequest()
106108

107109
$response = curl_exec($curl_request);
108110

109-
if ($this->_log_file) {
110-
111+
if ($this->_logger) {
111112
if ($curl_error = curl_error($curl_request)) {
112-
file_put_contents($this->_log_file, "----CURL ERROR----\n$curl_error\n\n", FILE_APPEND);
113+
$this->_logger->error("----CURL ERROR----\n$curl_error\n\n");
113114
}
114115
// Do not log requests that could contain CC info.
115-
file_put_contents($this->_log_file, "----Request----\n{$this->_post_string}\n", FILE_APPEND);
116-
117-
file_put_contents($this->_log_file, "----Response----\n$response\n\n", FILE_APPEND);
116+
$this->_logger->info("----Request----\n{$this->_post_string}\n");
117+
$this->_logger->info("----Response----\n$response\n\n");
118118
}
119119
curl_close($curl_request);
120120

0 commit comments

Comments
 (0)