Skip to content

Commit e4bae89

Browse files
author
brianmc
committed
Merge branch 'Future' of https://github.com/AuthorizeNet/sdk-php into Future
2 parents 5815227 + 09b7929 commit e4bae89

10 files changed

Lines changed: 535 additions & 31 deletions

classmap.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
2-
spl_autoload_extensions(".php"); // comma-separated list
3-
spl_autoload_register();
2+
spl_autoload_extensions(".php"); // comma-separated list
3+
spl_autoload_register();
44

55
/**
66
* A map of classname => filename for SPL autoloading.
@@ -219,6 +219,11 @@
219219
//'net\authorize\util\ObjectToXml' => $libDir . 'net/authorize/util/ObjectToXml.php',
220220
'net\authorize\util\HttpClient' => $libDir . 'net/authorize/util/HttpClient.php',
221221
'net\authorize\util\Helpers' => $libDir . 'net/authorize/util/Helpers.php',
222+
'net\authorize\util\Log' => $libDir . 'net/authorize/util/Log.php',
223+
'net\authorize\util\LogFactory' => $libDir . 'net/authorize/util/LogFactory.php',
224+
'net\authorize\util\ANetSensitiveFields' => $libDir . 'net/authorize/util/ANetSensitiveFields.php',
225+
'net\authorize\util\SensitiveTag' => $libDir . 'net/authorize/util/SensitiveTag.php',
226+
222227

223228
//constants
224229
'net\authorize\api\constants\ANetEnvironment' => $libDir . 'net/authorize/api/constants/ANetEnvironment.php',
@@ -437,4 +442,4 @@
437442
'net\authorize\api\controller\UpdateSplitTenderGroupController' => $libDir . 'net/authorize/api/controller/UpdateSplitTenderGroupController.php',
438443
'net\authorize\api\controller\ValidateCustomerPaymentProfileController' => $libDir . 'net/authorize/api/controller/ValidateCustomerPaymentProfileController.php',
439444

440-
);
445+
);

lib/AuthorizeNetAIM.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/**
33
* Easily interact with the Authorize.Net AIM API.
44
*
5+
*
56
* Example Authorize and Capture Transaction against the Sandbox:
67
* <code>
78
* <?php require_once 'AuthorizeNet.php'

lib/AuthorizeNetCIM.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,10 @@ public function getValidationResponse()
488488
public function getCustomerProfileIds()
489489
{
490490
$ids = (array)$this->xml->ids;
491-
return $ids["numericString"];
491+
if(!empty($ids))
492+
return $ids["numericString"];
493+
else
494+
return $ids;
492495
}
493496

494497
/**
@@ -497,7 +500,10 @@ public function getCustomerProfileIds()
497500
public function getCustomerPaymentProfileIds()
498501
{
499502
$ids = (array)$this->xml->customerPaymentProfileIdList;
500-
return $ids["numericString"];
503+
if(!empty($ids))
504+
return $ids["numericString"];
505+
else
506+
return $ids;
501507
}
502508

503509
/**
@@ -506,7 +512,10 @@ public function getCustomerPaymentProfileIds()
506512
public function getCustomerShippingAddressIds()
507513
{
508514
$ids = (array)$this->xml->customerShippingAddressIdList;
509-
return $ids["numericString"];
515+
if(!empty($ids))
516+
return $ids["numericString"];
517+
else
518+
return $ids;
510519
}
511520

512521
/**

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
use Goetas\Xsd\XsdToPhp\Jms\Handler\XmlSchemaDateHandler;
99

1010
use \net\authorize\util\HttpClient;
11+
use \net\authorize\util\Helpers;
12+
use \net\authorize\util\LogFactory as LogFactory;
13+
1114

1215
abstract class ApiOperationBase implements IApiOperation
1316
{
1417
/**
1518
* @var \net\authorize\api\contract\v1\AnetApiRequestType
1619
*/
1720
private $apiRequest = null;
18-
21+
1922
/**
2023
* @var \net\authorize\api\contract\v1\AnetApiResponseType
2124
*/
@@ -35,9 +38,7 @@ abstract class ApiOperationBase implements IApiOperation
3538
* @var \net\authorize\util\HttpClient;
3639
*/
3740
public $httpClient = null;
38-
39-
private $_log_file = false;
40-
41+
private $logger = null;
4142
/**
4243
* Constructor.
4344
*
@@ -48,7 +49,7 @@ abstract class ApiOperationBase implements IApiOperation
4849
public function __construct(\net\authorize\api\contract\v1\AnetApiRequestType $request, $responseType)
4950
{
5051
date_default_timezone_set('UTC');
51-
$this->_log_file = (defined('AUTHORIZENET_LOG_FILE') ? AUTHORIZENET_LOG_FILE : false);
52+
$this->logger = LogFactory::getLog(get_class($this));
5253

5354
if ( null == $request)
5455
{
@@ -109,21 +110,22 @@ public function execute($endPoint = \net\authorize\api\constants\ANetEnvironment
109110
{
110111
$this->beforeExecute();
111112

112-
file_put_contents($this->_log_file, sprintf("\n%s: Request Serialization Begin", $this->now()), FILE_APPEND);
113+
$this->logger->info("Request Serialization Begin");
114+
$this->logger->debug($this->apiRequest);
113115
$xmlRequest = $this->serializer->serialize($this->apiRequest, 'xml');
114-
file_put_contents($this->_log_file, sprintf("\n%s: Request Serialization End", $this->now()), FILE_APPEND);
115-
/*
116-
//$xmlRequest = '<?xml version="1.0" encoding="UTF-8"?> <ARBGetSubscriptionListRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <merchantAuthentication> <name>4YJmeW7V77us</name> <transactionKey>4qHK9u63F753be4Z</transactionKey> </merchantAuthentication> <refId><![CDATA[ref1416999093]]></refId> <searchType><![CDATA[subscriptionActive]]></searchType> <sorting> <orderBy><![CDATA[firstName]]></orderBy> <orderDescending>false</orderDescending> </sorting> <paging> <limit>10</limit> <offset>1</offset> </paging> </ARBGetSubscriptionListRequest> ';
117-
*/
116+
$this->logger->info("Request Serialization End");
117+
/*
118+
//$xmlRequest = '<?xml version="1.0" encoding="UTF-8"?> <ARBGetSubscriptionListRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <merchantAuthentication> <name>4YJmeW7V77us</name> <transactionKey>4qHK9u63F753be4Z</transactionKey> </merchantAuthentication> <refId><![CDATA[ref1416999093]]></refId> <searchType><![CDATA[subscriptionActive]]></searchType> <sorting> <orderBy><![CDATA[firstName]]></orderBy> <orderDescending>false</orderDescending> </sorting> <paging> <limit>10</limit> <offset>1</offset> </paging> </ARBGetSubscriptionListRequest> ';
119+
*/
118120
$this->httpClient->setPostUrl( $endPoint);
119121
$xmlResponse = $this->httpClient->_sendRequest($xmlRequest);
120122
if ( null == $xmlResponse)
121123
{
122124
throw new \Exception( "Error getting valid response from api. Check log file for error details");
123125
}
124-
file_put_contents($this->_log_file, sprintf("\n%s: Response De-Serialization Begin", $this->now()), FILE_APPEND);
126+
$this->logger->info("Response De-Serialization Begin");
125127
$this->apiResponse = $this->serializer->deserialize( $xmlResponse, $this->apiResponseType , 'xml');
126-
file_put_contents($this->_log_file, sprintf("\n%s: Response De-Serialization End", $this->now()), FILE_APPEND);
128+
$this->logger->info("Response De-Serialization End");
127129

