diff --git a/src/FilipSedivy/EET/Dispatcher.php b/src/FilipSedivy/EET/Dispatcher.php index 9b9a29e..64c85dd 100755 --- a/src/FilipSedivy/EET/Dispatcher.php +++ b/src/FilipSedivy/EET/Dispatcher.php @@ -4,6 +4,7 @@ use FilipSedivy\EET\Enum; use FilipSedivy\EET\Exceptions; +use FilipSedivy\EET\Utils\Debugger; use FilipSedivy\EET\Utils\Format; use RobRichards\XMLSecLibs\XMLSecurityKey; use Symfony\Component\Validator\Validation; @@ -93,6 +94,15 @@ public function check(Receipt $receipt): bool } } + public function test(Receipt $receipt, bool $hiddenSensitiveData = true): void + { + $this->check($receipt); + + $debugger = new Debugger\LastRequest($this->soapClient->lastRequest); + $debugger->hiddenSensitiveData = $hiddenSensitiveData; + $debugger->out(); + } + public function getCheckCodes(Receipt $receipt): array { if (isset($this->validator)) { diff --git a/src/FilipSedivy/EET/Utils/Debugger/LastRequest.php b/src/FilipSedivy/EET/Utils/Debugger/LastRequest.php new file mode 100644 index 0000000..a01bb43 --- /dev/null +++ b/src/FilipSedivy/EET/Utils/Debugger/LastRequest.php @@ -0,0 +1,105 @@ +lastRequest = $lastRequest; + } + + public function out(): void + { + if ($this->hiddenSensitiveData) { + $this->doHiddenSensitiveData(); + } + + if ($this->format) { + $this->doFormat(); + } + + if ($this->highlight) { + $this->doHighlight(); + } + + printf('
%s
', $this->lastRequest); + } + + private function doFormat(): void + { + $dom = new DOMDocument; + + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + + $dom->loadXML($this->lastRequest); + + $this->lastRequest = $dom->saveXML(); + } + + private function doHighlight(): void + { + $s = htmlspecialchars($this->lastRequest); + + $s = preg_replace("#<([/]*?)(.*)([\s]*?)>#sU", + "<\\1\\2\\3>", $s); + + $s = preg_replace("#<([\?])(.*)([\?])>#sU", + "<\\1\\2\\3>", $s); + + $s = preg_replace("#<([^\s\?/=])(.*)([\[\s/]|>)#iU", + "<\\1\\2\\3", $s); + + $s = preg_replace("#<([/])([^\s]*?)([\s\]]*?)>#iU", + "<\\1\\2\\3>", $s); + + $s = preg_replace("#([^\s]*?)\=("|')(.*)("|')#isU", + "\\1=\\2\\3\\4", $s); + + $s = preg_replace("#<(.*)(\[)(.*)(\])>#isU", + "<\\1\\2\\3\\4>", $s); + + $this->lastRequest = nl2br($s); + } + + private function doHiddenSensitiveData(): void + { + $dom = new DOMDocument; + $dom->loadXML($this->lastRequest); + + foreach (self::SENSITIVE_TAGS as $tag) { + $nodeList = $dom->getElementsByTagName($tag); + + for ($i = 0; $i < $nodeList->length; $i++) { + $node = $nodeList->item($i); + $node->nodeValue = $this->sensitiveValue; + } + } + + $this->lastRequest = $dom->saveXML(); + } +} \ No newline at end of file diff --git a/tests/Data/EET_CA1_Playground-CZ00000019.p12 b/tests/Data/EET_CA1_Playground-CZ00000019.p12 index 589d50a..6fb8d08 100644 Binary files a/tests/Data/EET_CA1_Playground-CZ00000019.p12 and b/tests/Data/EET_CA1_Playground-CZ00000019.p12 differ diff --git a/tests/Data/EET_CA1_Playground-CZ1212121218.p12 b/tests/Data/EET_CA1_Playground-CZ1212121218.p12 new file mode 100644 index 0000000..3173854 Binary files /dev/null and b/tests/Data/EET_CA1_Playground-CZ1212121218.p12 differ diff --git a/tests/Data/EET_CA1_Playground-CZ683555118.p12 b/tests/Data/EET_CA1_Playground-CZ683555118.p12 new file mode 100644 index 0000000..697fa9b Binary files /dev/null and b/tests/Data/EET_CA1_Playground-CZ683555118.p12 differ diff --git a/tests/Data/EET_CA1_Playground-ca.crt b/tests/Data/EET_CA1_Playground-ca.crt new file mode 100644 index 0000000..e5d3f23 Binary files /dev/null and b/tests/Data/EET_CA1_Playground-ca.crt differ