From 0d1cde3d5575c79f195a83b89eb26b5e2fb90de2 Mon Sep 17 00:00:00 2001 From: Kamba Abudu Date: Wed, 31 Oct 2018 13:19:38 +0000 Subject: [PATCH 1/3] implement query message type and a little refactoring --- composer.json | 1 + src/Omnipay/DataCash/Gateway.php | 19 ++--- src/Omnipay/DataCash/Message/QueryRequest.php | 70 +++++++++++++++++++ 3 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 src/Omnipay/DataCash/Message/QueryRequest.php diff --git a/composer.json b/composer.json index 1483e8b..27a1e34 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ "psr-0": { "Omnipay\\DataCash\\" : "src/" } }, "require": { + "ext-simplexml": "*", "omnipay/common": "2.*" }, "require-dev": { 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()); + } +} From e9f93cb6f99c6e0eea0ae0bd0694676de38c8254 Mon Sep 17 00:00:00 2001 From: Kamba Abudu Date: Thu, 1 Nov 2018 10:17:03 +0000 Subject: [PATCH 2/3] adding test suite --- .../DataCash/Message/QueryResponseTest.php | 27 ++++++++++++++ tests/Omnipay/DataCash/Mock/QueryFailure.txt | 17 +++++++++ tests/Omnipay/DataCash/Mock/QuerySuccess.txt | 36 +++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 tests/Omnipay/DataCash/Message/QueryResponseTest.php create mode 100644 tests/Omnipay/DataCash/Mock/QueryFailure.txt create mode 100644 tests/Omnipay/DataCash/Mock/QuerySuccess.txt 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 From 4927038de290ead5a6f9dc5db0efed6e46fc7647 Mon Sep 17 00:00:00 2001 From: Kamba Abudu Date: Thu, 1 Nov 2018 10:23:46 +0000 Subject: [PATCH 3/3] undo change to composer.json --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 27a1e34..1483e8b 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,6 @@ "psr-0": { "Omnipay\\DataCash\\" : "src/" } }, "require": { - "ext-simplexml": "*", "omnipay/common": "2.*" }, "require-dev": {