Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 1a9c4d6

Browse files
authored
4.0.2
2 parents dd9e8e1 + 478eebd commit 1a9c4d6

6 files changed

+115
-0
lines changed

src/FilipSedivy/EET/Dispatcher.php

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use FilipSedivy\EET\Enum;
66
use FilipSedivy\EET\Exceptions;
7+
use FilipSedivy\EET\Utils\Debugger;
78
use FilipSedivy\EET\Utils\Format;
89
use RobRichards\XMLSecLibs\XMLSecurityKey;
910
use Symfony\Component\Validator\Validation;
@@ -93,6 +94,15 @@ public function check(Receipt $receipt): bool
9394
}
9495
}
9596

97+
public function test(Receipt $receipt, bool $hiddenSensitiveData = true): void
98+
{
99+
$this->check($receipt);
100+
101+
$debugger = new Debugger\LastRequest($this->soapClient->lastRequest);
102+
$debugger->hiddenSensitiveData = $hiddenSensitiveData;
103+
$debugger->out();
104+
}
105+
96106
public function getCheckCodes(Receipt $receipt): array
97107
{
98108
if (isset($this->validator)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace FilipSedivy\EET\Utils\Debugger;
4+
5+
use DOMDocument;
6+
7+
class LastRequest
8+
{
9+
private const SENSITIVE_TAGS = [
10+
'DigestValue',
11+
'SignatureValue',
12+
'BinarySecurityToken'
13+
];
14+
15+
/** @var bool */
16+
public $highlight = true;
17+
18+
/** @var bool */
19+
public $format = true;
20+
21+
/** @var bool */
22+
public $hiddenSensitiveData = true;
23+
24+
/** @var string */
25+
public $sensitiveValue = '**** CENSURE ****';
26+
27+
/** @var string */
28+
private $lastRequest;
29+
30+
public function __construct(string $lastRequest)
31+
{
32+
$this->lastRequest = $lastRequest;
33+
}
34+
35+
public function out(): void
36+
{
37+
if ($this->hiddenSensitiveData) {
38+
$this->doHiddenSensitiveData();
39+
}
40+
41+
if ($this->format) {
42+
$this->doFormat();
43+
}
44+
45+
if ($this->highlight) {
46+
$this->doHighlight();
47+
}
48+
49+
printf('<pre>%s</pre>', $this->lastRequest);
50+
}
51+
52+
private function doFormat(): void
53+
{
54+
$dom = new DOMDocument;
55+
56+
$dom->preserveWhiteSpace = false;
57+
$dom->formatOutput = true;
58+
59+
$dom->loadXML($this->lastRequest);
60+
61+
$this->lastRequest = $dom->saveXML();
62+
}
63+
64+
private function doHighlight(): void
65+
{
66+
$s = htmlspecialchars($this->lastRequest);
67+
68+
$s = preg_replace("#&lt;([/]*?)(.*)([\s]*?)&gt;#sU",
69+
"<span style=\"color: #0000FF\">&lt;\\1\\2\\3&gt;</span>", $s);
70+
71+
$s = preg_replace("#&lt;([\?])(.*)([\?])&gt;#sU",
72+
"<span style=\"color: #800000\">&lt;\\1\\2\\3&gt;</span>", $s);
73+
74+
$s = preg_replace("#&lt;([^\s\?/=])(.*)([\[\s/]|&gt;)#iU",
75+
"&lt;<span style=\"color: #808000\">\\1\\2</span>\\3", $s);
76+
77+
$s = preg_replace("#&lt;([/])([^\s]*?)([\s\]]*?)&gt;#iU",
78+
"&lt;\\1<span style=\"color: #808000\">\\2</span>\\3&gt;", $s);
79+
80+
$s = preg_replace("#([^\s]*?)\=(&quot;|')(.*)(&quot;|')#isU",
81+
"<span style=\"color: #800080\">\\1</span>=<span style=\"color: #FF00FF\">\\2\\3\\4</span>", $s);
82+
83+
$s = preg_replace("#&lt;(.*)(\[)(.*)(\])&gt;#isU",
84+
"&lt;\\1<span style=\"color: #800080\">\\2\\3\\4</span>&gt;", $s);
85+
86+
$this->lastRequest = nl2br($s);
87+
}
88+
89+
private function doHiddenSensitiveData(): void
90+
{
91+
$dom = new DOMDocument;
92+
$dom->loadXML($this->lastRequest);
93+
94+
foreach (self::SENSITIVE_TAGS as $tag) {
95+
$nodeList = $dom->getElementsByTagName($tag);
96+
97+
for ($i = 0; $i < $nodeList->length; $i++) {
98+
$node = $nodeList->item($i);
99+
$node->nodeValue = $this->sensitiveValue;
100+
}
101+
}
102+
103+
$this->lastRequest = $dom->saveXML();
104+
}
105+
}
0 Bytes
Binary file not shown.
3.92 KB
Binary file not shown.
3.92 KB
Binary file not shown.

tests/Data/EET_CA1_Playground-ca.crt

1.22 KB
Binary file not shown.

0 commit comments

Comments
 (0)