Skip to content

Commit b476c9a

Browse files
committed
Merge pull request #85 from ashtru/Future
Add serializer for reading the json file, setECheck Fix #74
2 parents c4a753e + 0b79589 commit b476c9a

5 files changed

Lines changed: 91 additions & 20 deletions

File tree

classmap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@
223223
'net\authorize\util\LogFactory' => $libDir . 'net/authorize/util/LogFactory.php',
224224
'net\authorize\util\ANetSensitiveFields' => $libDir . 'net/authorize/util/ANetSensitiveFields.php',
225225
'net\authorize\util\SensitiveTag' => $libDir . 'net/authorize/util/SensitiveTag.php',
226-
226+
'net\authorize\util\SensitiveDataConfigType' => $libDir . 'net/authorize/util/SensitiveDataConfigType.php',
227227

228228
//constants
229229
'net\authorize\api\constants\ANetEnvironment' => $libDir . 'net/authorize/api/constants/ANetEnvironment.php',
@@ -251,7 +251,7 @@
251251
'net\authorize\api\contract\v1\AuthenticateTestRequest' => $libDir . 'net/authorize/api/contract/v1/AuthenticateTestRequest.php',
252252
'net\authorize\api\contract\v1\AuthenticateTestResponse' => $libDir . 'net/authorize/api/contract/v1/AuthenticateTestResponse.php',
253253
'net\authorize\api\contract\v1\BankAccountMaskedType' => $libDir . 'net/authorize/api/contract/v1/BankAccountMaskedType.php',
254-
'net\authorize\api\contract\v1\BankAccountType' => $libDir . 'net/authorize/api/contract/v1/Bank`AccountType.php',
254+
'net\authorize\api\contract\v1\BankAccountType' => $libDir . 'net/authorize/api/contract/v1/BankAccountType.php',
255255
'net\authorize\api\contract\v1\BatchDetailsType' => $libDir . 'net/authorize/api/contract/v1/BatchDetailsType.php',
256256
'net\authorize\api\contract\v1\BatchStatisticType' => $libDir . 'net/authorize/api/contract/v1/BatchStatisticType.php',
257257
'net\authorize\api\contract\v1\CardArtType' => $libDir . 'net/authorize/api/contract/v1/CardArtType.php',

lib/AuthorizeNetAIM.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public function setECheck($bank_aba_code, $bank_acct_num, $bank_acct_type, $bank
287287
'bank_acct_num' => $bank_acct_num,
288288
'bank_acct_type' => $bank_acct_type,
289289
'bank_name' => $bank_name,
290-
'bank_acct_name' => $bank_acct_type,
290+
'bank_acct_name' => $bank_acct_name,
291291
'echeck_type' => $echeck_type,
292292
)
293293
);

lib/net/authorize/util/ANetSensitiveFields.php

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,63 @@
11
<?php
22
namespace net\authorize\util;
33

4+
use JMS\Serializer\SerializerBuilder;
5+
46
define("ANET_SENSITIVE_XMLTAGS_JSON_FILE","AuthorizedNetSensitiveTagsConfig.json");
7+
define("ANET_SENSITIVE_DATE_CONFIG_CLASS",'net\authorize\util\SensitiveDataConfigType');
58