128130
$this->afterExecute();
129131
}
@@ -147,4 +149,4 @@ protected function now()
147149
{
148150
return date( DATE_RFC2822);
149151
}
150-
}
152+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
namespace net\authorize\util;
3+
4+
define("ANET_SENSITIVE_XMLTAGS_JSON_FILE","AuthorizedNetSensitiveTagsConfig.json");
5+
6+
class ANetSensitiveFields
7+
{
8+
private static $applySensitiveTags = NULL;
9+
private static $sensitiveStringRegexes = NULL;
10+
11+
private static function fetchFromConfigFiles(){
12+
$configFilePath = dirname(__FILE__) . "/" . ANET_SENSITIVE_XMLTAGS_JSON_FILE;
13+
$userConfigFilePath = ANET_SENSITIVE_XMLTAGS_JSON_FILE;
14+
$presentUserConfigFile = file_exists($userConfigFilePath);
15+
if ($presentUserConfigFile) { //client config for tags
16+
//read list of tags(and associate regex-patterns and replacements) from .json file
17+
$jsonFileObejct = json_decode(file_get_contents($userConfigFilePath));
18+
$sensitiveTags = $jsonFileObejct->sensitiveTags;
19+
self::$sensitiveStringRegexes = $jsonFileObejct->sensitiveStringRegexes;
20+
if (json_last_error() === JSON_ERROR_NONE) {// JSON is valid
21+
}
22+
else{
23+
echo "ERROR: Invalid json in: " . $userConfigFilePath . " json_last_error_msg : " . json_last_error_msg();
24+
$presentUserConfigFile = false;
25+
}
26+
}
27+
if (!$presentUserConfigFile) { //default sdk config for tags
28+
if(!file_exists($configFilePath)){
29+
exit("ERROR: No config file: " . $configFilePath);
30+
}
31+
$jsonFileObejct = json_decode(file_get_contents($configFilePath));
32+
file_put_contents($userConfigFilePath, json_encode($jsonFileObejct, JSON_PRETTY_PRINT));
33+
$sensitiveTags = $jsonFileObejct->sensitiveTags;
34+
self::$sensitiveStringRegexes = $jsonFileObejct->sensitiveStringRegexes;
35+
if (json_last_error() === JSON_ERROR_NONE) {
36+
}
37+
else{
38+
exit("ERROR: Invalid json in: " . $configFilePath . " json_last_error_msg : " . json_last_error_msg());
39+
}
40+
}
41+
//Check for disableMask flag in case of client json.
42+
self::$applySensitiveTags = array();
43+
foreach($sensitiveTags as $sensitiveTag){
44+
if($sensitiveTag->disableMask){
45+
//skip masking continue;
46+
}
47+
else{
48+
array_push(self::$applySensitiveTags,$sensitiveTag);
49+
}
50+
}
51+
}
52+
public static function getSensitiveStringRegexes(){
53+
if(NULL == self::$sensitiveStringRegexes) {
54+
self::fetchFromConfigFiles();
55+
}
56+
return self::$sensitiveStringRegexes;
57+
}
58+
public static function getSensitiveXmlTags(){
59+
if(NULL == self::$applySensitiveTags) {
60+
self::fetchFromConfigFiles();
61+
}
62+
return self::$applySensitiveTags;
63+
}
64+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"sensitiveTags": [
3+
{
4+
"tagName": "cardCode",
5+
"pattern": "",
6+
"replacement": "",
7+
"disableMask": false
8+
},
9+
{
10+
"tagName": "cardNumber",
11+
"pattern": "(\\p{N}+)(\\p{N}{4})",
12+
"replacement": "xxxx-$2",
13+
"disableMask": false
14+
},
15+
{
16+
"tagName": "expirationDate",
17+
"pattern": "",
18+
"replacement": "",
19+
"disableMask": false
20+
},
21+
{
22+
"tagName": "accountNumber",
23+
"pattern": "(\\p{N}+)(\\p{N}{4})",
24+
"replacement": "xxxx-$2",
25+
"disableMask": false
26+
},
27+
{
28+
"tagName": "nameOnAccount",
29+
"pattern": "",
30+
"replacement": "",
31+
"disableMask": false
32+
},
33+
{
34+
"tagName": "transactionKey",
35+
"pattern": "",
36+
"replacement": "",
37+
"disableMask": false
38+
}
39+
],
40+
"sensitiveStringRegexes": [
41+
"4\\p{N}{3}([\\ \\-]?)\\p{N}{4}\\1\\p{N}{4}\\1\\p{N}{4}",
42+
"4\\p{N}{3}([\\ \\-]?)(?:\\p{N}{4}\\1){2}\\p{N}(?:\\p{N}{3})?",
43+
"5[1-5]\\p{N}{2}([\\ \\-]?)\\p{N}{4}\\1\\p{N}{4}\\1\\p{N}{4}",
44+
"6(?:011|22(?:1(?=[\\ \\-]?(?:2[6-9]|[3-9]))|[2-8]|9(?=[\\ \\-]?(?:[01]|2[0-5])))|4[4-9]\\p{N}|5\\p{N}\\p{N})([\\ \\-]?)\\p{N}{4}\\1\\p{N}{4}\\1\\p{N}{4}",
45+
"35(?:2[89]|[3-8]\\p{N})([\\ \\-]?)\\p{N}{4}\\1\\p{N}{4}\\1\\p{N}{4}",
46+
"3[47]\\p{N}\\p{N}([\\ \\-]?)\\p{N}{6}\\1\\p{N}{5}"
47+
]
48+
}
49+

