Skip to content

Commit e3cec28

Browse files
author
Sukanya
committed
Added generator
1 parent 81db663 commit e3cec28

File tree

6 files changed

+23020
-7
lines changed

6 files changed

+23020
-7
lines changed

generator/cybersource-php-template/ApiClient.mustache

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ class ApiClient
155155
$resourcePath= utf8_encode($resourcePath);
156156
$authHeader = $this->callAuthenticationHeader($method, $postData, $resourcePath);
157157
$headers = array_merge($headers, $authHeader);
158+
foreach ($headers as $value) {
159+
$splitArr= explode(":", $value, 2);
160+
$this->config->addRequestHeader($splitArr[0], $splitArr[1]);
161+
}
158162
$url = GlobalParameter::HTTPS_PREFIX.$this->config->getHost() . $resourcePath;
159163

160164
$curl = curl_init();
@@ -231,6 +235,7 @@ class ApiClient
231235

232236
// debugging for curl
233237
if ($this->config->getDebug()) {
238+
//$postData = $this->dataMasking($postData);
234239
error_log("[DEBUG] HTTP Request body ~BEGIN~".PHP_EOL.print_r($postData, true).PHP_EOL."~END~".PHP_EOL, 3, $this->config->getDebugFile());
235240
236241
curl_setopt($curl, CURLOPT_VERBOSE, 1);
@@ -247,6 +252,7 @@ class ApiClient
247252
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
248253
$http_header = $this->httpParseHeaders(substr($response, 0, $http_header_size));
249254
$http_body = substr($response, $http_header_size);
255+
//$http_body = $this->dataMasking($http_body);
250256
$response_info = curl_getinfo($curl);
251257

252258
// debug HTTP response body
@@ -408,5 +414,43 @@ class ApiClient
408414
}
409415
return $headers;
410416

417+
}
418+
419+
//set Fields to be mask
420+
public function dataMasking($postData_json_raw)
421+
{
422+
$toBeMask = array("number"=>"XXXXX","expirationMonth"=>"XXXXX","expirationYear"=>"XXXX","email"=>"XXXXX","firstName"=>"XXXXX","lastName"=>"XXXXX","phoneNumber"=>"XXXXX","type"=>"XXXXX","securityCode"=>"XXXXX", "totalAmount" => "XXXXX", "token" => "XXXXX", "signature" => "XXXXX");
423+
424+
$postData_json = json_decode($postData_json_raw, JSON_UNESCAPED_SLASHES);
425+
if($postData_json == null){
426+
return $postData_json_raw;
427+
}else {
428+
$postData_json = $this->dataMaskingIterate($postData_json, $toBeMask);
429+
return json_encode($postData_json);
430+
431+
}
432+
433+
}
434+
435+
//Data masking iteration
436+
public function dataMaskingIterate($responceArr, $callback)
437+
{
438+
if(!empty($responceArr)){
439+
foreach ($responceArr as $k => $v)
440+
{
441+
if(is_array($v)) {
442+
$responceArr[$k] = $this->dataMaskingIterate($v, $callback);
443+
}
444+
else
445+
{
446+
if(array_key_exists($k, $callback))
447+
{
448+
$responceArr[$k]="XXXXXX";
449+
}
450+
}
451+
}
452+
}
453+
return $responceArr;
454+
411455
}
412456
}

