From aeecfeae2642208ab3ead98a85fd8eb8411f590a Mon Sep 17 00:00:00 2001 From: Jurian Sluiman Date: Sun, 11 Aug 2013 14:28:53 +0200 Subject: [PATCH] Return DirectoryResponse from directory request call --- src/SlmIdealPayment/Client/StandardClient.php | 20 ++++--- .../{IssuerCollection.php => Country.php} | 53 +++++++++++++++++-- src/SlmIdealPayment/Model/Issuer.php | 24 --------- .../Response/DirectoryResponse.php | 23 +++++--- 4 files changed, 78 insertions(+), 42 deletions(-) rename src/SlmIdealPayment/Model/{IssuerCollection.php => Country.php} (70%) diff --git a/src/SlmIdealPayment/Client/StandardClient.php b/src/SlmIdealPayment/Client/StandardClient.php index aa2badc..b204aae 100644 --- a/src/SlmIdealPayment/Client/StandardClient.php +++ b/src/SlmIdealPayment/Client/StandardClient.php @@ -126,22 +126,28 @@ public function sendDirectoryRequest(Request\DirectoryRequest $request) $countries = array(); foreach ($response->getElementsByTagName('Country') as $child) { - $country = $child->getElementsByTagName('countryNames')->item(0)->textContent; + $name = $child->getElementsByTagName('countryNames')->item(0)->textContent; - $list = array(); + $issuers = array(); foreach ($child->getElementsByTagName('Issuer') as $issuer) { $issuerModel = new Model\Issuer(); $issuerModel->setId($this->getTag($issuer, 'issuerID')); $issuerModel->setName($this->getTag($issuer, 'issuerName')); - $list[] = $issuerModel; + $issuers[] = $issuerModel; } - $countries[$country] = $list; + $country = new Model\Country; + $country->setName($name); + $country->setIssuers($issuers); + + $countries[] = $country; } - // @todo create a DirectoryResponse and insert all issuers there - return $countries; + $response = new Response\DirectoryResponse; + $response->setCountries($countries); + + return $response; } /** @@ -184,7 +190,7 @@ public function sendStatusRequest(Request\StatusRequest $request) $transaction = new Model\Transaction(); $transaction->setTransactionId($this->getTag($response, 'transactionID')); $transaction->setStatus($this->getTag($response, 'status')); - // statusDateTimestamp + // @todo add statusDateTimestamp $consumer = new Model\Consumer(); $consumer->setName($this->getTag($response, 'consumerName')); diff --git a/src/SlmIdealPayment/Model/IssuerCollection.php b/src/SlmIdealPayment/Model/Country.php similarity index 70% rename from src/SlmIdealPayment/Model/IssuerCollection.php rename to src/SlmIdealPayment/Model/Country.php index 3e2fd8a..8a2f12e 100644 --- a/src/SlmIdealPayment/Model/IssuerCollection.php +++ b/src/SlmIdealPayment/Model/Country.php @@ -32,8 +32,6 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * @package SlmIdealPayment - * @subpackage Model * @author Jurian Sluiman * @copyright 2012 Jurian Sluiman. * @license http://www.opensource.org/licenses/bsd-license.php BSD License @@ -42,8 +40,53 @@ namespace SlmIdealPayment\Model; -use ArrayObject; - -class IssuerCollection extends ArrayObject +class Country { + protected $name; + protected $issuers; + + /** + * Getter for name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Setter for name + * + * @param string $name Value to set + * @return self + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * Getter for issuers + * + * @return Issuer[] + */ + public function getIssuers() + { + return $this->issuers; + } + + /** + * Setter for issuers + * + * @param array $issuers Value to set + * @return self + */ + public function setIssuers(array $issuers) + { + $this->issuers = $issuers; + return $this; + } + } \ No newline at end of file diff --git a/src/SlmIdealPayment/Model/Issuer.php b/src/SlmIdealPayment/Model/Issuer.php index b85cfee..203c645 100644 --- a/src/SlmIdealPayment/Model/Issuer.php +++ b/src/SlmIdealPayment/Model/Issuer.php @@ -42,16 +42,10 @@ namespace SlmIdealPayment\Model; -use SlmIdealPayment\Exception; - class Issuer { - const TYPE_SHORT = 'Short'; - const TYPE_LONG = 'Long'; - protected $id; protected $name; - protected $type; public function getId() { @@ -74,22 +68,4 @@ public function setName($name) $this->name = $name; return $this; } - - public function getType() - { - return $this->type; - } - - public function setType($type) - { - if (!in_array($type, array(self::TYPE_SHORT, self::TYPE_LONG))) { - throw new Exception\InvalidArgumentException( - 'Type must be "%s" or "%s", "%s" given', - self::TYPE_SHORT, self::TYPE_LONG, $type - ); - } - - $this->type = $type; - return $this; - } } \ No newline at end of file diff --git a/src/SlmIdealPayment/Response/DirectoryResponse.php b/src/SlmIdealPayment/Response/DirectoryResponse.php index 64219b2..01668e7 100644 --- a/src/SlmIdealPayment/Response/DirectoryResponse.php +++ b/src/SlmIdealPayment/Response/DirectoryResponse.php @@ -42,20 +42,31 @@ namespace SlmIdealPayment\Response; -use SlmIdealPayment\Model\IssuerCollection; +use SlmIdealPayment\Model\Country; class DirectoryResponse extends AbstractResponse { - protected $issuers; + protected $countries; - public function getIssuers() + /** + * Getter for countries + * + * @return Country[] + */ + public function getCountries() { - return $this->issuers; + return $this->countries; } - public function setIssuers(IssuerCollection $issuers) + /** + * Setter for countries + * + * @param array $countries List of countries + * @return self + */ + public function setCountries(array $countries) { - $this->issuers = $issuers; + $this->countries = $countries; return $this; } } \ No newline at end of file