lib/net/authorize/util/HttpClient.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
namespace net\authorize\util;
33

4+
use net\authorize\util\LogFactory;
5+
use net\authorize\util\Log;
6+
47
/**
58
* A class to send a request to the XML API.
69
*
@@ -13,14 +16,15 @@ class HttpClient
1316

1417
public $VERIFY_PEER = true; // attempt trust validation of SSL certificates when establishing secure connections.
1518
private $_log_file = false;
16-
19+
private $logger = NULL;
1720
/**
1821
* Constructor.
1922
*
2023
*/
2124
public function __construct()
2225
{
2326
$this->_log_file = (defined('AUTHORIZENET_LOG_FILE') ? AUTHORIZENET_LOG_FILE : false);
27+
$this->logger = LogFactory::getLog(get_class($this));
2428
date_default_timezone_set('UTC');
2529
}
2630

@@ -71,38 +75,38 @@ public function _sendRequest($xmlRequest)
7175
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
7276
curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);
7377

74-
file_put_contents($this->_log_file, sprintf("\n%s: Url: %s", $this->now(), $post_url), FILE_APPEND);
78+
$this->logger->info(sprintf(" Url: %s", $post_url));
7579
// Do not log requests that could contain CC info.
76-
file_put_contents($this->_log_file, sprintf("\n%s:Request to AnetApi: \n%s", $this->now(), $xmlRequest), FILE_APPEND);
80+
$this->logger->info(sprintf("Request to AnetApi: \n%s", $xmlRequest));
7781