69
class ANetSensitiveFields
710
{
811
private static $applySensitiveTags = NULL;
912
private static $sensitiveStringRegexes = NULL;
1013

1114
private static function fetchFromConfigFiles(){
12-
$configFilePath = dirname(__FILE__) . "/" . ANET_SENSITIVE_XMLTAGS_JSON_FILE;
15+
if(!class_exists(ANET_SENSITIVE_DATE_CONFIG_CLASS))
16+
exit("Class (".ANET_SENSITIVE_DATE_CONFIG_CLASS.") doesn't exist; can't deserialize json; can't log. Exiting.");
17+
18+
$serializer = SerializerBuilder::create()->build();
19+
1320
$userConfigFilePath = ANET_SENSITIVE_XMLTAGS_JSON_FILE;
1421
$presentUserConfigFile = file_exists($userConfigFilePath);
22+
23+
$configFilePath = dirname(__FILE__) . "/" . ANET_SENSITIVE_XMLTAGS_JSON_FILE;
24+
$useDefaultConfigFile = !$presentUserConfigFile;
25+
1526
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
27+
//read list of tags (and associated regex-patterns and replacements) from .json file
28+
try{
29+
$jsonFileData=file_get_contents($userConfigFilePath);
30+
$sensitiveDataConfig = $serializer->deserialize($jsonFileData, ANET_SENSITIVE_DATE_CONFIG_CLASS, 'json');
31+
32+
$sensitiveTags = $sensitiveDataConfig->sensitiveTags;
33+
self::$sensitiveStringRegexes = $sensitiveDataConfig->sensitiveStringRegexes;
2134
}
22-
else{
23-
echo "ERROR: Invalid json in: " . $userConfigFilePath . " json_last_error_msg : " . json_last_error_msg();
24-
$presentUserConfigFile = false;
35+
36+
catch(Exception $e){
37+
echo "ERROR deserializing json from : " . $userConfigFilePath . "; Exception : " . $e->getMessage();
38+
$useDefaultConfigFile = true;
2539
}
2640
}
27-
if (!$presentUserConfigFile) { //default sdk config for tags
41+
42+
if ($useDefaultConfigFile) { //default sdk config for tags
2843
if(!file_exists($configFilePath)){
2944
exit("ERROR: No config file: " . $configFilePath);
3045
}
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) {
46+
47+
//read list of tags (and associated regex-patterns and replacements) from .json file
48+
try{
49+
$jsonFileData=file_get_contents($configFilePath);
50+
$sensitiveDataConfig = $serializer->deserialize($jsonFileData, ANET_SENSITIVE_DATE_CONFIG_CLASS, 'json');
51+
52+
$sensitiveTags = $sensitiveDataConfig->sensitiveTags;
53+
self::$sensitiveStringRegexes = $sensitiveDataConfig->sensitiveStringRegexes;
3654
}
37-
else{
38-
exit("ERROR: Invalid json in: " . $configFilePath . " json_last_error_msg : " . json_last_error_msg());
55+
56+
catch(Exception $e){
57+
exit( "ERROR deserializing json from : " . $configFilePath . "; Exception : " . $e->getMessage());
3958
}
4059
}
60+
4161
//Check for disableMask flag in case of client json.
4262
self::$applySensitiveTags = array();
4363
foreach($sensitiveTags as $sensitiveTag){
@@ -49,12 +69,14 @@ private static function fetchFromConfigFiles(){
4969
}
5070
}
5171
}
72+
5273
public static function getSensitiveStringRegexes(){
5374
if(NULL == self::$sensitiveStringRegexes) {
5475
self::fetchFromConfigFiles();
5576
}
5677
return self::$sensitiveStringRegexes;
5778
}
79+
5880
public static function getSensitiveXmlTags(){
5981
if(NULL == self::$applySensitiveTags) {
6082
self::fetchFromConfigFiles();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
namespace net\authorize\util;
3+
use JMS\Serializer\Annotation\Type;
4+
use JMS\Serializer\Annotation\SerializedName;
5+
6+
$type=new Type;
7+
$serializedName=new SerializedName(array("value"=>"Loading-SerializedName-Class"));
8+
//to do: use Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace to auto load classes
9+
10+
class SensitiveDataConfigType
11+
{
12+
/**
13+
* @Type("array<net\authorize\util\SensitiveTag>")
14+
* @SerializedName("sensitiveTags")
15+
*/
16+
public $sensitiveTags;
17+
18+
/**
19+
* @Type("array<string>")
20+
* @SerializedName("sensitiveStringRegexes")
21+
*/
22+
public $sensitiveStringRegexes;
23+
}
24+
?>

lib/net/authorize/util/SensitiveTag.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
<?php
22
namespace net\authorize\util;
3+
use JMS\Serializer\Annotation\Type;
4+
use JMS\Serializer\Annotation\SerializedName;
5+
6+
$type=new Type;
7+
$serializedName=new SerializedName(array("value"=>"Loading-SerializedName-Class"));
8+
//to do: use Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace to auto load classes
39

410
class SensitiveTag
511
{
12+
/**
13+
* @Type("string")
14+
* @SerializedName("tagName")
15+
*/
616
public $tagName;
17+
18+
/**
19+
* @Type("string")
20+
* @SerializedName("pattern")
21+
*/
722
public $pattern;
23+
24+
/**
25+
* @Type("string")
26+
* @SerializedName("replacement")
27+
*/
828
public $replacement;
29+
30+
/**
31+
* @Type("boolean")
32+
* @SerializedName("disableMask")
33+
*/
934
public $disableMask;
1035

1136
public function __construct($tagName, $pattern="", $replace="",$disableMask = false){

0 commit comments

Comments
 (0)