@@ -16,7 +16,9 @@ public static function parseTransportResponse(
1616 string $ transportResponse ,
1717 PaytureOperation $ operation
1818 ): TerminalResponse {
19- $ attributes = self ::parseAttributesFromXmlResponse ($ transportResponse , self ::mapOperationToRootNode ($ operation ));
19+ $ response = self ::parseXmlResponse ($ transportResponse , self ::mapOperationToRootNode ($ operation ));
20+
21+ $ attributes = $ response ['@attributes ' ];
2022
2123 if (!isset ($ attributes ['Success ' ])) {
2224 throw InvalidResponseException::becauseUndefinedSuccessAttribute ();
@@ -48,13 +50,17 @@ public static function parseTransportResponse(
4850 $ result ->setRrn ($ attributes ['RRN ' ]);
4951 }
5052
53+ if (isset ($ response ['AddInfo ' ])) {
54+ $ result ->setAdditionalInfo ($ response ['AddInfo ' ]);
55+ }
56+
5157 return $ result ;
5258 }
5359
5460 /**
5561 * @throws InvalidResponseException
5662 */
57- private static function parseAttributesFromXmlResponse (string $ xml , string $ operation ): array
63+ private static function parseXmlResponse (string $ xml , string $ operation ): array
5864 {
5965 $ oldUseInternalXmlErrors = libxml_use_internal_errors (true );
6066 $ rootNode = simplexml_load_string ($ xml );
@@ -74,7 +80,26 @@ private static function parseAttributesFromXmlResponse(string $xml, string $oper
7480 throw InvalidResponseException::becauseEmptyAttributes ();
7581 }
7682
77- return $ data ['@attributes ' ];
83+ $ result = [];
84+ $ result ['@attributes ' ] = $ data ['@attributes ' ];
85+
86+ if (isset ($ data ['AddInfo ' ])) {
87+ $ result ['AddInfo ' ] = self ::parseAddInfo ($ data ['AddInfo ' ]);
88+ }
89+
90+ return $ result ;
91+ }
92+
93+ private static function parseAddInfo (array $ rawAddInfo ): array
94+ {
95+ $ result = [];
96+
97+ foreach ($ rawAddInfo as $ info ) {
98+ $ infoArray = (array ) $ info ;
99+ $ result [$ infoArray ['@attributes ' ]['Key ' ]] = $ infoArray ['@attributes ' ]['Value ' ];
100+ }
101+
102+ return $ result ;
78103 }
79104
80105 private static function mapOperationToRootNode (PaytureOperation $ operation ): string
0 commit comments