From d10fc69873f6153abe66385e98b2720603d6eb27 Mon Sep 17 00:00:00 2001 From: marcelschoolenberg Date: Wed, 27 Jun 2018 15:21:11 +0200 Subject: [PATCH 1/2] add get refund/info function to api --- src/Api/Refund/Info.php | 65 ++++++++++++++++++++++++++++++++++++ src/Refund.php | 18 ++++++++++ src/Result/Refund/Refund.php | 44 ++++++++++++++++++++++++ src/Result/Result.php | 17 +++++++++- 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 src/Api/Refund/Info.php create mode 100644 src/Result/Refund/Refund.php diff --git a/src/Api/Refund/Info.php b/src/Api/Refund/Info.php new file mode 100644 index 00000000..5286e3cd --- /dev/null +++ b/src/Api/Refund/Info.php @@ -0,0 +1,65 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Paynl\Api\Refund; + +use Paynl\Error; + +/** + * Description of Info + * + * @author Andy Pieters + */ +class Info extends Refund +{ + protected $apiTokenRequired = true; + + /** + * @var string + */ + private $refundId; + /** + * Set the refundId + * + * @param string $refundId + */ + public function setRefundId($refundId){ + $this->refundId = $refundId; + } + + /** + * @inheritdoc + * @throws Error\Required RefundId is required + */ + protected function getData() { + if(empty($this->refundId)){ + throw new Error\Required('RefundId required'); + } + + $this->data['refundId'] = $this->refundId; + + return parent::getData(); + } + + /** + * @inheritdoc + */ + public function doRequest($endpoint = null, $version = null) { + return parent::doRequest('refund/info'); + } +} \ No newline at end of file diff --git a/src/Refund.php b/src/Refund.php index 5b7ba4fd..397c1a99 100644 --- a/src/Refund.php +++ b/src/Refund.php @@ -94,4 +94,22 @@ public static function add(array $options = array()) return new Result\Add($result); } + + /** + * Get the refund + * + * @param string $refundId + * + * @return Result\Refund + */ + public static function get($refundId) + { + $api = new Api\Info(); + $api->setRefundId($refundId); + $result = $api->doRequest(); + + $result['refundId'] = $refundId; + + return new Result\Refund($result); + } } \ No newline at end of file diff --git a/src/Result/Refund/Refund.php b/src/Result/Refund/Refund.php new file mode 100644 index 00000000..1259908f --- /dev/null +++ b/src/Result/Refund/Refund.php @@ -0,0 +1,44 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Paynl\Result\Refund; + +use Paynl\Error\Error; +use Paynl\Result\Result; + +/** + * Description of Transaction + * + * @author Andy Pieters + */ +class Refund extends Result +{ + /** + * @return string The transaction id + */ + public function getId() + { + return $this->data['refundId']; + } + + public function info() + { + return $this->data; + } + +} diff --git a/src/Result/Result.php b/src/Result/Result.php index fc4365e6..b2e4b818 100644 --- a/src/Result/Result.php +++ b/src/Result/Result.php @@ -30,7 +30,22 @@ class Result public function __construct($data) { $this->data = $data; - } + } + + public function isRefunded() + { + return $this->data['refund']['statusName'] == 'Verwerkt'; + } + + public function getRequest() + { + return $this->data['request']; + } + + public function getRefund() + { + return $this->data['refund']; + } /** * Get the complete result as an array From 5efb010355447e51f32ab4966f1937727d7b34ab Mon Sep 17 00:00:00 2001 From: marcelschoolenberg Date: Wed, 27 Jun 2018 16:06:06 +0200 Subject: [PATCH 2/2] getData function already exists and change some text --- src/Result/Refund/Refund.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Result/Refund/Refund.php b/src/Result/Refund/Refund.php index 1259908f..8901ecbb 100644 --- a/src/Result/Refund/Refund.php +++ b/src/Result/Refund/Refund.php @@ -22,23 +22,17 @@ use Paynl\Result\Result; /** - * Description of Transaction + * Description of Refund * * @author Andy Pieters */ class Refund extends Result { /** - * @return string The transaction id + * @return string The Refund id */ public function getId() { return $this->data['refundId']; } - - public function info() - { - return $this->data; - } - }