Skip to content

Commit 16cabe0

Browse files
WIP Authorize.net query actions
1 parent 11ebdf2 commit 16cabe0

File tree

6 files changed

+238
-5
lines changed

6 files changed

+238
-5
lines changed

vendor/omnipay/authorizenet/src/AIMGateway.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,19 @@ public function paymentPlanQuery(array $parameters = array())
165165

166166
/**
167167
* @param array $parameters
168-
* @return AIMRefundRequest
168+
* @return QueryResponse
169169
*/
170170
public function query(array $parameters = array())
171171
{
172172
return $this->createRequest('\Omnipay\AuthorizeNet\Message\QueryRequest', $parameters);
173173
}
174+
175+
/**
176+
* @param array $parameters
177+
* @return QueryBatchResponse
178+
*/
179+
public function queryBatch(array $parameters = array())
180+
{
181+
return $this->createRequest('\Omnipay\AuthorizeNet\Message\QueryBatchRequest', $parameters);
182+
}
174183
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
use Omnipay\Common\CreditCard;
6+
7+
/**
8+
* Authorize.Net AIM Authorize Request
9+
*/
10+
class QueryBatchRequest extends AIMAbstractRequest
11+
{
12+
protected $action = '';
13+
protected $requestType = 'getSettledBatchListRequest';
14+
protected $limit = 1000;
15+
protected $offset = 1;
16+
17+
/**
18+
* Get Limit.
19+
*
20+
* @return int
21+
*/
22+
public function getLimit() {
23+
return $this->limit;
24+
}
25+
26+
/**
27+
* Set Limit.
28+
*
29+
* @param int $limit
30+
*/
31+
public function setLimit($limit) {
32+
$this->limit = $limit;
33+
}
34+
35+
/**
36+
* Get offset.
37+
*
38+
* @return int
39+
*/
40+
public function getOffset() {
41+
return $this->offset;
42+
}
43+
44+
/**
45+
* Set offset.
46+
*
47+
* @param int $offset
48+
*/
49+
public function setOffset($offset) {
50+
$this->offset = $offset;
51+
}
52+
53+
/**
54+
* Get data to send.
55+
*/
56+
public function getData()
57+
{
58+
$data = $this->getBaseData();
59+
return $data;
60+
}
61+
62+
protected function addTransactionType(\SimpleXMLElement $data) {}
63+
64+
public function sendData($data)
65+
{
66+
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
67+
$data = $data->saveXml();
68+
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();
69+
70+
return $this->response = new QueryBatchResponse($this, $httpResponse->getBody());
71+
}
72+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
use Omnipay\AuthorizeNet\Model\CardReference;
6+
use Omnipay\AuthorizeNet\Model\TransactionReference;
7+
use Omnipay\Common\Exception\InvalidResponseException;
8+
use Omnipay\Common\Message\AbstractRequest;
9+
use Omnipay\Common\Message\AbstractResponse;
10+
11+
/**
12+
* Authorize.Net AIM Response
13+
*/
14+
class QueryBatchResponse extends AbstractResponse
15+
{
16+
/**
17+
* For Error codes: @see https://developer.authorize.net/api/reference/responseCodes.html
18+
*/
19+
const ERROR_RESPONSE_CODE_CANNOT_ISSUE_CREDIT = 54;
20+
21+
public function __construct(AbstractRequest $request, $data)
22+
{
23+
// Strip out the xmlns junk so that PHP can parse the XML
24+
$xml = preg_replace('/<getSettledBatchListRequest[^>]+>/', '<getSettledBatchListRequest>', (string)$data);
25+
26+
try {
27+
$xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOWARNING);
28+
} catch (\Exception $e) {
29+
throw new InvalidResponseException();
30+
}
31+
32+
if (!$xml) {
33+
throw new InvalidResponseException();
34+
}
35+
36+
parent::__construct($request, $xml);
37+
}
38+
39+
public function isSuccessful()
40+
{
41+
return 1 === $this->getResultCode();
42+
}
43+
44+
public function getData() {
45+
echo "resp";
46+
print_r($this->data);
47+
$result = $this->xml2array($this->data->subscriptionDetails, TRUE);
48+
return $result['subscriptionDetails'][0]['subscriptionDetail'];
49+
}
50+
51+
/**
52+
* http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/
53+
*
54+
* Convert a simpleXMLElement in to an array
55+
*
56+
* @todo this is duplicated from CIMAbstractResponse. Put somewhere shared.
57+
*
58+
* @param \SimpleXMLElement $xml
59+
*
60+
* @return array
61+
*/
62+
public function xml2array(\SimpleXMLElement $xml)
63+
{
64+
$arr = array();
65+
foreach ($xml as $element) {
66+
$tag = $element->getName();
67+
$e = get_object_vars($element);
68+
if (!empty($e)) {
69+
$arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e;
70+
} else {
71+
$arr[$tag] = trim($element);
72+
}
73+
}
74+
75+
return $arr;
76+
}
77+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
use Omnipay\Common\CreditCard;
6+
7+
/**
8+
* Authorize.Net AIM Authorize Request
9+
*/
10+
class QueryDetailRequest extends AIMAbstractRequest
11+
{
12+
protected $action = '';
13+
protected $requestType = 'getSettledBatchListRequest';
14+
protected $limit = 1000;
15+
protected $offset = 1;
16+
17+
/**
18+
* Get Limit.
19+
*
20+
* @return int
21+
*/
22+
public function getLimit() {
23+
return $this->limit;
24+
}
25+
26+
/**
27+
* Set Limit.
28+
*
29+
* @param int $limit
30+
*/
31+
public function setLimit($limit) {
32+
$this->limit = $limit;
33+
}
34+
35+
/**
36+
* Get offset.
37+
*
38+
* @return int
39+
*/
40+
public function getOffset() {
41+
return $this->offset;
42+
}
43+
44+
/**
45+
* Set offset.
46+
*
47+
* @param int $offset
48+
*/
49+
public function setOffset($offset) {
50+
$this->offset = $offset;
51+
}
52+
53+
/**
54+
* Get data to send.
55+
*/
56+
public function getData()
57+
{
58+
$data = $this->getBaseData();
59+
return $data;
60+
}
61+
62+
protected function addTransactionType(\SimpleXMLElement $data) {}
63+
64+
public function sendData($data)
65+
{
66+
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
67+
$data = $data->saveXml();
68+
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();
69+
70+
return $this->response = new QueryResponse($this, $httpResponse->getBody());
71+
}
72+
}

vendor/omnipay/authorizenet/src/Message/QueryRequest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace Omnipay\AuthorizeNet\Message;
44

55
use Omnipay\Common\CreditCard;
6+
use Omnipay\Omnipay;
67

78
/**
89
* Authorize.Net AIM Authorize Request
910
*/
10-
class QueryRequest extends AIMAbstractRequest
11+
class QueryRequest extends QueryBatchRequest
1112
{
1213
protected $action = '';
1314
protected $requestType = 'getSettledBatchListRequest';
@@ -72,6 +73,6 @@ public function sendData($data)
7273
$data = $data->saveXml();
7374
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();
7475

75-
return $this->response = new AIMPaymentPlanQueryResponse($this, $httpResponse->getBody());
76+
return $this->response = new QueryResponse($this, $httpResponse->getBody());
7677
}
7778
}

vendor/omnipay/authorizenet/src/Message/QueryResponse.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Authorize.Net AIM Response
1313
*/
14-
class AIMPaymentPlanQueryResponse extends AbstractResponse
14+
class QueryResponse extends AbstractResponse
1515
{
1616
/**
1717
* For Error codes: @see https://developer.authorize.net/api/reference/responseCodes.html
@@ -41,7 +41,9 @@ public function isSuccessful()
4141
return 1 === $this->getResultCode();
4242
}
4343

44-
public function getPlanData() {
44+
public function getData() {
45+
echo "resp";
46+
print_r($this->data);
4547
$result = $this->xml2array($this->data->subscriptionDetails, TRUE);
4648
return $result['subscriptionDetails'][0]['subscriptionDetail'];
4749
}

0 commit comments

Comments
 (0)