diff --git a/src/Omnipay/DataCash/Gateway.php b/src/Omnipay/DataCash/Gateway.php
index f8bdd0e..80a914a 100644
--- a/src/Omnipay/DataCash/Gateway.php
+++ b/src/Omnipay/DataCash/Gateway.php
@@ -2,8 +2,6 @@
namespace Omnipay\DataCash;
-use Omnipay\DataCash\Message\CompletePurchaseRequest;
-use Omnipay\DataCash\Message\PurchaseRequest;
use Omnipay\Common\AbstractGateway;
/**
@@ -20,11 +18,11 @@ public function getName()
public function getDefaultParameters()
{
- return array(
+ return [
'merchantId' => '',
'password' => '',
- 'testMode' => false
- );
+ 'testMode' => false,
+ ];
}
public function getMerchantId()
@@ -47,18 +45,23 @@ public function setPassword($value)
return $this->setParameter('password', $value);
}
- public function purchase(array $parameters = array())
+ public function purchase(array $parameters = [])
{
return $this->createRequest('\Omnipay\DataCash\Message\PurchaseRequest', $parameters);
}
- public function completePurchase(array $parameters = array())
+ public function completePurchase(array $parameters = [])
{
return $this->createRequest('\Omnipay\DataCash\Message\CompletePurchaseRequest', $parameters);
}
- public function refund(array $parameters = array())
+ public function refund(array $parameters = [])
{
return $this->createRequest('\Omnipay\DataCash\Message\RefundRequest', $parameters);
}
+
+ public function query(array $parameters = [])
+ {
+ return $this->createRequest('\Omnipay\DataCash\Message\QueryRequest', $parameters);
+ }
}
diff --git a/src/Omnipay/DataCash/Message/QueryRequest.php b/src/Omnipay/DataCash/Message/QueryRequest.php
new file mode 100644
index 0000000..6e5757d
--- /dev/null
+++ b/src/Omnipay/DataCash/Message/QueryRequest.php
@@ -0,0 +1,70 @@
+getParameter('merchantId');
+ }
+
+ public function setMerchantId($value)
+ {
+ return $this->setParameter('merchantId', $value);
+ }
+
+ public function getPassword()
+ {
+ return $this->getParameter('password');
+ }
+
+ public function setPassword($value)
+ {
+ return $this->setParameter('password', $value);
+ }
+
+ public function getData()
+ {
+ $this->validate('transactionReference');
+
+ $data = new SimpleXMLElement('');
+
+ $data->Authentication->client = $this->getMerchantId();
+ $data->Authentication->password = $this->getPassword();
+
+ $data->Transaction->HistoricTxn->reference = $this->getTransactionReference();
+ $data->Transaction->HistoricTxn->method = 'query';
+
+ return $data;
+ }
+
+ public function getEndpoint()
+ {
+ return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
+ }
+
+ /**
+ * @param SimpleXMLElement $data
+ * @return \Omnipay\Common\Message\ResponseInterface|Response
+ * @throws InvalidResponseException
+ */
+ public function sendData($data)
+ {
+ // post to DataCash
+ $xml = $data->saveXML();
+ $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $xml)->send();
+
+ return $this->response = new Response($this, $httpResponse->getBody());
+ }
+}
diff --git a/tests/Omnipay/DataCash/Message/QueryResponseTest.php b/tests/Omnipay/DataCash/Message/QueryResponseTest.php
new file mode 100644
index 0000000..068dfd5
--- /dev/null
+++ b/tests/Omnipay/DataCash/Message/QueryResponseTest.php
@@ -0,0 +1,27 @@
+getMockHttpResponse('QuerySuccess.txt');
+ $response = new Response($this->getMockRequest(), $httpResponse->getBody());
+
+ $this->assertTrue($response->isSuccessful());
+ $this->assertEquals('123456', $response->getData()->QueryTxnResult->authcode);
+ $this->assertSame('ACCEPTED', $response->getMessage());
+ }
+
+ public function testQueryFailure()
+ {
+ $httpResponse = $this->getMockHttpResponse('QueryFailure.txt');
+ $response = new Response($this->getMockRequest(), $httpResponse->getBody());
+
+ $this->assertFalse($response->isSuccessful());
+ $this->assertSame('Invalid query ref', $response->getMessage());
+ }
+}
diff --git a/tests/Omnipay/DataCash/Mock/QueryFailure.txt b/tests/Omnipay/DataCash/Mock/QueryFailure.txt
new file mode 100644
index 0000000..45379cb
--- /dev/null
+++ b/tests/Omnipay/DataCash/Mock/QueryFailure.txt
@@ -0,0 +1,17 @@
+HTTP/1.1 200 OK
+Cache-Control: private, max-age=0
+Content-Length: 944
+Content-Type: text/xml; charset=utf-8
+Node: VENUS
+X-Powered-By: ASP.NET
+X-AspNet-Version: 4.0.30319
+Date: Fri, 15 Feb 2013 14:10:53 GMT
+
+
+
+ 3100108890691001
+ LIVE
+ Invalid query ref
+ 22
+
+
\ No newline at end of file
diff --git a/tests/Omnipay/DataCash/Mock/QuerySuccess.txt b/tests/Omnipay/DataCash/Mock/QuerySuccess.txt
new file mode 100644
index 0000000..27568c8
--- /dev/null
+++ b/tests/Omnipay/DataCash/Mock/QuerySuccess.txt
@@ -0,0 +1,36 @@
+HTTP/1.1 200 OK
+Cache-Control: private, max-age=0
+Content-Length: 944
+Content-Type: text/xml; charset=utf-8
+Node: VENUS
+X-Powered-By: ASP.NET
+X-AspNet-Version: 4.0.30319
+Date: Fri, 15 Feb 2013 14:10:53 GMT
+
+
+
+
+
+ Personal
+ gbr
+ 12/21
+ Acme Bank
+ 444433******1111
+ VISA
+
+ Mickeycard
+ 123456
+ 3000001234567898
+ ecomm
+ 2018-10-15 18:41:06
+ ABCDEFG12345
+ ACCEPTED
+ Settled
+ 1
+ 2018-10-14 22:41:06
+
+ LIVE
+ ACCEPTED
+ 1
+
+
\ No newline at end of file