Skip to content

Commit

Permalink
Merge pull request #48 from marcelschoolenberg/add_refund-info
Browse files Browse the repository at this point in the history
add get refund/info function to api
  • Loading branch information
Andy Pieters authored Jun 27, 2018
2 parents d837f4c + 5efb010 commit 20276d7
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 1 deletion.
65 changes: 65 additions & 0 deletions src/Api/Refund/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/*
* Copyright (C) 2015 Andy Pieters <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/

namespace Paynl\Api\Refund;

use Paynl\Error;

/**
* Description of Info
*
* @author Andy Pieters <[email protected]>
*/
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');
}
}
18 changes: 18 additions & 0 deletions src/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
38 changes: 38 additions & 0 deletions src/Result/Refund/Refund.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/*
* Copyright (C) 2015 Andy Pieters <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/

namespace Paynl\Result\Refund;

use Paynl\Error\Error;
use Paynl\Result\Result;

/**
* Description of Refund
*
* @author Andy Pieters <[email protected]>
*/
class Refund extends Result
{
/**
* @return string The Refund id
*/
public function getId()
{
return $this->data['refundId'];
}
}
17 changes: 16 additions & 1 deletion src/Result/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20276d7

Please sign in to comment.