Skip to content

Commit

Permalink
Add reason parapeter to library
Browse files Browse the repository at this point in the history
  • Loading branch information
enrico.hofmann committed Feb 26, 2016
1 parent 1110880 commit ba85663
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
49 changes: 49 additions & 0 deletions lib/Paymill/Models/Request/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
*/
class Refund extends Base
{

CONST REASON_KEY_REQUESTED_BY_CUSTOMER = 'requested_by_customer';
CONST REASON_KEY_DUPLICATE = 'duplicate';
CONST REASON_KEY_FRAUDULENT = 'fraudulent';

/**
* @var string
*/
Expand All @@ -19,6 +24,11 @@ class Refund extends Base
*/
private $_description;

/**
* @var string
*/
private $_reason;

/**
* Creates an instance of the refund request model
*/
Expand All @@ -29,6 +39,7 @@ function __construct()

/**
* Returns the amount
*
* @return string
*/
public function getAmount()
Expand All @@ -39,6 +50,7 @@ public function getAmount()
/**
* Sets the amount
* @param string $amount
*
* @return \Paymill\Models\Request\Refund
*/
public function setAmount($amount)
Expand All @@ -49,6 +61,7 @@ public function setAmount($amount)

/**
* Returns the description
*
* @return string
*/
public function getDescription()
Expand All @@ -59,6 +72,7 @@ public function getDescription()
/**
* Sets the description
* @param string $description
*
* @return \Paymill\Models\Request\Refund
*/
public function setDescription($description)
Expand All @@ -67,9 +81,41 @@ public function setDescription($description)
return $this;
}

/**
* Returns the reason
* @return string
*/
public function getReason()
{
return $this->_reason;
}

/**
* Sets the reason possible Reasons are
* - Refund::REASON_KEY_REQUESTED_BY_CUSTOMER (requested_by_customer)
* - Refund::REASON_KEY_DUPLICATE (duplicate)
* - Refund::REASON_KEY_FRAUDULENT (fraudulent)
*
* @param string $reason
*
* @return \Paymill\Models\Request\Refund
*/
public function setReason($reason)
{
if (in_array(
$reason,
array(self::REASON_KEY_FRAUDULENT, self::REASON_KEY_REQUESTED_BY_CUSTOMER, self::REASON_KEY_DUPLICATE)
)) {
$this->_reason = $reason;
}

return $this;
}

/**
* Returns an array of parameters customized for the argumented methodname
* @param string $method
*
* @return array
*/
public function parameterize($method)
Expand All @@ -79,6 +125,9 @@ public function parameterize($method)
case 'create':
$parameterArray['amount'] = $this->getAmount();
$parameterArray['description'] = $this->getDescription();
if (!empty($this->_reason)) {
$parameterArray['reason'] = $this->_reason;
}
break;
case 'getOne':
$parameterArray['count'] = 1;
Expand Down
32 changes: 31 additions & 1 deletion lib/Paymill/Models/Response/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function getTransaction()
/**
* Sets the transaction model
* @param \Paymill\Models\Response\Transaction $transaction
*
* @return \Paymill\Models\Response\Refund
*/
public function setTransaction($transaction)
Expand All @@ -53,6 +54,7 @@ public function getAmount()
/**
* Sets the amount
* @param integer $amount
*
* @return \Paymill\Models\Response\Refund
*/
public function setAmount($amount)
Expand All @@ -79,6 +81,7 @@ public function getStatus()
/**
* Sets the Status of the refund
* @param string $status
*
* @return \Paymill\Models\Response\Refund
*/
public function setStatus($status)
Expand All @@ -105,14 +108,41 @@ public function getDescription()
/**
* Sets the description of this refund
* @param string $description
*
* @return \Paymill\Models\Response\Refund
*/
public function setDescription($description)
{
$this->_description = $description;
return $this;
}


/**
* @var string
*/
private $_reason;

/**
* Sets the reason
* @return string
*/
public function getReason()
{
return $this->_reason;
}

/**
* @param string $reason
*
* @return \Paymill\Models\Response\Refund
*/
public function setReason($reason)
{
$this->_reason = $reason;

return $this;
}

/**
* Whether this refund happend in test- or in livemode.
* @var boolean
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Paymill/Models/Request/RefundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function setGetTest()
{
$sample = array(
'amount' => '4200', // e.g. "4200" for 42.00 EUR
'description' => 'Sample Description'
'description' => 'Sample Description',
'reason' => 'requested_by_customer'
);

$this->_refund->setAmount($sample['amount'])
Expand Down

0 comments on commit ba85663

Please sign in to comment.