Skip to content

Query Request Implementation #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/Omnipay/DataCash/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Omnipay\DataCash;

use Omnipay\DataCash\Message\CompletePurchaseRequest;
use Omnipay\DataCash\Message\PurchaseRequest;
use Omnipay\Common\AbstractGateway;

/**
Expand All @@ -20,11 +18,11 @@ public function getName()

public function getDefaultParameters()
{
return array(
return [
'merchantId' => '',
'password' => '',
'testMode' => false
);
'testMode' => false,
];
}

public function getMerchantId()
Expand All @@ -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);
}
}
70 changes: 70 additions & 0 deletions src/Omnipay/DataCash/Message/QueryRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Omnipay\DataCash\Message;

use Omnipay\Common\Exception\InvalidResponseException;
use SimpleXMLElement;
use Omnipay\Common\Message\AbstractRequest;

/**
* DataCash Refund Request
*/
class QueryRequest extends AbstractRequest
{
protected $liveEndpoint = 'https://mars.transaction.datacash.com/Transaction';
protected $testEndpoint = 'https://testserver.datacash.com/Transaction';

public function getMerchantId()
{
return $this->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('<Request/>');

$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());
}
}
27 changes: 27 additions & 0 deletions tests/Omnipay/DataCash/Message/QueryResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Omnipay\DataCash\Message;

use Omnipay\Tests\TestCase;

class QueryResponseTest extends TestCase
{
public function testQuerySuccess()
{
$httpResponse = $this->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());
}
}
17 changes: 17 additions & 0 deletions tests/Omnipay/DataCash/Mock/QueryFailure.txt
Original file line number Diff line number Diff line change
@@ -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

<?xml version="1.0" encoding="utf-8"?>
<Response>
<datacash_reference>3100108890691001</datacash_reference>
<mode>LIVE</mode>
<reason>Invalid query ref</reason>
<status>22</status>
<time>1540994766</time>
</Response>
36 changes: 36 additions & 0 deletions tests/Omnipay/DataCash/Mock/QuerySuccess.txt
Original file line number Diff line number Diff line change
@@ -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

<?xml version="1.0" encoding="utf-8"?>
<Response>
<QueryTxnResult>
<Card>
<card_category>Personal</card_category>
<country>gbr</country>
<expirydate>12/21</expirydate>
<issuer>Acme Bank</issuer>
<pan>444433******1111</pan>
<scheme>VISA</scheme>
</Card>
<acquirer>Mickeycard</acquirer>
<authcode>123456</authcode>
<datacash_reference>3000001234567898</datacash_reference>
<environment>ecomm</environment>
<fulfill_date>2018-10-15 18:41:06</fulfill_date>
<merchant_reference>ABCDEFG12345</merchant_reference>
<reason>ACCEPTED</reason>
<sent>Settled</sent>
<status>1</status>
<transaction_date>2018-10-14 22:41:06</transaction_date>
</QueryTxnResult>
<mode>LIVE</mode>
<reason>ACCEPTED</reason>
<status>1</status>
<time>1540994766</time>
</Response>