Skip to content

Commit

Permalink
Merge pull request #126 from thephpleague/issue125
Browse files Browse the repository at this point in the history
Fixes to the query functions.
  • Loading branch information
judgej authored Feb 6, 2019
2 parents 58948ff + 671c8de commit bd23ae4
Show file tree
Hide file tree
Showing 35 changed files with 186 additions and 93 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
"psr-4": { "Omnipay\\AuthorizeNet\\" : "src/" }
},
"require": {
"omnipay/common": "^3"
"omnipay/common": "^3",
"ext-json": "*",
"ext-libxml": "*",
"ext-simplexml": "*"
},
"require-dev": {
"omnipay/tests": "^3",
Expand Down
74 changes: 56 additions & 18 deletions src/AIMGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace Omnipay\AuthorizeNet;

use Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest;
use Omnipay\AuthorizeNet\Message\AIMCaptureOnlyRequest;
use Omnipay\AuthorizeNet\Message\AIMCaptureRequest;
use Omnipay\AuthorizeNet\Message\AIMPaymentPlanQueryResponse;
use Omnipay\AuthorizeNet\Message\Query\AIMPaymentPlanQueryResponse;
use Omnipay\AuthorizeNet\Message\AIMPurchaseRequest;
use Omnipay\AuthorizeNet\Message\QueryRequest;
use Omnipay\AuthorizeNet\Message\AIMRefundRequest;
use Omnipay\AuthorizeNet\Message\AIMVoidRequest;
use Omnipay\AuthorizeNet\Message\Query\AIMPaymentPlansQueryRequest;
use Omnipay\AuthorizeNet\Message\Query\QueryResponse;
use Omnipay\Common\AbstractGateway;

/**
Expand Down Expand Up @@ -126,7 +128,10 @@ public function setDuplicateWindow($value)
*/
public function authorize(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest', $parameters);
return $this->createRequest(
AIMAuthorizeRequest::class,
$parameters
);
}

/**
Expand All @@ -135,7 +140,10 @@ public function authorize(array $parameters = array())
*/
public function capture(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMCaptureRequest', $parameters);
return $this->createRequest(
AIMCaptureRequest::class,
$parameters
);
}

/**
Expand All @@ -144,7 +152,10 @@ public function capture(array $parameters = array())
*/
public function captureOnly(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMCaptureOnlyRequest', $parameters);
return $this->createRequest(
AIMCaptureOnlyRequest::class,
$parameters
);
}

/**
Expand All @@ -153,7 +164,10 @@ public function captureOnly(array $parameters = array())
*/
public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMPurchaseRequest', $parameters);
return $this->createRequest(
AIMPurchaseRequest::class,
$parameters
);
}

/**
Expand All @@ -162,7 +176,10 @@ public function purchase(array $parameters = array())
*/
public function void(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMVoidRequest', $parameters);
return $this->createRequest(
AIMVoidRequest::class,
$parameters
);
}

/**
Expand All @@ -171,7 +188,10 @@ public function void(array $parameters = array())
*/
public function refund(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMRefundRequest', $parameters);
return $this->createRequest(
AIMRefundRequest::class,
$parameters
);
}

/**
Expand All @@ -180,16 +200,22 @@ public function refund(array $parameters = array())
*/
public function paymentPlansQuery(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\Query\AIMPaymentPlansQueryRequest', $parameters);
return $this->createRequest(
Message\Query\AIMPaymentPlansQueryRequest::class,
$parameters
);
}

/**
* @param array $parameters
* @return AIMPaymentPlanQueryResponse
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function paymentPlanQuery(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\Query\AIMPaymentPlanQueryRequest', $parameters);
return $this->createRequest(
Message\Query\AIMPaymentPlanQueryRequest::class,
$parameters
);
}

/**
Expand All @@ -198,33 +224,45 @@ public function paymentPlanQuery(array $parameters = array())
*/
public function query(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\Query\QueryRequest', $parameters);
return $this->createRequest(
Message\Query\QueryRequest::class,
$parameters
);
}

/**
* @param array $parameters
* @return QueryBatchResponse
* @return Message\Query\QueryBatchRequest
*/
public function queryBatch(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\QueryBatchRequest', $parameters);
return $this->createRequest(
Message\Query\QueryBatchRequest::class,
$parameters
);
}

/**
* @param array $parameters
* @return QueryBatchDetailResponse
* @return Message\Query\QueryBatchDetailRequest
*/
public function queryBatchDetail(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\QueryBatchDetailRequest', $parameters);
return $this->createRequest(
Message\Query\QueryBatchDetailRequest::class,
$parameters
);
}

/**
* @param array $parameters
* @return QueryDetailResponse
* @return Message\Query\QueryDetailRequest
*/
public function queryDetail(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\QueryDetailRequest', $parameters);
return $this->createRequest(
Message\Query\QueryDetailRequest::class,
$parameters
);
}
}
2 changes: 2 additions & 0 deletions src/DPMGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public function getName()