7882
if ($this->VERIFY_PEER) {
7983
curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/../../ssl/cert.pem');
8084
} else {
81-
if ($this->_log_file) {
82-
file_put_contents($this->_log_file, "\nInvalid SSL option for the request", FILE_APPEND);
83-
}
85+
$this->logger("Invalid SSL option for the request");
8486
return false;
8587
}
8688

8789
if (preg_match('/xml/',$post_url)) {
8890
curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
89-
file_put_contents($this->_log_file, "\nSending 'XML' Request type", FILE_APPEND);
91+
// file_put_contents($this->_log_file, "\nSending 'XML' Request type", FILE_APPEND);
92+
$this->logger->info("Sending 'XML' Request type");
9093
}
9194

9295
try
9396
{
94-
file_put_contents($this->_log_file, sprintf("\n%s:Sending http request via Curl", $this->now()), FILE_APPEND);
97+
$this->logger->info("Sending http request via Curl");
9598
$xmlResponse = curl_exec($curl_request);
96-
file_put_contents($this->_log_file, sprintf("\n%s:Response from AnetApi: \n%s\n", $this->now(), $xmlResponse), FILE_APPEND);
99+
$this->logger->info("Response from AnetApi: $xmlResponse");
100+
97101
} catch (\Exception $ex)
98102
{
99103
$errorMessage = sprintf("\n%s:Error making http request via curl: Code:'%s', Message:'%s', Trace:'%s', File:'%s':'%s'",
100104
$this->now(), $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), $ex->getFile(), $ex->getLine() );
101-
file_put_contents($this->_log_file, $errorMessage, FILE_APPEND);
105+
$this->logger->error($errorMessage);
102106
}
103107
if ($this->_log_file) {
104108
if ($curl_error = curl_error($curl_request)) {
105-
file_put_contents($this->_log_file, sprintf("\n%s:CURL ERROR: %s", $this->now(), $curl_error), FILE_APPEND);
109+
$this->logger->error("CURL ERROR: $curl_error");
106110
}
107111

108112
}
@@ -115,4 +119,4 @@ private function now()
115119
{
116120
return date( DATE_RFC2822);
117121
}
118-
}
122+
}

0 commit comments

Comments
 (0)