generator/cybersource-php-template/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ use \{{invokerPackage}}\ObjectSerializer;
288288
return [$this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader), $statusCode, $httpHeader];
289289
{{/returnType}}
290290
{{^returnType}}
291-
return [null, $statusCode, $httpHeader];
291+
return [$response, $statusCode, $httpHeader];
292292
{{/returnType}}
293293
} catch (ApiException $e) {
294294
switch ($e->getCode()) {

generator/cybersource-php-template/configuration.mustache

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class Configuration
7272
* @var array
7373
*/
7474
protected $defaultHeaders = [];
75+
76+
/**
77+
* The default header(s)
78+
*
79+
* @var array
80+
*/
81+
protected $requestHeaders = [];
7582
7683
/**
7784
* The host
@@ -331,8 +338,7 @@ class Configuration
331338
{
332339
return $this->defaultHeaders;
333340
}
334-
335-
/**
341+
/**
336342
* Deletes a default header
337343
*
338344
* @param string $headerName the header to delete
@@ -344,6 +350,48 @@ class Configuration
344350
unset($this->defaultHeaders[$headerName]);
345351
return $this;
346352
}
353+
354+
/**
355+
* Adds a request header
356+
*
357+
* @param string $headerName header name (e.g. Token)
358+
* @param string $headerValue header value (e.g. 1z8wp3)
359+
*
360+
* @throws \InvalidArgumentException
361+
* @return $this
362+
*/
363+
public function addRequestHeader($headerName, $headerValue)
364+
{
365+
if (!is_string($headerName)) {
366+
throw new \InvalidArgumentException('Header name must be a string.');
367+
}
368+
369+
$this->requestHeaders[$headerName] = $headerValue;
370+
return $this;
371+
}
372+
373+
/**
374+
* Gets the request header
375+
*
376+
* @return array An array of request header(s)
377+
*/
378+
public function getRequestHeaders()
379+
{
380+
return $this->requestHeaders;
381+
}
382+
383+
/**
384+
* Deletes a request header
385+
*
386+
* @param string $headerName the header to delete
387+
*
388+
* @return $this
389+
*/
390+
public function deleteRequestHeader($headerName)
391+
{
392+
unset($this->requestHeaders[$headerName]);
393+
return $this;
394+
}
347395

348396
/**
349397
* Sets the host

generator/cybersource-rest-spec.json

Lines changed: 22883 additions & 1 deletion
Large diffs are not rendered by default.

generator/cybersource_php_sdk_gen.bat

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
1-
mkdir %~dp0PHP
2-
cd %~dp0
3-
java -jar swagger-codegen-cli-2.2.3.jar generate -t cybersource-php-template -i cybersource-rest-spec.json -l php -o PHP -c %~dp0cybersource-php-config.json
1+
java -jar swagger-codegen-cli-2.2.3.jar generate -t cybersource-php-template -i cybersource-rest-spec.json -l php -o ../ -c cybersource-php-config.json
2+
3+
powershell -Command "(Get-Content ..\CyberSource\lib\Api\CaptureApi.php) | ForEach-Object { $_ -replace 'selectHeaderAccept\(\[''application/json', 'selectHeaderAccept([''application/hal+json' } | Set-Content ..\CyberSource\lib\Api\CaptureApi.php"
4+
5+
powershell -Command "(Get-Content ..\CyberSource\lib\Api\CreditApi.php) | ForEach-Object { $_ -replace 'selectHeaderAccept\(\[''application/json', 'selectHeaderAccept([''application/hal+json' } | Set-Content ..\CyberSource\lib\Api\CreditApi.php"
6+
7+
powershell -Command "(Get-Content ..\CyberSource\lib\Api\PaymentsApi.php) | ForEach-Object { $_ -replace 'selectHeaderAccept\(\[''application/json', 'selectHeaderAccept([''application/hal+json' } | Set-Content ..\CyberSource\lib\Api\PaymentsApi.php"
8+
9+
powershell -Command "(Get-Content ..\CyberSource\lib\Api\ProcessAPayoutApi.php) | ForEach-Object { $_ -replace 'selectHeaderAccept\(\[''application/json', 'selectHeaderAccept([''application/hal+json' } | Set-Content ..\CyberSource\lib\Api\ProcessAPayoutApi.php"
10+
11+
powershell -Command "(Get-Content ..\CyberSource\lib\Api\RefundApi.php) | ForEach-Object { $_ -replace 'selectHeaderAccept\(\[''application/json', 'selectHeaderAccept([''application/hal+json' } | Set-Content ..\CyberSource\lib\Api\RefundApi.php"
12+
13+
powershell -Command "(Get-Content ..\CyberSource\lib\Api\ReversalApi.php) | ForEach-Object { $_ -replace 'selectHeaderAccept\(\[''application/json', 'selectHeaderAccept([''application/hal+json' } | Set-Content ..\CyberSource\lib\Api\ReversalApi.php"
14+
15+
powershell -Command "(Get-Content ..\CyberSource\lib\Api\TransactionDetailsApi.php) | ForEach-Object { $_ -replace 'selectHeaderAccept\(\[''application/json', 'selectHeaderAccept([''application/hal+json' } | Set-Content ..\CyberSource\lib\Api\TransactionDetailsApi.php"
16+
17+
powershell -Command "(Get-Content ..\CyberSource\lib\Api\UserManagementApi.php) | ForEach-Object { $_ -replace 'selectHeaderAccept\(\[''application/json', 'selectHeaderAccept([''application/hal+json' } | Set-Content ..\CyberSource\lib\Api\UserManagementApi.php"
18+
19+
powershell -Command "(Get-Content ..\CyberSource\lib\Api\VoidApi.php) | ForEach-Object { $_ -replace 'selectHeaderAccept\(\[''application/json', 'selectHeaderAccept([''application/hal+json' } | Set-Content ..\CyberSource\lib\Api\VoidApi.php"
20+
21+
powershell -Command "(Get-Content ..\CyberSource\lib\Api\SearchTransactionsApi.php) | ForEach-Object { $_ -replace 'selectHeaderAccept\(\[''application/json;charset=utf-8', 'selectHeaderAccept([''*/*'} | Set-Content ..\CyberSource\lib\Api\SearchTransactionsApi.php"
22+
23+
powershell -Command "(Get-Content ..\CyberSource\lib\Model\Tmsv1paymentinstrumentsCard.php) | ForEach-Object { $_ -replace '\&\& \!in_array', '&& in_array'} | Set-Content ..\CyberSource\lib\Model\Tmsv1paymentinstrumentsCard.php"
24+
25+
REM Batch file to change the content type
26+
27+
powershell -Command "(Get-Content ..\CyberSource\lib\Api\SecureFileShareApi.php) | ForEach-Object { $_ -replace 'selectHeaderContentType\(\[''application/json;charset=utf-8', 'selectHeaderContentType([''*/*' } | Set-Content ..\CyberSource\lib\Api\SecureFileShareApi.php"
28+
29+
REM renaming long file name
30+
31+
powershell -Command " rename-item -Path ..\CyberSource\lib\Model\Tmsv1instrumentidentifiersProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransaction.php -newname Tmsv1instrumentidentifiersMerchantInitiatedTransaction.php"
32+
33+
powershell -Command " rename-item -Path ..\CyberSource\lib\Model\Ptsv2paymentsProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransaction.php -newname Ptsv2paymentsMerchantInitiatedTransaction.php"
34+
35+
powershell -Command " rename-item -Path ..\CyberSource\docs\Model\Tmsv1instrumentidentifiersProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransaction.md -newname Tmsv1instrumentidentifiersMerchantInitiatedTransaction.md"
36+
37+
powershell -Command " rename-item -Path ..\CyberSource\docs\Model\Ptsv2paymentsProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransaction.md -newname Ptsv2paymentsMerchantInitiatedTransaction.md"
38+
39+
powershell -Command " rename-item -Path ..\CyberSource\test\Model\Tmsv1instrumentidentifiersProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransactionTest.php -newname Tmsv1instrumentidentifiersMerchantInitiatedTransactionTest.php"
40+
41+
powershell -Command " rename-item -Path ..\CyberSource\test\Model\Ptsv2paymentsProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransactionTest.php -newname Ptsv2paymentsMerchantInitiatedTransactionTest.php"
42+
443

544
pause
645

13.2 MB
Binary file not shown.

0 commit comments

Comments
 (0)