/**
* Helper to generate the authorize direct-post form.
* @param array $parameters
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function authorize(array $parameters = array())
{
Expand Down
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
2 changes: 0 additions & 2 deletions src/Message/AIMCaptureOnlyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Omnipay\AuthorizeNet\Message;

use Omnipay\Common\CreditCard;

/**
* Authorize.Net AIM Capture Only Request
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Message/CIMAbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public function xml2array(\SimpleXMLElement $xml)
{
return json_decode(json_encode($xml), true);

// Old parser below, just keeping on a hunch.

$arr = array();

foreach ($xml as $element) {
Expand Down
2 changes: 1 addition & 1 deletion src/Message/CIMCreateCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getData()
/**
* Validate card or skip if opaque data is available
*
* @param \SimpleXMLElement $data
* @throws \Omnipay\Common\Exception\InvalidCreditCardException
*/
protected function cardValidate()
{
Expand Down
2 changes: 0 additions & 2 deletions src/Message/CIMCreatePaymentProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Omnipay\AuthorizeNet\Message;

use Omnipay\Common\CreditCard;

/**
* Request to create customer payment profile for existing customer.
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Message/CIMUpdatePaymentProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Omnipay\AuthorizeNet\Message;

use Omnipay\Common\CreditCard;

/**
* Request to create customer payment profile for existing customer.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Message/DPMAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function getData()
* The form may have most of the fields hidden, or may allow the user to change some details -
* that depends on the use-case.
* So this method will provide us with an object used to build the form.
* @param $data
* @return DPMResponse
*/
public function sendData($data)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Message/DPMCompleteRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Omnipay\AuthorizeNet\Message;

use Omnipay\Common\Exception\InvalidRequestException;

/**
* Authorize.Net DPM Complete Authorize Request
*/
Expand Down
5 changes: 3 additions & 2 deletions src/Message/DPMResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class DPMResponse extends AbstractResponse implements RedirectResponseInterface

public function __construct(RequestInterface $request, $data, $postUrl)
{
$this->request = $request;
$this->data = $data;
parent::__construct($request, $data);

$this->postUrl = $postUrl;
}

Expand Down Expand Up @@ -127,6 +127,7 @@ public function getRedirectData()
* Move a field to the list of hidden form fields.
* The hidden fields are those we don't want to show the user, but
* must still be posted.
* @param $field_name
*/
public function hideField($field_name)
{
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
2 changes: 0 additions & 2 deletions src/Message/Query/AIMPaymentPlanQueryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Omnipay\AuthorizeNet\Message\Query;

use Omnipay\Common\CreditCard;

/**
* Authorize.Net AIM Authorize Request
*/
Expand Down
9 changes: 6 additions & 3 deletions src/Message/Query/AIMPaymentPlanQueryResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Omnipay\AuthorizeNet\Message\Query;

use Omnipay\AuthorizeNet\Model\CardReference;
use Omnipay\AuthorizeNet\Model\TransactionReference;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\Common\Message\AbstractResponse;
Expand All @@ -20,7 +18,12 @@ class AIMPaymentPlanQueryResponse extends AbstractQueryResponse
public function __construct(AbstractRequest $request, $data)
{
// Strip out the xmlns junk so that PHP can parse the XML
$xml = preg_replace('/<ARBGetSubscriptionRequest[^>]+>/', '<ARBGetSubscriptionRequest>', (string)$data);
$xml = preg_replace(
'/<ARBGetSubscriptionRequest[^>]+>/',
'<ARBGetSubscriptionRequest>',
(string)$data
);

try {
$xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOWARNING);
} catch (\Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/Message/Query/AIMPaymentPlansQueryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Omnipay\AuthorizeNet\Message\Query;

use Omnipay\Common\CreditCard;
use Omnipay\AuthorizeNet\Message\AIMAbstractRequest;

/**
* Authorize.Net AIM Authorize Request
Expand Down
2 changes: 0 additions & 2 deletions src/Message/Query/AIMPaymentPlansQueryResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Omnipay\AuthorizeNet\Message\Query;

use Omnipay\AuthorizeNet\Model\CardReference;
use Omnipay\AuthorizeNet\Model\TransactionReference;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\Common\Message\AbstractResponse;
Expand Down
3 changes: 0 additions & 3 deletions src/Message/Query/AbstractQueryResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Omnipay\AuthorizeNet\Message\Query;

use Omnipay\AuthorizeNet\Model\CardReference;
use Omnipay\AuthorizeNet\Model\TransactionReference;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\Common\Message\AbstractResponse;
use Omnipay\Omnipay;
Expand Down
Loading

0 comments on commit bd23ae4

Please sign in to comment.