-
Notifications
You must be signed in to change notification settings - Fork 52
/
ExternalConfiguration.php
183 lines (162 loc) · 7.73 KB
/
ExternalConfiguration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/*
* Purpose : passing Authentication config object to the configuration
*/
namespace CyberSource;
require_once __DIR__. DIRECTORY_SEPARATOR .'../vendor/autoload.php';
class ExternalConfiguration
{
private $merchantConfig;
private $intermediateMerchantConfig;
//initialize variable on constructor
function __construct()
{
$this->authType = "http_signature";//http_signature/jwt
$this->merchantID = "testrest";
$this->apiKeyID = "08c94330-f618-42a3-b09d-e1e43be5efda";
$this->secretKey = "yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE=";
// MetaKey configuration [Start]
$this->useMetaKey = false;
$this->portfolioID = "";
// MetaKey configuration [End]
$this->keyAlias = "testrest";
$this->keyPass = "testrest";
$this->keyFilename = "testrest";
$this->keyDirectory = "Resources/";
$this->runEnv = "apitest.cybersource.com";
// new property has been added for user to configure the base path so that request can route the API calls via Azure Management URL.
// Example: If intermediate url is https://manage.windowsazure.com then in property input can be same url or manage.windowsazure.com.
$this->IntermediateHost = "https://manage.windowsazure.com";
//PEM Key file path for decoding JWE Response Enter the folder path where the .pem file is located.
// It is optional property, require adding only during JWE decryption.
$this -> jwePEMFileDirectory = "Resources/NetworkTokenCert.pem";
//OAuth related config
$this->enableClientCert = false;
$this->clientCertDirectory = "Resources/";
$this->clientCertFile = "";
$this->clientCertPassword = "";
$this->clientId = "";
$this->clientSecret = "";
// New Logging
$this->enableLogging = true;
$this->debugLogFile = __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "Log" . DIRECTORY_SEPARATOR . "debugTest.log";
$this->errorLogFile = __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "Log" . DIRECTORY_SEPARATOR . "errorTest.log";
$this->logDateFormat = "Y-m-d\TH:i:s";
$this->logFormat = "[%datetime%] [%level_name%] [%channel%] : %message%\n";
$this->logMaxFiles = 3;
$this->logLevel = "debug";
$this->enableMasking = true;
$this->merchantConfigObject();
$this->merchantConfigObjectForIntermediateHost();
$this->jwePEMFileDirectory = "Resources".DIRECTORY_SEPARATOR."NetworkTokenCert.pem";
}
//creating merchant config object
function merchantConfigObject()
{
if (!isset($this->merchantConfig)) {
$config = new \CyberSource\Authentication\Core\MerchantConfiguration();
$config->setauthenticationType(strtoupper(trim($this->authType)));
$config->setMerchantID(trim($this->merchantID));
$config->setApiKeyID($this->apiKeyID);
$config->setSecretKey($this->secretKey);
$config->setKeyFileName(trim($this->keyFilename));
$config->setKeyAlias($this->keyAlias);
$config->setKeyPassword($this->keyPass);
$config->setUseMetaKey($this->useMetaKey);
$config->setPortfolioID($this->portfolioID);
$config->setKeysDirectory(__DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . $this->keyDirectory);
$config->setJwePEMFileDirectory($this -> jwePEMFileDirectory);
$config->setRunEnvironment($this->runEnv);
// New Logging
$logConfiguration = new \CyberSource\Logging\LogConfiguration();
$logConfiguration->enableLogging($this->enableLogging);
$logConfiguration->setDebugLogFile($this->debugLogFile);
$logConfiguration->setErrorLogFile($this->errorLogFile);
$logConfiguration->setLogDateFormat($this->logDateFormat);
$logConfiguration->setLogFormat($this->logFormat);
$logConfiguration->setLogMaxFiles($this->logMaxFiles);
$logConfiguration->setLogLevel($this->logLevel);
$logConfiguration->enableMasking($this->enableMasking);
$config->setLogConfiguration($logConfiguration);
$config->validateMerchantData();
$this->merchantConfig = $config;
} else {
return $this->merchantConfig;
}
}
//creating merchant config for intermediate host object
function merchantConfigObjectForIntermediateHost()
{
if (!isset($this->intermediateMerchantConfig)) {
$config = new \CyberSource\Authentication\Core\MerchantConfiguration();
$config->setauthenticationType(strtoupper(trim($this->authType)));
$config->setMerchantID(trim($this->merchantID));
$config->setApiKeyID($this->apiKeyID);
$config->setSecretKey($this->secretKey);
$config->setKeyFileName(trim($this->keyFilename));
$config->setKeyAlias($this->keyAlias);
$config->setKeyPassword($this->keyPass);
$config->setUseMetaKey($this->useMetaKey);
$config->setPortfolioID($this->portfolioID);
$config->setKeysDirectory(__DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . $this->keyDirectory);
$config->setRunEnvironment($this->runEnv);
$config->setIntermediateHost($this->IntermediateHost);
// New Logging
$logConfiguration = new \CyberSource\Logging\LogConfiguration();
$logConfiguration->enableLogging($this->enableLogging);
$logConfiguration->setDebugLogFile($this->debugLogFile);
$logConfiguration->setErrorLogFile($this->errorLogFile);
$logConfiguration->setLogDateFormat($this->logDateFormat);
$logConfiguration->setLogFormat($this->logFormat);
$logConfiguration->setLogMaxFiles($this->logMaxFiles);
$logConfiguration->setLogLevel($this->logLevel);
$logConfiguration->enableMasking($this->enableMasking);
$config->setLogConfiguration($logConfiguration);
$config->validateMerchantData();
$this->intermediateMerchantConfig = $config;
} else {
return $this->intermediateMerchantConfig;
}
}
function ConnectionHost()
{
$merchantConf = $this->merchantConfigObject();
$config = new Configuration();
$config->setHost($merchantConf->getHost());
$config->setLogConfiguration($merchantConf->getLogConfiguration());
return $config;
}
function ConnectionHostForIntermediateHost()
{
$intermediatemerchantConf = $this->merchantConfigObjectForIntermediateHost();
$config = new Configuration();
$config->setHost($intermediatemerchantConf->getHost());
$config->setLogConfiguration($intermediatemerchantConf->getLogConfiguration());
return $config;
}
function FutureDate($format){
if($format){
$rdate = date("Y-m-d",strtotime("+7 days"));
$retDate = date($format,strtotime($rdate));
}
else{
$retDate = date("Y-m",strtotime("+7 days"));
}
echo $retDate;
return $retDate;
}
function CallTestLogging($testId, $apiName, $responseMessage){
$runtime = date('d-m-Y H:i:s');
$file = fopen("./CSV_Files/TestReport/TestResults.csv", "a+");
fputcsv($file, array($testId, $runtime, $apiName, $responseMessage));
fclose($file);
}
function downloadReport($downloadData, $fileName){
$filePathName = __DIR__. DIRECTORY_SEPARATOR .$fileName;
$file = fopen($filePathName, "w");
fwrite($file, $downloadData);
fclose($file);
return __DIR__.'\\'.$fileName;
}
}
?>