11<?php
2+
23namespace Omnipay \Ecopayz \Message ;
34
45use Omnipay \Common \Exception \InvalidRequestException ;
@@ -17,8 +18,8 @@ class FetchTransactionRequest extends AbstractRequest
1718 /**
1819 * Get the data for this request.
1920 *
20- * @throws InvalidRequestException
2121 * @return string request data
22+ * @throws InvalidRequestException
2223 */
2324 public function getData ()
2425 {
@@ -43,7 +44,6 @@ public function getData()
4344 );
4445
4546 if ($ transactionReference = $ this ->getTransactionReference ()) {
46-
4747 $ query = $ body ->appendChild (
4848 $ document ->createElement ('q0:QueryBySVSTransactionID ' )
4949 );
@@ -63,9 +63,7 @@ public function getData()
6363 $ request ->appendChild (
6464 $ document ->createElement ('q0:SVSTxID ' , $ transactionReference )
6565 );
66-
6766 } elseif ($ transactionId = $ this ->getTransactionId ()) {
68-
6967 $ query = $ body ->appendChild (
7068 $ document ->createElement ('q0:QueryByCustomerTransactionID ' )
7169 );
@@ -85,11 +83,8 @@ public function getData()
8583 $ request ->appendChild (
8684 $ document ->createElement ('q0:TxID ' , $ transactionId )
8785 );
88-
8986 } else {
90-
9187 throw new InvalidRequestException ('The transactionId or transactionReference parameter is required ' );
92-
9388 }
9489
9590 return $ document ->saveXML ();
@@ -98,23 +93,21 @@ public function getData()
9893 /**
9994 * Send the request with specified data
10095 *
101- * @param mixed $data The data to send
102- * @throws InvalidResponseException
103- * @throws InvalidRequestException
96+ * @param mixed $data The data to send
10497 * @return FetchTransactionResponse
98+ * @throws InvalidRequestException
99+ * @throws InvalidResponseException
105100 */
106101 public function sendData ($ data )
107102 {
108103 if (strpos ($ data , 'QueryBySVSTransactionID ' ) !== false ) {
109-
110104 $ headers = array (
111105 'Content-Type ' => 'text/xml; charset=utf-8 ' ,
112106 'SOAPAction ' => 'http://www.ecocard.com/merchantAPI/QueryBySVSTransactionID '
113107 );
114108
115- $ httpRequest = $ this ->httpClient ->createRequest ('POST ' , $ this ->getEndpoint (), $ headers , $ data );
116- $ httpResponse = $ httpRequest ->send ();
117- $ xmlResponse = $ httpResponse ->xml ()
109+ $ httpResponse = $ this ->httpClient ->request ('POST ' , $ this ->getEndpoint (), $ headers , $ data );
110+ $ xmlResponse = simplexml_load_string ($ httpResponse ->getBody ()->getContents ())
118111 ->children ('http://schemas.xmlsoap.org/soap/envelope/ ' )
119112 ->children ('http://www.ecocard.com/merchantAPI/ ' );
120113
@@ -132,17 +125,14 @@ public function sendData($data)
132125 ->QueryBySVSTransactionIDResponse
133126 ->TransactionResponse
134127 );
135-
136128 } elseif (strpos ($ data , 'QueryByCustomerTransactionID ' ) !== false ) {
137-
138129 $ headers = array (
139130 'Content-Type ' => 'text/xml; charset=utf-8 ' ,
140131 'SOAPAction ' => 'http://www.ecocard.com/merchantAPI/QueryByCustomerTransactionID '
141132 );
142133
143- $ httpRequest = $ this ->httpClient ->createRequest ('POST ' , $ this ->getEndpoint (), $ headers , $ data );
144- $ httpResponse = $ httpRequest ->send ();
145- $ xmlResponse = $ httpResponse ->xml ()
134+ $ httpResponse = $ this ->httpClient ->request ('POST ' , $ this ->getEndpoint (), $ headers , $ data );
135+ $ xmlResponse = simplexml_load_string ($ httpResponse ->getBody ()->getContents ())
146136 ->children ('http://schemas.xmlsoap.org/soap/envelope/ ' )
147137 ->children ('http://www.ecocard.com/merchantAPI/ ' );
148138
@@ -160,11 +150,8 @@ public function sendData($data)
160150 ->QueryByCustomerTransactionIDResponse
161151 ->TransactionResponse
162152 );
163-
164153 } else {
165-
166154 throw new InvalidRequestException ('The transactionId or transactionReference parameter is required ' );
167-
168155 }
169156 }
170157}
0 commit comments