Skip to content

Commit

Permalink
Merge branch 'ramittal-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmc committed Aug 5, 2014
2 parents bc8a536 + d07d4ed commit 91c96b2
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/AuthorizeNetARB.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class AuthorizeNetARB extends AuthorizeNetRequest
const LIVE_URL = "https://api.authorize.net/xml/v1/request.api";
const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api";


private $_request_type;
private $_request_payload;

Expand Down Expand Up @@ -91,6 +92,20 @@ public function cancelSubscription($subscriptionId)
return $this->_sendRequest();
}

/**
* Create an ARB subscription
*
* @param AuthorizeNet_Subscription $subscription
*
* @return AuthorizeNetARB_Response
*/
public function getSubscriptionList(AuthorizeNet_GetSubscriptionList $subscriptionList)
{
$this->_request_type = "GetSubscriptionListRequest";
$this->_request_payload .= $subscriptionList->getXml();
return $this->_sendRequest();
}

/**
*
*
Expand Down
81 changes: 81 additions & 0 deletions lib/shared/AuthorizeNetTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,84 @@ public function getXml()
}
}

/**
* A class that contains all fields for an AuthorizeNet ARB SubscriptionList.
*
* @package AuthorizeNet
* @subpackage AuthorizeNetARB
*/
class AuthorizeNet_GetSubscriptionList
{
public $searchType;
public $sorting;
public $paging;

public function getXml()
{
$emptyString = "";
$sortingXml = (is_null($this->sorting)) ? $emptyString : $this->sorting->getXml();
$pagingXml = (is_null($this->paging)) ? $emptyString : $this->paging->getXml();

$xml = "
<searchType>{$this->searchType}</searchType>"
.$sortingXml
.$pagingXml
;

$xml_clean = "";
// Remove any blank child elements
foreach (preg_split("/(\r?\n)/", $xml) as $key => $line) {
if (!preg_match('/><\//', $line)) {
$xml_clean .= $line . "\n";
}
}

// Remove any blank parent elements
$element_removed = 1;
// Recursively repeat if a change is made
while ($element_removed) {
$element_removed = 0;
if (preg_match('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', $xml_clean)) {
$xml_clean = preg_replace('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', '', $xml_clean);
$element_removed = 1;
}
}

// Remove any blank lines
// $xml_clean = preg_replace('/\r\n[\s]+\r\n/','',$xml_clean);
return $xml_clean;
}
}

class paging
{
public $limit;
public $offset;

public function getXml()
{
$xml = "<paging>
<limit>{$this->limit}</limit>
<offset>{$this->offset}</offset>
</paging>";

return $xml;
}
}

class sorting
{
public $orderBy;
public $orderDescending;

public function getXml()
{
$xml = "
<sorting>
<orderBy>{$this->orderBy}</orderBy>
<orderDescending>{$this->orderDescending}</orderDescending>
</sorting>";

return $xml;
}
}
28 changes: 28 additions & 0 deletions tests/AuthorizeNetARB_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,32 @@ public function testCreateSubscriptionECheck()

}

public function testGetSubscriptionList()
{
$refId = "ref" . time();

$paging = new paging();
$paging->limit=10;
$paging->offset=1;
$sorting=new sorting();
$sorting->orderBy="firstName";
$sorting->orderDescending="false";

$getSubscriptionList = new AuthorizeNet_GetSubscriptionList;
$getSubscriptionList->searchType = "subscriptionActive";
$getSubscriptionList->paging = $paging;
$getSubscriptionList->sorting = $sorting;

// Create the request and send it.
$request = new AuthorizeNetARB;
$request->setRefId($refId);
$response = $request->getSubscriptionList($getSubscriptionList);

// Handle the response.
$this->assertTrue($response->isOk());
$this->assertEquals($response->getMessageCode(), "I00001");
$this->assertEquals($response->getMessageText(), "Successful.");
$this->assertEquals($response->getRefId(), $refId);
$this->assertEquals($response->getResultCode(), "Ok");
}
}

0 comments on commit 91c96b2

Please sign in to comment.