Skip to content

Commit 91c96b2

Browse files
author
brianmc
committed
Merge branch 'ramittal-master'
2 parents bc8a536 + d07d4ed commit 91c96b2

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

lib/AuthorizeNetARB.php

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class AuthorizeNetARB extends AuthorizeNetRequest
2020
const LIVE_URL = "https://api.authorize.net/xml/v1/request.api";
2121
const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api";
2222

23+
2324
private $_request_type;
2425
private $_request_payload;
2526

@@ -91,6 +92,20 @@ public function cancelSubscription($subscriptionId)
9192
return $this->_sendRequest();
9293
}
9394

95+
/**
96+
* Create an ARB subscription
97+
*
98+
* @param AuthorizeNet_Subscription $subscription
99+
*
100+
* @return AuthorizeNetARB_Response
101+
*/
102+
public function getSubscriptionList(AuthorizeNet_GetSubscriptionList $subscriptionList)
103+
{
104+
$this->_request_type = "GetSubscriptionListRequest";
105+
$this->_request_payload .= $subscriptionList->getXml();
106+
return $this->_sendRequest();
107+
}
108+
94109
/**
95110
*
96111
*

lib/shared/AuthorizeNetTypes.php

+81
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,84 @@ public function getXml()
321321
}
322322
}
323323

324+
/**
325+
* A class that contains all fields for an AuthorizeNet ARB SubscriptionList.
326+
*
327+
* @package AuthorizeNet
328+
* @subpackage AuthorizeNetARB
329+
*/
330+
class AuthorizeNet_GetSubscriptionList
331+
{
332+
public $searchType;
333+
public $sorting;
334+
public $paging;
335+
336+
public function getXml()
337+
{
338+
$emptyString = "";
339+
$sortingXml = (is_null($this->sorting)) ? $emptyString : $this->sorting->getXml();
340+
$pagingXml = (is_null($this->paging)) ? $emptyString : $this->paging->getXml();
341+
342+
$xml = "
343+
<searchType>{$this->searchType}</searchType>"
344+
.$sortingXml
345+
.$pagingXml
346+
;
347+
348+
$xml_clean = "";
349+
// Remove any blank child elements
350+
foreach (preg_split("/(\r?\n)/", $xml) as $key => $line) {
351+
if (!preg_match('/><\//', $line)) {
352+
$xml_clean .= $line . "\n";
353+
}
354+
}
355+
356+
// Remove any blank parent elements
357+
$element_removed = 1;
358+
// Recursively repeat if a change is made
359+
while ($element_removed) {
360+
$element_removed = 0;
361+
if (preg_match('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', $xml_clean)) {
362+
$xml_clean = preg_replace('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', '', $xml_clean);
363+
$element_removed = 1;
364+
}
365+
}
366+
367+
// Remove any blank lines
368+
// $xml_clean = preg_replace('/\r\n[\s]+\r\n/','',$xml_clean);
369+
return $xml_clean;
370+
}
371+
}
372+
373+
class paging
374+
{
375+
public $limit;
376+
public $offset;
377+
378+
public function getXml()
379+
{
380+
$xml = "<paging>
381+
<limit>{$this->limit}</limit>
382+
<offset>{$this->offset}</offset>
383+
</paging>";
384+
385+
return $xml;
386+
}
387+
}
388+
389+
class sorting
390+
{
391+
public $orderBy;
392+
public $orderDescending;
393+
394+
public function getXml()
395+
{
396+
$xml = "
397+
<sorting>
398+
<orderBy>{$this->orderBy}</orderBy>
399+
<orderDescending>{$this->orderDescending}</orderDescending>
400+
</sorting>";
401+
402+
return $xml;
403+
}
404+
}

tests/AuthorizeNetARB_Test.php

+28
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,32 @@ public function testCreateSubscriptionECheck()
196196

197197
}
198198

199+
public function testGetSubscriptionList()
200+
{
201+
$refId = "ref" . time();
202+
203+
$paging = new paging();
204+
$paging->limit=10;
205+
$paging->offset=1;
206+
$sorting=new sorting();
207+
$sorting->orderBy="firstName";
208+
$sorting->orderDescending="false";
209+
210+
$getSubscriptionList = new AuthorizeNet_GetSubscriptionList;
211+
$getSubscriptionList->searchType = "subscriptionActive";
212+
$getSubscriptionList->paging = $paging;
213+
$getSubscriptionList->sorting = $sorting;
214+
215+
// Create the request and send it.
216+
$request = new AuthorizeNetARB;
217+
$request->setRefId($refId);
218+
$response = $request->getSubscriptionList($getSubscriptionList);
219+
220+
// Handle the response.
221+
$this->assertTrue($response->isOk());
222+
$this->assertEquals($response->getMessageCode(), "I00001");
223+
$this->assertEquals($response->getMessageText(), "Successful.");
224+
$this->assertEquals($response->getRefId(), $refId);
225+
$this->assertEquals($response->getResultCode(), "Ok");
226+
}
199227
}

0 commit comments

Comments
 (0)