Skip to content

Commit

Permalink
Issue #125 mask "action" validation error in "query" functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Feb 6, 2019
1 parent 475085a commit aa43c8b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Message/AIMAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ protected function addReferenceId(\SimpleXMLElement $data)

protected function addTransactionType(\SimpleXMLElement $data)
{
if (!$this->action) {
// The extending class probably hasn't specified an "action"
if (! $this->action) {
// The extending class probably hasn't specified an "action".
throw new InvalidRequestException();
}

Expand Down
14 changes: 12 additions & 2 deletions src/Message/Query/AIMAbstractQueryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

namespace Omnipay\AuthorizeNet\Message\Query;

use Omnipay\AuthorizeNet\Message\AIMAbstractRequest;

/**
* Authorize.Net AIM Abstract Request
*/

use Omnipay\AuthorizeNet\Message\AIMAbstractRequest;
use SimpleXMLElement;

abstract class AIMAbstractQueryRequest extends AIMAbstractRequest
{
protected $limit = 1000;
protected $offset = 1;

/**
* Disable validation check on the parent method.
*/
protected function addTransactionType(SimpleXMLElement $data)
{
// NOOP
}

/**
* Get Limit.
*
Expand Down
15 changes: 12 additions & 3 deletions src/Message/Query/QueryBatchRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
/**
* Authorize.Net AIM Authorize Request
*/

class QueryBatchRequest extends AIMAbstractQueryRequest
{
protected $action = '';
protected $requestType = 'getSettledBatchListRequest';

public function sendData($data)
{
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
$data = $data->saveXml();
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data);

return $this->response = new QueryBatchResponse($this, $httpResponse->getBody()->getContents());
$httpResponse = $this->httpClient->request(
'POST',
$this->getEndpoint(),
$headers,
$data
);

return $this->response = new QueryBatchResponse(
$this,
$httpResponse->getBody()->getContents()
);
}
}
40 changes: 31 additions & 9 deletions src/Message/Query/QueryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,40 @@
/**
* Authorize.Net AIM Authorize Request
*/

class QueryRequest extends QueryBatchRequest
{
const DATE_TIME_FORMAT = 'Y-m-d\Th:i:s\Z';

protected $startTimestamp;
protected $endTimestamp;

/**
* @return mixed
* @return int|null
*/
public function getStartTimestamp()
{
return $this->startTimestamp;
}

/**
* @param mixed $startTimestamp
* @param int|null $startTimestamp unix timestamp
*/
public function setStartTimestamp($startTimestamp)
{
$this->startTimestamp = $startTimestamp;
}

/**
* @return mixed
* @return int|null
*/
public function getEndTimestamp()
{
return $this->endTimestamp;
}

/**
* @param mixed $endTimestamp
* @param int|null $endTimestamp unix timestamp
*/
public function setEndTimestamp($endTimestamp)
{
Expand All @@ -48,23 +51,42 @@ public function setEndTimestamp($endTimestamp)
public function getData()
{
$data = $this->getBaseData();

if ($this->getStartTimestamp()) {
$data->firstSettlementDate = date('Y-m-d\Th:i:s\Z', $this->getStartTimestamp());
$data->lastSettlementDate = date('Y-m-d\Th:i:s\Z');
$data->firstSettlementDate = date(
static::DATE_TIME_FORMAT,
$this->getStartTimestamp()
);
$data->lastSettlementDate = date(static::DATE_TIME_FORMAT);
}

if ($this->getEndTimestamp()) {
$data->lastSettlementDate = date('Y-m-d\Th:i:s\Z', $this->getEndTimestamp());
$data->lastSettlementDate = date(
static::DATE_TIME_FORMAT,
$this->getEndTimestamp()
);
}

return $data;
}

public function sendData($data)
{
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
$data = $data->saveXml();
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data);

$this->response = new QueryResponse($this, $httpResponse->getBody()->getContents());
$httpResponse = $this->httpClient->request(
'POST',
$this->getEndpoint(),
$headers,
$data
);

$this->response = new QueryResponse(
$this,
$httpResponse->getBody()->getContents()
);

return $this->response;
}
}

0 comments on commit aa43c8b

Please sign in to comment.